Mercurial > dotfiles
annotate .elisp/settings/50.localfuncs.el @ 501:514374a2a5bc
emacs: migrate rust config to use rls and lsp
author | Augie Fackler <raf@durin42.com> |
---|---|
date | Sat, 03 Oct 2020 11:30:21 -0400 |
parents | 026344f083ef |
children |
rev | line source |
---|---|
180
cd4e645d1207
emacs localfuncs: add advice for ido to avoid blocking in flex matching
Augie Fackler <durin42@gmail.com>
parents:
158
diff
changeset
|
1 ;; advice to prevent ido from using flex matches on huge lists of files |
cd4e645d1207
emacs localfuncs: add advice for ido to avoid blocking in flex matching
Augie Fackler <durin42@gmail.com>
parents:
158
diff
changeset
|
2 ;; with enough characters typed and blocking for an absurd amount of time |
cd4e645d1207
emacs localfuncs: add advice for ido to avoid blocking in flex matching
Augie Fackler <durin42@gmail.com>
parents:
158
diff
changeset
|
3 ;; after a stupid typo |
cd4e645d1207
emacs localfuncs: add advice for ido to avoid blocking in flex matching
Augie Fackler <durin42@gmail.com>
parents:
158
diff
changeset
|
4 ;; The value af-ido-flex-fuzzy-limit is the maximum value of the product |
cd4e645d1207
emacs localfuncs: add advice for ido to avoid blocking in flex matching
Augie Fackler <durin42@gmail.com>
parents:
158
diff
changeset
|
5 ;; of the number of characters the user has entered and the number of |
cd4e645d1207
emacs localfuncs: add advice for ido to avoid blocking in flex matching
Augie Fackler <durin42@gmail.com>
parents:
158
diff
changeset
|
6 ;; options in the ido list. |
cd4e645d1207
emacs localfuncs: add advice for ido to avoid blocking in flex matching
Augie Fackler <durin42@gmail.com>
parents:
158
diff
changeset
|
7 ;; The default value was determined experimentally and seemed to be |
cd4e645d1207
emacs localfuncs: add advice for ido to avoid blocking in flex matching
Augie Fackler <durin42@gmail.com>
parents:
158
diff
changeset
|
8 ;; the boundary of sane wait times when this was written. |
cd4e645d1207
emacs localfuncs: add advice for ido to avoid blocking in flex matching
Augie Fackler <durin42@gmail.com>
parents:
158
diff
changeset
|
9 (defvar af-ido-flex-fuzzy-limit (* 2000 5)) |
cd4e645d1207
emacs localfuncs: add advice for ido to avoid blocking in flex matching
Augie Fackler <durin42@gmail.com>
parents:
158
diff
changeset
|
10 (defadvice ido-set-matches-1 (around my-ido-set-matches-1 activate) |
cd4e645d1207
emacs localfuncs: add advice for ido to avoid blocking in flex matching
Augie Fackler <durin42@gmail.com>
parents:
158
diff
changeset
|
11 "Conditionally disable flex matching if the list is huge. |
cd4e645d1207
emacs localfuncs: add advice for ido to avoid blocking in flex matching
Augie Fackler <durin42@gmail.com>
parents:
158
diff
changeset
|
12 |
cd4e645d1207
emacs localfuncs: add advice for ido to avoid blocking in flex matching
Augie Fackler <durin42@gmail.com>
parents:
158
diff
changeset
|
13 This is useful because when the ido list is huge, ido flex matching |
cd4e645d1207
emacs localfuncs: add advice for ido to avoid blocking in flex matching
Augie Fackler <durin42@gmail.com>
parents:
158
diff
changeset
|
14 spends an eternity in a regex if you make a typo." |
cd4e645d1207
emacs localfuncs: add advice for ido to avoid blocking in flex matching
Augie Fackler <durin42@gmail.com>
parents:
158
diff
changeset
|
15 (let ((ido-enable-flex-matching (< (* (length (ad-get-arg 0)) (length ido-text)) |
cd4e645d1207
emacs localfuncs: add advice for ido to avoid blocking in flex matching
Augie Fackler <durin42@gmail.com>
parents:
158
diff
changeset
|
16 af-ido-flex-fuzzy-limit))) |
cd4e645d1207
emacs localfuncs: add advice for ido to avoid blocking in flex matching
Augie Fackler <durin42@gmail.com>
parents:
158
diff
changeset
|
17 ad-do-it)) |
cd4e645d1207
emacs localfuncs: add advice for ido to avoid blocking in flex matching
Augie Fackler <durin42@gmail.com>
parents:
158
diff
changeset
|
18 |
cd4e645d1207
emacs localfuncs: add advice for ido to avoid blocking in flex matching
Augie Fackler <durin42@gmail.com>
parents:
158
diff
changeset
|
19 ;; Generic repository differ. Requires textmate.el and mercurial.el. |
295
026344f083ef
af-generic-diff-repo: use monky or magit if available
Augie Fackler <raf@durin42.com>
parents:
238
diff
changeset
|
20 ;; Will use monky or magit if either one is present. |
158
36a4e4b0f9c3
localfuncs: smart multi-vcs diff command
Augie Fackler <durin42@gmail.com>
parents:
141
diff
changeset
|
21 (defun af-generic-diff-repo () |
36a4e4b0f9c3
localfuncs: smart multi-vcs diff command
Augie Fackler <durin42@gmail.com>
parents:
141
diff
changeset
|
22 (interactive) |
36a4e4b0f9c3
localfuncs: smart multi-vcs diff command
Augie Fackler <durin42@gmail.com>
parents:
141
diff
changeset
|
23 (let ((root (textmate-project-root))) |
295
026344f083ef
af-generic-diff-repo: use monky or magit if available
Augie Fackler <raf@durin42.com>
parents:
238
diff
changeset
|
24 (cond ((and (string= (textmate-project-root-type root) "hg") (fboundp 'monky-status)) (monky-status)) |
026344f083ef
af-generic-diff-repo: use monky or magit if available
Augie Fackler <raf@durin42.com>
parents:
238
diff
changeset
|
25 ((and (string= (textmate-project-root-type root) "git") (fboundp 'magit-status)) (magit-status root)) |
026344f083ef
af-generic-diff-repo: use monky or magit if available
Augie Fackler <raf@durin42.com>
parents:
238
diff
changeset
|
26 (t (progn |
026344f083ef
af-generic-diff-repo: use monky or magit if available
Augie Fackler <raf@durin42.com>
parents:
238
diff
changeset
|
27 (cd root) |
026344f083ef
af-generic-diff-repo: use monky or magit if available
Augie Fackler <raf@durin42.com>
parents:
238
diff
changeset
|
28 (hg-view-output |
026344f083ef
af-generic-diff-repo: use monky or magit if available
Augie Fackler <raf@durin42.com>
parents:
238
diff
changeset
|
29 ((format "project diff for %s" root)) |
026344f083ef
af-generic-diff-repo: use monky or magit if available
Augie Fackler <raf@durin42.com>
parents:
238
diff
changeset
|
30 (call-process (textmate-project-root-type root) nil t nil "diff") |
026344f083ef
af-generic-diff-repo: use monky or magit if available
Augie Fackler <raf@durin42.com>
parents:
238
diff
changeset
|
31 (diff-mode) |
026344f083ef
af-generic-diff-repo: use monky or magit if available
Augie Fackler <raf@durin42.com>
parents:
238
diff
changeset
|
32 (setq diff (not (= (point-min) (point-max)))) |
026344f083ef
af-generic-diff-repo: use monky or magit if available
Augie Fackler <raf@durin42.com>
parents:
238
diff
changeset
|
33 (font-lock-fontify-buffer) |
026344f083ef
af-generic-diff-repo: use monky or magit if available
Augie Fackler <raf@durin42.com>
parents:
238
diff
changeset
|
34 (cd root))))))) |
026344f083ef
af-generic-diff-repo: use monky or magit if available
Augie Fackler <raf@durin42.com>
parents:
238
diff
changeset
|
35 |
158
36a4e4b0f9c3
localfuncs: smart multi-vcs diff command
Augie Fackler <durin42@gmail.com>
parents:
141
diff
changeset
|
36 (global-set-key [(control c)(t)(=)] 'af-generic-diff-repo) |
36a4e4b0f9c3
localfuncs: smart multi-vcs diff command
Augie Fackler <durin42@gmail.com>
parents:
141
diff
changeset
|
37 (global-set-key [(control c)(d)] 'af-generic-diff-repo) |
36a4e4b0f9c3
localfuncs: smart multi-vcs diff command
Augie Fackler <durin42@gmail.com>
parents:
141
diff
changeset
|
38 |
295
026344f083ef
af-generic-diff-repo: use monky or magit if available
Augie Fackler <raf@durin42.com>
parents:
238
diff
changeset
|
39 |
207
c965d5dbd868
emacs localfuncs: add list rotation and string-joining functions I sometimes use
Augie Fackler <durin42@gmail.com>
parents:
188
diff
changeset
|
40 (defun af-rotate-list (l) |
c965d5dbd868
emacs localfuncs: add list rotation and string-joining functions I sometimes use
Augie Fackler <durin42@gmail.com>
parents:
188
diff
changeset
|
41 "Move the head of l to the end of the list." |
c965d5dbd868
emacs localfuncs: add list rotation and string-joining functions I sometimes use
Augie Fackler <durin42@gmail.com>
parents:
188
diff
changeset
|
42 (append (cdr l) (list (car l)))) |
c965d5dbd868
emacs localfuncs: add list rotation and string-joining functions I sometimes use
Augie Fackler <durin42@gmail.com>
parents:
188
diff
changeset
|
43 |
c965d5dbd868
emacs localfuncs: add list rotation and string-joining functions I sometimes use
Augie Fackler <durin42@gmail.com>
parents:
188
diff
changeset
|
44 (defun af-spacejoin (l) |
c965d5dbd868
emacs localfuncs: add list rotation and string-joining functions I sometimes use
Augie Fackler <durin42@gmail.com>
parents:
188
diff
changeset
|
45 "Given list of strings l, join them with spaces and return. |
c965d5dbd868
emacs localfuncs: add list rotation and string-joining functions I sometimes use
Augie Fackler <durin42@gmail.com>
parents:
188
diff
changeset
|
46 |
c965d5dbd868
emacs localfuncs: add list rotation and string-joining functions I sometimes use
Augie Fackler <durin42@gmail.com>
parents:
188
diff
changeset
|
47 Returns the empty string if l is nil." |
c965d5dbd868
emacs localfuncs: add list rotation and string-joining functions I sometimes use
Augie Fackler <durin42@gmail.com>
parents:
188
diff
changeset
|
48 (if l |
c965d5dbd868
emacs localfuncs: add list rotation and string-joining functions I sometimes use
Augie Fackler <durin42@gmail.com>
parents:
188
diff
changeset
|
49 (reduce '(lambda (x &optional y) (concat x " " (if y y))) l) |
c965d5dbd868
emacs localfuncs: add list rotation and string-joining functions I sometimes use
Augie Fackler <durin42@gmail.com>
parents:
188
diff
changeset
|
50 "")) |
c965d5dbd868
emacs localfuncs: add list rotation and string-joining functions I sometimes use
Augie Fackler <durin42@gmail.com>
parents:
188
diff
changeset
|
51 |
89
f34d90569fdc
Add a file for local functions not yet extracted into a module. Includes a function to run pyflakes on the current buffer.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
52 (defun pyflakes-this-buffer () |
f34d90569fdc
Add a file for local functions not yet extracted into a module. Includes a function to run pyflakes on the current buffer.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
53 (interactive) |
91
075b45c5aecc
cd to the file dir before running pyflakes to make output less verbose.
Augie Fackler <durin42@gmail.com>
parents:
89
diff
changeset
|
54 (compilation-start (concat "cd " |
075b45c5aecc
cd to the file dir before running pyflakes to make output less verbose.
Augie Fackler <durin42@gmail.com>
parents:
89
diff
changeset
|
55 (file-name-directory buffer-file-name) |
96
0eabfd7a8ffa
Add a fullscreen function, cleanup.
Augie Fackler <durin42@gmail.com>
parents:
91
diff
changeset
|
56 "; pyflakes " (file-name-nondirectory |
0eabfd7a8ffa
Add a fullscreen function, cleanup.
Augie Fackler <durin42@gmail.com>
parents:
91
diff
changeset
|
57 buffer-file-name)) |
91
075b45c5aecc
cd to the file dir before running pyflakes to make output less verbose.
Augie Fackler <durin42@gmail.com>
parents:
89
diff
changeset
|
58 nil |
075b45c5aecc
cd to the file dir before running pyflakes to make output less verbose.
Augie Fackler <durin42@gmail.com>
parents:
89
diff
changeset
|
59 (lambda (mode) "*pyflakes*"))) |
96
0eabfd7a8ffa
Add a fullscreen function, cleanup.
Augie Fackler <durin42@gmail.com>
parents:
91
diff
changeset
|
60 |
188
e77c01b7b0f4
localfuncs: add tool for running check-code on hg
Augie Fackler <durin42@gmail.com>
parents:
180
diff
changeset
|
61 (defun hg-check-code () |
e77c01b7b0f4
localfuncs: add tool for running check-code on hg
Augie Fackler <durin42@gmail.com>
parents:
180
diff
changeset
|
62 (interactive) |
e77c01b7b0f4
localfuncs: add tool for running check-code on hg
Augie Fackler <durin42@gmail.com>
parents:
180
diff
changeset
|
63 (textmate-start-compile-in-root "python contrib/check-code.py `hg man`" |
e77c01b7b0f4
localfuncs: add tool for running check-code on hg
Augie Fackler <durin42@gmail.com>
parents:
180
diff
changeset
|
64 nil |
e77c01b7b0f4
localfuncs: add tool for running check-code on hg
Augie Fackler <durin42@gmail.com>
parents:
180
diff
changeset
|
65 '(lambda (x) "*check-code*") )) |
e77c01b7b0f4
localfuncs: add tool for running check-code on hg
Augie Fackler <durin42@gmail.com>
parents:
180
diff
changeset
|
66 |
96
0eabfd7a8ffa
Add a fullscreen function, cleanup.
Augie Fackler <durin42@gmail.com>
parents:
91
diff
changeset
|
67 (defun fullscreen () |
0eabfd7a8ffa
Add a fullscreen function, cleanup.
Augie Fackler <durin42@gmail.com>
parents:
91
diff
changeset
|
68 (interactive) |
0eabfd7a8ffa
Add a fullscreen function, cleanup.
Augie Fackler <durin42@gmail.com>
parents:
91
diff
changeset
|
69 (set-frame-parameter nil 'fullscreen |
0eabfd7a8ffa
Add a fullscreen function, cleanup.
Augie Fackler <durin42@gmail.com>
parents:
91
diff
changeset
|
70 (if (frame-parameter nil 'fullscreen) nil 'fullboth))) |
117
67bfc48b2a61
Function for removing a file from Mercurial.
Augie Fackler <durin42@gmail.com>
parents:
98
diff
changeset
|
71 |
67bfc48b2a61
Function for removing a file from Mercurial.
Augie Fackler <durin42@gmail.com>
parents:
98
diff
changeset
|
72 |
67bfc48b2a61
Function for removing a file from Mercurial.
Augie Fackler <durin42@gmail.com>
parents:
98
diff
changeset
|
73 (defun hg-rm-this-file () |
67bfc48b2a61
Function for removing a file from Mercurial.
Augie Fackler <durin42@gmail.com>
parents:
98
diff
changeset
|
74 (interactive) |
124
2ae20e96f6c0
Should really shell quote this arg.
Augie Fackler <durin42@gmail.com>
parents:
117
diff
changeset
|
75 (shell-command-to-string (concat "hg rm " (shell-quote-argument buffer-file-name)))) |
125
15bcc3e0afeb
Function for selecting text inside of a quote pair.
Augie Fackler <durin42@gmail.com>
parents:
124
diff
changeset
|
76 |
15bcc3e0afeb
Function for selecting text inside of a quote pair.
Augie Fackler <durin42@gmail.com>
parents:
124
diff
changeset
|
77 ;; Lifted from http://code.google.com/p/ergoemacs/ |
15bcc3e0afeb
Function for selecting text inside of a quote pair.
Augie Fackler <durin42@gmail.com>
parents:
124
diff
changeset
|
78 (defun select-text-in-quote () |
15bcc3e0afeb
Function for selecting text inside of a quote pair.
Augie Fackler <durin42@gmail.com>
parents:
124
diff
changeset
|
79 "Select text between the nearest left and right delimiters. |
15bcc3e0afeb
Function for selecting text inside of a quote pair.
Augie Fackler <durin42@gmail.com>
parents:
124
diff
changeset
|
80 Delimiters are paired characters: ()[]<>«»“”‘’「」, including \"\"." |
15bcc3e0afeb
Function for selecting text inside of a quote pair.
Augie Fackler <durin42@gmail.com>
parents:
124
diff
changeset
|
81 (interactive) |
15bcc3e0afeb
Function for selecting text inside of a quote pair.
Augie Fackler <durin42@gmail.com>
parents:
124
diff
changeset
|
82 (let (b1 b2) |
15bcc3e0afeb
Function for selecting text inside of a quote pair.
Augie Fackler <durin42@gmail.com>
parents:
124
diff
changeset
|
83 (skip-chars-backward "^<>(“{[「«\"‘") |
15bcc3e0afeb
Function for selecting text inside of a quote pair.
Augie Fackler <durin42@gmail.com>
parents:
124
diff
changeset
|
84 (setq b1 (point)) |
15bcc3e0afeb
Function for selecting text inside of a quote pair.
Augie Fackler <durin42@gmail.com>
parents:
124
diff
changeset
|
85 (skip-chars-forward "^<>)”}]」»\"’") |
15bcc3e0afeb
Function for selecting text inside of a quote pair.
Augie Fackler <durin42@gmail.com>
parents:
124
diff
changeset
|
86 (setq b2 (point)) |
15bcc3e0afeb
Function for selecting text inside of a quote pair.
Augie Fackler <durin42@gmail.com>
parents:
124
diff
changeset
|
87 (set-mark b1) |
15bcc3e0afeb
Function for selecting text inside of a quote pair.
Augie Fackler <durin42@gmail.com>
parents:
124
diff
changeset
|
88 ) |
15bcc3e0afeb
Function for selecting text inside of a quote pair.
Augie Fackler <durin42@gmail.com>
parents:
124
diff
changeset
|
89 ) |
126 | 90 |
91 ;; Most of this was extracted from show-paren-function in paren.el from an emacs 23 nightly | |
92 ;; Also, it seems like this really ought to be builtin, but I can't find it. | |
93 (defun bounce-to-other-paren () | |
94 (interactive) | |
95 (let ((oldpos (point)) | |
96 (dir (cond ((eq (syntax-class (syntax-after (1- (point)))) 5) -1) | |
97 ((eq (syntax-class (syntax-after (point))) 4) 1))) | |
98 pos mismatch face) | |
99 ;; | |
100 ;; Find the other end of the sexp. | |
101 (when dir | |
102 (save-excursion | |
103 (save-restriction | |
104 ;; Determine the range within which to look for a match. | |
105 (when blink-matching-paren-distance | |
106 (narrow-to-region | |
107 (max (point-min) (- (point) blink-matching-paren-distance)) | |
108 (min (point-max) (+ (point) blink-matching-paren-distance)))) | |
109 ;; Scan across one sexp within that range. | |
110 ;; Errors or nil mean there is a mismatch. | |
111 (condition-case () | |
112 (setq pos (scan-sexps (point) dir)) | |
113 (error (setq pos t mismatch t))) | |
114 ;; Move back the other way and verify we get back to the | |
115 ;; starting point. If not, these two parens don't really match. | |
116 ;; Maybe the one at point is escaped and doesn't really count. | |
117 (when (integerp pos) | |
118 (unless (condition-case () | |
119 (eq (point) (scan-sexps pos (- dir))) | |
120 (error nil)) | |
121 (setq pos nil))) | |
122 ))) | |
123 ;; Highlight the other end of the sexp, or unhighlight if none. | |
124 (if (and pos (integerp pos)) | |
125 (goto-char pos) | |
126 (message "No matching other paren found.") | |
127 ))) | |
237
b9f4d059eb69
emacs: function to set window width interactively
Augie Fackler <durin42@gmail.com>
parents:
207
diff
changeset
|
128 |
b9f4d059eb69
emacs: function to set window width interactively
Augie Fackler <durin42@gmail.com>
parents:
207
diff
changeset
|
129 (defun af-set-window-width (&optional columns) |
b9f4d059eb69
emacs: function to set window width interactively
Augie Fackler <durin42@gmail.com>
parents:
207
diff
changeset
|
130 "Make selected window COLUMNS wide. |
b9f4d059eb69
emacs: function to set window width interactively
Augie Fackler <durin42@gmail.com>
parents:
207
diff
changeset
|
131 |
b9f4d059eb69
emacs: function to set window width interactively
Augie Fackler <durin42@gmail.com>
parents:
207
diff
changeset
|
132 Interactively, if no argument is given, make selected window 80 |
b9f4d059eb69
emacs: function to set window width interactively
Augie Fackler <durin42@gmail.com>
parents:
207
diff
changeset
|
133 columns wide. |
b9f4d059eb69
emacs: function to set window width interactively
Augie Fackler <durin42@gmail.com>
parents:
207
diff
changeset
|
134 " |
b9f4d059eb69
emacs: function to set window width interactively
Augie Fackler <durin42@gmail.com>
parents:
207
diff
changeset
|
135 (interactive "p") |
238
3d5c595c229e
emacs: slightly better window-width resizing behavior
Lucas Bergman <slb@google.com>
parents:
237
diff
changeset
|
136 (let* ((cols (if (or (not columns) (>= 0 columns)) 80 columns))) |
237
b9f4d059eb69
emacs: function to set window width interactively
Augie Fackler <durin42@gmail.com>
parents:
207
diff
changeset
|
137 (shrink-window-horizontally (- (window-width) cols)))) |