comparison .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
comparison
equal deleted inserted replaced
156:59ea03d7029a 157:95b7dc384677
136 136
137 (defvar *textmate-find-in-project-default* nil) 137 (defvar *textmate-find-in-project-default* nil)
138 138
139 (defvar *textmate-find-in-project-type-default* nil) 139 (defvar *textmate-find-in-project-type-default* nil)
140 140
141 (defvar *textmate-compile-default* nil)
142
141 ;;; Bindings 143 ;;; Bindings
142 144
143 (defun textmate-ido-fix () 145 (defun textmate-ido-fix ()
144 "Add up/down keybindings for ido." 146 "Add up/down keybindings for ido."
145 (define-key ido-completion-map [up] 'ido-prev-match) 147 (define-key ido-completion-map [up] 'ido-prev-match)
238 (textmate-completing-read 240 (textmate-completing-read
239 "Find file: " 241 "Find file: "
240 (textmate-project-files root)))))) 242 (textmate-project-files root))))))
241 243
242 (defun textmate-find-in-project-type () 244 (defun textmate-find-in-project-type ()
245 "Run grep over project files of a specific type and put the results
246 in a grep-mode buffer."
243 (interactive) 247 (interactive)
244 (let ((pat (read-string (concat "Suffix" 248 (let ((pat (read-string (concat "Suffix"
245 (if *textmate-find-in-project-type-default* 249 (if *textmate-find-in-project-type-default*
246 (format " [\"%s\"]" *textmate-find-in-project-type-default*) 250 (format " [\"%s\"]" *textmate-find-in-project-type-default*)
247 "") 251 "")
248 ": " 252 ": "
249 ) nil nil *textmate-find-in-project-type-default*))) 253 ) nil nil *textmate-find-in-project-type-default*)))
250 (setq *textmate-find-in-project-type-default* pat) 254 (setq *textmate-find-in-project-type-default* pat)
251 (textmate-find-in-project (concat "*." pat)))) 255 (textmate-find-in-project (concat "*." pat))))
252 256
253 (defun textmate-find-in-project (&optional pattern) 257 (defun textmate-start-compile-in-root (command &optional mode
254 (interactive) 258 name-function
255 (let ((root (textmate-project-root)) 259 highlight-regexp)
256 (default *textmate-find-in-project-default*) 260 "Idential to compilation-start, except it automatically changes to the
257 ) 261 project root directory before starting the command."
262 (let ((root (textmate-project-root)))
258 (when (null root) 263 (when (null root)
259 (error "Not in a project area.")) 264 (error "Not in a project area."))
260 (let ((re (read-string (concat "Search for " 265 (let ((realcommand (concat "cd " root " ; " command)))
266 (compilation-start realcommand mode name-function highlight-regexp))))
267
268 (defun textmate-compile ()
269 "Run a command in compilation-mode rooted at the project root."
270 (interactive)
271 (let* ((default *textmate-compile-default*)
272 (command (read-string
273 (concat "Command"
274 (if default (format " [\"%s\"]" default) "")
275 ": ") nil 'textmate-compile-history default)))
276 (setq *textmate-compile-default* command)
277 (textmate-start-compile-in-root command)))
278
279 (defun textmate-find-in-project (&optional pattern)
280 "Run grep over project files with results in grep-mode.
281
282 Takes an optional argument (see also textmate-find-in-project-type)
283 of a file extension to limit the search. Useful for finding results in only a
284 specific type of file."
285 (interactive)
286 (let* ((default *textmate-find-in-project-default*)
287 (re (read-string (concat "Search for "
261 (if (and default (> (length default) 0)) 288 (if (and default (> (length default) 0))
262 (format "[\"%s\"]" default)) ": ") 289 (format "[\"%s\"]" default)) ": ")
263 nil 'textmate-find-in-project-history default) 290 nil 'textmate-find-in-project-history default))
264 ) 291 (incpat (if pattern pattern "*"))
265 (incpat (if pattern pattern "*"))) 292 (type (textmate-project-root-type (textmate-project-root)))
266 (append textmate-find-in-project-history (list re)) 293 (command
267 (setq *textmate-find-in-project-default* re) 294 (cond ((not (string= type "unknown"))
268 (let ((type (textmate-project-root-type root))) 295 (concat (cond ((string= type "git") "git ls-files")
269 (let ((command
270 (cond ((not (string= type "unknown"))
271 (concat "cd "
272 root
273 " ; "
274 (cond ((string= type "git") "git ls-files")
275 ((string= type "hg") "hg manifest")) 296 ((string= type "hg") "hg manifest"))
276 (if *textmate-vcs-exclude* 297 (if *textmate-vcs-exclude*
277 (concat " | grep -v " (shell-quote-argument *textmate-vcs-exclude*)) 298 (concat " | grep -v "
299 (shell-quote-argument *textmate-vcs-exclude*))
278 "") 300 "")
279 " | xargs grep -nR " 301 " | xargs egrep -nR "
280 (if pattern (concat " --include='" pattern "' ") "") 302 (if pattern (concat " --include='" pattern "' ") "")
281 " -- " 303 " -- "
282 (shell-quote-argument re))) 304 (shell-quote-argument re)))
283 (t (concat "cd " root "; egrep -nR --exclude='" 305 (t (concat "egrep -nR --exclude='"
284 *textmate-gf-exclude* 306 *textmate-gf-exclude*
285 "' --include='" 307 "' --include='"
286 incpat 308 incpat
287 "' -- " 309 "' -- "
288 (shell-quote-argument re) 310 (shell-quote-argument re)
289 " . | grep -vE '" 311 " . | grep -vE '"
290 *textmate-gf-exclude* 312 *textmate-gf-exclude*
291 "' | sed s:./::" 313 "' | sed s:./::"
292 ))))) 314 )))))
293 (compilation-start command 'grep-mode))) 315 (setq *textmate-find-in-project-default* re)
294 ))) 316 (textmate-start-compile-in-root command 'grep-mode)))
295 317
296 (defun textmate-clear-cache () 318 (defun textmate-clear-cache ()
297 (interactive) 319 (interactive)
298 (setq *textmate-project-root* nil) 320 (setq *textmate-project-root* nil)
299 (setq *textmate-project-files* nil) 321 (setq *textmate-project-files* nil)