annotate .elisp/textmate.el @ 157:95b7dc384677

textmate.el: bring in upstream changes
author Augie Fackler <durin42@gmail.com>
date Tue, 24 Nov 2009 14:24:09 -0600
parents e30655eb7050
children 668268f29a88
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
141
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
3 ;; Copyright (C) 2008 Chris Wanstrath <chris@ozmm.org> and others
22
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
141
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
10 ;; Author: Chris Wanstrath <chris@ozmm.org> and others
22
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 ;;; Commentary:
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 ;; This minor mode exists to mimick TextMate's awesome
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
17 ;; features.
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
18
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
19 ;; ⌘T - Go to File
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
20 ;; ⇧⌘T - Go to Symbol
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
21 ;; ⌘L - Go to Line
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
22 ;; ⌘/ - Comment Line (or Selection/Region)
141
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
23 ;; ⌘] - Shift Right
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
24 ;; ⌘[ - Shift Left
22
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
25 ;; ⌥⌘] - Align Assignments
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
26 ;; ⌥⌘[ - Indent Line
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
27 ;; ⌘RET - Insert Newline at Line's End
141
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
28 ;; ⌥⌘T - Reset File Cache (for Go to File, cache unused if using git/hg root,
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
29 ;; but resets cached root location, useful if roots
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
30 ;; are nested)
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
141
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
57 ;;; Needed for flet
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
58 (eval-when-compile
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
59 (require 'cl))
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
60
22
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
61 ;;; Minor mode
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
62
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
63 (defvar textmate-use-file-cache t
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
64 "* Should `textmate-goto-file' keep a local cache of files?")
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
65
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
66 (defvar textmate-completing-library 'ido
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
67 "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
68
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
69 (defvar *textmate-completing-function-alist* '((ido ido-completing-read)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
70 (icicles icicle-completing-read)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
71 (none completing-read))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
72 "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
73
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
74 (defvar *textmate-completing-minor-mode-alist*
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
75 `((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
76 (icicles ,(lambda (a) (icy-mode a)))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
77 (none ,(lambda (a) ())))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
78 "The list of functions to enable and disable completing minor modes")
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
79
141
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
80 (defvar *textmate-mode-map*
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
81 (let ((map (make-sparse-keymap)))
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
82 (cond ((featurep 'aquamacs)
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
83 (define-key map [A-return] 'textmate-next-line)
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
84 (define-key map (kbd "A-M-t") 'textmate-clear-cache)
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
85 (define-key map (kbd "A-M-]") 'align)
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
86 (define-key map (kbd "A-M-[") 'indent-according-to-mode)
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
87 (define-key map (kbd "A-]") 'textmate-shift-right)
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
88 (define-key map (kbd "A-[") 'textmate-shift-left)
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
89 (define-key map (kbd "A-/") 'comment-or-uncomment-region-or-line)
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
90 (define-key map (kbd "A-t") 'textmate-goto-file)
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
91 (define-key map (kbd "A-T") 'textmate-goto-symbol))
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
92 ((and (featurep 'mac-carbon) (eq window-system 'mac) mac-key-mode)
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
93 (define-key map [(alt meta return)] 'textmate-next-line)
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
94 (define-key map [(alt meta t)] 'textmate-clear-cache)
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
95 (define-key map [(alt meta \])] 'align)
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
96 (define-key map [(alt meta \[)] 'indent-according-to-mode)
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
97 (define-key map [(alt \])] 'textmate-shift-right)
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
98 (define-key map [(alt \[)] 'textmate-shift-left)
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
99 (define-key map [(meta /)] 'comment-or-uncomment-region-or-line)
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
100 (define-key map [(alt t)] 'textmate-goto-file)
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
101 (define-key map [(alt shift t)] 'textmate-goto-symbol))
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
102 ((featurep 'ns) ;; Emacs.app
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
103 (define-key map [(super meta return)] 'textmate-next-line)
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
104 (define-key map [(super meta t)] 'textmate-clear-cache)
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
105 (define-key map [(super meta \])] 'align)
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
106 (define-key map [(super meta \[)] 'indent-according-to-mode)
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
107 (define-key map [(super \])] 'textmate-shift-right)
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
108 (define-key map [(super \[)] 'textmate-shift-left)
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
109 (define-key map [(super /)] 'comment-or-uncomment-region-or-line)
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
110 (define-key map [(super t)] 'textmate-goto-file)
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
111 (define-key map [(super shift t)] 'textmate-goto-symbol))
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
112 (t ;; Any other version
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
113 (define-key map [(meta return)] 'textmate-next-line)
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
114 (define-key map [(control c)(control t)] 'textmate-clear-cache)
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
115 (define-key map [(control c)(control a)] 'align)
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
116 (define-key map [(control tab)] 'textmate-shift-right)
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
117 (define-key map [(control shift tab)] 'textmate-shift-left)
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
118 (define-key map [(control c)(control k)] 'comment-or-uncomment-region-or-line)
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
119 (define-key map [(meta t)] 'textmate-goto-file)
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
120 (define-key map [(meta shift t)] 'textmate-goto-symbol)))
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
121 map))
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
122
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
123
22
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
124 (defvar *textmate-project-root* nil)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
125 (defvar *textmate-project-files* '())
141
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
126
22
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
127 (defvar *textmate-gf-exclude*
141
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
128 "/\\.|vendor|fixtures|tmp|log|build|\\.xcodeproj|\\.nib|\\.framework|\\.app|\\.pbproj|\\.pbxproj|\\.xcode|\\.xcodeproj|\\.bundle|\\.pyc")
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
129
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
130 (defvar *textmate-project-roots*
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
131 '(".git" ".hg" "Rakefile" "Makefile" "README" "build.xml"))
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
132
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
133 (defvar *textmate-vcs-exclude* nil
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
134 "string to give to grep -V to exclude some VCS paths from being grepped."
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
135 )
22
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
136
28
260deb14fbc8 Add textmate-find-in-project.
Augie Fackler <durin42@gmail.com>
parents: 25
diff changeset
137 (defvar *textmate-find-in-project-default* nil)
141
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
138
28
260deb14fbc8 Add textmate-find-in-project.
Augie Fackler <durin42@gmail.com>
parents: 25
diff changeset
139 (defvar *textmate-find-in-project-type-default* nil)
260deb14fbc8 Add textmate-find-in-project.
Augie Fackler <durin42@gmail.com>
parents: 25
diff changeset
140
157
95b7dc384677 textmate.el: bring in upstream changes
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
141 (defvar *textmate-compile-default* nil)
95b7dc384677 textmate.el: bring in upstream changes
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
142
22
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
143 ;;; Bindings
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 (defun textmate-ido-fix ()
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
146 "Add up/down keybindings for ido."
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
147 (define-key ido-completion-map [up] 'ido-prev-match)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
148 (define-key ido-completion-map [down] 'ido-next-match))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
149
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
150 (defun textmate-completing-read (&rest args)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
151 (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
152 (apply (symbol-function reading-fn) args)))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
153
141
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
154 ;;; allow-line-as-region-for-function adds an "-or-line" version of
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
155 ;;; the given comment function which (un)comments the current line is
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
156 ;;; the mark is not active. This code comes from Aquamac's osxkeys.el
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
157 ;;; and is licensed under the GPL
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
158
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
159 (defmacro allow-line-as-region-for-function (orig-function)
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
160 `(defun ,(intern (concat (symbol-name orig-function) "-or-line"))
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
161 ()
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
162 ,(format "Like `%s', but acts on the current line if mark is not active." orig-function)
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
163 (interactive)
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
164 (if mark-active
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
165 (call-interactively (function ,orig-function))
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
166 (save-excursion
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
167 ;; define a region (temporarily) -- so any C-u prefixes etc. are preserved.
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
168 (beginning-of-line)
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
169 (set-mark (point))
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
170 (end-of-line)
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
171 (call-interactively (function ,orig-function))))))
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
172
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
173 (defun textmate-define-comment-line ()
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
174 "Add or-line (un)comment function if not already defined"
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
175 (unless (fboundp 'comment-or-uncomment-region-or-line)
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
176 (allow-line-as-region-for-function comment-or-uncomment-region)))
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
177
22
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
178 ;;; Commands
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
179
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
180 (defun textmate-next-line ()
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
181 (interactive)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
182 (end-of-line)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
183 (newline-and-indent))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
184
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
185 ;; http://chopmo.blogspot.com/2008/09/quickly-jumping-to-symbols.html
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
186 (defun textmate-goto-symbol ()
141
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
187 "Update the imenu index and then use ido to select a symbol to navigate to.
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
188 Symbols matching the text at point are put first in the completion list."
22
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
189 (interactive)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
190 (imenu--make-index-alist)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
191 (let ((name-and-pos '())
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
192 (symbol-names '()))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
193 (flet ((addsymbols (symbol-list)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
194 (when (listp symbol-list)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
195 (dolist (symbol symbol-list)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
196 (let ((name nil) (position nil))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
197 (cond
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
198 ((and (listp symbol) (imenu--subalist-p symbol))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
199 (addsymbols symbol))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
200
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
201 ((listp symbol)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
202 (setq name (car symbol))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
203 (setq position (cdr symbol)))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
204
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
205 ((stringp symbol)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
206 (setq name symbol)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
207 (setq position (get-text-property 1 'org-imenu-marker symbol))))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
208
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
209 (unless (or (null position) (null name))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
210 (add-to-list 'symbol-names name)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
211 (add-to-list 'name-and-pos (cons name position))))))))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
212 (addsymbols imenu--index-alist))
141
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
213 ;; If there are matching symbols at point, put them at the beginning of `symbol-names'.
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
214 (let ((symbol-at-point (thing-at-point 'symbol)))
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
215 (when symbol-at-point
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
216 (let* ((regexp (concat (regexp-quote symbol-at-point) "$"))
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
217 (matching-symbols (delq nil (mapcar (lambda (symbol)
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
218 (if (string-match regexp symbol) symbol))
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
219 symbol-names))))
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
220 (when matching-symbols
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
221 (sort matching-symbols (lambda (a b) (> (length a) (length b))))
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
222 (mapc (lambda (symbol) (setq symbol-names (cons symbol (delete symbol symbol-names))))
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
223 matching-symbols)))))
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
224 (let* ((selected-symbol (ido-completing-read "Symbol? " symbol-names))
22
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
225 (position (cdr (assoc selected-symbol name-and-pos))))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
226 (goto-char position))))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
227
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
228 (defun textmate-goto-file ()
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
229 (interactive)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
230 (let ((root (textmate-project-root)))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
231 (when (null root)
141
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
232 (error
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
233 (concat
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
234 "Can't find a sutiable project root ("
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
235 (string-join " " *textmate-project-roots* )
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
236 ")")))
22
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
237 (find-file
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
238 (concat
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
239 (expand-file-name root) "/"
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
240 (textmate-completing-read
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
241 "Find file: "
29
e5f414619ea7 Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents: 28
diff changeset
242 (textmate-project-files root))))))
22
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
243
28
260deb14fbc8 Add textmate-find-in-project.
Augie Fackler <durin42@gmail.com>
parents: 25
diff changeset
244 (defun textmate-find-in-project-type ()
157
95b7dc384677 textmate.el: bring in upstream changes
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
245 "Run grep over project files of a specific type and put the results
95b7dc384677 textmate.el: bring in upstream changes
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
246 in a grep-mode buffer."
28
260deb14fbc8 Add textmate-find-in-project.
Augie Fackler <durin42@gmail.com>
parents: 25
diff changeset
247 (interactive)
260deb14fbc8 Add textmate-find-in-project.
Augie Fackler <durin42@gmail.com>
parents: 25
diff changeset
248 (let ((pat (read-string (concat "Suffix"
260deb14fbc8 Add textmate-find-in-project.
Augie Fackler <durin42@gmail.com>
parents: 25
diff changeset
249 (if *textmate-find-in-project-type-default*
260deb14fbc8 Add textmate-find-in-project.
Augie Fackler <durin42@gmail.com>
parents: 25
diff changeset
250 (format " [\"%s\"]" *textmate-find-in-project-type-default*)
260deb14fbc8 Add textmate-find-in-project.
Augie Fackler <durin42@gmail.com>
parents: 25
diff changeset
251 "")
260deb14fbc8 Add textmate-find-in-project.
Augie Fackler <durin42@gmail.com>
parents: 25
diff changeset
252 ": "
260deb14fbc8 Add textmate-find-in-project.
Augie Fackler <durin42@gmail.com>
parents: 25
diff changeset
253 ) nil nil *textmate-find-in-project-type-default*)))
260deb14fbc8 Add textmate-find-in-project.
Augie Fackler <durin42@gmail.com>
parents: 25
diff changeset
254 (setq *textmate-find-in-project-type-default* pat)
260deb14fbc8 Add textmate-find-in-project.
Augie Fackler <durin42@gmail.com>
parents: 25
diff changeset
255 (textmate-find-in-project (concat "*." pat))))
260deb14fbc8 Add textmate-find-in-project.
Augie Fackler <durin42@gmail.com>
parents: 25
diff changeset
256
157
95b7dc384677 textmate.el: bring in upstream changes
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
257 (defun textmate-start-compile-in-root (command &optional mode
95b7dc384677 textmate.el: bring in upstream changes
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
258 name-function
95b7dc384677 textmate.el: bring in upstream changes
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
259 highlight-regexp)
95b7dc384677 textmate.el: bring in upstream changes
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
260 "Idential to compilation-start, except it automatically changes to the
95b7dc384677 textmate.el: bring in upstream changes
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
261 project root directory before starting the command."
95b7dc384677 textmate.el: bring in upstream changes
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
262 (let ((root (textmate-project-root)))
28
260deb14fbc8 Add textmate-find-in-project.
Augie Fackler <durin42@gmail.com>
parents: 25
diff changeset
263 (when (null root)
260deb14fbc8 Add textmate-find-in-project.
Augie Fackler <durin42@gmail.com>
parents: 25
diff changeset
264 (error "Not in a project area."))
157
95b7dc384677 textmate.el: bring in upstream changes
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
265 (let ((realcommand (concat "cd " root " ; " command)))
95b7dc384677 textmate.el: bring in upstream changes
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
266 (compilation-start realcommand mode name-function highlight-regexp))))
95b7dc384677 textmate.el: bring in upstream changes
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
267
95b7dc384677 textmate.el: bring in upstream changes
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
268 (defun textmate-compile ()
95b7dc384677 textmate.el: bring in upstream changes
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
269 "Run a command in compilation-mode rooted at the project root."
95b7dc384677 textmate.el: bring in upstream changes
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
270 (interactive)
95b7dc384677 textmate.el: bring in upstream changes
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
271 (let* ((default *textmate-compile-default*)
95b7dc384677 textmate.el: bring in upstream changes
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
272 (command (read-string
95b7dc384677 textmate.el: bring in upstream changes
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
273 (concat "Command"
95b7dc384677 textmate.el: bring in upstream changes
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
274 (if default (format " [\"%s\"]" default) "")
95b7dc384677 textmate.el: bring in upstream changes
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
275 ": ") nil 'textmate-compile-history default)))
95b7dc384677 textmate.el: bring in upstream changes
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
276 (setq *textmate-compile-default* command)
95b7dc384677 textmate.el: bring in upstream changes
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
277 (textmate-start-compile-in-root command)))
95b7dc384677 textmate.el: bring in upstream changes
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
278
95b7dc384677 textmate.el: bring in upstream changes
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
279 (defun textmate-find-in-project (&optional pattern)
95b7dc384677 textmate.el: bring in upstream changes
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
280 "Run grep over project files with results in grep-mode.
95b7dc384677 textmate.el: bring in upstream changes
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
281
95b7dc384677 textmate.el: bring in upstream changes
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
282 Takes an optional argument (see also textmate-find-in-project-type)
95b7dc384677 textmate.el: bring in upstream changes
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
283 of a file extension to limit the search. Useful for finding results in only a
95b7dc384677 textmate.el: bring in upstream changes
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
284 specific type of file."
95b7dc384677 textmate.el: bring in upstream changes
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
285 (interactive)
95b7dc384677 textmate.el: bring in upstream changes
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
286 (let* ((default *textmate-find-in-project-default*)
95b7dc384677 textmate.el: bring in upstream changes
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
287 (re (read-string (concat "Search for "
28
260deb14fbc8 Add textmate-find-in-project.
Augie Fackler <durin42@gmail.com>
parents: 25
diff changeset
288 (if (and default (> (length default) 0))
260deb14fbc8 Add textmate-find-in-project.
Augie Fackler <durin42@gmail.com>
parents: 25
diff changeset
289 (format "[\"%s\"]" default)) ": ")
157
95b7dc384677 textmate.el: bring in upstream changes
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
290 nil 'textmate-find-in-project-history default))
95b7dc384677 textmate.el: bring in upstream changes
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
291 (incpat (if pattern pattern "*"))
95b7dc384677 textmate.el: bring in upstream changes
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
292 (type (textmate-project-root-type (textmate-project-root)))
95b7dc384677 textmate.el: bring in upstream changes
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
293 (command
95b7dc384677 textmate.el: bring in upstream changes
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
294 (cond ((not (string= type "unknown"))
95b7dc384677 textmate.el: bring in upstream changes
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
295 (concat (cond ((string= type "git") "git ls-files")
29
e5f414619ea7 Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents: 28
diff changeset
296 ((string= type "hg") "hg manifest"))
141
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
297 (if *textmate-vcs-exclude*
157
95b7dc384677 textmate.el: bring in upstream changes
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
298 (concat " | grep -v "
95b7dc384677 textmate.el: bring in upstream changes
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
299 (shell-quote-argument *textmate-vcs-exclude*))
141
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
300 "")
157
95b7dc384677 textmate.el: bring in upstream changes
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
301 " | xargs egrep -nR "
30
43e751bdedeb Latest textmate.el - fixed a bug in find in type.
Augie Fackler <durin42@gmail.com>
parents: 29
diff changeset
302 (if pattern (concat " --include='" pattern "' ") "")
99
26450200777a Latest textmate.el
Augie Fackler <durin42@gmail.com>
parents: 49
diff changeset
303 " -- "
49
60dbe5b005cc Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents: 30
diff changeset
304 (shell-quote-argument re)))
157
95b7dc384677 textmate.el: bring in upstream changes
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
305 (t (concat "egrep -nR --exclude='"
29
e5f414619ea7 Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents: 28
diff changeset
306 *textmate-gf-exclude*
e5f414619ea7 Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents: 28
diff changeset
307 "' --include='"
e5f414619ea7 Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents: 28
diff changeset
308 incpat
99
26450200777a Latest textmate.el
Augie Fackler <durin42@gmail.com>
parents: 49
diff changeset
309 "' -- "
49
60dbe5b005cc Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents: 30
diff changeset
310 (shell-quote-argument re)
60dbe5b005cc Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents: 30
diff changeset
311 " . | grep -vE '"
29
e5f414619ea7 Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents: 28
diff changeset
312 *textmate-gf-exclude*
e5f414619ea7 Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents: 28
diff changeset
313 "' | sed s:./::"
e5f414619ea7 Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents: 28
diff changeset
314 )))))
157
95b7dc384677 textmate.el: bring in upstream changes
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
315 (setq *textmate-find-in-project-default* re)
95b7dc384677 textmate.el: bring in upstream changes
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
316 (textmate-start-compile-in-root command 'grep-mode)))
28
260deb14fbc8 Add textmate-find-in-project.
Augie Fackler <durin42@gmail.com>
parents: 25
diff changeset
317
22
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
318 (defun textmate-clear-cache ()
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
319 (interactive)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
320 (setq *textmate-project-root* nil)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
321 (setq *textmate-project-files* nil)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
322 (message "textmate-mode cache cleared."))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
323
24
d6fd2964258c New version of textmate.el
Augie Fackler <durin42@gmail.com>
parents: 22
diff changeset
324 (defun textmate-toggle-camel-case ()
d6fd2964258c New version of textmate.el
Augie Fackler <durin42@gmail.com>
parents: 22
diff changeset
325 "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
326 (interactive)
d6fd2964258c New version of textmate.el
Augie Fackler <durin42@gmail.com>
parents: 22
diff changeset
327 (if (thing-at-point 'word)
d6fd2964258c New version of textmate.el
Augie Fackler <durin42@gmail.com>
parents: 22
diff changeset
328 (progn
49
60dbe5b005cc Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents: 30
diff changeset
329 (unless (looking-at "\\<") (backward-sexp))
60dbe5b005cc Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents: 30
diff changeset
330 (let ((case-fold-search nil)
60dbe5b005cc Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents: 30
diff changeset
331 (start (point))
60dbe5b005cc Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents: 30
diff changeset
332 (end (save-excursion (forward-sexp) (point))))
60dbe5b005cc Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents: 30
diff changeset
333 (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
334 (progn
60dbe5b005cc Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents: 30
diff changeset
335 (goto-char start)
60dbe5b005cc Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents: 30
diff changeset
336 (while (re-search-forward "_[a-z]" end t)
60dbe5b005cc Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents: 30
diff changeset
337 (goto-char (1- (point)))
60dbe5b005cc Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents: 30
diff changeset
338 (delete-char -1)
60dbe5b005cc Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents: 30
diff changeset
339 (upcase-region (point) (1+ (point)))
60dbe5b005cc Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents: 30
diff changeset
340 (setq end (1- end))))
60dbe5b005cc Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents: 30
diff changeset
341 (downcase-region (point) (1+ (point)))
60dbe5b005cc Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents: 30
diff changeset
342 (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
343 (forward-char -2)
60dbe5b005cc Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents: 30
diff changeset
344 (insert "_")
60dbe5b005cc Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents: 30
diff changeset
345 (downcase-region (point) (1+ (point)))
60dbe5b005cc Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents: 30
diff changeset
346 (forward-char 1)
60dbe5b005cc Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents: 30
diff changeset
347 (setq end (1+ end)))
60dbe5b005cc Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents: 30
diff changeset
348 (downcase-region start end)
60dbe5b005cc Fix a bug in shell quoting.
Augie Fackler <durin42@gmail.com>
parents: 30
diff changeset
349 )))))
24
d6fd2964258c New version of textmate.el
Augie Fackler <durin42@gmail.com>
parents: 22
diff changeset
350
22
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
351 ;;; Utilities
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
352
29
e5f414619ea7 Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents: 28
diff changeset
353 (defun textmate-project-root-type (root)
e5f414619ea7 Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents: 28
diff changeset
354 (cond ((member ".git" (directory-files root)) "git")
e5f414619ea7 Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents: 28
diff changeset
355 ((member ".hg" (directory-files root)) "hg")
e5f414619ea7 Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents: 28
diff changeset
356 (t "unknown")
e5f414619ea7 Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents: 28
diff changeset
357 ))
e5f414619ea7 Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents: 28
diff changeset
358
22
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
359 (defun textmate-project-files (root)
29
e5f414619ea7 Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents: 28
diff changeset
360 (let ((type (textmate-project-root-type root)))
e5f414619ea7 Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents: 28
diff changeset
361 (cond ((string= type "git") (split-string
e5f414619ea7 Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents: 28
diff changeset
362 (shell-command-to-string
e5f414619ea7 Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents: 28
diff changeset
363 (concat "cd " root " && git ls-files")) "\n" t))
e5f414619ea7 Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents: 28
diff changeset
364 ((string= type "hg") (split-string
e5f414619ea7 Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents: 28
diff changeset
365 (shell-command-to-string
e5f414619ea7 Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents: 28
diff changeset
366 (concat "cd " root " && hg manifest")) "\n" t))
e5f414619ea7 Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents: 28
diff changeset
367 ((string= type "unknown") (textmate-cached-project-files-find root))
e5f414619ea7 Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents: 28
diff changeset
368 )))
e5f414619ea7 Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents: 28
diff changeset
369
e5f414619ea7 Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents: 28
diff changeset
370 (defun textmate-project-files-find (root)
22
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
371 (split-string
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
372 (shell-command-to-string
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
373 (concat
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
374 "find "
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
375 root
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
376 " -type f | grep -vE '"
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
377 *textmate-gf-exclude*
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
378 "' | sed 's:"
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
379 *textmate-project-root*
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
380 "/::'")) "\n" t))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
381
29
e5f414619ea7 Latest version of textmate.el
Augie Fackler <durin42@gmail.com>
parents: 28
diff changeset
382 (defun textmate-cached-project-files-find (&optional root)
22
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
383 (cond
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
384 ((null textmate-use-file-cache) (textmate-project-files root))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
385 ((equal (textmate-project-root) (car *textmate-project-files*))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
386 (cdr *textmate-project-files*))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
387 (t (cdr (setq *textmate-project-files*
134
fe9d358b9fe8 textmate.el: Fix an infinite recursion bug when not using a supported VCS
Augie Fackler <durin42@gmail.com>
parents: 99
diff changeset
388 `(,root . ,(textmate-project-files-find root)))))))
22
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
389
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
390 (defun textmate-project-root ()
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
391 (when (or
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
392 (null *textmate-project-root*)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
393 (not (string-match *textmate-project-root* default-directory)))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
394 (let ((root (textmate-find-project-root)))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
395 (if root
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
396 (setq *textmate-project-root* (expand-file-name (concat root "/")))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
397 (setq *textmate-project-root* nil))))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
398 *textmate-project-root*)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
399
141
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
400 (defun root-match(root names)
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
401 (member (car names) (directory-files root)))
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
402
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
403 (defun root-matches(root names)
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
404 (if (root-match root names)
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
405 (root-match root names)
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
406 (if (eq (length (cdr names)) 0)
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
407 'nil
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
408 (root-matches root (cdr names))
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
409 )))
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
410
22
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
411 (defun textmate-find-project-root (&optional root)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
412 (when (null root) (setq root default-directory))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
413 (cond
141
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
414 ((root-matches root *textmate-project-roots*)
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
415 (expand-file-name root))
22
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
416 ((equal (expand-file-name root) "/") nil)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
417 (t (textmate-find-project-root (concat (file-name-as-directory root) "..")))))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
418
141
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
419 (defun textmate-shift-right (&optional arg)
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
420 "Shift the line or region to the ARG places to the right.
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
421
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
422 A place is considered `tab-width' character columns."
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
423 (interactive)
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
424 (let ((deactivate-mark nil)
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
425 (beg (or (and mark-active (region-beginning))
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
426 (line-beginning-position)))
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
427 (end (or (and mark-active (region-end)) (line-end-position))))
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
428 (indent-rigidly beg end (* (or arg 1) tab-width))))
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
429
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
430 (defun textmate-shift-left (&optional arg)
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
431 "Shift the line or region to the ARG places to the left."
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
432 (interactive)
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
433 (textmate-shift-right (* -1 (or arg 1))))
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
434
22
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
435 ;;;###autoload
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
436 (define-minor-mode textmate-mode "TextMate Emulation Minor Mode"
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
437 :lighter " mate" :global t :keymap *textmate-mode-map*
141
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
438 (add-hook 'ido-setup-hook 'textmate-ido-fix)
e30655eb7050 textmate.el: synced with upstream
Augie Fackler <durin42@gmail.com>
parents: 134
diff changeset
439 (textmate-define-comment-line)
22
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
440 ; activate preferred completion library
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
441 (dolist (mode *textmate-completing-minor-mode-alist*)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
442 (if (eq (car mode) textmate-completing-library)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
443 (funcall (cadr mode) t)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
444 (when (fboundp
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
445 (cadr (assoc (car mode) *textmate-completing-function-alist*)))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
446 (funcall (cadr mode) -1)))))
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
447
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
448 (provide 'textmate)
8715ccb6f61b Start using textmate.el.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
449 ;;; textmate.el ends here