annotate .elisp/settings/50.localfuncs.el @ 207:c965d5dbd868

emacs localfuncs: add list rotation and string-joining functions I sometimes use
author Augie Fackler <durin42@gmail.com>
date Tue, 11 May 2010 15:32:19 -0500
parents e77c01b7b0f4
children b9f4d059eb69
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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.
158
36a4e4b0f9c3 localfuncs: smart multi-vcs diff command
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
20 (defun af-generic-diff-repo ()
36a4e4b0f9c3 localfuncs: smart multi-vcs diff command
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
21 (interactive)
36a4e4b0f9c3 localfuncs: smart multi-vcs diff command
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
22 (let ((root (textmate-project-root)))
36a4e4b0f9c3 localfuncs: smart multi-vcs diff command
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
23 (cd root)
36a4e4b0f9c3 localfuncs: smart multi-vcs diff command
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
24 (hg-view-output
36a4e4b0f9c3 localfuncs: smart multi-vcs diff command
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
25 ((format "project diff for %s" root))
36a4e4b0f9c3 localfuncs: smart multi-vcs diff command
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
26 (call-process (textmate-project-root-type root) nil t nil "diff")
36a4e4b0f9c3 localfuncs: smart multi-vcs diff command
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
27 (diff-mode)
36a4e4b0f9c3 localfuncs: smart multi-vcs diff command
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
28 (setq diff (not (= (point-min) (point-max))))
36a4e4b0f9c3 localfuncs: smart multi-vcs diff command
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
29 (font-lock-fontify-buffer)
36a4e4b0f9c3 localfuncs: smart multi-vcs diff command
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
30 (cd root))))
36a4e4b0f9c3 localfuncs: smart multi-vcs diff command
Augie Fackler <durin42@gmail.com>
parents: 141
diff changeset
31 (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
32 (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
33
207
c965d5dbd868 emacs localfuncs: add list rotation and string-joining functions I sometimes use
Augie Fackler <durin42@gmail.com>
parents: 188
diff changeset
34 (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
35 "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
36 (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
37
c965d5dbd868 emacs localfuncs: add list rotation and string-joining functions I sometimes use
Augie Fackler <durin42@gmail.com>
parents: 188
diff changeset
38 (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
39 "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
40
c965d5dbd868 emacs localfuncs: add list rotation and string-joining functions I sometimes use
Augie Fackler <durin42@gmail.com>
parents: 188
diff changeset
41 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
42 (if l
c965d5dbd868 emacs localfuncs: add list rotation and string-joining functions I sometimes use
Augie Fackler <durin42@gmail.com>
parents: 188
diff changeset
43 (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
44 ""))
c965d5dbd868 emacs localfuncs: add list rotation and string-joining functions I sometimes use
Augie Fackler <durin42@gmail.com>
parents: 188
diff changeset
45
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
46 (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
47 (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
48 (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
49 (file-name-directory buffer-file-name)
96
0eabfd7a8ffa Add a fullscreen function, cleanup.
Augie Fackler <durin42@gmail.com>
parents: 91
diff changeset
50 "; pyflakes " (file-name-nondirectory
0eabfd7a8ffa Add a fullscreen function, cleanup.
Augie Fackler <durin42@gmail.com>
parents: 91
diff changeset
51 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
52 nil
075b45c5aecc cd to the file dir before running pyflakes to make output less verbose.
Augie Fackler <durin42@gmail.com>
parents: 89
diff changeset
53 (lambda (mode) "*pyflakes*")))
96
0eabfd7a8ffa Add a fullscreen function, cleanup.
Augie Fackler <durin42@gmail.com>
parents: 91
diff changeset
54
188
e77c01b7b0f4 localfuncs: add tool for running check-code on hg
Augie Fackler <durin42@gmail.com>
parents: 180
diff changeset
55 (defun hg-check-code ()
e77c01b7b0f4 localfuncs: add tool for running check-code on hg
Augie Fackler <durin42@gmail.com>
parents: 180
diff changeset
56 (interactive)
e77c01b7b0f4 localfuncs: add tool for running check-code on hg
Augie Fackler <durin42@gmail.com>
parents: 180
diff changeset
57 (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
58 nil
e77c01b7b0f4 localfuncs: add tool for running check-code on hg
Augie Fackler <durin42@gmail.com>
parents: 180
diff changeset
59 '(lambda (x) "*check-code*") ))
e77c01b7b0f4 localfuncs: add tool for running check-code on hg
Augie Fackler <durin42@gmail.com>
parents: 180
diff changeset
60
96
0eabfd7a8ffa Add a fullscreen function, cleanup.
Augie Fackler <durin42@gmail.com>
parents: 91
diff changeset
61 (defun fullscreen ()
0eabfd7a8ffa Add a fullscreen function, cleanup.
Augie Fackler <durin42@gmail.com>
parents: 91
diff changeset
62 (interactive)
0eabfd7a8ffa Add a fullscreen function, cleanup.
Augie Fackler <durin42@gmail.com>
parents: 91
diff changeset
63 (set-frame-parameter nil 'fullscreen
0eabfd7a8ffa Add a fullscreen function, cleanup.
Augie Fackler <durin42@gmail.com>
parents: 91
diff changeset
64 (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
65
67bfc48b2a61 Function for removing a file from Mercurial.
Augie Fackler <durin42@gmail.com>
parents: 98
diff changeset
66
67bfc48b2a61 Function for removing a file from Mercurial.
Augie Fackler <durin42@gmail.com>
parents: 98
diff changeset
67 (defun hg-rm-this-file ()
67bfc48b2a61 Function for removing a file from Mercurial.
Augie Fackler <durin42@gmail.com>
parents: 98
diff changeset
68 (interactive)
124
2ae20e96f6c0 Should really shell quote this arg.
Augie Fackler <durin42@gmail.com>
parents: 117
diff changeset
69 (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
70
15bcc3e0afeb Function for selecting text inside of a quote pair.
Augie Fackler <durin42@gmail.com>
parents: 124
diff changeset
71 ;; 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
72 (defun select-text-in-quote ()
15bcc3e0afeb Function for selecting text inside of a quote pair.
Augie Fackler <durin42@gmail.com>
parents: 124
diff changeset
73 "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
74 Delimiters are paired characters: ()[]<>«»“”‘’「」, including \"\"."
15bcc3e0afeb Function for selecting text inside of a quote pair.
Augie Fackler <durin42@gmail.com>
parents: 124
diff changeset
75 (interactive)
15bcc3e0afeb Function for selecting text inside of a quote pair.
Augie Fackler <durin42@gmail.com>
parents: 124
diff changeset
76 (let (b1 b2)
15bcc3e0afeb Function for selecting text inside of a quote pair.
Augie Fackler <durin42@gmail.com>
parents: 124
diff changeset
77 (skip-chars-backward "^<>(“{[「«\"‘")
15bcc3e0afeb Function for selecting text inside of a quote pair.
Augie Fackler <durin42@gmail.com>
parents: 124
diff changeset
78 (setq b1 (point))
15bcc3e0afeb Function for selecting text inside of a quote pair.
Augie Fackler <durin42@gmail.com>
parents: 124
diff changeset
79 (skip-chars-forward "^<>)”}]」»\"’")
15bcc3e0afeb Function for selecting text inside of a quote pair.
Augie Fackler <durin42@gmail.com>
parents: 124
diff changeset
80 (setq b2 (point))
15bcc3e0afeb Function for selecting text inside of a quote pair.
Augie Fackler <durin42@gmail.com>
parents: 124
diff changeset
81 (set-mark b1)
15bcc3e0afeb Function for selecting text inside of a quote pair.
Augie Fackler <durin42@gmail.com>
parents: 124
diff changeset
82 )
15bcc3e0afeb Function for selecting text inside of a quote pair.
Augie Fackler <durin42@gmail.com>
parents: 124
diff changeset
83 )
126
34b698771af9 emacs keybinding fixes
Augie Fackler <durin42@gmail.com>
parents: 125
diff changeset
84
34b698771af9 emacs keybinding fixes
Augie Fackler <durin42@gmail.com>
parents: 125
diff changeset
85 ;; Most of this was extracted from show-paren-function in paren.el from an emacs 23 nightly
34b698771af9 emacs keybinding fixes
Augie Fackler <durin42@gmail.com>
parents: 125
diff changeset
86 ;; Also, it seems like this really ought to be builtin, but I can't find it.
34b698771af9 emacs keybinding fixes
Augie Fackler <durin42@gmail.com>
parents: 125
diff changeset
87 (defun bounce-to-other-paren ()
34b698771af9 emacs keybinding fixes
Augie Fackler <durin42@gmail.com>
parents: 125
diff changeset
88 (interactive)
34b698771af9 emacs keybinding fixes
Augie Fackler <durin42@gmail.com>
parents: 125
diff changeset
89 (let ((oldpos (point))
34b698771af9 emacs keybinding fixes
Augie Fackler <durin42@gmail.com>
parents: 125
diff changeset
90 (dir (cond ((eq (syntax-class (syntax-after (1- (point)))) 5) -1)
34b698771af9 emacs keybinding fixes
Augie Fackler <durin42@gmail.com>
parents: 125
diff changeset
91 ((eq (syntax-class (syntax-after (point))) 4) 1)))
34b698771af9 emacs keybinding fixes
Augie Fackler <durin42@gmail.com>
parents: 125
diff changeset
92 pos mismatch face)
34b698771af9 emacs keybinding fixes
Augie Fackler <durin42@gmail.com>
parents: 125
diff changeset
93 ;;
34b698771af9 emacs keybinding fixes
Augie Fackler <durin42@gmail.com>
parents: 125
diff changeset
94 ;; Find the other end of the sexp.
34b698771af9 emacs keybinding fixes
Augie Fackler <durin42@gmail.com>
parents: 125
diff changeset
95 (when dir
34b698771af9 emacs keybinding fixes
Augie Fackler <durin42@gmail.com>
parents: 125
diff changeset
96 (save-excursion
34b698771af9 emacs keybinding fixes
Augie Fackler <durin42@gmail.com>
parents: 125
diff changeset
97 (save-restriction
34b698771af9 emacs keybinding fixes
Augie Fackler <durin42@gmail.com>
parents: 125
diff changeset
98 ;; Determine the range within which to look for a match.
34b698771af9 emacs keybinding fixes
Augie Fackler <durin42@gmail.com>
parents: 125
diff changeset
99 (when blink-matching-paren-distance
34b698771af9 emacs keybinding fixes
Augie Fackler <durin42@gmail.com>
parents: 125
diff changeset
100 (narrow-to-region
34b698771af9 emacs keybinding fixes
Augie Fackler <durin42@gmail.com>
parents: 125
diff changeset
101 (max (point-min) (- (point) blink-matching-paren-distance))
34b698771af9 emacs keybinding fixes
Augie Fackler <durin42@gmail.com>
parents: 125
diff changeset
102 (min (point-max) (+ (point) blink-matching-paren-distance))))
34b698771af9 emacs keybinding fixes
Augie Fackler <durin42@gmail.com>
parents: 125
diff changeset
103 ;; Scan across one sexp within that range.
34b698771af9 emacs keybinding fixes
Augie Fackler <durin42@gmail.com>
parents: 125
diff changeset
104 ;; Errors or nil mean there is a mismatch.
34b698771af9 emacs keybinding fixes
Augie Fackler <durin42@gmail.com>
parents: 125
diff changeset
105 (condition-case ()
34b698771af9 emacs keybinding fixes
Augie Fackler <durin42@gmail.com>
parents: 125
diff changeset
106 (setq pos (scan-sexps (point) dir))
34b698771af9 emacs keybinding fixes
Augie Fackler <durin42@gmail.com>
parents: 125
diff changeset
107 (error (setq pos t mismatch t)))
34b698771af9 emacs keybinding fixes
Augie Fackler <durin42@gmail.com>
parents: 125
diff changeset
108 ;; Move back the other way and verify we get back to the
34b698771af9 emacs keybinding fixes
Augie Fackler <durin42@gmail.com>
parents: 125
diff changeset
109 ;; starting point. If not, these two parens don't really match.
34b698771af9 emacs keybinding fixes
Augie Fackler <durin42@gmail.com>
parents: 125
diff changeset
110 ;; Maybe the one at point is escaped and doesn't really count.
34b698771af9 emacs keybinding fixes
Augie Fackler <durin42@gmail.com>
parents: 125
diff changeset
111 (when (integerp pos)
34b698771af9 emacs keybinding fixes
Augie Fackler <durin42@gmail.com>
parents: 125
diff changeset
112 (unless (condition-case ()
34b698771af9 emacs keybinding fixes
Augie Fackler <durin42@gmail.com>
parents: 125
diff changeset
113 (eq (point) (scan-sexps pos (- dir)))
34b698771af9 emacs keybinding fixes
Augie Fackler <durin42@gmail.com>
parents: 125
diff changeset
114 (error nil))
34b698771af9 emacs keybinding fixes
Augie Fackler <durin42@gmail.com>
parents: 125
diff changeset
115 (setq pos nil)))
34b698771af9 emacs keybinding fixes
Augie Fackler <durin42@gmail.com>
parents: 125
diff changeset
116 )))
34b698771af9 emacs keybinding fixes
Augie Fackler <durin42@gmail.com>
parents: 125
diff changeset
117 ;; Highlight the other end of the sexp, or unhighlight if none.
34b698771af9 emacs keybinding fixes
Augie Fackler <durin42@gmail.com>
parents: 125
diff changeset
118 (if (and pos (integerp pos))
34b698771af9 emacs keybinding fixes
Augie Fackler <durin42@gmail.com>
parents: 125
diff changeset
119 (goto-char pos)
34b698771af9 emacs keybinding fixes
Augie Fackler <durin42@gmail.com>
parents: 125
diff changeset
120 (message "No matching other paren found.")
34b698771af9 emacs keybinding fixes
Augie Fackler <durin42@gmail.com>
parents: 125
diff changeset
121 )))