Mercurial > dotfiles
diff .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 |
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." @@ -148,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 @@ -178,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)) @@ -226,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 @@ -316,6 +344,7 @@ specific type of file." (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) @@ -357,6 +386,7 @@ specific type of file." )) (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 @@ -368,6 +398,7 @@ specific type of file." ))) (defun textmate-project-files-find (root) + "Finds all files in a given project using find." (split-string (shell-command-to-string (concat @@ -380,6 +411,7 @@ specific type of file." "/::'")) "\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*)) @@ -388,6 +420,7 @@ specific type of file." `(,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))) @@ -409,6 +442,7 @@ specific type of file." ))) (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*)