changeset 152:a24d5587386f

textmate.el: update to latest version
author Augie Fackler <durin42@gmail.com>
date Fri, 09 Oct 2009 21:48:03 -0400 (2009-10-10)
parents bf6b5a0dc1f3
children eb7cb3d25060
files .elisp/textmate.el
diffstat 1 files changed, 97 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/.elisp/textmate.el
+++ b/.elisp/textmate.el
@@ -1,10 +1,9 @@
 ;; textmate.el --- TextMate minor mode for Emacs
 
-;; Copyright (C) 2008 Chris Wanstrath <chris@ozmm.org> and others
+;; Copyright (C) 2008, 2009 Chris Wanstrath <chris@ozmm.org> and others
 
 ;; Licensed under the same terms as Emacs.
 
-;; Version: 0.1.0
 ;; Keywords: textmate osx mac
 ;; Created: 22 Nov 2008
 ;; Author: Chris Wanstrath <chris@ozmm.org> and others
@@ -30,16 +29,35 @@
 ;;                           are nested)
 
 ;; A "project" in textmate-mode is determined by the presence of
-;; a .git directory. If no .git directory is found in your current
-;; directory, textmate-mode will traverse upwards until one (or none)
-;; is found. The directory housing the .git directory is presumed
-;; to be the project's root.
+;; a .git directory, an .hg directory, a Rakefile, or a Makefile.
+
+;; You can configure what makes a project root by appending a file
+;; or directory name onto the `*textmate-project-roots*' list.
+
+;; If no project root indicator is found in your current directory,
+;; textmate-mode will traverse upwards until one (or none) is found.
+;; The directory housing the project root indicator (e.g. a .git or .hg
+;; directory) is presumed to be the project's root.
 
 ;; In other words, calling Go to File from
 ;; ~/Projects/fieldrunners/app/views/towers/show.html.erb will use
 ;; ~/Projects/fieldrunners/ as the root if ~/Projects/fieldrunners/.git
 ;; exists.
 
+;; In the event that the project root was defined by either .git or .hg,
+;; fast file-listing with no caching is provided by the version control
+;; system.
+
+;; Not bound to keys, but available are textmate-find-in-project and
+;; textmate-find-in-project-type, which use grep, the file listing,
+;; and grep-mode to provide excellent (and blindingly fast with git and
+;; hg!) grep integration with emacs and your project.
+
+;; Also available (and unbound) is textmate-compile, which is like
+;; compile but prepends a cd to the project root to the command. It is
+;; used to build the find-in-project commands, but has other possible
+;; uses as well (eg, a test runner or some kind of compile command).
+
 ;;; Installation
 
 ;; $ cd ~/.emacs.d/vendor
@@ -60,11 +78,20 @@
 
 ;;; Minor mode
 
+(defvar *textmate-gf-exclude*
+  "/\\.|vendor|fixtures|tmp|log|build|\\.xcodeproj|\\.nib|\\.framework|\\.app|\\.pbproj|\\.pbxproj|\\.xcode|\\.xcodeproj|\\.bundle|\\.pyc"
+  "Regexp of files to exclude from `textmate-goto-file'.")
+
+(defvar *textmate-project-roots*
+  '(".git" ".hg" "Rakefile" "Makefile" "README" "build.xml")
+  "The presence of any file/directory in this list indicates a project root.")
+
 (defvar textmate-use-file-cache t
-  "* Should `textmate-goto-file' keep a local cache of files?")
+  "Should `textmate-goto-file' keep a local cache of files?")
 
 (defvar textmate-completing-library 'ido
-  "The library `textmade-goto-symbol' and `textmate-goto-file' should use for completing filenames and symbols (`ido' by default)")
+  "The library `textmade-goto-symbol' and `textmate-goto-file' should use for
+completing filenames and symbols (`ido' by default)")
 
 (defvar *textmate-completing-function-alist* '((ido ido-completing-read)
                                                (icicles  icicle-completing-read)
@@ -120,15 +147,10 @@
            (define-key map [(meta shift t)] 'textmate-goto-symbol)))
           map))
 
-
-(defvar *textmate-project-root* nil)
-(defvar *textmate-project-files* '())
-
-(defvar *textmate-gf-exclude*
-  "/\\.|vendor|fixtures|tmp|log|build|\\.xcodeproj|\\.nib|\\.framework|\\.app|\\.pbproj|\\.pbxproj|\\.xcode|\\.xcodeproj|\\.bundle|\\.pyc")
-
-(defvar *textmate-project-roots*
-  '(".git" ".hg" "Rakefile" "Makefile" "README" "build.xml"))
+(defvar *textmate-project-root* nil
+  "Used internally to cache the project root.")
+(defvar *textmate-project-files* '()
+  "Used internally to cache the files in a project.")
 
 (defvar *textmate-vcs-exclude* nil
   "string to give to grep -V to exclude some VCS paths from being grepped."
@@ -138,6 +160,8 @@
 
 (defvar *textmate-find-in-project-type-default* nil)
 
+(defvar *textmate-compile-default* nil)
+
 ;;; Bindings
 
 (defun textmate-ido-fix ()
@@ -146,7 +170,11 @@
   (define-key ido-completion-map [down] 'ido-next-match))
 
 (defun textmate-completing-read (&rest args)
-  (let ((reading-fn (cadr (assoc textmate-completing-library *textmate-completing-function-alist*))))
+  "Uses `*textmate-completing-function-alist*' to call the appropriate completing
+function."
+  (let ((reading-fn
+         (cadr (assoc textmate-completing-library
+                      *textmate-completing-function-alist*))))
   (apply (symbol-function reading-fn) args)))
 
 ;;; allow-line-as-region-for-function adds an "-or-line" version of
@@ -176,6 +204,7 @@
 ;;; Commands
 
 (defun textmate-next-line ()
+  "Inserts an indented newline after the current line and moves the point to it."
   (interactive)
   (end-of-line)
   (newline-and-indent))
@@ -224,12 +253,13 @@ Symbols matching the text at point are p
       (goto-char position))))
 
 (defun textmate-goto-file ()
+  "Uses your completing read to quickly jump to a file in a project."
   (interactive)
   (let ((root (textmate-project-root)))
     (when (null root)
       (error
        (concat
-        "Can't find a sutiable project root ("
+        "Can't find a suitable project root ("
         (string-join " " *textmate-project-roots* )
         ")")))
     (find-file
@@ -240,6 +270,8 @@ Symbols matching the text at point are p
        (textmate-project-files root))))))
 
 (defun textmate-find-in-project-type ()
+  "Run grep over project files of a specific type and put the results
+in a grep-mode buffer."
   (interactive)
   (let ((pat (read-string (concat "Suffix"
                                   (if *textmate-find-in-project-type-default*
@@ -250,37 +282,55 @@ Symbols matching the text at point are p
     (setq *textmate-find-in-project-type-default* pat)
     (textmate-find-in-project (concat "*." pat))))
 
-(defun textmate-find-in-project (&optional pattern)
-  (interactive)
-  (let ((root (textmate-project-root))
-        (default *textmate-find-in-project-default*)
-        )
+(defun textmate-start-compile-in-root (command &optional mode
+                                                         name-function
+                                                         highlight-regexp)
+  "Idential to compilation-start, except it automatically changes to the
+project root directory before starting the command."
+  (let ((root (textmate-project-root)))
     (when (null root)
       (error "Not in a project area."))
-    (let ((re (read-string (concat "Search for "
+    (let ((realcommand (concat "cd " root " ; " command)))
+      (compilation-start realcommand mode name-function highlight-regexp))))
+
+(defun textmate-compile ()
+  "Run a command in compilation-mode rooted at the project root."
+  (interactive)
+  (let* ((default *textmate-compile-default*)
+         (command (read-string
+                   (concat "Command"
+                           (if default (format " [\"%s\"]" default) "")
+                           ": ") nil 'textmate-compile-history default)))
+    (setq *textmate-compile-default* command)
+    (textmate-start-compile-in-root command)))
+
+(defun textmate-find-in-project (&optional pattern)
+  "Run grep over project files with results in grep-mode.
+
+Takes an optional argument (see also textmate-find-in-project-type)
+of a file extension to limit the search. Useful for finding results in only a
+specific type of file."
+  (interactive)
+    (let* ((default *textmate-find-in-project-default*)
+           (re (read-string (concat "Search for "
                          (if (and default (> (length default) 0))
                              (format "[\"%s\"]" default)) ": ")
-                 nil 'textmate-find-in-project-history default)
-              )
-          (incpat (if pattern pattern "*")))
-      (append textmate-find-in-project-history (list re))
-      (setq *textmate-find-in-project-default* re)
-      (let ((type (textmate-project-root-type root)))
-        (let ((command
-            (cond ((not (string= type "unknown"))
-                   (concat "cd "
-                           root
-                           " ; "
-                           (cond ((string= type "git") "git ls-files")
+                 nil 'textmate-find-in-project-history default))
+          (incpat (if pattern pattern "*"))
+          (type (textmate-project-root-type (textmate-project-root)))
+          (command
+           (cond ((not (string= type "unknown"))
+                   (concat (cond ((string= type "git") "git ls-files")
                                  ((string= type "hg") "hg manifest"))
                            (if *textmate-vcs-exclude*
-                               (concat " | grep -v " (shell-quote-argument *textmate-vcs-exclude*))
+                               (concat " | grep -v "
+                                       (shell-quote-argument *textmate-vcs-exclude*))
                              "")
                            " | xargs grep -nR "
                            (if pattern (concat " --include='" pattern "' ") "")
                            " -- "
                            (shell-quote-argument re)))
-                  (t (concat "cd " root "; egrep -nR --exclude='"
+                  (t (concat "egrep -nR --exclude='"
                             *textmate-gf-exclude*
                             "' --include='"
                             incpat
@@ -290,10 +340,11 @@ Symbols matching the text at point are p
                             *textmate-gf-exclude*
                             "' | sed s:./::"
                             )))))
-                  (compilation-start command 'grep-mode)))
-  )))
+          (setq *textmate-find-in-project-default* re)
+          (textmate-start-compile-in-root command 'grep-mode)))
 
 (defun textmate-clear-cache ()
+  "Clears the project root and project files cache. Use after adding files."
   (interactive)
   (setq *textmate-project-root* nil)
   (setq *textmate-project-files* nil)
@@ -335,6 +386,7 @@ Symbols matching the text at point are p
    ))
 
 (defun textmate-project-files (root)
+  "Finds all files in a given project using either hg, git, or find."
   (let ((type (textmate-project-root-type root)))
     (cond ((string= type "git") (split-string
                            (shell-command-to-string
@@ -346,6 +398,7 @@ Symbols matching the text at point are p
   )))
 
 (defun textmate-project-files-find (root)
+  "Finds all files in a given project using find."
   (split-string
     (shell-command-to-string
      (concat
@@ -358,6 +411,7 @@ Symbols matching the text at point are p
       "/::'")) "\n" t))
 
 (defun textmate-cached-project-files-find (&optional root)
+  "Finds and caches all files in a given project using find."
   (cond
    ((null textmate-use-file-cache) (textmate-project-files root))
    ((equal (textmate-project-root) (car *textmate-project-files*))
@@ -366,6 +420,7 @@ Symbols matching the text at point are p
                  `(,root . ,(textmate-project-files-find root)))))))
 
 (defun textmate-project-root ()
+  "Returns the current project root."
   (when (or
          (null *textmate-project-root*)
          (not (string-match *textmate-project-root* default-directory)))
@@ -387,6 +442,7 @@ Symbols matching the text at point are p
                                         )))
 
 (defun textmate-find-project-root (&optional root)
+  "Determines the current project root by recursively searching for an indicator."
   (when (null root) (setq root default-directory))
   (cond
    ((root-matches root *textmate-project-roots*)