diff --git a/core/prelude-core.el b/core/prelude-core.el index 5e3beff..ea65f51 100644 --- a/core/prelude-core.el +++ b/core/prelude-core.el @@ -483,5 +483,54 @@ With a prefix argument ARG, find the `user-init-file' instead." (interactive "P") (sp-wrap-with-pair ,s))) +(defun prelude-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) + (prelude-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))) + (recenter))) + ((listp symbol-list) + (dolist (symbol symbol-list) + (let (name position) + (cond + ((and (listp symbol) (imenu--subalist-p symbol)) + (prelude-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 (substring-no-properties name)) + (add-to-list 'name-and-pos (cons (substring-no-properties name) position)))))))) + (provide 'prelude-core) ;;; prelude-core.el ends here diff --git a/core/prelude-mode.el b/core/prelude-mode.el index caab80b..ab3eeb4 100644 --- a/core/prelude-mode.el +++ b/core/prelude-mode.el @@ -63,6 +63,7 @@ (define-key map (kbd "C-c TAB") 'prelude-indent-rigidly-and-copy-to-clipboard) (define-key map (kbd "C-c I") 'prelude-find-user-init-file) (define-key map (kbd "C-c S") 'prelude-find-shell-init-file) + (define-key map (kbd "C-c i") 'prelude-ido-goto-symbol) ;; extra prefix for projectile (define-key map (kbd "s-p") 'projectile-command-map) ;; make some use of the Super key diff --git a/modules/prelude-programming.el b/modules/prelude-programming.el index cb445aa..b303430 100644 --- a/modules/prelude-programming.el +++ b/modules/prelude-programming.el @@ -34,58 +34,9 @@ (prelude-require-packages '(guru-mode)) -(defun prelude-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) - (prelude-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))) - (recenter))) - ((listp symbol-list) - (dolist (symbol symbol-list) - (let (name position) - (cond - ((and (listp symbol) (imenu--subalist-p symbol)) - (prelude-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 (substring-no-properties name)) - (add-to-list 'name-and-pos (cons (substring-no-properties name) position)))))))) - ;; add a shortcut for prelude-ido-goto-symbol (eval-after-load 'prelude-mode - '(define-key prelude-mode-map (kbd "C-c i") 'prelude-ido-goto-symbol)) + ') (defun prelude-local-comment-auto-fill () (set (make-local-variable 'comment-auto-fill-only-comments) t))