Last active
June 8, 2019 04:13
-
-
Save tonini/473ecfaf29e136a94698 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; From: http://www.emacswiki.org/emacs/ImenuMode | |
| ;; Overview | |
| ;; Imenu produces menus for accessing locations in documents, typically in the current buffer. | |
| ;; You can access the locations using an ordinary menu (menu bar or other) or using minibuffer completion. | |
| ;; A typical use of Imenu shows a menu-bar menu that is an index or table of contents for the current buffer. | |
| ;; For a source-code buffer it is typical to index definitions of functions, variables, and so on. | |
| ;; You can use Imenu with any major mode and any programming language or document type. | |
| ;; If there is no Imenu support | |
| ;; for your context, you can add it using EmacsLisp and the constructs provided in library imenu.el. | |
| ;; There are two ways to generate an Imenu menu (index): | |
| ;; Provide regexps that match the locations to index. See variable ‘imenu-generic-expression’. | |
| ;; Provide a function that generates the index. See variable ‘imenu-create-index-function’. | |
| ;; For a source-code buffer the locations to index are typically definitions of functions, variables, | |
| ;; and so on. For a text or markup buffer (e.g. LaTeX) the locations might be section headings. | |
| ;; You can use an EmacsLisp marker as a target destination, so that targets need not be limited | |
| ;; to the current buffer. | |
| ;; http://www.emacswiki.org/emacs/ImenuMode | |
| ;; http://www.gnu.org/software/emacs/manual/html_node/emacs/Imenu.html | |
| ;; source: http://www.emacswiki.org/emacs/ImenuMode | |
| ;; by shjk (updated by MattKeller to handle overlays as “positions”; updated by VegardOye to set the mark before jumping). | |
| (defun ido-goto-symbol (&optional symbol-list) | |
| "Refresh imenu and jump to a place in the buffer using Ido." | |
| (interactive) | |
| (unless (featurep 'imenu) | |
| (require 'imenu nil t)) | |
| (cond | |
| ((not symbol-list) | |
| (let ((ido-mode ido-mode) | |
| (ido-enable-flex-matching | |
| (if (boundp 'ido-enable-flex-matching) | |
| ido-enable-flex-matching t)) | |
| name-and-pos symbol-names position) | |
| (unless ido-mode | |
| (ido-mode 1) | |
| (setq ido-enable-flex-matching t)) | |
| (while (progn | |
| (imenu--cleanup) | |
| (setq imenu--index-alist nil) | |
| (ido-goto-symbol (imenu--make-index-alist)) | |
| (setq selected-symbol | |
| (ido-completing-read "Symbol? " symbol-names)) | |
| (string= (car imenu--rescan-item) selected-symbol))) | |
| (unless (and (boundp 'mark-active) mark-active) | |
| (push-mark nil t nil)) | |
| (setq position (cdr (assoc selected-symbol name-and-pos))) | |
| (cond | |
| ((overlayp position) | |
| (goto-char (overlay-start position))) | |
| (t | |
| (goto-char position))))) | |
| ((listp symbol-list) | |
| (dolist (symbol symbol-list) | |
| (let (name position) | |
| (cond | |
| ((and (listp symbol) (imenu--subalist-p symbol)) | |
| (ido-goto-symbol 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)))) | |
| (unless (or (null position) (null name) | |
| (string= (car imenu--rescan-item) name)) | |
| (add-to-list 'symbol-names name) | |
| (add-to-list 'name-and-pos (cons name position)))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment