annotate .elisp/textmate.el @ 84:f013f40e7b63

Import latest nosemacs, set nose to output dots instead of verbose output.
author Augie Fackler <durin42@gmail.com>
date Tue, 14 Apr 2009 20:07:12 -0500
parents 60dbe5b005cc
children 26450200777a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1 ;; textmate.el --- TextMate minor mode for Emacs
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3 ;; Copyright (C) 2008 Chris Wanstrath <chris@ozmm.org>
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
4
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
5 ;; Licensed under the same terms as Emacs.
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
6
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
7 ;; Version: 0.1.0
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
8 ;; Keywords: textmate osx mac
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
9 ;; Created: 22 Nov 2008
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
10 ;; Author: Chris Wanstrath <chris@ozmm.org>
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
11
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
12 ;; This file is NOT part of GNU Emacs.
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
13
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
14 ;; Licensed under the same terms as Emacs.
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
15
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
16 ;;; Commentary:
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
17
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
18 ;; This minor mode exists to mimick TextMate's awesome
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
19 ;; features.
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
20
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
21 ;; ⌘T - Go to File
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
22 ;; ⇧⌘T - Go to Symbol
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
23 ;; ⌘L - Go to Line
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
24 ;; ⌘/ - Comment Line (or Selection/Region)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
25 ;; ⌘] - Shift Right (currently indents region)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
26 ;; ⌘[ - Shift Left (not yet implemented)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
27 ;; ⌥⌘] - Align Assignments
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
28 ;; ⌥⌘[ - Indent Line
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
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
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
31
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
32 ;; A "project" in textmate-mode is determined by the presence of
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
33 ;; a .git directory. If no .git directory is found in your current
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
34 ;; directory, textmate-mode will traverse upwards until one (or none)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
35 ;; is found. The directory housing the .git directory is presumed
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
36 ;; to be the project's root.
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
37
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
38 ;; In other words, calling Go to File from
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
39 ;; ~/Projects/fieldrunners/app/views/towers/show.html.erb will use
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
40 ;; ~/Projects/fieldrunners/ as the root if ~/Projects/fieldrunners/.git
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
41 ;; exists.
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
42
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
43 ;;; Installation
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
44
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
45 ;; $ cd ~/.emacs.d/vendor
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
46 ;; $ git clone git://github.com/defunkt/textmate.el.git
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
47 ;;
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
48 ;; In your emacs config:
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
49 ;;
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
50 ;; (add-to-list 'load-path "~/.emacs.d/vendor/textmate.el")
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
51 ;; (require 'textmate)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
52 ;; (textmate-mode)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
53
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
54 ;;; Depends on imenu
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
55 (require 'imenu)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
56
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
57 ;;; Minor mode
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
58
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
59 (defvar textmate-use-file-cache t
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
60 "* Should `textmate-goto-file' keep a local cache of files?")
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
61
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
62 (defvar textmate-completing-library 'ido
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
63 "The library `textmade-goto-symbol' and `textmate-goto-file' should use for completing filenames and symbols (`ido' by default)")
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
64
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
65 (defvar *textmate-completing-function-alist* '((ido ido-completing-read)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
66 (icicles icicle-completing-read)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
67 (none completing-read))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
68 "The function to call to read file names and symbols from the user")
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
69
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
70 (defvar *textmate-completing-minor-mode-alist*
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
71 `((ido ,(lambda (a) (progn (ido-mode a) (setq ido-enable-flex-matching t))))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
72 (icicles ,(lambda (a) (icy-mode a)))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
73 (none ,(lambda (a) ())))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
74 "The list of functions to enable and disable completing minor modes")
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
75
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
76 (defvar *textmate-mode-map* (make-sparse-keymap))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
77 (defvar *textmate-project-root* nil)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
78 (defvar *textmate-project-files* '())
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
79 (defvar *textmate-gf-exclude*
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
80 "/\\.|vendor|fixtures|tmp|log|build|\\.xcodeproj|\\.nib|\\.framework|\\.app|\\.pbproj|\\.pbxproj|\\.xcode|\\.xcodeproj|\\.bundle")
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
81
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
82 (defvar *textmate-keybindings-list* `((textmate-next-line
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
83 [A-return] [M-return])
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
84 (textmate-clear-cache
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
85 ,(kbd "A-M-t") [(control c)(control t)])
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
86 (align
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
87 ,(kbd "A-M-]") [(control c)(control a)])
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
88 (indent-according-to-mode
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
89 ,(kbd "A-M-[") nil)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
90 (indent-region
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
91 ,(kbd "A-]") [(control tab)])
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
92 (comment-or-uncomment-region-or-line
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
93 ,(kbd "A-/") [(control c)(control k)])
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
94 (textmate-goto-file
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
95 ,(kbd "A-t") [(meta t)])
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
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
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
100
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
101 (defvar *textmate-project-root-p*
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
102 #'(lambda (coll) (or (member ".git" coll)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
103 (member ".hg" coll)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
104 ))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
105 "*Lambda that, given a collection of directory entries, returns
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
106 non-nil if it represents the project root.")
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
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
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
111 ;;; Bindings
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
112
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
113 (defun textmate-ido-fix ()
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
114 "Add up/down keybindings for ido."
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
115 (define-key ido-completion-map [up] 'ido-prev-match)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
116 (define-key ido-completion-map [down] 'ido-next-match))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
117
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
118 (defun textmate-bind-keys ()
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
119 (add-hook 'ido-setup-hook 'textmate-ido-fix)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
120
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
121 ; weakness until i figure out how to do this right
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
122 (when (boundp 'osx-key-mode-map)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
123 (define-key osx-key-mode-map (kbd "A-t") 'textmate-goto-file)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
124 (define-key osx-key-mode-map (kbd "A-T") 'textmate-goto-symbol))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
125
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
126 (let ((member) (i 0) (access (if (boundp 'aquamacs-version) 'cadr 'caddr)))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
127 (setq member (nth i *textmate-keybindings-list*))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
128 (while member
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
129 (if (funcall access member)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
130 (define-key *textmate-mode-map* (funcall access member) (car member)))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
131 (setq member (nth i *textmate-keybindings-list*))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
132 (setq i (+ i 1)))))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
133
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
134 (defun textmate-completing-read (&rest args)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
135 (let ((reading-fn (cadr (assoc textmate-completing-library *textmate-completing-function-alist*))))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
136 (apply (symbol-function reading-fn) args)))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
137
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
138 ;;; Commands
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
139
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
140 (defun textmate-next-line ()
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
141 (interactive)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
142 (end-of-line)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
143 (newline-and-indent))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
144
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
145 ;; http://chopmo.blogspot.com/2008/09/quickly-jumping-to-symbols.html
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
146 (defun textmate-goto-symbol ()
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
147 "Will update the imenu index and then use ido to select a symbol to navigate to"
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
148 (interactive)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
149 (imenu--make-index-alist)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
150 (let ((name-and-pos '())
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
151 (symbol-names '()))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
152 (flet ((addsymbols (symbol-list)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
153 (when (listp symbol-list)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
154 (dolist (symbol symbol-list)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
155 (let ((name nil) (position nil))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
156 (cond
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
157 ((and (listp symbol) (imenu--subalist-p symbol))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
158 (addsymbols symbol))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
159
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
160 ((listp symbol)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
161 (setq name (car symbol))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
162 (setq position (cdr symbol)))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
163
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
164 ((stringp symbol)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
165 (setq name symbol)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
166 (setq position (get-text-property 1 'org-imenu-marker symbol))))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
167
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
168 (unless (or (null position) (null name))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
169 (add-to-list 'symbol-names name)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
170 (add-to-list 'name-and-pos (cons name position))))))))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
171 (addsymbols imenu--index-alist))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
172 (let* ((selected-symbol (textmate-completing-read "Symbol: " symbol-names))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
173 (position (cdr (assoc selected-symbol name-and-pos))))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
174 (goto-char position))))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
175
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
176 (defun textmate-goto-file ()
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
177 (interactive)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
178 (let ((root (textmate-project-root)))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
179 (when (null root)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
180 (error "Can't find any .git directory"))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
181 (find-file
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
182 (concat
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
183 (expand-file-name root) "/"
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
184 (textmate-completing-read
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
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
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
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
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
238 (defun textmate-clear-cache ()
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
239 (interactive)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
240 (setq *textmate-project-root* nil)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
241 (setq *textmate-project-files* nil)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
242 (message "textmate-mode cache cleared."))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
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
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
271 ;;; Utilities
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
272
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
273 (defun textmate-also-ignore (pattern)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
274 "Also ignore PATTERN in project files."
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
275 (setq *textmate-gf-exclude*
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
276 (concat *textmate-gf-exclude* "|" pattern)))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
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
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
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
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
296 (split-string
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
297 (shell-command-to-string
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
298 (concat
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
299 "find "
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
300 root
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
301 " -type f | grep -vE '"
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
302 *textmate-gf-exclude*
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
303 "' | sed 's:"
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
304 *textmate-project-root*
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
305 "/::'")) "\n" t))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
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
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
308 (cond
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
309 ((null textmate-use-file-cache) (textmate-project-files root))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
310 ((equal (textmate-project-root) (car *textmate-project-files*))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
311 (cdr *textmate-project-files*))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
312 (t (cdr (setq *textmate-project-files*
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
313 `(,root . ,(textmate-project-files root)))))))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
314
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
315 (defun textmate-project-root ()
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
316 (when (or
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
317 (null *textmate-project-root*)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
318 (not (string-match *textmate-project-root* default-directory)))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
319 (let ((root (textmate-find-project-root)))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
320 (if root
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
321 (setq *textmate-project-root* (expand-file-name (concat root "/")))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
322 (setq *textmate-project-root* nil))))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
323 *textmate-project-root*)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
324
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
325 (defun textmate-find-project-root (&optional root)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
326 (when (null root) (setq root default-directory))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
327 (cond
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
328 ((funcall *textmate-project-root-p* (directory-files root))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
329 (expand-file-name root))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
330 ((equal (expand-file-name root) "/") nil)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
331 (t (textmate-find-project-root (concat (file-name-as-directory root) "..")))))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
332
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
333 ;;;###autoload
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
334 (define-minor-mode textmate-mode "TextMate Emulation Minor Mode"
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
335 :lighter " mate" :global t :keymap *textmate-mode-map*
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
336 (textmate-bind-keys)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
337 ; activate preferred completion library
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
338 (dolist (mode *textmate-completing-minor-mode-alist*)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
339 (if (eq (car mode) textmate-completing-library)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
340 (funcall (cadr mode) t)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
341 (when (fboundp
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
342 (cadr (assoc (car mode) *textmate-completing-function-alist*)))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
343 (funcall (cadr mode) -1)))))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
344
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
345 (provide 'textmate)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
346 ;;; textmate.el ends here