annotate misc.el @ 42:597d985bf448

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