Skip to content

Commit

Permalink
80c + whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
defunkt committed Feb 17, 2010
1 parent 44ee782 commit 9e21143
Showing 1 changed file with 53 additions and 44 deletions.
97 changes: 53 additions & 44 deletions textmate.el
Expand Up @@ -13,7 +13,7 @@
;;; Commentary:

;; This minor mode exists to mimick TextMate's awesome
;; features.
;; features.

;; ⌘T - Go to File
;; ⇧⌘T - Go to Symbol
Expand All @@ -32,12 +32,12 @@
;; You can configure what makes a project root by appending a file
;; or directory name onto the `*textmate-project-roots*' list.

;; If no project root indicator is found in your current directory,
;; If no project root indicator is found in your current directory,
;; textmate-mode will traverse upwards until one (or none) is found.
;; The directory housing the project root indicator (e.g. a .git or .hg
;; directory) is presumed to be the project's root.

;; In other words, calling Go to File from
;; In other words, calling Go to File from
;; ~/Projects/fieldrunners/app/views/towers/show.html.erb will use
;; ~/Projects/fieldrunners/ as the root if ~/Projects/fieldrunners/.git
;; exists.
Expand All @@ -62,7 +62,7 @@

;;; Minor mode

(defvar *textmate-gf-exclude*
(defvar *textmate-gf-exclude*
"/\\.|vendor|fixtures|tmp|log|build|\\.xcodeproj|\\.nib|\\.framework|\\.app|\\.pbproj|\\.pbxproj|\\.xcode|\\.xcodeproj|\\.bundle|\\.pyc"
"Regexp of files to exclude from `textmate-goto-file'.")

Expand All @@ -73,18 +73,18 @@
(defvar textmate-use-file-cache t
"Should `textmate-goto-file' keep a local cache of files?")

(defvar textmate-completing-library 'ido
"The library `textmade-goto-symbol' and `textmate-goto-file' should use for
(defvar textmate-completing-library 'ido
"The library `textmade-goto-symbol' and `textmate-goto-file' should use for
completing filenames and symbols (`ido' by default)")

(defvar *textmate-completing-function-alist* '((ido ido-completing-read)
(icicles icicle-completing-read)
(none completing-read))
(defvar *textmate-completing-function-alist* '((ido ido-completing-read)
(icicles icicle-completing-read)
(none completing-read))
"The function to call to read file names and symbols from the user")

(defvar *textmate-completing-minor-mode-alist*
`((ido ,(lambda (a) (progn (ido-mode a) (setq ido-enable-flex-matching t))))
(icicles ,(lambda (a) (icy-mode a)))
(defvar *textmate-completing-minor-mode-alist*
`((ido ,(lambda (a) (progn (ido-mode a) (setq ido-enable-flex-matching t))))
(icicles ,(lambda (a) (icy-mode a)))
(none ,(lambda (a) ())))
"The list of functions to enable and disable completing minor modes")

Expand Down Expand Up @@ -146,8 +146,8 @@ completing filenames and symbols (`ido' by default)")
(defun textmate-completing-read (&rest args)
"Uses `*textmate-completing-function-alist*' to call the appropriate completing
function."
(let ((reading-fn
(cadr (assoc textmate-completing-library
(let ((reading-fn
(cadr (assoc textmate-completing-library
*textmate-completing-function-alist*))))
(apply (symbol-function reading-fn) args)))

Expand All @@ -157,13 +157,14 @@ function."
;;; and is licensed under the GPL

(defmacro allow-line-as-region-for-function (orig-function)
`(defun ,(intern (concat (symbol-name orig-function) "-or-line"))
`(defun ,(intern (concat (symbol-name orig-function) "-or-line"))
()
,(format "Like `%s', but acts on the current line if mark is not active." orig-function)
,(format "Like `%s', but acts on the current line if mark is not active."
orig-function)
(interactive)
(if mark-active
(call-interactively (function ,orig-function))
(save-excursion
(save-excursion
;; define a region (temporarily) -- so any C-u prefixes etc. are preserved.
(beginning-of-line)
(set-mark (point))
Expand Down Expand Up @@ -198,29 +199,37 @@ Symbols matching the text at point are put first in the completion list."
(cond
((and (listp symbol) (imenu--subalist-p symbol))
(addsymbols symbol))

((listp symbol)
(setq name (car symbol))
(setq position (cdr symbol)))

((stringp symbol)
(setq name symbol)
(setq position (get-text-property 1 'org-imenu-marker symbol))))

(setq position
(get-text-property 1 'org-imenu-marker
symbol))))

(unless (or (null position) (null name))
(add-to-list 'symbol-names name)
(add-to-list 'name-and-pos (cons name position))))))))
(addsymbols imenu--index-alist))
;; If there are matching symbols at point, put them at the beginning of `symbol-names'.
;; If there are matching symbols at point, put them at the beginning
;; of `symbol-names'.
(let ((symbol-at-point (thing-at-point 'symbol)))
(when symbol-at-point
(let* ((regexp (concat (regexp-quote symbol-at-point) "$"))
(matching-symbols (delq nil (mapcar (lambda (symbol)
(if (string-match regexp symbol) symbol))
symbol-names))))
(matching-symbols (delq nil
(mapcar
(lambda (symbol)
(if (string-match regexp symbol)
symbol))
symbol-names))))
(when matching-symbols
(sort matching-symbols (lambda (a b) (> (length a) (length b))))
(mapc (lambda (symbol) (setq symbol-names (cons symbol (delete symbol symbol-names))))
(mapc (lambda (symbol)
(setq symbol-names (cons symbol
(delete symbol symbol-names))))
matching-symbols)))))
(let* ((selected-symbol (ido-completing-read "Symbol? " symbol-names))
(position (cdr (assoc selected-symbol name-and-pos))))
Expand All @@ -231,15 +240,15 @@ Symbols matching the text at point are put first in the completion list."
(interactive)
(let ((root (textmate-project-root)))
(when (null root)
(error
(concat
"Can't find a suitable project root ("
(error
(concat
"Can't find a suitable project root ("
(string-join " " *textmate-project-roots* )
")")))
(find-file
(concat
(find-file
(concat
(expand-file-name root) "/"
(textmate-completing-read
(textmate-completing-read
"Find file: "
(textmate-cached-project-files root))))))

Expand All @@ -254,15 +263,15 @@ Symbols matching the text at point are put first in the completion list."

(defun textmate-project-files (root)
"Finds all files in a given project."
(split-string
(shell-command-to-string
(concat
"find "
(split-string
(shell-command-to-string
(concat
"find "
root
" -type f | grep -vE '"
*textmate-gf-exclude*
"' | sed 's:"
*textmate-project-root*
*textmate-project-root*
"/::'")) "\n" t))

(defun textmate-cached-project-files (&optional root)
Expand All @@ -271,13 +280,13 @@ Symbols matching the text at point are put first in the completion list."
((null textmate-use-file-cache) (textmate-project-files root))
((equal (textmate-project-root) (car *textmate-project-files*))
(cdr *textmate-project-files*))
(t (cdr (setq *textmate-project-files*
(t (cdr (setq *textmate-project-files*
`(,root . ,(textmate-project-files root)))))))

(defun textmate-project-root ()
"Returns the current project root."
(when (or
(null *textmate-project-root*)
(when (or
(null *textmate-project-root*)
(not (string-match *textmate-project-root* default-directory)))
(let ((root (textmate-find-project-root)))
(if root
Expand All @@ -289,15 +298,15 @@ Symbols matching the text at point are put first in the completion list."
(member (car names) (directory-files root)))

(defun root-matches(root names)
(if (root-match root names)
(root-match root names)
(if (root-match root names)
(root-match root names)
(if (eq (length (cdr names)) 0)
'nil
(root-matches root (cdr names))
)))

(defun textmate-find-project-root (&optional root)
"Determines the current project root by recursively searching for an indicator."
"Determines the current project root by recursively searching for an indicator."
(when (null root) (setq root default-directory))
(cond
((root-matches root *textmate-project-roots*)
Expand Down Expand Up @@ -330,7 +339,7 @@ A place is considered `tab-width' character columns."
(dolist (mode *textmate-completing-minor-mode-alist*)
(if (eq (car mode) textmate-completing-library)
(funcall (cadr mode) t)
(when (fboundp
(when (fboundp
(cadr (assoc (car mode) *textmate-completing-function-alist*)))
(funcall (cadr mode) -1)))))

Expand Down

0 comments on commit 9e21143

Please sign in to comment.