annotate misc.el @ 10:1675d4eff896

*** empty log message ***
author ht
date Sun, 06 May 2007 14:22:37 +0100
parents 5f3a215f12eb
children 5738cc494f7f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
1 ;; various hacks
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
2 ;; a compiled version exists!
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
3 ;; Last edited: Thu Oct 2 16:47:40 1986
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
4
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
5 (provide 'misc)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
6
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
7 (defun
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
8 insert-time ()
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
9 (interactive)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
10 (insert-string (current-time-string)))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
11
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
12 (global-set-key "\et" 'insert-time)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
13
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
14 (defun
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
15 note-edit ()
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
16 (interactive)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
17 (beginning-of-buffer)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
18 (if
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
19 (not (search-forward "Last edited: " nil t))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
20 (progn (insert-string ";; Last edited: ")
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
21 (newline)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
22 (forward-char -1))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
23 (if (not (looking-at "\n"))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
24 (kill-line)))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
25 (insert-time))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
26
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
27 (global-set-key "\em" 'note-edit)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
28
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
29 (defun save-and-pause()
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
30 (interactive)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
31 (save-some-buffers t)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
32 (suspend-emacs))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
33
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
34 (global-set-key "\C-x." 'save-and-pause)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
35
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
36 (defun fix-comment-line ()
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
37 "split comment onto enough lines to avoid overflow"
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
38 (interactive)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
39 (indent-for-comment)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
40 (end-of-line)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
41 (if (> (current-column) 79)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
42 (progn
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
43 (while (> (current-column) 79)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
44 (re-search-backward "[ ]"))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
45 (indent-new-comment-line)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
46 (end-of-line))))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
47
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
48 (defun fix-all-comments ()
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
49 "iterate over file with fix-comment-line"
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
50 (interactive)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
51 (while (search-forward ";" nil t)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
52 (fix-comment-line)))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
53
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
54 (global-set-key "\e:" 'fix-comment-line)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
55
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
56 (defun grind-file ()
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
57 "grind all forms in a lisp file"
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
58 (interactive)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
59 (beginning-of-buffer)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
60 (while (re-search-forward "^(" nil t)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
61 (beginning-of-line)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
62 (indent-sexp)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
63 (end-of-line)))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
64
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
65 (defun suggest-breaks ()
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
66 "suggest line breaks to improve indentation"
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
67 (interactive)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
68 (set-mark (point))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
69 (message "Trying to add line breaks to over-long lines . . .")
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
70 (let (finished)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
71 (while (not (or finished
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
72 (= (point)(point-max))))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
73 (end-of-line)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
74 (if (> (current-column) 79)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
75 (let* ((left (progn (beginning-of-line)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
76 (re-search-forward "[ ]*")
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
77 (current-column)))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
78 (min-pt (point))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
79 (target (min 69 (/ (+ 79 left) 2))))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
80 (end-of-line)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
81 (while (and (> (current-column) target)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
82 (> (point) min-pt)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
83 (search-backward " " nil t)))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
84 (if (<= (point) min-pt)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
85 (progn (goto-char min-pt)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
86 (if (search-forward " " nil t)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
87 (backward-char 1)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
88 (message "losing %d %d %d" min-pt left target))))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
89 (let ((help-form (quote
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
90 "y or <space> to break here,n or . or ! to stop, others interpreted"))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
91 (re-probe t)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
92 (char nil))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
93 (while re-probe
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
94 (setq re-probe nil)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
95 (setq char (read-char))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
96 (cond ((or (= char ??)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
97 (= char help-char))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
98 (message help-form))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
99 ((or (= char ?\ )
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
100 (= char ?y))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
101 (while (looking-at " ")
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
102 (delete-char 1))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
103 (newline-and-indent)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
104 (message
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
105 "Trying to add line breaks to over-long lines . . ."))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
106 ((or (= char ?n)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
107 (= char ?\.)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
108 (= char ?\!))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
109 nil)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
110 ((= char ?f)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
111 (forward-char 1)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
112 (search-forward " ")
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
113 (backward-char 1)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
114 (setq re-probe t))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
115 ((= char ?b)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
116 (search-backward " ")
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
117 (setq re-probe t))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
118 (t (setq unread-command-char char)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
119 (setq finished t))))))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
120 (forward-line)))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
121 (message "Trying to add line breaks to over-long lines . . . done.")))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
122
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
123 (defun set-left-margin ()
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
124 (interactive)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
125 (if (and margin-stack
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
126 (< (current-column)(car margin-stack)))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
127 (setq margin-stack nil)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
128 (if (> (current-column) left-margin)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
129 (setq margin-stack (cons left-margin margin-stack))))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
130 (setq left-margin (current-column))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
131 (set-fill-prefix))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
132
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
133 (defun pop-left-margin ()
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
134 (interactive)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
135 (if margin-stack
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
136 (progn (setq left-margin (car margin-stack))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
137 (setq margin-stack (cdr margin-stack)))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
138 (setq left-margin 0))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
139 (move-to-column left-margin)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
140 (set-fill-prefix))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
141
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
142 (setq text-mode-hook `(lambda nil (progn ,@ (mapcar (function list)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
143 text-mode-hook))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
144 (turn-on-auto-fill)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
145 (abbrev-mode 1)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
146 (local-set-key "\C-cl" 'set-left-margin)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
147 (local-set-key "\C-cs" 'submerge-region)))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
148
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
149 (global-set-key "\C-cp" 'pop-left-margin)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
150
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
151 (setq margin-stack nil)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
152
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
153 (global-set-key "\^Xn" 'other-window) ; as per emacs - used to be narrow
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
154 (global-set-key "\^Xp" 'other-window-up) ; "
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
155
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
156 (defun other-window-up (n)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
157 (interactive "p")
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
158 (other-window (- (or n 1))))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
159
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
160 (defun minibuffer-electric-tilde ()
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
161 ;; by Stig@hackvan.com
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
162 (interactive)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
163 (and (eq ?/ (preceding-char))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
164 (delete-region (point-min) (point)))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
165 (insert ?~))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
166
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
167
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
168
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
169 ;; Created by: Joe Wells, jbw@cs.bu.edu
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
170 ;; Created on: Fri May 15 13:16:01 1992
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
171 ;; Last modified by: Joe Wells, jbw@csd
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
172 ;; Last modified on: Fri May 15 17:03:28 1992
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
173 ;; Filename: backtrace-fix.el
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
174 ;; Purpose: make backtrace useful when circular structures are on the stack
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
175
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
176 (or (fboundp 'original-backtrace)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
177 (fset 'original-backtrace
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
178 (symbol-function 'backtrace)))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
179
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
180 (defconst backtrace-junk "\
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
181 original-backtrace()
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
182 (condition-case ...)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
183 (let ...)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
184 (save-excursion ...)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
185 (let ...)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
186 ")
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
187
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
188 (defun circ-backtrace ()
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
189 "Print a trace of Lisp function calls currently active.
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
190 Output stream used is value of standard-output."
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
191 (let (err-flag)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
192 (save-excursion
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
193 (set-buffer (get-buffer-create " backtrace-temp"))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
194 (buffer-flush-undo (current-buffer))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
195 (erase-buffer)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
196 (let ((standard-output (current-buffer)))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
197 (condition-case err
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
198 (original-backtrace)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
199 (error
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
200 (setq error-flag err))))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
201 (cond (err-flag
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
202 (goto-char (point-max))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
203 (beginning-of-line 1)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
204 ;; don't leave any unbalanced parens lying around
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
205 (delete-region (point) (point-max))))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
206 (goto-char (point-min))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
207 (search-forward backtrace-junk nil t)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
208 (delete-region (point-min) (point))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
209 (princ (buffer-substring (point-min) (point-max)))))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
210 nil)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
211
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
212 (defun install-circ-bt ()
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
213 (fset 'backtrace
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
214 (symbol-function 'circ-backtrace)))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
215
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
216 (defvar submerge-prefix "> "
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
217 "prefix to submerge quoted text with")
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
218
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
219 (defun submerge-region (&optional start end)
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
220 "submerge the current region"
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
221 (interactive "r")
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
222 (let ((fill-prefix submerge-prefix))
5f3a215f12eb *** empty log message ***
ht
parents:
diff changeset
223 (indent-region start end nil)))