Mercurial > dotfiles
annotate .elisp/textmate.el @ 87:b958738c16f3
Fix an oops in the .hgrc.
| author | Augie Fackler <durin42@gmail.com> |
|---|---|
| date | Thu, 16 Apr 2009 14:56:15 -0500 |
| parents | 60dbe5b005cc |
| children | 26450200777a |
| 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 "' ") "") |
|
49
60dbe5b005cc
Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents:
30
diff
changeset
|
224 (shell-quote-argument re))) |
|
29
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
225 (t (concat "cd " root "; egrep -nR --exclude='" |
|
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
226 *textmate-gf-exclude* |
|
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
227 "' --include='" |
|
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
228 incpat |
|
49
60dbe5b005cc
Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents:
30
diff
changeset
|
229 "' " |
|
60dbe5b005cc
Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents:
30
diff
changeset
|
230 (shell-quote-argument re) |
|
60dbe5b005cc
Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents:
30
diff
changeset
|
231 " . | grep -vE '" |
|
29
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
232 *textmate-gf-exclude* |
|
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
233 "' | sed s:./::" |
|
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
234 ))))) |
|
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
235 (compilation-start command 'grep-mode))) |
|
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
236 ))) |
|
28
260deb14fbc8
Add textmate-find-in-project.
Augie Fackler <durin42@gmail.com>
parents:
25
diff
changeset
|
237 |
| 22 | 238 (defun textmate-clear-cache () |
| 239 (interactive) | |
| 240 (setq *textmate-project-root* nil) | |
| 241 (setq *textmate-project-files* nil) | |
| 242 (message "textmate-mode cache cleared.")) | |
| 243 | |
|
24
d6fd2964258c
New version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
22
diff
changeset
|
244 (defun textmate-toggle-camel-case () |
|
d6fd2964258c
New version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
22
diff
changeset
|
245 "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
|
246 (interactive) |
|
d6fd2964258c
New version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
22
diff
changeset
|
247 (if (thing-at-point 'word) |
|
d6fd2964258c
New version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
22
diff
changeset
|
248 (progn |
|
49
60dbe5b005cc
Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents:
30
diff
changeset
|
249 (unless (looking-at "\\<") (backward-sexp)) |
|
60dbe5b005cc
Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents:
30
diff
changeset
|
250 (let ((case-fold-search nil) |
|
60dbe5b005cc
Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents:
30
diff
changeset
|
251 (start (point)) |
|
60dbe5b005cc
Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents:
30
diff
changeset
|
252 (end (save-excursion (forward-sexp) (point)))) |
|
60dbe5b005cc
Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents:
30
diff
changeset
|
253 (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
|
254 (progn |
|
60dbe5b005cc
Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents:
30
diff
changeset
|
255 (goto-char start) |
|
60dbe5b005cc
Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents:
30
diff
changeset
|
256 (while (re-search-forward "_[a-z]" end t) |
|
60dbe5b005cc
Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents:
30
diff
changeset
|
257 (goto-char (1- (point))) |
|
60dbe5b005cc
Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents:
30
diff
changeset
|
258 (delete-char -1) |
|
60dbe5b005cc
Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents:
30
diff
changeset
|
259 (upcase-region (point) (1+ (point))) |
|
60dbe5b005cc
Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents:
30
diff
changeset
|
260 (setq end (1- end)))) |
|
60dbe5b005cc
Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents:
30
diff
changeset
|
261 (downcase-region (point) (1+ (point))) |
|
60dbe5b005cc
Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents:
30
diff
changeset
|
262 (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
|
263 (forward-char -2) |
|
60dbe5b005cc
Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents:
30
diff
changeset
|
264 (insert "_") |
|
60dbe5b005cc
Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents:
30
diff
changeset
|
265 (downcase-region (point) (1+ (point))) |
|
60dbe5b005cc
Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents:
30
diff
changeset
|
266 (forward-char 1) |
|
60dbe5b005cc
Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents:
30
diff
changeset
|
267 (setq end (1+ end))) |
|
60dbe5b005cc
Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents:
30
diff
changeset
|
268 (downcase-region start end) |
|
60dbe5b005cc
Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents:
30
diff
changeset
|
269 ))))) |
|
24
d6fd2964258c
New version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
22
diff
changeset
|
270 |
| 22 | 271 ;;; Utilities |
| 272 | |
| 273 (defun textmate-also-ignore (pattern) | |
| 274 "Also ignore PATTERN in project files." | |
| 275 (setq *textmate-gf-exclude* | |
| 276 (concat *textmate-gf-exclude* "|" pattern))) | |
| 277 | |
|
29
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
278 (defun textmate-project-root-type (root) |
|
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
279 (cond ((member ".git" (directory-files root)) "git") |
|
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
280 ((member ".hg" (directory-files root)) "hg") |
|
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
281 (t "unknown") |
|
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
282 )) |
|
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
283 |
| 22 | 284 (defun textmate-project-files (root) |
|
29
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
285 (let ((type (textmate-project-root-type root))) |
|
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
286 (cond ((string= type "git") (split-string |
|
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
287 (shell-command-to-string |
|
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
288 (concat "cd " root " && git ls-files")) "\n" t)) |
|
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
289 ((string= type "hg") (split-string |
|
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
290 (shell-command-to-string |
|
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
291 (concat "cd " root " && hg manifest")) "\n" t)) |
|
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
292 ((string= type "unknown") (textmate-cached-project-files-find root)) |
|
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
293 ))) |
|
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 (defun textmate-project-files-find (root) |
| 22 | 296 (split-string |
| 297 (shell-command-to-string | |
| 298 (concat | |
| 299 "find " | |
| 300 root | |
| 301 " -type f | grep -vE '" | |
| 302 *textmate-gf-exclude* | |
| 303 "' | sed 's:" | |
| 304 *textmate-project-root* | |
| 305 "/::'")) "\n" t)) | |
| 306 | |
|
29
e5f414619ea7
Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents:
28
diff
changeset
|
307 (defun textmate-cached-project-files-find (&optional root) |
| 22 | 308 (cond |
| 309 ((null textmate-use-file-cache) (textmate-project-files root)) | |
| 310 ((equal (textmate-project-root) (car *textmate-project-files*)) | |
| 311 (cdr *textmate-project-files*)) | |
| 312 (t (cdr (setq *textmate-project-files* | |
| 313 `(,root . ,(textmate-project-files root))))))) | |
| 314 | |
| 315 (defun textmate-project-root () | |
| 316 (when (or | |
| 317 (null *textmate-project-root*) | |
| 318 (not (string-match *textmate-project-root* default-directory))) | |
| 319 (let ((root (textmate-find-project-root))) | |
| 320 (if root | |
| 321 (setq *textmate-project-root* (expand-file-name (concat root "/"))) | |
| 322 (setq *textmate-project-root* nil)))) | |
| 323 *textmate-project-root*) | |
| 324 | |
| 325 (defun textmate-find-project-root (&optional root) | |
| 326 (when (null root) (setq root default-directory)) | |
| 327 (cond | |
| 328 ((funcall *textmate-project-root-p* (directory-files root)) | |
| 329 (expand-file-name root)) | |
| 330 ((equal (expand-file-name root) "/") nil) | |
| 331 (t (textmate-find-project-root (concat (file-name-as-directory root) ".."))))) | |
| 332 | |
| 333 ;;;###autoload | |
| 334 (define-minor-mode textmate-mode "TextMate Emulation Minor Mode" | |
| 335 :lighter " mate" :global t :keymap *textmate-mode-map* | |
| 336 (textmate-bind-keys) | |
| 337 ; activate preferred completion library | |
| 338 (dolist (mode *textmate-completing-minor-mode-alist*) | |
| 339 (if (eq (car mode) textmate-completing-library) | |
| 340 (funcall (cadr mode) t) | |
| 341 (when (fboundp | |
| 342 (cadr (assoc (car mode) *textmate-completing-function-alist*))) | |
| 343 (funcall (cadr mode) -1))))) | |
| 344 | |
| 345 (provide 'textmate) | |
| 346 ;;; textmate.el ends here |
