Mercurial > dotfiles
comparison .elisp/textmate.el @ 161:668268f29a88
Merge
author | Augie Fackler <durin42@gmail.com> |
---|---|
date | Tue, 24 Nov 2009 15:20:07 -0600 |
parents | 95b7dc384677 a24d5587386f |
children | 2f865a7f84e6 |
comparison
equal
deleted
inserted
replaced
160:dafd5586742e | 161:668268f29a88 |
---|---|
1 ;; textmate.el --- TextMate minor mode for Emacs | 1 ;; textmate.el --- TextMate minor mode for Emacs |
2 | 2 |
3 ;; Copyright (C) 2008 Chris Wanstrath <chris@ozmm.org> and others | 3 ;; Copyright (C) 2008, 2009 Chris Wanstrath <chris@ozmm.org> and others |
4 | 4 |
5 ;; Licensed under the same terms as Emacs. | 5 ;; Licensed under the same terms as Emacs. |
6 | 6 |
7 ;; Version: 0.1.0 | |
8 ;; Keywords: textmate osx mac | 7 ;; Keywords: textmate osx mac |
9 ;; Created: 22 Nov 2008 | 8 ;; Created: 22 Nov 2008 |
10 ;; Author: Chris Wanstrath <chris@ozmm.org> and others | 9 ;; Author: Chris Wanstrath <chris@ozmm.org> and others |
11 | 10 |
12 ;; This file is NOT part of GNU Emacs. | 11 ;; This file is NOT part of GNU Emacs. |
28 ;; ⌥⌘T - Reset File Cache (for Go to File, cache unused if using git/hg root, | 27 ;; ⌥⌘T - Reset File Cache (for Go to File, cache unused if using git/hg root, |
29 ;; but resets cached root location, useful if roots | 28 ;; but resets cached root location, useful if roots |
30 ;; are nested) | 29 ;; are nested) |
31 | 30 |
32 ;; A "project" in textmate-mode is determined by the presence of | 31 ;; A "project" in textmate-mode is determined by the presence of |
33 ;; a .git directory. If no .git directory is found in your current | 32 ;; a .git directory, an .hg directory, a Rakefile, or a Makefile. |
34 ;; directory, textmate-mode will traverse upwards until one (or none) | 33 |
35 ;; is found. The directory housing the .git directory is presumed | 34 ;; You can configure what makes a project root by appending a file |
36 ;; to be the project's root. | 35 ;; or directory name onto the `*textmate-project-roots*' list. |
36 | |
37 ;; If no project root indicator is found in your current directory, | |
38 ;; textmate-mode will traverse upwards until one (or none) is found. | |
39 ;; The directory housing the project root indicator (e.g. a .git or .hg | |
40 ;; directory) is presumed to be the project's root. | |
37 | 41 |
38 ;; In other words, calling Go to File from | 42 ;; In other words, calling Go to File from |
39 ;; ~/Projects/fieldrunners/app/views/towers/show.html.erb will use | 43 ;; ~/Projects/fieldrunners/app/views/towers/show.html.erb will use |
40 ;; ~/Projects/fieldrunners/ as the root if ~/Projects/fieldrunners/.git | 44 ;; ~/Projects/fieldrunners/ as the root if ~/Projects/fieldrunners/.git |
41 ;; exists. | 45 ;; exists. |
46 | |
47 ;; In the event that the project root was defined by either .git or .hg, | |
48 ;; fast file-listing with no caching is provided by the version control | |
49 ;; system. | |
50 | |
51 ;; Not bound to keys, but available are textmate-find-in-project and | |
52 ;; textmate-find-in-project-type, which use grep, the file listing, | |
53 ;; and grep-mode to provide excellent (and blindingly fast with git and | |
54 ;; hg!) grep integration with emacs and your project. | |
55 | |
56 ;; Also available (and unbound) is textmate-compile, which is like | |
57 ;; compile but prepends a cd to the project root to the command. It is | |
58 ;; used to build the find-in-project commands, but has other possible | |
59 ;; uses as well (eg, a test runner or some kind of compile command). | |
42 | 60 |
43 ;;; Installation | 61 ;;; Installation |
44 | 62 |
45 ;; $ cd ~/.emacs.d/vendor | 63 ;; $ cd ~/.emacs.d/vendor |
46 ;; $ git clone git://github.com/defunkt/textmate.el.git | 64 ;; $ git clone git://github.com/defunkt/textmate.el.git |
58 (eval-when-compile | 76 (eval-when-compile |
59 (require 'cl)) | 77 (require 'cl)) |
60 | 78 |
61 ;;; Minor mode | 79 ;;; Minor mode |
62 | 80 |
81 (defvar *textmate-gf-exclude* | |
82 "/\\.|vendor|fixtures|tmp|log|build|\\.xcodeproj|\\.nib|\\.framework|\\.app|\\.pbproj|\\.pbxproj|\\.xcode|\\.xcodeproj|\\.bundle|\\.pyc" | |
83 "Regexp of files to exclude from `textmate-goto-file'.") | |
84 | |
85 (defvar *textmate-project-roots* | |
86 '(".git" ".hg" "Rakefile" "Makefile" "README" "build.xml") | |
87 "The presence of any file/directory in this list indicates a project root.") | |
88 | |
63 (defvar textmate-use-file-cache t | 89 (defvar textmate-use-file-cache t |
64 "* Should `textmate-goto-file' keep a local cache of files?") | 90 "Should `textmate-goto-file' keep a local cache of files?") |
65 | 91 |
66 (defvar textmate-completing-library 'ido | 92 (defvar textmate-completing-library 'ido |
67 "The library `textmade-goto-symbol' and `textmate-goto-file' should use for completing filenames and symbols (`ido' by default)") | 93 "The library `textmade-goto-symbol' and `textmate-goto-file' should use for |
94 completing filenames and symbols (`ido' by default)") | |
68 | 95 |
69 (defvar *textmate-completing-function-alist* '((ido ido-completing-read) | 96 (defvar *textmate-completing-function-alist* '((ido ido-completing-read) |
70 (icicles icicle-completing-read) | 97 (icicles icicle-completing-read) |
71 (none completing-read)) | 98 (none completing-read)) |
72 "The function to call to read file names and symbols from the user") | 99 "The function to call to read file names and symbols from the user") |
118 (define-key map [(control c)(control k)] 'comment-or-uncomment-region-or-line) | 145 (define-key map [(control c)(control k)] 'comment-or-uncomment-region-or-line) |
119 (define-key map [(meta t)] 'textmate-goto-file) | 146 (define-key map [(meta t)] 'textmate-goto-file) |
120 (define-key map [(meta shift t)] 'textmate-goto-symbol))) | 147 (define-key map [(meta shift t)] 'textmate-goto-symbol))) |
121 map)) | 148 map)) |
122 | 149 |
123 | 150 (defvar *textmate-project-root* nil |
124 (defvar *textmate-project-root* nil) | 151 "Used internally to cache the project root.") |
125 (defvar *textmate-project-files* '()) | 152 (defvar *textmate-project-files* '() |
126 | 153 "Used internally to cache the files in a project.") |
127 (defvar *textmate-gf-exclude* | |
128 "/\\.|vendor|fixtures|tmp|log|build|\\.xcodeproj|\\.nib|\\.framework|\\.app|\\.pbproj|\\.pbxproj|\\.xcode|\\.xcodeproj|\\.bundle|\\.pyc") | |
129 | |
130 (defvar *textmate-project-roots* | |
131 '(".git" ".hg" "Rakefile" "Makefile" "README" "build.xml")) | |
132 | 154 |
133 (defvar *textmate-vcs-exclude* nil | 155 (defvar *textmate-vcs-exclude* nil |
134 "string to give to grep -V to exclude some VCS paths from being grepped." | 156 "string to give to grep -V to exclude some VCS paths from being grepped." |
135 ) | 157 ) |
136 | 158 |
146 "Add up/down keybindings for ido." | 168 "Add up/down keybindings for ido." |
147 (define-key ido-completion-map [up] 'ido-prev-match) | 169 (define-key ido-completion-map [up] 'ido-prev-match) |
148 (define-key ido-completion-map [down] 'ido-next-match)) | 170 (define-key ido-completion-map [down] 'ido-next-match)) |
149 | 171 |
150 (defun textmate-completing-read (&rest args) | 172 (defun textmate-completing-read (&rest args) |
151 (let ((reading-fn (cadr (assoc textmate-completing-library *textmate-completing-function-alist*)))) | 173 "Uses `*textmate-completing-function-alist*' to call the appropriate completing |
174 function." | |
175 (let ((reading-fn | |
176 (cadr (assoc textmate-completing-library | |
177 *textmate-completing-function-alist*)))) | |
152 (apply (symbol-function reading-fn) args))) | 178 (apply (symbol-function reading-fn) args))) |
153 | 179 |
154 ;;; allow-line-as-region-for-function adds an "-or-line" version of | 180 ;;; allow-line-as-region-for-function adds an "-or-line" version of |
155 ;;; the given comment function which (un)comments the current line is | 181 ;;; the given comment function which (un)comments the current line is |
156 ;;; the mark is not active. This code comes from Aquamac's osxkeys.el | 182 ;;; the mark is not active. This code comes from Aquamac's osxkeys.el |
176 (allow-line-as-region-for-function comment-or-uncomment-region))) | 202 (allow-line-as-region-for-function comment-or-uncomment-region))) |
177 | 203 |
178 ;;; Commands | 204 ;;; Commands |
179 | 205 |
180 (defun textmate-next-line () | 206 (defun textmate-next-line () |
207 "Inserts an indented newline after the current line and moves the point to it." | |
181 (interactive) | 208 (interactive) |
182 (end-of-line) | 209 (end-of-line) |
183 (newline-and-indent)) | 210 (newline-and-indent)) |
184 | 211 |
185 ;; http://chopmo.blogspot.com/2008/09/quickly-jumping-to-symbols.html | 212 ;; http://chopmo.blogspot.com/2008/09/quickly-jumping-to-symbols.html |
224 (let* ((selected-symbol (ido-completing-read "Symbol? " symbol-names)) | 251 (let* ((selected-symbol (ido-completing-read "Symbol? " symbol-names)) |
225 (position (cdr (assoc selected-symbol name-and-pos)))) | 252 (position (cdr (assoc selected-symbol name-and-pos)))) |
226 (goto-char position)))) | 253 (goto-char position)))) |
227 | 254 |
228 (defun textmate-goto-file () | 255 (defun textmate-goto-file () |
256 "Uses your completing read to quickly jump to a file in a project." | |
229 (interactive) | 257 (interactive) |
230 (let ((root (textmate-project-root))) | 258 (let ((root (textmate-project-root))) |
231 (when (null root) | 259 (when (null root) |
232 (error | 260 (error |
233 (concat | 261 (concat |
234 "Can't find a sutiable project root (" | 262 "Can't find a suitable project root (" |
235 (string-join " " *textmate-project-roots* ) | 263 (string-join " " *textmate-project-roots* ) |
236 ")"))) | 264 ")"))) |
237 (find-file | 265 (find-file |
238 (concat | 266 (concat |
239 (expand-file-name root) "/" | 267 (expand-file-name root) "/" |
314 ))))) | 342 ))))) |
315 (setq *textmate-find-in-project-default* re) | 343 (setq *textmate-find-in-project-default* re) |
316 (textmate-start-compile-in-root command 'grep-mode))) | 344 (textmate-start-compile-in-root command 'grep-mode))) |
317 | 345 |
318 (defun textmate-clear-cache () | 346 (defun textmate-clear-cache () |
347 "Clears the project root and project files cache. Use after adding files." | |
319 (interactive) | 348 (interactive) |
320 (setq *textmate-project-root* nil) | 349 (setq *textmate-project-root* nil) |
321 (setq *textmate-project-files* nil) | 350 (setq *textmate-project-files* nil) |
322 (message "textmate-mode cache cleared.")) | 351 (message "textmate-mode cache cleared.")) |
323 | 352 |
355 ((member ".hg" (directory-files root)) "hg") | 384 ((member ".hg" (directory-files root)) "hg") |
356 (t "unknown") | 385 (t "unknown") |
357 )) | 386 )) |
358 | 387 |
359 (defun textmate-project-files (root) | 388 (defun textmate-project-files (root) |
389 "Finds all files in a given project using either hg, git, or find." | |
360 (let ((type (textmate-project-root-type root))) | 390 (let ((type (textmate-project-root-type root))) |
361 (cond ((string= type "git") (split-string | 391 (cond ((string= type "git") (split-string |
362 (shell-command-to-string | 392 (shell-command-to-string |
363 (concat "cd " root " && git ls-files")) "\n" t)) | 393 (concat "cd " root " && git ls-files")) "\n" t)) |
364 ((string= type "hg") (split-string | 394 ((string= type "hg") (split-string |
366 (concat "cd " root " && hg manifest")) "\n" t)) | 396 (concat "cd " root " && hg manifest")) "\n" t)) |
367 ((string= type "unknown") (textmate-cached-project-files-find root)) | 397 ((string= type "unknown") (textmate-cached-project-files-find root)) |
368 ))) | 398 ))) |
369 | 399 |
370 (defun textmate-project-files-find (root) | 400 (defun textmate-project-files-find (root) |
401 "Finds all files in a given project using find." | |
371 (split-string | 402 (split-string |
372 (shell-command-to-string | 403 (shell-command-to-string |
373 (concat | 404 (concat |
374 "find " | 405 "find " |
375 root | 406 root |
378 "' | sed 's:" | 409 "' | sed 's:" |
379 *textmate-project-root* | 410 *textmate-project-root* |
380 "/::'")) "\n" t)) | 411 "/::'")) "\n" t)) |
381 | 412 |
382 (defun textmate-cached-project-files-find (&optional root) | 413 (defun textmate-cached-project-files-find (&optional root) |
414 "Finds and caches all files in a given project using find." | |
383 (cond | 415 (cond |
384 ((null textmate-use-file-cache) (textmate-project-files root)) | 416 ((null textmate-use-file-cache) (textmate-project-files root)) |
385 ((equal (textmate-project-root) (car *textmate-project-files*)) | 417 ((equal (textmate-project-root) (car *textmate-project-files*)) |
386 (cdr *textmate-project-files*)) | 418 (cdr *textmate-project-files*)) |
387 (t (cdr (setq *textmate-project-files* | 419 (t (cdr (setq *textmate-project-files* |
388 `(,root . ,(textmate-project-files-find root))))))) | 420 `(,root . ,(textmate-project-files-find root))))))) |
389 | 421 |
390 (defun textmate-project-root () | 422 (defun textmate-project-root () |
423 "Returns the current project root." | |
391 (when (or | 424 (when (or |
392 (null *textmate-project-root*) | 425 (null *textmate-project-root*) |
393 (not (string-match *textmate-project-root* default-directory))) | 426 (not (string-match *textmate-project-root* default-directory))) |
394 (let ((root (textmate-find-project-root))) | 427 (let ((root (textmate-find-project-root))) |
395 (if root | 428 (if root |
407 'nil | 440 'nil |
408 (root-matches root (cdr names)) | 441 (root-matches root (cdr names)) |
409 ))) | 442 ))) |
410 | 443 |
411 (defun textmate-find-project-root (&optional root) | 444 (defun textmate-find-project-root (&optional root) |
445 "Determines the current project root by recursively searching for an indicator." | |
412 (when (null root) (setq root default-directory)) | 446 (when (null root) (setq root default-directory)) |
413 (cond | 447 (cond |
414 ((root-matches root *textmate-project-roots*) | 448 ((root-matches root *textmate-project-roots*) |
415 (expand-file-name root)) | 449 (expand-file-name root)) |
416 ((equal (expand-file-name root) "/") nil) | 450 ((equal (expand-file-name root) "/") nil) |