Skip to content

Commit

Permalink
I had an improved varation on this in my emacs setup. No idea where i…
Browse files Browse the repository at this point in the history
…t is from.
  • Loading branch information
durin42 authored and defunkt committed Sep 19, 2009
1 parent acd2019 commit 44ee782
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions textmate.el
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ function."

;; http://chopmo.blogspot.com/2008/09/quickly-jumping-to-symbols.html
(defun textmate-goto-symbol ()
"Will update the imenu index then use your completing read to jump to a symbol."
"Update the imenu index and then use ido to select a symbol to navigate to.
Symbols matching the text at point are put first in the completion list."
(interactive)
(imenu--make-index-alist)
(let ((name-and-pos '())
Expand All @@ -210,7 +211,18 @@ function."
(add-to-list 'symbol-names name)
(add-to-list 'name-and-pos (cons name position))))))))
(addsymbols imenu--index-alist))
(let* ((selected-symbol (textmate-completing-read "Symbol: " 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))))
(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))))
matching-symbols)))))
(let* ((selected-symbol (ido-completing-read "Symbol? " symbol-names))
(position (cdr (assoc selected-symbol name-and-pos))))
(goto-char position))))

Expand Down

0 comments on commit 44ee782

Please sign in to comment.