X-Git-Url: https://iankelling.org/git/?a=blobdiff_plain;f=dev.org;h=0b2998857d8cdc6b9463a1bae3728f2c8e40a815;hb=23b4a1a660d78999f72019414fc669239b8eed55;hp=f7bceddefa035cc386b305d4ded56b737a10acb8;hpb=f2df0ec96647b7545b09dab8a8792ddefd3c5ce3;p=dot-emacs diff --git a/dev.org b/dev.org index f7bcedd..0b29988 100644 --- a/dev.org +++ b/dev.org @@ -4,5 +4,118 @@ and since it's pretty big, it's a bit annoying. We need at least one of these, even a blank one to avoid error on startup. #+begin_src emacs-lisp +(ivy-mode 1) +(add-hook 'text-mode-hook (lambda () (auto-fill-mode t))) +#+end_src + + +* ido +#+begin_src emacs-lisp + +;; easier to read, and more than the default 12 +(setq ido-separator nil) +(setq ido-max-prospects 20) + +(ido-mode t) +(ido-everywhere t) ;; file dialogs + +;; do out of order matching when all else fails +(setq ido-enable-flex-matching t + ido-create-new-buffer 'always ;; create new buffer/file without asking + ido-use-filename-at-point 'guess ;; use filename at point if it makes sense + ido-save-directory-list-file "~/.emacs.d/.ido.last" + ido-default-file-method 'selected-window) ;; make duplicate windows +;; todo, the next 2 functions seem to do roughly the same. +;; figure out which one is better. the first comes from emacs starter kit, +;; i forget about the second. +(defun ido-imenu () + "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 '()) + (symbol-names '())) + (cl-flet ((addsymbols (symbol-list) + (when (listp symbol-list) + (dolist (symbol symbol-list) + (let ((name nil) (position nil)) + (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)))) + + (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'. + (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)))) + +(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 (substring-no-properties name)) + (add-to-list 'name-and-pos (cons (substring-no-properties name) position)))))))) #+end_src