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