various fixes
[dot-emacs] / dev.org
1 Things in development in this separate file, because
2 we recompile / reparse my-init.org whenever it changes,
3 and since it's pretty big, it's a bit annoying.
4
5 We need at least one of these, even a blank one to avoid error on startup.
6 #+begin_src emacs-lisp
7 (ivy-mode 1)
8 (add-hook 'text-mode-hook (lambda () (auto-fill-mode t)))
9 #+end_src
10
11
12 * ido
13 #+begin_src emacs-lisp
14
15 ;; easier to read, and more than the default 12
16 (setq ido-separator nil)
17 (setq ido-max-prospects 20)
18
19 (ido-mode t)
20 (ido-everywhere t) ;; file dialogs
21
22 ;; do out of order matching when all else fails
23 (setq ido-enable-flex-matching t
24 ido-create-new-buffer 'always ;; create new buffer/file without asking
25 ido-use-filename-at-point 'guess ;; use filename at point if it makes sense
26 ido-save-directory-list-file "~/.emacs.d/.ido.last"
27 ido-default-file-method 'selected-window) ;; make duplicate windows
28 ;; todo, the next 2 functions seem to do roughly the same.
29 ;; figure out which one is better. the first comes from emacs starter kit,
30 ;; i forget about the second.
31 (defun ido-imenu ()
32 "Update the imenu index and then use ido to select a symbol to navigate to.
33 Symbols matching the text at point are put first in the completion list."
34 (interactive)
35 (imenu--make-index-alist)
36 (let ((name-and-pos '())
37 (symbol-names '()))
38 (cl-flet ((addsymbols (symbol-list)
39 (when (listp symbol-list)
40 (dolist (symbol symbol-list)
41 (let ((name nil) (position nil))
42 (cond
43 ((and (listp symbol) (imenu--subalist-p symbol))
44 (addsymbols symbol))
45
46 ((listp symbol)
47 (setq name (car symbol))
48 (setq position (cdr symbol)))
49
50 ((stringp symbol)
51 (setq name symbol)
52 (setq position (get-text-property 1 'org-imenu-marker symbol))))
53
54 (unless (or (null position) (null name))
55 (add-to-list 'symbol-names name)
56 (add-to-list 'name-and-pos (cons name position))))))))
57 (addsymbols imenu--index-alist))
58 ;; If there are matching symbols at point, put them at the beginning of `symbol-names'.
59 (let ((symbol-at-point (thing-at-point 'symbol)))
60 (when symbol-at-point
61 (let* ((regexp (concat (regexp-quote symbol-at-point) "$"))
62 (matching-symbols (delq nil (mapcar (lambda (symbol)
63 (if (string-match regexp symbol) symbol))
64 symbol-names))))
65 (when matching-symbols
66 (sort matching-symbols (lambda (a b) (> (length a) (length b))))
67 (mapc (lambda (symbol) (setq symbol-names (cons symbol (delete symbol symbol-names))))
68 matching-symbols)))))
69 (let* ((selected-symbol (ido-completing-read "Symbol? " symbol-names))
70 (position (cdr (assoc selected-symbol name-and-pos))))
71 (goto-char position))))
72
73 (defun ido-goto-symbol (&optional symbol-list)
74 "Refresh imenu and jump to a place in the buffer using Ido."
75 (interactive)
76 (unless (featurep 'imenu)
77 (require 'imenu nil t))
78 (cond
79 ((not symbol-list)
80 (let ((ido-mode ido-mode)
81 (ido-enable-flex-matching
82 (if (boundp 'ido-enable-flex-matching)
83 ido-enable-flex-matching t))
84 name-and-pos symbol-names position)
85 (unless ido-mode
86 (ido-mode 1)
87 (setq ido-enable-flex-matching t))
88 (while (progn
89 (imenu--cleanup)
90 (setq imenu--index-alist nil)
91 (ido-goto-symbol (imenu--make-index-alist))
92 (setq selected-symbol
93 (ido-completing-read "Symbol? " symbol-names))
94 (string= (car imenu--rescan-item) selected-symbol)))
95 (unless (and (boundp 'mark-active) mark-active)
96 (push-mark nil t nil))
97 (setq position (cdr (assoc selected-symbol name-and-pos)))
98 (cond
99 ((overlayp position)
100 (goto-char (overlay-start position)))
101 (t
102 (goto-char position)))))
103 ((listp symbol-list)
104 (dolist (symbol symbol-list)
105 (let (name position)
106 (cond
107 ((and (listp symbol) (imenu--subalist-p symbol))
108 (ido-goto-symbol symbol))
109 ((listp symbol)
110 (setq name (car symbol))
111 (setq position (cdr symbol)))
112 ((stringp symbol)
113 (setq name symbol)
114 (setq position
115 (get-text-property 1 'org-imenu-marker symbol))))
116 (unless (or (null position) (null name)
117 (string= (car imenu--rescan-item) name))
118 (add-to-list 'symbol-names (substring-no-properties name))
119 (add-to-list 'name-and-pos (cons (substring-no-properties name) position))))))))
120
121 #+end_src