Mercurial > dotfiles
annotate .elisp/textmate.el @ 109:8e04d9d41a55
reindent-then-newline-and-indent is the best discovery of the week.
author | Augie Fackler <durin42@gmail.com> |
---|---|
date | Wed, 17 Jun 2009 15:47:51 -0500 |
parents | 26450200777a |
children | fe9d358b9fe8 |
rev | line source |
---|---|
22 | 1 ;; textmate.el --- TextMate minor mode for Emacs |
2 | |
3 ;; Copyright (C) 2008 Chris Wanstrath <chris@ozmm.org> | |
4 | |
5 ;; Licensed under the same terms as Emacs. | |
6 | |
7 ;; Version: 0.1.0 | |
8 ;; Keywords: textmate osx mac | |
9 ;; Created: 22 Nov 2008 | |
10 ;; Author: Chris Wanstrath <chris@ozmm.org> | |
11 | |
12 ;; This file is NOT part of GNU Emacs. | |
13 | |
14 ;; Licensed under the same terms as Emacs. | |
15 | |
16 ;;; Commentary: | |
17 | |
18 ;; This minor mode exists to mimick TextMate's awesome | |
19 ;; features. | |
20 | |
21 ;; ⌘T - Go to File | |
22 ;; ⇧⌘T - Go to Symbol | |
23 ;; ⌘L - Go to Line | |
24 ;; ⌘/ - Comment Line (or Selection/Region) | |
25 ;; ⌘] - Shift Right (currently indents region) | |
26 ;; ⌘[ - Shift Left (not yet implemented) | |
27 ;; ⌥⌘] - Align Assignments | |
28 ;; ⌥⌘[ - Indent Line | |
29 ;; ⌘RET - Insert Newline at Line's End | |
29
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
30 ;; ⌥⌘T - Reset File Cache (for Go to File, cache unused if using git/hg root) |
22 | 31 |
32 ;; A "project" in textmate-mode is determined by the presence of | |
33 ;; a .git directory. If no .git directory is found in your current | |
34 ;; directory, textmate-mode will traverse upwards until one (or none) | |
35 ;; is found. The directory housing the .git directory is presumed | |
36 ;; to be the project's root. | |
37 | |
38 ;; In other words, calling Go to File from | |
39 ;; ~/Projects/fieldrunners/app/views/towers/show.html.erb will use | |
40 ;; ~/Projects/fieldrunners/ as the root if ~/Projects/fieldrunners/.git | |
41 ;; exists. | |
42 | |
43 ;;; Installation | |
44 | |
45 ;; $ cd ~/.emacs.d/vendor | |
46 ;; $ git clone git://github.com/defunkt/textmate.el.git | |
47 ;; | |
48 ;; In your emacs config: | |
49 ;; | |
50 ;; (add-to-list 'load-path "~/.emacs.d/vendor/textmate.el") | |
51 ;; (require 'textmate) | |
52 ;; (textmate-mode) | |
53 | |
54 ;;; Depends on imenu | |
55 (require 'imenu) | |
56 | |
57 ;;; Minor mode | |
58 | |
59 (defvar textmate-use-file-cache t | |
60 "* Should `textmate-goto-file' keep a local cache of files?") | |
61 | |
62 (defvar textmate-completing-library 'ido | |
63 "The library `textmade-goto-symbol' and `textmate-goto-file' should use for completing filenames and symbols (`ido' by default)") | |
64 | |
65 (defvar *textmate-completing-function-alist* '((ido ido-completing-read) | |
66 (icicles icicle-completing-read) | |
67 (none completing-read)) | |
68 "The function to call to read file names and symbols from the user") | |
69 | |
70 (defvar *textmate-completing-minor-mode-alist* | |
71 `((ido ,(lambda (a) (progn (ido-mode a) (setq ido-enable-flex-matching t)))) | |
72 (icicles ,(lambda (a) (icy-mode a))) | |
73 (none ,(lambda (a) ()))) | |
74 "The list of functions to enable and disable completing minor modes") | |
75 | |
76 (defvar *textmate-mode-map* (make-sparse-keymap)) | |
77 (defvar *textmate-project-root* nil) | |
78 (defvar *textmate-project-files* '()) | |
79 (defvar *textmate-gf-exclude* | |
80 "/\\.|vendor|fixtures|tmp|log|build|\\.xcodeproj|\\.nib|\\.framework|\\.app|\\.pbproj|\\.pbxproj|\\.xcode|\\.xcodeproj|\\.bundle") | |
81 | |
82 (defvar *textmate-keybindings-list* `((textmate-next-line | |
83 [A-return] [M-return]) | |
84 (textmate-clear-cache | |
85 ,(kbd "A-M-t") [(control c)(control t)]) | |
86 (align | |
87 ,(kbd "A-M-]") [(control c)(control a)]) | |
88 (indent-according-to-mode | |
89 ,(kbd "A-M-[") nil) | |
90 (indent-region | |
91 ,(kbd "A-]") [(control tab)]) | |
92 (comment-or-uncomment-region-or-line | |
93 ,(kbd "A-/") [(control c)(control k)]) | |
94 (textmate-goto-file | |
95 ,(kbd "A-t") [(meta t)]) | |
96 (textmate-goto-symbol | |
24
d6fd2964258c
New version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
22
diff
changeset
|
97 ,(kbd "A-T") [(meta T)]) |
49
60dbe5b005cc
Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents:
30
diff
changeset
|
98 (textmate-toggle-camel-case |
60dbe5b005cc
Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents:
30
diff
changeset
|
99 ,(kbd "C-_") [(control _)]))) |
22 | 100 |
101 (defvar *textmate-project-root-p* | |
102 #'(lambda (coll) (or (member ".git" coll) | |
103 (member ".hg" coll) | |
104 )) | |
105 "*Lambda that, given a collection of directory entries, returns | |
106 non-nil if it represents the project root.") | |
107 | |
28
260deb14fbc8
Add textmate-find-in-project.
Augie Fackler <durin42@gmail.com>
parents:
25
diff
changeset
|
108 (defvar *textmate-find-in-project-default* nil) |
260deb14fbc8
Add textmate-find-in-project.
Augie Fackler <durin42@gmail.com>
parents:
25
diff
changeset
|
109 (defvar *textmate-find-in-project-type-default* nil) |
260deb14fbc8
Add textmate-find-in-project.
Augie Fackler <durin42@gmail.com>
parents:
25
diff
changeset
|
110 |
22 | 111 ;;; Bindings |
112 | |
113 (defun textmate-ido-fix () | |
114 "Add up/down keybindings for ido." | |
115 (define-key ido-completion-map [up] 'ido-prev-match) | |
116 (define-key ido-completion-map [down] 'ido-next-match)) | |
117 | |
118 (defun textmate-bind-keys () | |
119 (add-hook 'ido-setup-hook 'textmate-ido-fix) | |
120 | |
121 ; weakness until i figure out how to do this right | |
122 (when (boundp 'osx-key-mode-map) | |
123 (define-key osx-key-mode-map (kbd "A-t") 'textmate-goto-file) | |
124 (define-key osx-key-mode-map (kbd "A-T") 'textmate-goto-symbol)) | |
125 | |
126 (let ((member) (i 0) (access (if (boundp 'aquamacs-version) 'cadr 'caddr))) | |
127 (setq member (nth i *textmate-keybindings-list*)) | |
128 (while member | |
129 (if (funcall access member) | |
130 (define-key *textmate-mode-map* (funcall access member) (car member))) | |
131 (setq member (nth i *textmate-keybindings-list*)) | |
132 (setq i (+ i 1))))) | |
133 | |
134 (defun textmate-completing-read (&rest args) | |
135 (let ((reading-fn (cadr (assoc textmate-completing-library *textmate-completing-function-alist*)))) | |
136 (apply (symbol-function reading-fn) args))) | |
137 | |
138 ;;; Commands | |
139 | |
140 (defun textmate-next-line () | |
141 (interactive) | |
142 (end-of-line) | |
143 (newline-and-indent)) | |
144 | |
145 ;; http://chopmo.blogspot.com/2008/09/quickly-jumping-to-symbols.html | |
146 (defun textmate-goto-symbol () | |
147 "Will update the imenu index and then use ido to select a symbol to navigate to" | |
148 (interactive) | |
149 (imenu--make-index-alist) | |
150 (let ((name-and-pos '()) | |
151 (symbol-names '())) | |
152 (flet ((addsymbols (symbol-list) | |
153 (when (listp symbol-list) | |
154 (dolist (symbol symbol-list) | |
155 (let ((name nil) (position nil)) | |
156 (cond | |
157 ((and (listp symbol) (imenu--subalist-p symbol)) | |
158 (addsymbols symbol)) | |
159 | |
160 ((listp symbol) | |
161 (setq name (car symbol)) | |
162 (setq position (cdr symbol))) | |
163 | |
164 ((stringp symbol) | |
165 (setq name symbol) | |
166 (setq position (get-text-property 1 'org-imenu-marker symbol)))) | |
167 | |
168 (unless (or (null position) (null name)) | |
169 (add-to-list 'symbol-names name) | |
170 (add-to-list 'name-and-pos (cons name position)))))))) | |
171 (addsymbols imenu--index-alist)) | |
172 (let* ((selected-symbol (textmate-completing-read "Symbol: " symbol-names)) | |
173 (position (cdr (assoc selected-symbol name-and-pos)))) | |
174 (goto-char position)))) | |
175 | |
176 (defun textmate-goto-file () | |
177 (interactive) | |
178 (let ((root (textmate-project-root))) | |
179 (when (null root) | |
180 (error "Can't find any .git directory")) | |
181 (find-file | |
182 (concat | |
183 (expand-file-name root) "/" | |
184 (textmate-completing-read | |
185 "Find file: " | |
29
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
186 (textmate-project-files root)))))) |
22 | 187 |
28
260deb14fbc8
Add textmate-find-in-project.
Augie Fackler <durin42@gmail.com>
parents:
25
diff
changeset
|
188 (defun textmate-find-in-project-type () |
260deb14fbc8
Add textmate-find-in-project.
Augie Fackler <durin42@gmail.com>
parents:
25
diff
changeset
|
189 (interactive) |
260deb14fbc8
Add textmate-find-in-project.
Augie Fackler <durin42@gmail.com>
parents:
25
diff
changeset
|
190 (let ((pat (read-string (concat "Suffix" |
260deb14fbc8
Add textmate-find-in-project.
Augie Fackler <durin42@gmail.com>
parents:
25
diff
changeset
|
191 (if *textmate-find-in-project-type-default* |
260deb14fbc8
Add textmate-find-in-project.
Augie Fackler <durin42@gmail.com>
parents:
25
diff
changeset
|
192 (format " [\"%s\"]" *textmate-find-in-project-type-default*) |
260deb14fbc8
Add textmate-find-in-project.
Augie Fackler <durin42@gmail.com>
parents:
25
diff
changeset
|
193 "") |
260deb14fbc8
Add textmate-find-in-project.
Augie Fackler <durin42@gmail.com>
parents:
25
diff
changeset
|
194 ": " |
260deb14fbc8
Add textmate-find-in-project.
Augie Fackler <durin42@gmail.com>
parents:
25
diff
changeset
|
195 ) nil nil *textmate-find-in-project-type-default*))) |
260deb14fbc8
Add textmate-find-in-project.
Augie Fackler <durin42@gmail.com>
parents:
25
diff
changeset
|
196 (setq *textmate-find-in-project-type-default* pat) |
260deb14fbc8
Add textmate-find-in-project.
Augie Fackler <durin42@gmail.com>
parents:
25
diff
changeset
|
197 (textmate-find-in-project (concat "*." pat)))) |
260deb14fbc8
Add textmate-find-in-project.
Augie Fackler <durin42@gmail.com>
parents:
25
diff
changeset
|
198 |
260deb14fbc8
Add textmate-find-in-project.
Augie Fackler <durin42@gmail.com>
parents:
25
diff
changeset
|
199 (defun textmate-find-in-project (&optional pattern) |
260deb14fbc8
Add textmate-find-in-project.
Augie Fackler <durin42@gmail.com>
parents:
25
diff
changeset
|
200 (interactive) |
260deb14fbc8
Add textmate-find-in-project.
Augie Fackler <durin42@gmail.com>
parents:
25
diff
changeset
|
201 (let ((root (textmate-project-root)) |
260deb14fbc8
Add textmate-find-in-project.
Augie Fackler <durin42@gmail.com>
parents:
25
diff
changeset
|
202 (default *textmate-find-in-project-default*) |
260deb14fbc8
Add textmate-find-in-project.
Augie Fackler <durin42@gmail.com>
parents:
25
diff
changeset
|
203 ) |
260deb14fbc8
Add textmate-find-in-project.
Augie Fackler <durin42@gmail.com>
parents:
25
diff
changeset
|
204 (when (null root) |
260deb14fbc8
Add textmate-find-in-project.
Augie Fackler <durin42@gmail.com>
parents:
25
diff
changeset
|
205 (error "Not in a project area.")) |
260deb14fbc8
Add textmate-find-in-project.
Augie Fackler <durin42@gmail.com>
parents:
25
diff
changeset
|
206 (let ((re (read-string (concat "Search for " |
260deb14fbc8
Add textmate-find-in-project.
Augie Fackler <durin42@gmail.com>
parents:
25
diff
changeset
|
207 (if (and default (> (length default) 0)) |
260deb14fbc8
Add textmate-find-in-project.
Augie Fackler <durin42@gmail.com>
parents:
25
diff
changeset
|
208 (format "[\"%s\"]" default)) ": ") |
260deb14fbc8
Add textmate-find-in-project.
Augie Fackler <durin42@gmail.com>
parents:
25
diff
changeset
|
209 nil 'textmate-find-in-project-history default) |
260deb14fbc8
Add textmate-find-in-project.
Augie Fackler <durin42@gmail.com>
parents:
25
diff
changeset
|
210 ) |
260deb14fbc8
Add textmate-find-in-project.
Augie Fackler <durin42@gmail.com>
parents:
25
diff
changeset
|
211 (incpat (if pattern pattern "*"))) |
260deb14fbc8
Add textmate-find-in-project.
Augie Fackler <durin42@gmail.com>
parents:
25
diff
changeset
|
212 (append textmate-find-in-project-history (list re)) |
260deb14fbc8
Add textmate-find-in-project.
Augie Fackler <durin42@gmail.com>
parents:
25
diff
changeset
|
213 (setq *textmate-find-in-project-default* re) |
29
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
214 (let ((type (textmate-project-root-type root))) |
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
215 (let ((command |
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
216 (cond ((not (string= type "unknown")) |
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
217 (concat "cd " |
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
218 root |
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
219 " ; " |
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
220 (cond ((string= type "git") "git ls-files") |
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
221 ((string= type "hg") "hg manifest")) |
30
43e751bdedeb
Latest textmate.el - fixed a bug in find in type.
Augie Fackler <durin42@gmail.com>
parents:
29
diff
changeset
|
222 " | xargs grep -nR " |
43e751bdedeb
Latest textmate.el - fixed a bug in find in type.
Augie Fackler <durin42@gmail.com>
parents:
29
diff
changeset
|
223 (if pattern (concat " --include='" pattern "' ") "") |
99 | 224 " -- " |
49
60dbe5b005cc
Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents:
30
diff
changeset
|
225 (shell-quote-argument re))) |
29
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
226 (t (concat "cd " root "; egrep -nR --exclude='" |
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
227 *textmate-gf-exclude* |
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
228 "' --include='" |
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
229 incpat |
99 | 230 "' -- " |
49
60dbe5b005cc
Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents:
30
diff
changeset
|
231 (shell-quote-argument re) |
60dbe5b005cc
Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents:
30
diff
changeset
|
232 " . | grep -vE '" |
29
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
233 *textmate-gf-exclude* |
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
234 "' | sed s:./::" |
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
235 ))))) |
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
236 (compilation-start command 'grep-mode))) |
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
237 ))) |
28
260deb14fbc8
Add textmate-find-in-project.
Augie Fackler <durin42@gmail.com>
parents:
25
diff
changeset
|
238 |
22 | 239 (defun textmate-clear-cache () |
240 (interactive) | |
241 (setq *textmate-project-root* nil) | |
242 (setq *textmate-project-files* nil) | |
243 (message "textmate-mode cache cleared.")) | |
244 | |
24
d6fd2964258c
New version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
22
diff
changeset
|
245 (defun textmate-toggle-camel-case () |
d6fd2964258c
New version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
22
diff
changeset
|
246 "Toggle current sexp between camelCase and snake_case, like TextMate C-_." |
d6fd2964258c
New version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
22
diff
changeset
|
247 (interactive) |
d6fd2964258c
New version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
22
diff
changeset
|
248 (if (thing-at-point 'word) |
d6fd2964258c
New version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
22
diff
changeset
|
249 (progn |
49
60dbe5b005cc
Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents:
30
diff
changeset
|
250 (unless (looking-at "\\<") (backward-sexp)) |
60dbe5b005cc
Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents:
30
diff
changeset
|
251 (let ((case-fold-search nil) |
60dbe5b005cc
Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents:
30
diff
changeset
|
252 (start (point)) |
60dbe5b005cc
Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents:
30
diff
changeset
|
253 (end (save-excursion (forward-sexp) (point)))) |
60dbe5b005cc
Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents:
30
diff
changeset
|
254 (if (and (looking-at "[a-z0-9_]+") (= end (match-end 0))) ; snake-case |
60dbe5b005cc
Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents:
30
diff
changeset
|
255 (progn |
60dbe5b005cc
Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents:
30
diff
changeset
|
256 (goto-char start) |
60dbe5b005cc
Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents:
30
diff
changeset
|
257 (while (re-search-forward "_[a-z]" end t) |
60dbe5b005cc
Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents:
30
diff
changeset
|
258 (goto-char (1- (point))) |
60dbe5b005cc
Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents:
30
diff
changeset
|
259 (delete-char -1) |
60dbe5b005cc
Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents:
30
diff
changeset
|
260 (upcase-region (point) (1+ (point))) |
60dbe5b005cc
Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents:
30
diff
changeset
|
261 (setq end (1- end)))) |
60dbe5b005cc
Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents:
30
diff
changeset
|
262 (downcase-region (point) (1+ (point))) |
60dbe5b005cc
Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents:
30
diff
changeset
|
263 (while (re-search-forward "[A-Z][a-z]" end t) |
60dbe5b005cc
Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents:
30
diff
changeset
|
264 (forward-char -2) |
60dbe5b005cc
Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents:
30
diff
changeset
|
265 (insert "_") |
60dbe5b005cc
Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents:
30
diff
changeset
|
266 (downcase-region (point) (1+ (point))) |
60dbe5b005cc
Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents:
30
diff
changeset
|
267 (forward-char 1) |
60dbe5b005cc
Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents:
30
diff
changeset
|
268 (setq end (1+ end))) |
60dbe5b005cc
Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents:
30
diff
changeset
|
269 (downcase-region start end) |
60dbe5b005cc
Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents:
30
diff
changeset
|
270 ))))) |
24
d6fd2964258c
New version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
22
diff
changeset
|
271 |
22 | 272 ;;; Utilities |
273 | |
274 (defun textmate-also-ignore (pattern) | |
275 "Also ignore PATTERN in project files." | |
276 (setq *textmate-gf-exclude* | |
277 (concat *textmate-gf-exclude* "|" pattern))) | |
278 | |
29
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
279 (defun textmate-project-root-type (root) |
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
280 (cond ((member ".git" (directory-files root)) "git") |
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
281 ((member ".hg" (directory-files root)) "hg") |
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
282 (t "unknown") |
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
283 )) |
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
284 |
22 | 285 (defun textmate-project-files (root) |
29
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
286 (let ((type (textmate-project-root-type root))) |
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
287 (cond ((string= type "git") (split-string |
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
288 (shell-command-to-string |
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
289 (concat "cd " root " && git ls-files")) "\n" t)) |
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
290 ((string= type "hg") (split-string |
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
291 (shell-command-to-string |
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
292 (concat "cd " root " && hg manifest")) "\n" t)) |
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
293 ((string= type "unknown") (textmate-cached-project-files-find root)) |
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
294 ))) |
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
295 |
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
296 (defun textmate-project-files-find (root) |
22 | 297 (split-string |
298 (shell-command-to-string | |
299 (concat | |
300 "find " | |
301 root | |
302 " -type f | grep -vE '" | |
303 *textmate-gf-exclude* | |
304 "' | sed 's:" | |
305 *textmate-project-root* | |
306 "/::'")) "\n" t)) | |
307 | |
29
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
308 (defun textmate-cached-project-files-find (&optional root) |
22 | 309 (cond |
310 ((null textmate-use-file-cache) (textmate-project-files root)) | |
311 ((equal (textmate-project-root) (car *textmate-project-files*)) | |
312 (cdr *textmate-project-files*)) | |
313 (t (cdr (setq *textmate-project-files* | |
314 `(,root . ,(textmate-project-files root))))))) | |
315 | |
316 (defun textmate-project-root () | |
317 (when (or | |
318 (null *textmate-project-root*) | |
319 (not (string-match *textmate-project-root* default-directory))) | |
320 (let ((root (textmate-find-project-root))) | |
321 (if root | |
322 (setq *textmate-project-root* (expand-file-name (concat root "/"))) | |
323 (setq *textmate-project-root* nil)))) | |
324 *textmate-project-root*) | |
325 | |
326 (defun textmate-find-project-root (&optional root) | |
327 (when (null root) (setq root default-directory)) | |
328 (cond | |
329 ((funcall *textmate-project-root-p* (directory-files root)) | |
330 (expand-file-name root)) | |
331 ((equal (expand-file-name root) "/") nil) | |
332 (t (textmate-find-project-root (concat (file-name-as-directory root) ".."))))) | |
333 | |
334 ;;;###autoload | |
335 (define-minor-mode textmate-mode "TextMate Emulation Minor Mode" | |
336 :lighter " mate" :global t :keymap *textmate-mode-map* | |
337 (textmate-bind-keys) | |
338 ; activate preferred completion library | |
339 (dolist (mode *textmate-completing-minor-mode-alist*) | |
340 (if (eq (car mode) textmate-completing-library) | |
341 (funcall (cadr mode) t) | |
342 (when (fboundp | |
343 (cadr (assoc (car mode) *textmate-completing-function-alist*))) | |
344 (funcall (cadr mode) -1))))) | |
345 | |
346 (provide 'textmate) | |
347 ;;; textmate.el ends here |