0
|
1 ;;; simple.el --- basic editing commands for XEmacs
|
|
2
|
|
3 ;; Copyright (C) 1985, 1986, 1987, 1993-1995 Free Software Foundation, Inc.
|
|
4 ;; Copyright (C) 1995 Tinker Systems and INS Engineering Corp.
|
|
5
|
|
6 ;; This file is part of XEmacs.
|
|
7
|
|
8 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
9 ;; under the terms of the GNU General Public License as published by
|
|
10 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
11 ;; any later version.
|
|
12
|
|
13 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
14 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
16 ;; General Public License for more details.
|
|
17
|
|
18 ;; You should have received a copy of the GNU General Public License
|
|
19 ;; along with XEmacs; see the file COPYING. If not, write to the Free
|
4
|
20 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
|
21 ;; 02111-1307, USA.
|
0
|
22
|
4
|
23 ;;; Synched up with: FSF 19.34 [But not very closely].
|
0
|
24
|
|
25 ;;; Commentary:
|
|
26
|
|
27 ;; A grab-bag of basic XEmacs commands not specifically related to some
|
|
28 ;; major mode or to file-handling.
|
|
29
|
4
|
30 ;; Changes for zmacs-style active-regions:
|
|
31 ;;
|
|
32 ;; beginning-of-buffer, end-of-buffer, count-lines-region,
|
|
33 ;; count-lines-buffer, what-line, what-cursor-position, set-goal-column,
|
|
34 ;; set-fill-column, prefix-arg-internal, and line-move (which is used by
|
|
35 ;; next-line and previous-line) set zmacs-region-stays to t, so that they
|
|
36 ;; don't affect the current region-hilighting state.
|
|
37 ;;
|
|
38 ;; mark-whole-buffer, mark-word, exchange-point-and-mark, and
|
|
39 ;; set-mark-command (without an argument) call zmacs-activate-region.
|
|
40 ;;
|
|
41 ;; mark takes an optional arg like the new Fmark_marker() does. When
|
|
42 ;; the region is not active, mark returns nil unless the optional arg is true.
|
|
43 ;;
|
|
44 ;; push-mark, pop-mark, exchange-point-and-mark, and set-marker, and
|
|
45 ;; set-mark-command use (mark t) so that they can access the mark whether
|
|
46 ;; the region is active or not.
|
|
47 ;;
|
|
48 ;; shell-command, shell-command-on-region, yank, and yank-pop (which all
|
|
49 ;; push a mark) have been altered to call exchange-point-and-mark with an
|
|
50 ;; argument, meaning "don't activate the region". These commands only use
|
|
51 ;; exchange-point-and-mark to position the newly-pushed mark correctly, so
|
|
52 ;; this isn't a user-visible change. These functions have also been altered
|
|
53 ;; to use (mark t) for the same reason.
|
0
|
54
|
|
55 ;;; Code:
|
|
56
|
|
57 (defun newline (&optional arg)
|
|
58 "Insert a newline, and move to left margin of the new line if it's blank.
|
|
59 The newline is marked with the text-property `hard'.
|
|
60 With arg, insert that many newlines.
|
|
61 In Auto Fill mode, if no numeric arg, break the preceding line if it's long."
|
|
62 (interactive "*P")
|
|
63 (barf-if-buffer-read-only nil (point))
|
|
64 ;; Inserting a newline at the end of a line produces better redisplay in
|
|
65 ;; try_window_id than inserting at the beginning of a line, and the textual
|
|
66 ;; result is the same. So, if we're at beginning of line, pretend to be at
|
|
67 ;; the end of the previous line.
|
|
68 (let ((flag (and (not (bobp))
|
|
69 (bolp)
|
4
|
70 ;; Make sure the newline before point isn't intangible.
|
|
71 (not (get-char-property (1- (point)) 'intangible))
|
|
72 ;; Make sure the newline before point isn't read-only.
|
|
73 (not (get-char-property (1- (point)) 'read-only))
|
|
74 ;; Make sure the newline before point isn't invisible.
|
|
75 (not (get-char-property (1- (point)) 'invisible))
|
|
76 ;; Make sure the newline before point has the same
|
|
77 ;; properties as the char before it (if any).
|
0
|
78 (< (or (previous-extent-change (point)) -2)
|
|
79 (- (point) 2))))
|
|
80 (was-page-start (and (bolp)
|
|
81 (looking-at page-delimiter)))
|
|
82 (beforepos (point)))
|
|
83 (if flag (backward-char 1))
|
|
84 ;; Call self-insert so that auto-fill, abbrev expansion etc. happens.
|
|
85 ;; Set last-command-char to tell self-insert what to insert.
|
|
86 (let ((last-command-char ?\n)
|
|
87 ;; Don't auto-fill if we have a numeric argument.
|
|
88 ;; Also not if flag is true (it would fill wrong line);
|
|
89 ;; there is no need to since we're at BOL.
|
|
90 (auto-fill-function (if (or arg flag) nil auto-fill-function)))
|
|
91 (unwind-protect
|
|
92 (self-insert-command (prefix-numeric-value arg))
|
|
93 ;; If we get an error in self-insert-command, put point at right place.
|
|
94 (if flag (forward-char 1))))
|
|
95 ;; If we did *not* get an error, cancel that forward-char.
|
|
96 (if flag (backward-char 1))
|
|
97 ;; Mark the newline(s) `hard'.
|
|
98 (if use-hard-newlines
|
|
99 (let* ((from (- (point) (if arg (prefix-numeric-value arg) 1)))
|
4
|
100 (sticky (get-text-property from 'end-open))) ; XEmacs
|
0
|
101 (put-text-property from (point) 'hard 't)
|
|
102 ;; If end-open is not "t", add 'hard to end-open list
|
|
103 (if (and (listp sticky) (not (memq 'hard sticky)))
|
4
|
104 (put-text-property from (point) 'end-open ; XEmacs
|
0
|
105 (cons 'hard sticky)))))
|
|
106 ;; If the newline leaves the previous line blank,
|
|
107 ;; and we have a left margin, delete that from the blank line.
|
|
108 (or flag
|
|
109 (save-excursion
|
|
110 (goto-char beforepos)
|
|
111 (beginning-of-line)
|
|
112 (and (looking-at "[ \t]$")
|
|
113 (> (current-left-margin) 0)
|
|
114 (delete-region (point) (progn (end-of-line) (point))))))
|
|
115 (if flag (forward-char 1))
|
|
116 ;; Indent the line after the newline, except in one case:
|
|
117 ;; when we added the newline at the beginning of a line
|
|
118 ;; which starts a page.
|
|
119 (or was-page-start
|
|
120 (move-to-left-margin nil t)))
|
|
121 nil)
|
|
122
|
|
123 (defun open-line (arg)
|
|
124 "Insert a newline and leave point before it.
|
|
125 If there is a fill prefix and/or a left-margin, insert them on the new line
|
|
126 if the line would have been blank.
|
|
127 With arg N, insert N newlines."
|
|
128 (interactive "*p")
|
|
129 (let* ((do-fill-prefix (and fill-prefix (bolp)))
|
|
130 (do-left-margin (and (bolp) (> (current-left-margin) 0)))
|
|
131 (loc (point)))
|
|
132 (newline arg)
|
|
133 (goto-char loc)
|
|
134 (while (> arg 0)
|
|
135 (cond ((bolp)
|
|
136 (if do-left-margin (indent-to (current-left-margin)))
|
|
137 (if do-fill-prefix (insert fill-prefix))))
|
|
138 (forward-line 1)
|
|
139 (setq arg (1- arg)))
|
|
140 (goto-char loc)
|
|
141 (end-of-line)))
|
|
142
|
|
143 (defun split-line ()
|
|
144 "Split current line, moving portion beyond point vertically down."
|
|
145 (interactive "*")
|
|
146 (skip-chars-forward " \t")
|
|
147 (let ((col (current-column))
|
|
148 (pos (point)))
|
|
149 (newline 1)
|
|
150 (indent-to col 0)
|
|
151 (goto-char pos)))
|
|
152
|
|
153 (defun quoted-insert (arg)
|
|
154 "Read next input character and insert it.
|
|
155 This is useful for inserting control characters.
|
|
156 You may also type up to 3 octal digits, to insert a character with that code.
|
|
157
|
|
158 In overwrite mode, this function inserts the character anyway, and
|
|
159 does not handle octal digits specially. This means that if you use
|
|
160 overwrite as your normal editing mode, you can use this function to
|
|
161 insert characters when necessary.
|
|
162
|
|
163 In binary overwrite mode, this function does overwrite, and octal
|
|
164 digits are interpreted as a character code. This is supposed to make
|
|
165 this function useful in editing binary files."
|
|
166 (interactive "*p")
|
|
167 (let ((char (if (or (not overwrite-mode)
|
|
168 (eq overwrite-mode 'overwrite-mode-binary))
|
|
169 (read-quoted-char)
|
|
170 (read-char))))
|
|
171 (if (> arg 0)
|
|
172 (if (eq overwrite-mode 'overwrite-mode-binary)
|
|
173 (delete-char arg)))
|
|
174 (while (> arg 0)
|
|
175 (insert char)
|
|
176 (setq arg (1- arg)))))
|
|
177
|
|
178 (defun delete-indentation (&optional arg)
|
|
179 "Join this line to previous and fix up whitespace at join.
|
|
180 If there is a fill prefix, delete it from the beginning of this line.
|
|
181 With argument, join this line to following line."
|
|
182 (interactive "*P")
|
|
183 (beginning-of-line)
|
|
184 (if arg (forward-line 1))
|
|
185 (if (eq (preceding-char) ?\n)
|
|
186 (progn
|
|
187 (delete-region (point) (1- (point)))
|
|
188 ;; If the second line started with the fill prefix,
|
|
189 ;; delete the prefix.
|
|
190 (if (and fill-prefix
|
|
191 (<= (+ (point) (length fill-prefix)) (point-max))
|
|
192 (string= fill-prefix
|
|
193 (buffer-substring (point)
|
|
194 (+ (point) (length fill-prefix)))))
|
|
195 (delete-region (point) (+ (point) (length fill-prefix))))
|
|
196 (fixup-whitespace))))
|
|
197
|
|
198 (defun fixup-whitespace ()
|
|
199 "Fixup white space between objects around point.
|
|
200 Leave one space or none, according to the context."
|
|
201 (interactive "*")
|
|
202 (save-excursion
|
|
203 (delete-horizontal-space)
|
|
204 (if (or (looking-at "^\\|\\s)")
|
|
205 (save-excursion (forward-char -1)
|
|
206 (looking-at "$\\|\\s(\\|\\s'")))
|
|
207 nil
|
|
208 (insert ?\ ))))
|
|
209
|
|
210 (defun delete-horizontal-space ()
|
|
211 "Delete all spaces and tabs around point."
|
|
212 (interactive "*")
|
|
213 (skip-chars-backward " \t")
|
|
214 (delete-region (point) (progn (skip-chars-forward " \t") (point))))
|
|
215
|
|
216 (defun just-one-space ()
|
|
217 "Delete all spaces and tabs around point, leaving one space."
|
|
218 (interactive "*")
|
4
|
219 (if abbrev-mode ; XEmacs
|
2
|
220 (expand-abbrev))
|
0
|
221 (skip-chars-backward " \t")
|
|
222 (if (= (following-char) ? )
|
|
223 (forward-char 1)
|
|
224 (insert ? ))
|
|
225 (delete-region (point) (progn (skip-chars-forward " \t") (point))))
|
|
226
|
|
227 (defun delete-blank-lines ()
|
|
228 "On blank line, delete all surrounding blank lines, leaving just one.
|
|
229 On isolated blank line, delete that one.
|
|
230 On nonblank line, delete any immediately following blank lines."
|
|
231 (interactive "*")
|
|
232 (let (thisblank singleblank)
|
|
233 (save-excursion
|
|
234 (beginning-of-line)
|
|
235 (setq thisblank (looking-at "[ \t]*$"))
|
|
236 ;; Set singleblank if there is just one blank line here.
|
|
237 (setq singleblank
|
|
238 (and thisblank
|
|
239 (not (looking-at "[ \t]*\n[ \t]*$"))
|
|
240 (or (bobp)
|
|
241 (progn (forward-line -1)
|
|
242 (not (looking-at "[ \t]*$")))))))
|
|
243 ;; Delete preceding blank lines, and this one too if it's the only one.
|
|
244 (if thisblank
|
|
245 (progn
|
|
246 (beginning-of-line)
|
|
247 (if singleblank (forward-line 1))
|
|
248 (delete-region (point)
|
|
249 (if (re-search-backward "[^ \t\n]" nil t)
|
|
250 (progn (forward-line 1) (point))
|
|
251 (point-min)))))
|
|
252 ;; Delete following blank lines, unless the current line is blank
|
|
253 ;; and there are no following blank lines.
|
|
254 (if (not (and thisblank singleblank))
|
|
255 (save-excursion
|
|
256 (end-of-line)
|
|
257 (forward-line 1)
|
|
258 (delete-region (point)
|
|
259 (if (re-search-forward "[^ \t\n]" nil t)
|
|
260 (progn (beginning-of-line) (point))
|
|
261 (point-max)))))
|
|
262 ;; Handle the special case where point is followed by newline and eob.
|
|
263 ;; Delete the line, leaving point at eob.
|
|
264 (if (looking-at "^[ \t]*\n\\'")
|
|
265 (delete-region (point) (point-max)))))
|
|
266
|
|
267 (defun back-to-indentation ()
|
|
268 "Move point to the first non-whitespace character on this line."
|
4
|
269 ;; XEmacs change
|
0
|
270 (interactive "_")
|
|
271 (beginning-of-line 1)
|
|
272 (skip-chars-forward " \t"))
|
|
273
|
|
274 (defun newline-and-indent ()
|
|
275 "Insert a newline, then indent according to major mode.
|
|
276 Indentation is done using the value of `indent-line-function'.
|
|
277 In programming language modes, this is the same as TAB.
|
|
278 In some text modes, where TAB inserts a tab, this command indents to the
|
|
279 column specified by the function `current-left-margin'."
|
|
280 (interactive "*")
|
|
281 (delete-region (point) (progn (skip-chars-backward " \t") (point)))
|
|
282 (newline)
|
|
283 (indent-according-to-mode))
|
|
284
|
|
285 (defun reindent-then-newline-and-indent ()
|
|
286 "Reindent current line, insert newline, then indent the new line.
|
|
287 Indentation of both lines is done according to the current major mode,
|
|
288 which means calling the current value of `indent-line-function'.
|
|
289 In programming language modes, this is the same as TAB.
|
|
290 In some text modes, where TAB inserts a tab, this indents to the
|
|
291 column specified by the function `current-left-margin'."
|
|
292 (interactive "*")
|
|
293 (save-excursion
|
|
294 (delete-region (point) (progn (skip-chars-backward " \t") (point)))
|
|
295 (indent-according-to-mode))
|
|
296 (newline)
|
|
297 (indent-according-to-mode))
|
|
298
|
|
299 ;; Internal subroutine of delete-char
|
|
300 (defun kill-forward-chars (arg)
|
|
301 (if (listp arg) (setq arg (car arg)))
|
|
302 (if (eq arg '-) (setq arg -1))
|
|
303 (kill-region (point) (+ (point) arg)))
|
|
304
|
|
305 ;; Internal subroutine of backward-delete-char
|
|
306 (defun kill-backward-chars (arg)
|
|
307 (if (listp arg) (setq arg (car arg)))
|
|
308 (if (eq arg '-) (setq arg -1))
|
|
309 (kill-region (point) (- (point) arg)))
|
|
310
|
|
311 (defun backward-delete-char-untabify (arg &optional killp)
|
|
312 "Delete characters backward, changing tabs into spaces.
|
|
313 Delete ARG chars, and kill (save in kill ring) if KILLP is non-nil.
|
|
314 Interactively, ARG is the prefix arg (default 1)
|
|
315 and KILLP is t if a prefix arg was specified."
|
|
316 (interactive "*p\nP")
|
|
317 (let ((count arg))
|
|
318 (save-excursion
|
|
319 (while (and (> count 0) (not (bobp)))
|
|
320 (if (= (preceding-char) ?\t)
|
|
321 (let ((col (current-column)))
|
|
322 (forward-char -1)
|
|
323 (setq col (- col (current-column)))
|
|
324 (insert-char ?\ col)
|
|
325 (delete-char 1)))
|
|
326 (forward-char -1)
|
|
327 (setq count (1- count)))))
|
|
328 (delete-backward-char arg killp)
|
4
|
329 ;; XEmacs: In overwrite mode, back over columns while clearing them out,
|
0
|
330 ;; unless at end of line.
|
|
331 (and overwrite-mode (not (eolp))
|
|
332 (save-excursion (insert-char ?\ arg))))
|
|
333
|
|
334 (defun zap-to-char (arg char)
|
|
335 "Kill up to and including ARG'th occurrence of CHAR.
|
|
336 Goes backward if ARG is negative; error if CHAR not found."
|
|
337 (interactive "*p\ncZap to char: ")
|
|
338 (kill-region (point) (progn
|
|
339 (search-forward (char-to-string char) nil nil arg)
|
|
340 ; (goto-char (if (> arg 0) (1- (point)) (1+ (point))))
|
|
341 (point))))
|
|
342
|
|
343 (defun beginning-of-buffer (&optional arg)
|
|
344 "Move point to the beginning of the buffer; leave mark at previous position.
|
|
345 With arg N, put point N/10 of the way from the beginning.
|
|
346
|
|
347 If the buffer is narrowed, this command uses the beginning and size
|
|
348 of the accessible part of the buffer.
|
|
349
|
|
350 Don't use this command in Lisp programs!
|
|
351 \(goto-char (point-min)) is faster and avoids clobbering the mark."
|
4
|
352 ;; XEmacs change
|
0
|
353 (interactive "_P")
|
|
354 (push-mark)
|
|
355 (let ((size (- (point-max) (point-min))))
|
|
356 (goto-char (if arg
|
|
357 (+ (point-min)
|
|
358 (if (> size 10000)
|
|
359 ;; Avoid overflow for large buffer sizes!
|
|
360 (* (prefix-numeric-value arg)
|
|
361 (/ size 10))
|
|
362 (/ (+ 10 (* size (prefix-numeric-value arg))) 10)))
|
|
363 (point-min))))
|
|
364 (if arg (forward-line 1)))
|
|
365
|
|
366 (defun end-of-buffer (&optional arg)
|
|
367 "Move point to the end of the buffer; leave mark at previous position.
|
|
368 With arg N, put point N/10 of the way from the end.
|
|
369
|
|
370 If the buffer is narrowed, this command uses the beginning and size
|
|
371 of the accessible part of the buffer.
|
|
372
|
|
373 Don't use this command in Lisp programs!
|
|
374 \(goto-char (point-max)) is faster and avoids clobbering the mark."
|
4
|
375 ;; XEmacs change
|
0
|
376 (interactive "_P")
|
|
377 (push-mark)
|
|
378 ;; XEmacs changes here.
|
|
379 (let ((scroll-to-end (not (pos-visible-in-window-p (point-max))))
|
|
380 (size (- (point-max) (point-min))))
|
|
381 (goto-char (if arg
|
|
382 (- (point-max)
|
|
383 (if (> size 10000)
|
|
384 ;; Avoid overflow for large buffer sizes!
|
|
385 (* (prefix-numeric-value arg)
|
|
386 (/ size 10))
|
|
387 (/ (* size (prefix-numeric-value arg)) 10)))
|
|
388 (point-max)))
|
|
389 (cond (arg
|
|
390 ;; If we went to a place in the middle of the buffer,
|
|
391 ;; adjust it to the beginning of a line.
|
|
392 (forward-line 1))
|
4
|
393 ;; XEmacs change
|
0
|
394 (scroll-to-end
|
|
395 ;; If the end of the buffer is not already on the screen,
|
|
396 ;; then scroll specially to put it near, but not at, the bottom.
|
|
397 (recenter -3)))))
|
|
398
|
4
|
399 ;; XEmacs (not in FSF)
|
0
|
400 (defun mark-beginning-of-buffer (&optional arg)
|
|
401 "Push a mark at the beginning of the buffer; leave point where it is.
|
|
402 With arg N, push mark N/10 of the way from the true beginning."
|
|
403 (interactive "P")
|
|
404 (push-mark (if arg
|
|
405 (if (> (buffer-size) 10000)
|
|
406 ;; Avoid overflow for large buffer sizes!
|
|
407 (* (prefix-numeric-value arg)
|
|
408 (/ (buffer-size) 10))
|
|
409 (/ (+ 10 (* (buffer-size) (prefix-numeric-value arg))) 10))
|
|
410 (point-min))
|
|
411 nil
|
|
412 t))
|
|
413 (define-function 'mark-bob 'mark-beginning-of-buffer)
|
|
414
|
4
|
415 ;; XEmacs (not in FSF)
|
0
|
416 (defun mark-end-of-buffer (&optional arg)
|
|
417 "Push a mark at the end of the buffer; leave point where it is.
|
|
418 With arg N, push mark N/10 of the way from the true end."
|
|
419 (interactive "P")
|
|
420 (push-mark (if arg
|
|
421 (- (1+ (buffer-size))
|
|
422 (if (> (buffer-size) 10000)
|
|
423 ;; Avoid overflow for large buffer sizes!
|
|
424 (* (prefix-numeric-value arg)
|
|
425 (/ (buffer-size) 10))
|
|
426 (/ (* (buffer-size) (prefix-numeric-value arg)) 10)))
|
|
427 (point-max))
|
|
428 nil
|
|
429 t))
|
|
430 (define-function 'mark-eob 'mark-end-of-buffer)
|
|
431
|
|
432 (defun mark-whole-buffer ()
|
|
433 "Put point at beginning and mark at end of buffer.
|
|
434 You probably should not use this function in Lisp programs;
|
|
435 it is usually a mistake for a Lisp function to use any subroutine
|
|
436 that uses or sets the mark."
|
|
437 (interactive)
|
|
438 (push-mark (point))
|
|
439 (push-mark (point-max) nil t)
|
|
440 (goto-char (point-min)))
|
|
441
|
4
|
442 ;; XEmacs
|
0
|
443 (defun eval-current-buffer (&optional printflag)
|
|
444 "Evaluate the current buffer as Lisp code.
|
|
445 Programs can pass argument PRINTFLAG which controls printing of output:
|
|
446 nil means discard it; anything else is stream for print."
|
|
447 (interactive)
|
|
448 (eval-buffer (current-buffer) printflag))
|
|
449
|
4
|
450 ;; XEmacs
|
0
|
451 (defun count-words-buffer (b)
|
|
452 (interactive "b")
|
|
453 (save-excursion
|
|
454 (let ((buf (or b (current-buffer))))
|
|
455 (set-buffer buf)
|
|
456 (message "Buffer has %d words"
|
|
457 (count-words-region (point-min) (point-max))))))
|
|
458
|
4
|
459 ;; XEmacs
|
0
|
460 (defun count-words-region (start end)
|
|
461 (interactive "r")
|
|
462 (save-excursion
|
|
463 (let ((n 0))
|
|
464 (goto-char start)
|
|
465 (while (< (point) end)
|
|
466 (if (forward-word 1)
|
|
467 (setq n (1+ n))))
|
|
468 (message "Region has %d words" n)
|
|
469 n)))
|
|
470
|
|
471 (defun count-lines-region (start end)
|
|
472 "Print number of lines and characters in the region."
|
4
|
473 ;; XEmacs change
|
0
|
474 (interactive "_r")
|
4
|
475 (message "Region has %d lines, %d characters"
|
|
476 (count-lines start end) (- end start)))
|
0
|
477
|
4
|
478 ;; XEmacs
|
0
|
479 (defun count-lines-buffer (b)
|
|
480 "Print number of lines and charcters in the specified buffer."
|
|
481 (interactive "_b")
|
|
482 (save-excursion
|
|
483 (let ((buf (or b (current-buffer)))
|
|
484 cnt)
|
|
485 (set-buffer buf)
|
|
486 (setq cnt (count-lines (point-min) (point-max)))
|
4
|
487 (message "Buffer has %d lines, %d characters"
|
0
|
488 cnt (- (point-max) (point-min)))
|
|
489 cnt)))
|
|
490
|
|
491 (defun what-line ()
|
|
492 "Print the current buffer line number and narrowed line number of point."
|
4
|
493 ;; XEmacs change
|
0
|
494 (interactive "_")
|
|
495 (let ((opoint (point)) start)
|
|
496 (save-excursion
|
|
497 (save-restriction
|
|
498 (goto-char (point-min))
|
|
499 (widen)
|
|
500 (beginning-of-line)
|
|
501 (setq start (point))
|
|
502 (goto-char opoint)
|
|
503 (beginning-of-line)
|
|
504 (if (/= start 1)
|
|
505 (message "line %d (narrowed line %d)"
|
|
506 (1+ (count-lines 1 (point)))
|
|
507 (1+ (count-lines start (point))))
|
|
508 (message "Line %d" (1+ (count-lines 1 (point)))))))))
|
|
509
|
|
510
|
|
511 (defun count-lines (start end)
|
|
512 "Return number of lines between START and END.
|
|
513 This is usually the number of newlines between them,
|
|
514 but can be one more if START is not equal to END
|
|
515 and the greater of them is not at the start of a line."
|
|
516 (save-excursion
|
|
517 (save-restriction
|
|
518 (narrow-to-region start end)
|
|
519 (goto-char (point-min))
|
|
520 (if (eq selective-display t)
|
|
521 (save-match-data
|
|
522 (let ((done 0))
|
|
523 (while (re-search-forward "[\n\C-m]" nil t 40)
|
|
524 (setq done (+ 40 done)))
|
|
525 (while (re-search-forward "[\n\C-m]" nil t 1)
|
|
526 (setq done (+ 1 done)))
|
|
527 (goto-char (point-max))
|
|
528 (if (and (/= start end)
|
|
529 (not (bolp)))
|
|
530 (1+ done)
|
|
531 done)))
|
|
532 (- (buffer-size) (forward-line (buffer-size)))))))
|
|
533
|
|
534 (defun what-cursor-position ()
|
|
535 "Print info on cursor position (on screen and within buffer)."
|
4
|
536 ;; XEmacs change
|
0
|
537 (interactive "_")
|
|
538 (let* ((char (following-char))
|
|
539 (beg (point-min))
|
|
540 (end (point-max))
|
|
541 (pos (point))
|
|
542 (total (buffer-size))
|
|
543 (percent (if (> total 50000)
|
|
544 ;; Avoid overflow from multiplying by 100!
|
|
545 (/ (+ (/ total 200) (1- pos)) (max (/ total 100) 1))
|
|
546 (/ (+ (/ total 2) (* 100 (1- pos))) (max total 1))))
|
|
547 (hscroll (if (= (window-hscroll) 0)
|
|
548 ""
|
|
549 (format " Hscroll=%d" (window-hscroll))))
|
|
550 (col (current-column)))
|
|
551 (if (= pos end)
|
|
552 (if (or (/= beg 1) (/= end (1+ total)))
|
|
553 (message "point=%d of %d(%d%%) <%d - %d> column %d %s"
|
|
554 pos total percent beg end col hscroll)
|
|
555 (message "point=%d of %d(%d%%) column %d %s"
|
|
556 pos total percent col hscroll))
|
4
|
557 ;; XEmacs: don't use single-key-description
|
0
|
558 (if (or (/= beg 1) (/= end (1+ total)))
|
|
559 (message "Char: %s (0%o, %d, 0x%x) point=%d of %d(%d%%) <%d - %d> column %d %s"
|
|
560 (text-char-description char) char char char pos total
|
|
561 percent beg end col hscroll)
|
|
562 (message "Char: %s (0%o, %d, 0x%x) point=%d of %d(%d%%) column %d %s"
|
|
563 (text-char-description char) char char char pos total
|
|
564 percent col hscroll)))))
|
|
565
|
|
566 (defun fundamental-mode ()
|
|
567 "Major mode not specialized for anything in particular.
|
|
568 Other major modes are defined by comparison with this one."
|
|
569 (interactive)
|
|
570 (kill-all-local-variables))
|
|
571
|
4
|
572 ;; XEmacs the following are declared elsewhere
|
|
573 ;(defvar read-expression-map (cons 'keymap minibuffer-local-map)
|
|
574 ; "Minibuffer keymap used for reading Lisp expressions.")
|
|
575 ;(define-key read-expression-map "\M-\t" 'lisp-complete-symbol)
|
|
576
|
|
577 ;(put 'eval-expression 'disabled t)
|
|
578
|
|
579 ;(defvar read-expression-history nil)
|
0
|
580
|
|
581 ;; We define this, rather than making `eval' interactive,
|
|
582 ;; for the sake of completion of names like eval-region, eval-current-buffer.
|
|
583 (defun eval-expression (expression)
|
|
584 "Evaluate EXPRESSION and print value in minibuffer.
|
|
585 Value is also consed on to front of the variable `values'."
|
4
|
586 ;(interactive "xEval: ")
|
|
587 (interactive
|
|
588 (list (read-from-minibuffer "Eval: "
|
|
589 nil read-expression-map t
|
|
590 'read-expression-history)))
|
0
|
591 (setq values (cons (eval expression) values))
|
|
592 (prin1 (car values) t))
|
|
593
|
4
|
594 ;; XEmacs -- extra parameter (variant, but equivalent logic)
|
0
|
595 (defun edit-and-eval-command (prompt command &optional history)
|
|
596 "Prompting with PROMPT, let user edit COMMAND and eval result.
|
|
597 COMMAND is a Lisp expression. Let user edit that expression in
|
|
598 the minibuffer, then read and evaluate the result."
|
|
599 (let ((command (read-expression prompt
|
|
600 ;; first try to format the thing readably;
|
|
601 ;; and if that fails, print it normally.
|
|
602 (condition-case ()
|
|
603 (let ((print-readably t))
|
|
604 (prin1-to-string command))
|
|
605 (error (prin1-to-string command)))
|
|
606 (or history '(command-history . 1)))))
|
|
607 (or history (setq history 'command-history))
|
|
608 (if (consp history)
|
|
609 (setq history (car history)))
|
|
610 (if (eq history t)
|
|
611 nil
|
|
612 ;; If command was added to the history as a string,
|
|
613 ;; get rid of that. We want only evallable expressions there.
|
|
614 (if (stringp (car (symbol-value history)))
|
|
615 (set history (cdr (symbol-value history))))
|
|
616
|
|
617 ;; If command to be redone does not match front of history,
|
|
618 ;; add it to the history.
|
|
619 (or (equal command (car (symbol-value history)))
|
|
620 (set history (cons command (symbol-value history)))))
|
|
621 (eval command)))
|
|
622
|
|
623 (defun repeat-complex-command (arg)
|
|
624 "Edit and re-evaluate last complex command, or ARGth from last.
|
|
625 A complex command is one which used the minibuffer.
|
|
626 The command is placed in the minibuffer as a Lisp form for editing.
|
|
627 The result is executed, repeating the command as changed.
|
|
628 If the command has been changed or is not the most recent previous command
|
|
629 it is added to the front of the command history.
|
|
630 You can use the minibuffer history commands \\<minibuffer-local-map>\\[next-history-element] and \\[previous-history-element]
|
|
631 to get different commands to edit and resubmit."
|
|
632 (interactive "p")
|
4
|
633 ;; XEmacs: It looks like our version is better -sb
|
0
|
634 (let ((print-level nil))
|
|
635 (edit-and-eval-command "Redo: "
|
|
636 (or (nth (1- arg) command-history)
|
|
637 (error ""))
|
|
638 (cons 'command-history arg))))
|
4
|
639
|
|
640 ;; XEmacs: Functions moved to minibuf.el
|
|
641 ;; previous-matching-history-element
|
|
642 ;; next-matching-history-element
|
|
643 ;; next-history-element
|
|
644 ;; previous-history-element
|
|
645 ;; next-complete-history-element
|
|
646 ;; previous-complete-history-element
|
0
|
647
|
|
648 (defun goto-line (arg)
|
|
649 "Goto line ARG, counting from line 1 at beginning of buffer."
|
|
650 (interactive "NGoto line: ")
|
|
651 (setq arg (prefix-numeric-value arg))
|
|
652 (save-restriction
|
|
653 (widen)
|
|
654 (goto-char 1)
|
|
655 (if (eq selective-display t)
|
|
656 (re-search-forward "[\n\C-m]" nil 'end (1- arg))
|
|
657 (forward-line (1- arg)))))
|
|
658
|
|
659 ;Put this on C-x u, so we can force that rather than C-_ into startup msg
|
|
660 (define-function 'advertised-undo 'undo)
|
|
661
|
|
662 (defun undo (&optional arg)
|
|
663 "Undo some previous changes.
|
|
664 Repeat this command to undo more changes.
|
|
665 A numeric argument serves as a repeat count."
|
|
666 (interactive "*p")
|
|
667 ;; If we don't get all the way through, make last-command indicate that
|
|
668 ;; for the following command.
|
|
669 (setq this-command t)
|
|
670 (let ((modified (buffer-modified-p))
|
|
671 (recent-save (recent-auto-save-p)))
|
|
672 (or (eq (selected-window) (minibuffer-window))
|
|
673 (message "Undo!"))
|
|
674 (or (and (eq last-command 'undo)
|
4
|
675 (eq (current-buffer) last-undo-buffer)) ; XEmacs
|
0
|
676 (progn (undo-start)
|
|
677 (undo-more 1)))
|
|
678 (undo-more (or arg 1))
|
|
679 ;; Don't specify a position in the undo record for the undo command.
|
|
680 ;; Instead, undoing this should move point to where the change is.
|
|
681 (let ((tail buffer-undo-list)
|
|
682 done)
|
|
683 (while (and tail (not done) (not (null (car tail))))
|
|
684 (if (integerp (car tail))
|
|
685 (progn
|
|
686 (setq done t)
|
|
687 (setq buffer-undo-list (delq (car tail) buffer-undo-list))))
|
|
688 (setq tail (cdr tail))))
|
|
689 (and modified (not (buffer-modified-p))
|
|
690 (delete-auto-save-file-if-necessary recent-save)))
|
|
691 ;; If we do get all the way through, make this-command indicate that.
|
|
692 (setq this-command 'undo))
|
|
693
|
|
694 (defvar pending-undo-list nil
|
|
695 "Within a run of consecutive undo commands, list remaining to be undone.")
|
|
696
|
4
|
697 (defvar last-undo-buffer nil) ; XEmacs
|
0
|
698
|
|
699 (defun undo-start ()
|
|
700 "Set `pending-undo-list' to the front of the undo list.
|
|
701 The next call to `undo-more' will undo the most recently made change."
|
|
702 (if (eq buffer-undo-list t)
|
|
703 (error "No undo information in this buffer"))
|
|
704 (setq pending-undo-list buffer-undo-list))
|
|
705
|
|
706 (defun undo-more (count)
|
|
707 "Undo back N undo-boundaries beyond what was already undone recently.
|
|
708 Call `undo-start' to get ready to undo recent changes,
|
|
709 then call `undo-more' one or more times to undo them."
|
|
710 (or pending-undo-list
|
|
711 (error "No further undo information"))
|
|
712 (setq pending-undo-list (primitive-undo count pending-undo-list)
|
4
|
713 last-undo-buffer (current-buffer))) ; XEmacs
|
0
|
714
|
4
|
715 ;; XEmacs
|
0
|
716 (defun call-with-transparent-undo (fn &rest args)
|
|
717 "Apply FN to ARGS, and then undo all changes made by FN to the current
|
|
718 buffer. The undo records are processed even if FN returns non-locally.
|
|
719 There is no trace of the changes made by FN in the buffer's undo history.
|
|
720
|
|
721 You can use this in a write-file-hooks function with continue-save-buffer
|
|
722 to make the contents of a disk file differ from its in-memory buffer."
|
|
723 (let ((buffer-undo-list nil)
|
|
724 ;; Kludge to prevent undo list truncation:
|
|
725 (undo-high-threshold -1)
|
|
726 (undo-threshold -1)
|
|
727 (obuffer (current-buffer)))
|
|
728 (unwind-protect
|
|
729 (apply fn args)
|
|
730 ;; Go to the buffer we will restore and make it writable:
|
|
731 (set-buffer obuffer)
|
|
732 (save-excursion
|
|
733 (let ((buffer-read-only nil))
|
|
734 (save-restriction
|
|
735 (widen)
|
|
736 ;; Perform all undos, with further undo logging disabled:
|
|
737 (let ((tail buffer-undo-list))
|
|
738 (setq buffer-undo-list t)
|
|
739 (while tail
|
|
740 (setq tail (primitive-undo (length tail) tail))))))))))
|
|
741
|
4
|
742 ;; XEmacs: The following are in other files
|
|
743 ;; shell-command-history
|
|
744 ;; shell-command-switch
|
|
745 ;; shell-command
|
|
746 ;; shell-command-sentinel
|
|
747
|
0
|
748
|
|
749 (defconst universal-argument-map
|
|
750 (let ((map (make-sparse-keymap)))
|
|
751 (set-keymap-default-binding map 'universal-argument-other-key)
|
|
752 ;FSFmacs (define-key map [switch-frame] nil)
|
4
|
753 (define-key map [(t)] 'universal-argument-other-key)
|
|
754 (define-key map [(meta t)] 'universal-argument-other-key)
|
0
|
755 (define-key map [(control u)] 'universal-argument-more)
|
4
|
756 (define-key map [?-] 'universal-argument-minus)
|
|
757 (define-key map [?0] 'digit-argument)
|
|
758 (define-key map [?1] 'digit-argument)
|
|
759 (define-key map [?2] 'digit-argument)
|
|
760 (define-key map [?3] 'digit-argument)
|
|
761 (define-key map [?4] 'digit-argument)
|
|
762 (define-key map [?5] 'digit-argument)
|
|
763 (define-key map [?6] 'digit-argument)
|
|
764 (define-key map [?7] 'digit-argument)
|
|
765 (define-key map [?8] 'digit-argument)
|
|
766 (define-key map [?9] 'digit-argument)
|
0
|
767 map)
|
|
768 "Keymap used while processing \\[universal-argument].")
|
|
769
|
|
770 (defvar universal-argument-num-events nil
|
|
771 "Number of argument-specifying events read by `universal-argument'.
|
|
772 `universal-argument-other-key' uses this to discard those events
|
|
773 from (this-command-keys), and reread only the final command.")
|
|
774
|
|
775 (defun universal-argument ()
|
|
776 "Begin a numeric argument for the following command.
|
|
777 Digits or minus sign following \\[universal-argument] make up the numeric argument.
|
|
778 \\[universal-argument] following the digits or minus sign ends the argument.
|
|
779 \\[universal-argument] without digits or minus sign provides 4 as argument.
|
|
780 Repeating \\[universal-argument] without digits or minus sign
|
|
781 multiplies the argument by 4 each time."
|
|
782 (interactive)
|
|
783 (setq prefix-arg (list 4))
|
4
|
784 (setq zmacs-region-stays t) ; XEmacs
|
0
|
785 (setq universal-argument-num-events (length (this-command-keys)))
|
|
786 (setq overriding-terminal-local-map universal-argument-map))
|
|
787
|
|
788 ;; A subsequent C-u means to multiply the factor by 4 if we've typed
|
|
789 ;; nothing but C-u's; otherwise it means to terminate the prefix arg.
|
|
790 (defun universal-argument-more (arg)
|
|
791 (interactive "P")
|
|
792 (if (consp arg)
|
|
793 (setq prefix-arg (list (* 4 (car arg))))
|
|
794 (setq prefix-arg arg)
|
|
795 (setq overriding-terminal-local-map nil))
|
4
|
796 (setq zmacs-region-stays t) ; XEmacs
|
0
|
797 (setq universal-argument-num-events (length (this-command-keys))))
|
|
798
|
|
799 (defun negative-argument (arg)
|
|
800 "Begin a negative numeric argument for the next command.
|
|
801 \\[universal-argument] following digits or minus sign ends the argument."
|
|
802 (interactive "P")
|
|
803 (cond ((integerp arg)
|
|
804 (setq prefix-arg (- arg)))
|
|
805 ((eq arg '-)
|
|
806 (setq prefix-arg nil))
|
|
807 (t
|
|
808 (setq prefix-arg '-)))
|
4
|
809 (setq zmacs-region-stays t) ; XEmacs
|
0
|
810 (setq universal-argument-num-events (length (this-command-keys)))
|
|
811 (setq overriding-terminal-local-map universal-argument-map))
|
|
812
|
4
|
813 ;; XEmacs: This function not synched with FSF
|
0
|
814 (defun digit-argument (arg)
|
|
815 "Part of the numeric argument for the next command.
|
|
816 \\[universal-argument] following digits or minus sign ends the argument."
|
|
817 (interactive "P")
|
|
818 (let* ((event last-command-event)
|
|
819 (key (and (key-press-event-p event)
|
|
820 (event-key event)))
|
|
821 (digit (and key (characterp key) (>= key ?0) (<= key ?9)
|
|
822 (- key ?0))))
|
|
823 (if (null digit)
|
|
824 (universal-argument-other-key arg)
|
|
825 (cond ((integerp arg)
|
|
826 (setq prefix-arg (+ (* arg 10)
|
|
827 (if (< arg 0) (- digit) digit))))
|
|
828 ((eq arg '-)
|
|
829 ;; Treat -0 as just -, so that -01 will work.
|
|
830 (setq prefix-arg (if (zerop digit) '- (- digit))))
|
|
831 (t
|
|
832 (setq prefix-arg digit)))
|
|
833 (setq zmacs-region-stays t)
|
|
834 (setq universal-argument-num-events (length (this-command-keys)))
|
|
835 (setq overriding-terminal-local-map universal-argument-map))))
|
|
836
|
|
837 ;; For backward compatibility, minus with no modifiers is an ordinary
|
|
838 ;; command if digits have already been entered.
|
|
839 (defun universal-argument-minus (arg)
|
|
840 (interactive "P")
|
|
841 (if (integerp arg)
|
|
842 (universal-argument-other-key arg)
|
|
843 (negative-argument arg)))
|
|
844
|
|
845 ;; Anything else terminates the argument and is left in the queue to be
|
|
846 ;; executed as a command.
|
|
847 (defun universal-argument-other-key (arg)
|
|
848 (interactive "P")
|
|
849 (setq prefix-arg arg)
|
4
|
850 (setq zmacs-region-stays t) ; XEmacs
|
0
|
851 (let* ((key (this-command-keys))
|
|
852 ;; FSF calls silly function `listify-key-sequence' here.
|
|
853 (keylist (append key nil)))
|
|
854 (setq unread-command-events
|
|
855 (append (nthcdr universal-argument-num-events keylist)
|
|
856 unread-command-events)))
|
|
857 (reset-this-command-lengths)
|
|
858 (setq overriding-terminal-local-map nil))
|
|
859
|
|
860
|
4
|
861 ;; XEmacs -- shouldn't these functions keep the zmacs region active?
|
0
|
862 (defun forward-to-indentation (arg)
|
|
863 "Move forward ARG lines and position at first nonblank character."
|
6
|
864 (interactive "_p")
|
0
|
865 (forward-line arg)
|
|
866 (skip-chars-forward " \t"))
|
|
867
|
|
868 (defun backward-to-indentation (arg)
|
|
869 "Move backward ARG lines and position at first nonblank character."
|
6
|
870 (interactive "_p")
|
0
|
871 (forward-line (- arg))
|
|
872 (skip-chars-forward " \t"))
|
|
873
|
|
874 (defvar kill-whole-line nil
|
|
875 "*If non-nil, `kill-line' with no arg at beg of line kills the whole line.")
|
|
876
|
|
877 (defun kill-line (&optional arg)
|
|
878 "Kill the rest of the current line; if no nonblanks there, kill thru newline.
|
|
879 With prefix argument, kill that many lines from point.
|
|
880 Negative arguments kill lines backward.
|
|
881
|
|
882 When calling from a program, nil means \"no arg\",
|
|
883 a number counts as a prefix arg.
|
|
884
|
|
885 If `kill-whole-line' is non-nil, then kill the whole line
|
|
886 when given no argument at the beginning of a line."
|
|
887 (interactive "*P")
|
|
888 (kill-region (point)
|
|
889 ;; Don't shift point before doing the delete; that way,
|
|
890 ;; undo will record the right position of point.
|
4
|
891 ;; FSF
|
|
892 ; ;; It is better to move point to the other end of the kill
|
|
893 ; ;; before killing. That way, in a read-only buffer, point
|
|
894 ; ;; moves across the text that is copied to the kill ring.
|
|
895 ; ;; The choice has no effect on undo now that undo records
|
|
896 ; ;; the value of point from before the command was run.
|
|
897 ; (progn
|
0
|
898 (save-excursion
|
|
899 (if arg
|
|
900 (forward-line (prefix-numeric-value arg))
|
|
901 (if (eobp)
|
|
902 (signal 'end-of-buffer nil))
|
|
903 (if (or (looking-at "[ \t]*$") (and kill-whole-line (bolp)))
|
|
904 (forward-line 1)
|
|
905 (end-of-line)))
|
|
906 (point))))
|
|
907
|
4
|
908 ;; XEmacs
|
0
|
909 (defun backward-kill-line nil
|
|
910 "Kill back to the beginning of the line."
|
|
911 (interactive)
|
|
912 (let ((point (point)))
|
|
913 (beginning-of-line nil)
|
|
914 (kill-region (point) point)))
|
|
915
|
|
916
|
|
917 ;;;; Window system cut and paste hooks.
|
|
918 ;;;
|
|
919 ;;; I think that kill-hooks is a better name and more general mechanism
|
|
920 ;;; than interprogram-cut-function (from FSFmacs). I don't like the behavior
|
|
921 ;;; of interprogram-paste-function: ^Y should always come from the kill ring,
|
|
922 ;;; not the X selection. But if that were provided, it should be called (and
|
|
923 ;;; behave as) yank-hooks instead. -- jwz
|
|
924
|
|
925 ;(defvar interprogram-cut-function nil
|
|
926 ; "Function to call to make a killed region available to other programs.
|
|
927 ;
|
|
928 ;Most window systems provide some sort of facility for cutting and
|
|
929 ;pasting text between the windows of different programs.
|
|
930 ;This variable holds a function that XEmacs calls whenever text
|
|
931 ;is put in the kill ring, to make the new kill available to other
|
|
932 ;programs.
|
|
933 ;
|
|
934 ;The function takes one or two arguments.
|
|
935 ;The first argument, TEXT, is a string containing
|
|
936 ;the text which should be made available.
|
|
937 ;The second, PUSH, if non-nil means this is a \"new\" kill;
|
|
938 ;nil means appending to an \"old\" kill.")
|
|
939 ;
|
|
940 ;(defvar interprogram-paste-function nil
|
|
941 ; "Function to call to get text cut from other programs.
|
|
942 ;
|
|
943 ;Most window systems provide some sort of facility for cutting and
|
|
944 ;pasting text between the windows of different programs.
|
|
945 ;This variable holds a function that Emacs calls to obtain
|
|
946 ;text that other programs have provided for pasting.
|
|
947 ;
|
|
948 ;The function should be called with no arguments. If the function
|
|
949 ;returns nil, then no other program has provided such text, and the top
|
|
950 ;of the Emacs kill ring should be used. If the function returns a
|
|
951 ;string, that string should be put in the kill ring as the latest kill.
|
|
952 ;
|
|
953 ;Note that the function should return a string only if a program other
|
|
954 ;than Emacs has provided a string for pasting; if Emacs provided the
|
|
955 ;most recent string, the function should return nil. If it is
|
|
956 ;difficult to tell whether Emacs or some other program provided the
|
|
957 ;current string, it is probably good enough to return nil if the string
|
|
958 ;is equal (according to `string=') to the last text Emacs provided.")
|
|
959
|
|
960 (defvar kill-hooks nil
|
|
961 "Functions run when something is added to the XEmacs kill ring.
|
|
962 These functions are called with one argument, the string most recently
|
|
963 cut or copied. You can use this to, for example, make the most recent
|
|
964 kill become the X Clipboard selection.")
|
|
965
|
|
966
|
|
967 ;;;; The kill ring data structure.
|
|
968
|
|
969 (defvar kill-ring nil
|
|
970 "List of killed text sequences.
|
4
|
971 Since the kill ring is supposed to interact nicely with cut-and-paste
|
|
972 facilities offered by window systems, use of this variable should
|
|
973 interact nicely with `interprogram-cut-function' and
|
|
974 `interprogram-paste-function'. The functions `kill-new',
|
|
975 `kill-append', and `current-kill' are supposed to implement this
|
|
976 interaction; you may want to use them instead of manipulating the kill
|
|
977 ring directly.")
|
0
|
978
|
4
|
979 (defconst kill-ring-max 30
|
0
|
980 "*Maximum length of kill ring before oldest elements are thrown away.")
|
|
981
|
|
982 (defvar kill-ring-yank-pointer nil
|
|
983 "The tail of the kill ring whose car is the last thing yanked.")
|
|
984
|
|
985 (defun kill-new (string &optional replace)
|
|
986 "Make STRING the latest kill in the kill ring.
|
|
987 Set the kill-ring-yank pointer to point to it.
|
|
988 Run `kill-hooks'.
|
|
989 Optional second argument REPLACE non-nil means that STRING will replace
|
|
990 the front of the kill ring, rather than being added to the list."
|
|
991 ; (and (fboundp 'menu-bar-update-yank-menu)
|
|
992 ; (menu-bar-update-yank-menu string (and replace (car kill-ring))))
|
|
993 (if replace
|
|
994 (setcar kill-ring string)
|
|
995 (setq kill-ring (cons string kill-ring))
|
|
996 (if (> (length kill-ring) kill-ring-max)
|
|
997 (setcdr (nthcdr (1- kill-ring-max) kill-ring) nil)))
|
|
998 (setq kill-ring-yank-pointer kill-ring)
|
|
999 ; (if interprogram-cut-function
|
|
1000 ; (funcall interprogram-cut-function string (not replace)))
|
|
1001 (run-hook-with-args 'kill-hooks string))
|
|
1002
|
|
1003 (defun kill-append (string before-p)
|
|
1004 "Append STRING to the end of the latest kill in the kill ring.
|
|
1005 If BEFORE-P is non-nil, prepend STRING to the kill.
|
|
1006 Run `kill-hooks'."
|
|
1007 (kill-new (if before-p
|
|
1008 (concat string (car kill-ring))
|
|
1009 (concat (car kill-ring) string)) t))
|
|
1010
|
|
1011 (defun current-kill (n &optional do-not-move)
|
|
1012 "Rotate the yanking point by N places, and then return that kill.
|
|
1013 If optional arg DO-NOT-MOVE is non-nil, then don't actually move the
|
|
1014 yanking point\; just return the Nth kill forward."
|
|
1015 (or kill-ring (error "Kill ring is empty"))
|
|
1016 (let* ((tem (nthcdr (mod (- n (length kill-ring-yank-pointer))
|
|
1017 (length kill-ring))
|
|
1018 kill-ring)))
|
|
1019 (or do-not-move
|
|
1020 (setq kill-ring-yank-pointer tem))
|
|
1021 (car tem)))
|
|
1022
|
|
1023
|
|
1024
|
|
1025 ;;;; Commands for manipulating the kill ring.
|
|
1026
|
|
1027 ;;FSFmacs
|
|
1028 ;(defvar kill-read-only-ok nil
|
|
1029 ; "*Non-nil means don't signal an error for killing read-only text.")
|
|
1030
|
4
|
1031 ;(put 'text-read-only 'error-conditions
|
|
1032 ; '(text-read-only buffer-read-only error))
|
|
1033 ;(put 'text-read-only 'error-message "Text is read-only")
|
|
1034
|
0
|
1035 (defun kill-region (beg end &optional verbose) ; verbose is XEmacs addition
|
|
1036 "Kill between point and mark.
|
|
1037 The text is deleted but saved in the kill ring.
|
|
1038 The command \\[yank] can retrieve it from there.
|
|
1039 \(If you want to kill and then yank immediately, use \\[copy-region-as-kill].)
|
|
1040
|
|
1041 This is the primitive for programs to kill text (as opposed to deleting it).
|
|
1042 Supply two arguments, character numbers indicating the stretch of text
|
|
1043 to be killed.
|
|
1044 Any command that calls this function is a \"kill command\".
|
|
1045 If the previous command was also a kill command,
|
|
1046 the text killed this time appends to the text killed last time
|
|
1047 to make one entry in the kill ring."
|
|
1048 (interactive "*r\np")
|
|
1049 ; (interactive
|
|
1050 ; (let ((region-hack (and zmacs-regions (eq last-command 'yank))))
|
|
1051 ; ;; This lets "^Y^W" work. I think this is dumb, but zwei did it.
|
|
1052 ; (if region-hack (zmacs-activate-region))
|
|
1053 ; (prog1
|
|
1054 ; (list (point) (mark) current-prefix-arg)
|
|
1055 ; (if region-hack (zmacs-deactivate-region)))))
|
|
1056 ;; beg and end can be markers but the rest of this function is
|
|
1057 ;; written as if they are only integers
|
|
1058 (if (markerp beg) (setq beg (marker-position beg)))
|
|
1059 (if (markerp end) (setq end (marker-position end)))
|
|
1060 (or (and beg end) (if zmacs-regions ;; rewritten for I18N3 snarfing
|
|
1061 (error "The region is not active now")
|
|
1062 (error "The mark is not set now")))
|
|
1063 (if verbose (if buffer-read-only
|
|
1064 (message "Copying %d characters"
|
|
1065 (- (max beg end) (min beg end)))
|
|
1066 (message "Killing %d characters"
|
|
1067 (- (max beg end) (min beg end)))))
|
|
1068 (cond
|
|
1069
|
|
1070 ;; I don't like this large change in behavior -- jwz
|
4
|
1071 ;; Read-Only text means it shouldn't be deleted, so I'm restoring
|
|
1072 ;; this code, but only for text-properties and not full extents. -sb
|
0
|
1073 ;; If the buffer is read-only, we should beep, in case the person
|
|
1074 ;; just isn't aware of this. However, there's no harm in putting
|
|
1075 ;; the region's text in the kill ring, anyway.
|
4
|
1076 ((or (and buffer-read-only (not inhibit-read-only))
|
|
1077 (text-property-not-all beg end 'read-only nil))
|
|
1078 ;; This is redundant.
|
0
|
1079 ;; (if verbose (message "Copying %d characters"
|
4
|
1080 ;; (- (max beg end) (min beg end))))
|
|
1081 (copy-region-as-kill beg end)
|
0
|
1082 ;; ;; This should always barf, and give us the correct error.
|
|
1083 ;; (if kill-read-only-ok
|
|
1084 ;; (message "Read only text copied to kill ring")
|
4
|
1085 (setq this-command 'kill-region)
|
|
1086 (barf-if-buffer-read-only)
|
|
1087 (signal 'text-read-only (list (current-buffer))))
|
0
|
1088
|
|
1089 ;; In certain cases, we can arrange for the undo list and the kill
|
|
1090 ;; ring to share the same string object. This code does that.
|
|
1091 ((not (or (eq buffer-undo-list t)
|
|
1092 (eq last-command 'kill-region)
|
|
1093 ;; Use = since positions may be numbers or markers.
|
|
1094 (= beg end)))
|
|
1095 ;; Don't let the undo list be truncated before we can even access it.
|
4
|
1096 ;; FSF calls this `undo-strong-limit'
|
0
|
1097 (let ((undo-high-threshold (+ (- (max beg end) (min beg end)) 100))
|
|
1098 ;(old-list buffer-undo-list)
|
|
1099 tail)
|
|
1100 (delete-region beg end)
|
|
1101 ;; Search back in buffer-undo-list for this string,
|
|
1102 ;; in case a change hook made property changes.
|
|
1103 (setq tail buffer-undo-list)
|
4
|
1104 (while (not (stringp (car-safe (car-safe tail)))) ; XEmacs
|
0
|
1105 (setq tail (cdr tail)))
|
|
1106 ;; Take the same string recorded for undo
|
|
1107 ;; and put it in the kill-ring.
|
|
1108 (kill-new (car (car tail)))))
|
|
1109
|
|
1110 (t
|
|
1111 ;; if undo is not kept, grab the string then delete it (which won't
|
|
1112 ;; add another string to the undo list).
|
|
1113 (copy-region-as-kill beg end)
|
|
1114 (delete-region beg end)))
|
|
1115 (setq this-command 'kill-region))
|
|
1116
|
|
1117 ;; copy-region-as-kill no longer sets this-command, because it's confusing
|
|
1118 ;; to get two copies of the text when the user accidentally types M-w and
|
|
1119 ;; then corrects it with the intended C-w.
|
|
1120 (defun copy-region-as-kill (beg end)
|
|
1121 "Save the region as if killed, but don't kill it.
|
|
1122 Run `kill-hooks'."
|
|
1123 (interactive "r")
|
|
1124 (if (eq last-command 'kill-region)
|
|
1125 (kill-append (buffer-substring beg end) (< end beg))
|
|
1126 (kill-new (buffer-substring beg end)))
|
|
1127 nil)
|
|
1128
|
|
1129 (defun kill-ring-save (beg end)
|
|
1130 "Save the region as if killed, but don't kill it.
|
|
1131 This command is similar to `copy-region-as-kill', except that it gives
|
|
1132 visual feedback indicating the extent of the region being copied."
|
|
1133 (interactive "r")
|
|
1134 (copy-region-as-kill beg end)
|
|
1135 ;; copy before delay, for xclipboard's benefit
|
|
1136 (if (interactive-p)
|
|
1137 (let ((other-end (if (= (point) beg) end beg))
|
|
1138 (opoint (point))
|
|
1139 ;; Inhibit quitting so we can make a quit here
|
|
1140 ;; look like a C-g typed as a command.
|
|
1141 (inhibit-quit t))
|
|
1142 (if (pos-visible-in-window-p other-end (selected-window))
|
|
1143 (progn
|
4
|
1144 ;; FSF (I'm not sure what this does -sb)
|
|
1145 ; ;; Swap point and mark.
|
|
1146 ; (set-marker (mark-marker) (point) (current-buffer))
|
0
|
1147 (goto-char other-end)
|
|
1148 (sit-for 1)
|
4
|
1149 ; ;; Swap back.
|
|
1150 ; (set-marker (mark-marker) other-end (current-buffer))
|
0
|
1151 (goto-char opoint)
|
|
1152 ;; If user quit, deactivate the mark
|
|
1153 ;; as C-g would as a command.
|
|
1154 (and quit-flag (mark)
|
|
1155 (zmacs-deactivate-region)))
|
|
1156 ;; too noisy. -- jwz
|
|
1157 ; (let* ((killed-text (current-kill 0))
|
|
1158 ; (message-len (min (length killed-text) 40)))
|
|
1159 ; (if (= (point) beg)
|
|
1160 ; ;; Don't say "killed"; that is misleading.
|
|
1161 ; (message "Saved text until \"%s\""
|
|
1162 ; (substring killed-text (- message-len)))
|
|
1163 ; (message "Saved text from \"%s\""
|
|
1164 ; (substring killed-text 0 message-len))))
|
|
1165 ))))
|
|
1166
|
|
1167 (defun append-next-kill ()
|
|
1168 "Cause following command, if it kills, to append to previous kill."
|
4
|
1169 ;; XEmacs
|
0
|
1170 (interactive "_")
|
|
1171 (if (interactive-p)
|
|
1172 (progn
|
|
1173 (setq this-command 'kill-region)
|
|
1174 (message "If the next command is a kill, it will append"))
|
|
1175 (setq last-command 'kill-region)))
|
|
1176
|
|
1177 (defun yank-pop (arg)
|
|
1178 "Replace just-yanked stretch of killed text with a different stretch.
|
|
1179 This command is allowed only immediately after a `yank' or a `yank-pop'.
|
|
1180 At such a time, the region contains a stretch of reinserted
|
|
1181 previously-killed text. `yank-pop' deletes that text and inserts in its
|
|
1182 place a different stretch of killed text.
|
|
1183
|
|
1184 With no argument, the previous kill is inserted.
|
|
1185 With argument N, insert the Nth previous kill.
|
|
1186 If N is negative, this is a more recent kill.
|
|
1187
|
|
1188 The sequence of kills wraps around, so that after the oldest one
|
|
1189 comes the newest one."
|
|
1190 (interactive "*p")
|
|
1191 (if (not (eq last-command 'yank))
|
|
1192 (error "Previous command was not a yank"))
|
|
1193 (setq this-command 'yank)
|
4
|
1194 (let ((inhibit-read-only t)
|
|
1195 (before (< (point) (mark t))))
|
0
|
1196 (delete-region (point) (mark t))
|
4
|
1197 ;;(set-marker (mark-marker) (point) (current-buffer))
|
0
|
1198 (set-mark (point))
|
|
1199 (insert (current-kill arg))
|
4
|
1200 (if before
|
|
1201 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
|
|
1202 ;; It is cleaner to avoid activation, even though the command
|
|
1203 ;; loop would deactivate the mark because we inserted text.
|
|
1204 (goto-char (prog1 (mark t)
|
|
1205 (set-marker (mark-marker) (point) (current-buffer))))))
|
|
1206 nil)
|
|
1207
|
0
|
1208
|
|
1209 (defun yank (&optional arg)
|
|
1210 "Reinsert the last stretch of killed text.
|
|
1211 More precisely, reinsert the stretch of killed text most recently
|
|
1212 killed OR yanked. Put point at end, and set mark at beginning.
|
|
1213 With just C-u as argument, same but put point at beginning (and mark at end).
|
4
|
1214 With argument N, reinsert the Nth most recently killed stretch of killed
|
|
1215 text.
|
0
|
1216 See also the command \\[yank-pop]."
|
|
1217 (interactive "*P")
|
|
1218 ;; If we don't get all the way through, make last-command indicate that
|
|
1219 ;; for the following command.
|
|
1220 (setq this-command t)
|
|
1221 (push-mark (point))
|
|
1222 (insert (current-kill (cond
|
|
1223 ((listp arg) 0)
|
|
1224 ((eq arg '-) -1)
|
|
1225 (t (1- arg)))))
|
|
1226 (if (consp arg)
|
4
|
1227 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
|
|
1228 ;; It is cleaner to avoid activation, even though the command
|
|
1229 ;; loop would deactivate the mark because we inserted text.
|
6
|
1230 ;; (But doesn't work in XEmacs)
|
|
1231 ;(goto-char (prog1 (mark t)
|
|
1232 ;(set-marker (mark-marker) (point) (current-buffer)))))
|
|
1233 (exchange-point-and-mark t))
|
4
|
1234 ;; If we do get all the way thru, make this-command indicate that.
|
|
1235 (setq this-command 'yank)
|
|
1236 nil)
|
0
|
1237
|
|
1238 (defun rotate-yank-pointer (arg)
|
|
1239 "Rotate the yanking point in the kill ring.
|
|
1240 With argument, rotate that many kills forward (or backward, if negative)."
|
|
1241 (interactive "p")
|
|
1242 (current-kill arg))
|
|
1243
|
|
1244
|
|
1245 (defun insert-buffer (buffer)
|
|
1246 "Insert after point the contents of BUFFER.
|
|
1247 Puts mark after the inserted text.
|
|
1248 BUFFER may be a buffer or a buffer name."
|
4
|
1249 (interactive
|
|
1250 (list
|
|
1251 (progn
|
|
1252 (barf-if-buffer-read-only)
|
|
1253 (read-buffer "Insert buffer: "
|
|
1254 ;; XEmacs: we have different args
|
|
1255 (other-buffer (current-buffer) nil t)
|
|
1256 t))))
|
0
|
1257 (or (bufferp buffer)
|
|
1258 (setq buffer (get-buffer buffer)))
|
|
1259 (let (start end newmark)
|
|
1260 (save-excursion
|
|
1261 (save-excursion
|
|
1262 (set-buffer buffer)
|
|
1263 (setq start (point-min) end (point-max)))
|
|
1264 (insert-buffer-substring buffer start end)
|
|
1265 (setq newmark (point)))
|
|
1266 (push-mark newmark))
|
|
1267 nil)
|
|
1268
|
|
1269 (defun append-to-buffer (buffer start end)
|
|
1270 "Append to specified buffer the text of the region.
|
|
1271 It is inserted into that buffer before its point.
|
|
1272
|
|
1273 When calling from a program, give three arguments:
|
|
1274 BUFFER (or buffer name), START and END.
|
|
1275 START and END specify the portion of the current buffer to be copied."
|
|
1276 (interactive
|
|
1277 ;; XEmacs: we have different args to other-buffer
|
|
1278 (list (read-buffer "Append to buffer: " (other-buffer (current-buffer)
|
|
1279 nil t))
|
|
1280 (region-beginning) (region-end)))
|
|
1281 (let ((oldbuf (current-buffer)))
|
|
1282 (save-excursion
|
|
1283 (set-buffer (get-buffer-create buffer))
|
|
1284 (insert-buffer-substring oldbuf start end))))
|
|
1285
|
|
1286 (defun prepend-to-buffer (buffer start end)
|
|
1287 "Prepend to specified buffer the text of the region.
|
|
1288 It is inserted into that buffer after its point.
|
|
1289
|
|
1290 When calling from a program, give three arguments:
|
|
1291 BUFFER (or buffer name), START and END.
|
|
1292 START and END specify the portion of the current buffer to be copied."
|
|
1293 (interactive "BPrepend to buffer: \nr")
|
|
1294 (let ((oldbuf (current-buffer)))
|
|
1295 (save-excursion
|
|
1296 (set-buffer (get-buffer-create buffer))
|
|
1297 (save-excursion
|
|
1298 (insert-buffer-substring oldbuf start end)))))
|
|
1299
|
|
1300 (defun copy-to-buffer (buffer start end)
|
|
1301 "Copy to specified buffer the text of the region.
|
|
1302 It is inserted into that buffer, replacing existing text there.
|
|
1303
|
|
1304 When calling from a program, give three arguments:
|
|
1305 BUFFER (or buffer name), START and END.
|
|
1306 START and END specify the portion of the current buffer to be copied."
|
|
1307 (interactive "BCopy to buffer: \nr")
|
|
1308 (let ((oldbuf (current-buffer)))
|
|
1309 (save-excursion
|
|
1310 (set-buffer (get-buffer-create buffer))
|
|
1311 (erase-buffer)
|
|
1312 (save-excursion
|
|
1313 (insert-buffer-substring oldbuf start end)))))
|
|
1314
|
|
1315 ;FSFmacs
|
4
|
1316 ;(put 'mark-inactive 'error-conditions '(mark-inactive error))
|
|
1317 ;(put 'mark-inactive 'error-message "The mark is not active now")
|
0
|
1318
|
|
1319 (defun mark (&optional force buffer)
|
|
1320 "Return this buffer's mark value as integer, or nil if no mark.
|
|
1321
|
|
1322 If `zmacs-regions' is true, then this returns nil unless the region is
|
|
1323 currently in the active (highlighted) state. With an argument of t, this
|
|
1324 returns the mark (if there is one) regardless of the active-region state.
|
|
1325 You should *generally* not use the mark unless the region is active, if
|
|
1326 the user has expressed a preference for the active-region model.
|
|
1327
|
|
1328 If you are using this in an editing command, you are most likely making
|
|
1329 a mistake; see the documentation of `set-mark'."
|
|
1330 (setq buffer (decode-buffer buffer))
|
|
1331 ;FSFmacs version:
|
|
1332 ; (if (or force (not transient-mark-mode) mark-active mark-even-if-inactive)
|
|
1333 ; (marker-position (mark-marker))
|
|
1334 ; (signal 'mark-inactive nil)))
|
|
1335 (let ((m (mark-marker force buffer)))
|
|
1336 (and m (marker-position m))))
|
|
1337
|
|
1338 ;;;#### FSFmacs
|
|
1339 ;;; Many places set mark-active directly, and several of them failed to also
|
|
1340 ;;; run deactivate-mark-hook. This shorthand should simplify.
|
|
1341 ;(defsubst deactivate-mark ()
|
|
1342 ; "Deactivate the mark by setting `mark-active' to nil.
|
|
1343 ;\(That makes a difference only in Transient Mark mode.)
|
|
1344 ;Also runs the hook `deactivate-mark-hook'."
|
|
1345 ; (if transient-mark-mode
|
|
1346 ; (progn
|
|
1347 ; (setq mark-active nil)
|
|
1348 ; (run-hooks 'deactivate-mark-hook))))
|
|
1349
|
|
1350 (defun set-mark (pos &optional buffer)
|
|
1351 "Set this buffer's mark to POS. Don't use this function!
|
|
1352 That is to say, don't use this function unless you want
|
|
1353 the user to see that the mark has moved, and you want the previous
|
|
1354 mark position to be lost.
|
|
1355
|
|
1356 Normally, when a new mark is set, the old one should go on the stack.
|
|
1357 This is why most applications should use push-mark, not set-mark.
|
|
1358
|
|
1359 Novice Emacs Lisp programmers often try to use the mark for the wrong
|
|
1360 purposes. The mark saves a location for the user's convenience.
|
|
1361 Most editing commands should not alter the mark.
|
|
1362 To remember a location for internal use in the Lisp program,
|
|
1363 store it in a Lisp variable. Example:
|
|
1364
|
|
1365 (let ((beg (point))) (forward-line 1) (delete-region beg (point)))."
|
|
1366
|
|
1367 (setq buffer (decode-buffer buffer))
|
|
1368 (set-marker (mark-marker t buffer) pos buffer))
|
4
|
1369 ;; FSF
|
|
1370 ; (if pos
|
|
1371 ; (progn
|
|
1372 ; (setq mark-active t)
|
|
1373 ; (run-hooks 'activate-mark-hook)
|
|
1374 ; (set-marker (mark-marker) pos (current-buffer)))
|
|
1375 ; ;; Normally we never clear mark-active except in Transient Mark mode.
|
|
1376 ; ;; But when we actually clear out the mark value too,
|
|
1377 ; ;; we must clear mark-active in any mode.
|
|
1378 ; (setq mark-active nil)
|
|
1379 ; (run-hooks 'deactivate-mark-hook)
|
|
1380 ; (set-marker (mark-marker) nil)))
|
0
|
1381
|
|
1382 (defvar mark-ring nil
|
|
1383 "The list of former marks of the current buffer, most recent first.")
|
|
1384 (make-variable-buffer-local 'mark-ring)
|
|
1385 (put 'mark-ring 'permanent-local t)
|
|
1386
|
4
|
1387 (defconst mark-ring-max 16
|
0
|
1388 "*Maximum size of mark ring. Start discarding off end if gets this big.")
|
|
1389
|
|
1390 (defvar global-mark-ring nil
|
|
1391 "The list of saved global marks, most recent first.")
|
|
1392
|
|
1393 (defconst global-mark-ring-max 16
|
|
1394 "*Maximum size of global mark ring. \
|
|
1395 Start discarding off end if gets this big.")
|
|
1396
|
|
1397 (defun set-mark-command (arg)
|
|
1398 "Set mark at where point is, or jump to mark.
|
4
|
1399 With no prefix argument, set mark, push old mark position on local mark
|
0
|
1400 ring, and push mark on global mark ring.
|
|
1401 With argument, jump to mark, and pop a new position for mark off the ring
|
|
1402 \(does not affect global mark ring\).
|
|
1403
|
|
1404 Novice Emacs Lisp programmers often try to use the mark for the wrong
|
|
1405 purposes. See the documentation of `set-mark' for more information."
|
|
1406 (interactive "P")
|
|
1407 (if (null arg)
|
|
1408 (push-mark nil nil t)
|
|
1409 (if (null (mark t))
|
|
1410 (error "No mark set in this buffer")
|
|
1411 (goto-char (mark t))
|
|
1412 (pop-mark))))
|
|
1413
|
4
|
1414 ;; XEmacs: Extra parameter
|
0
|
1415 (defun push-mark (&optional location nomsg activate-region buffer)
|
|
1416 "Set mark at LOCATION (point, by default) and push old mark on mark ring.
|
|
1417 If the last global mark pushed was not in the current buffer,
|
|
1418 also push LOCATION on the global mark ring.
|
|
1419 Display `Mark set' unless the optional second arg NOMSG is non-nil.
|
|
1420 Activate mark if optional third arg ACTIVATE-REGION non-nil.
|
|
1421
|
|
1422 Novice Emacs Lisp programmers often try to use the mark for the wrong
|
|
1423 purposes. See the documentation of `set-mark' for more information."
|
4
|
1424 (setq buffer (decode-buffer buffer)) ; XEmacs
|
|
1425 (if (null (mark t buffer)) ; XEmacs
|
0
|
1426 nil
|
|
1427 ;; The save-excursion / set-buffer is necessary because mark-ring
|
|
1428 ;; is a buffer local variable
|
|
1429 (save-excursion
|
|
1430 (set-buffer buffer)
|
|
1431 (setq mark-ring (cons (copy-marker (mark-marker t buffer)) mark-ring))
|
|
1432 (if (> (length mark-ring) mark-ring-max)
|
|
1433 (progn
|
|
1434 (move-marker (car (nthcdr mark-ring-max mark-ring)) nil buffer)
|
|
1435 (setcdr (nthcdr (1- mark-ring-max) mark-ring) nil)))))
|
|
1436 (set-mark (or location (point buffer)) buffer)
|
4
|
1437 ; (set-marker (mark-marker) (or location (point)) (current-buffer)) ; FSF
|
0
|
1438 ;; Now push the mark on the global mark ring.
|
|
1439 (if (or (null global-mark-ring)
|
|
1440 (not (eq (marker-buffer (car global-mark-ring)) buffer)))
|
|
1441 ;; The last global mark pushed wasn't in this same buffer.
|
|
1442 (progn
|
|
1443 (setq global-mark-ring (cons (copy-marker (mark-marker t buffer))
|
|
1444 global-mark-ring))
|
|
1445 (if (> (length global-mark-ring) global-mark-ring-max)
|
|
1446 (progn
|
|
1447 (move-marker (car (nthcdr global-mark-ring-max global-mark-ring))
|
|
1448 nil buffer)
|
|
1449 (setcdr (nthcdr (1- global-mark-ring-max) global-mark-ring) nil)))))
|
|
1450 (or nomsg executing-kbd-macro (> (minibuffer-depth) 0)
|
|
1451 (message "Mark set"))
|
|
1452 (if activate-region
|
|
1453 (progn
|
|
1454 (setq zmacs-region-stays t)
|
|
1455 (zmacs-activate-region)))
|
4
|
1456 ; (if (or activate (not transient-mark-mode)) ; FSF
|
|
1457 ; (set-mark (mark t))) ; FSF
|
0
|
1458 nil)
|
|
1459
|
|
1460 (defun pop-mark ()
|
|
1461 "Pop off mark ring into the buffer's actual mark.
|
|
1462 Does not set point. Does nothing if mark ring is empty."
|
|
1463 (if mark-ring
|
|
1464 (progn
|
|
1465 (setq mark-ring (nconc mark-ring (list (copy-marker (mark-marker t)))))
|
|
1466 (set-mark (car mark-ring))
|
|
1467 (move-marker (car mark-ring) nil)
|
|
1468 (if (null (mark t)) (ding))
|
|
1469 (setq mark-ring (cdr mark-ring)))))
|
|
1470
|
|
1471 (define-function 'exchange-dot-and-mark 'exchange-point-and-mark)
|
|
1472 (defun exchange-point-and-mark (&optional dont-activate-region)
|
|
1473 "Put the mark where point is now, and point where the mark is now.
|
|
1474 The mark is activated unless DONT-ACTIVATE-REGION is non-nil."
|
|
1475 (interactive nil)
|
|
1476 (let ((omark (mark t)))
|
|
1477 (if (null omark)
|
|
1478 (error "No mark set in this buffer"))
|
|
1479 (set-mark (point))
|
|
1480 (goto-char omark)
|
4
|
1481 (or dont-activate-region (zmacs-activate-region)) ; XEmacs
|
0
|
1482 nil))
|
|
1483
|
4
|
1484 ;; XEmacs
|
0
|
1485 (defun mark-something (mark-fn movement-fn arg)
|
|
1486 "internal function used by mark-sexp, mark-word, etc."
|
|
1487 (let (newmark (pushp t))
|
|
1488 (save-excursion
|
|
1489 (if (and (eq last-command mark-fn) (mark))
|
|
1490 ;; Extend the previous state in the same direction:
|
|
1491 (progn
|
|
1492 (if (< (mark) (point)) (setq arg (- arg)))
|
|
1493 (goto-char (mark))
|
|
1494 (setq pushp nil)))
|
|
1495 (funcall movement-fn arg)
|
|
1496 (setq newmark (point)))
|
|
1497 (if pushp
|
|
1498 (push-mark newmark nil t)
|
|
1499 ;; Do not mess with the mark stack, but merely adjust the previous state:
|
|
1500 (set-mark newmark)
|
|
1501 (activate-region))))
|
|
1502
|
|
1503 ;(defun transient-mark-mode (arg)
|
|
1504 ; "Toggle Transient Mark mode.
|
|
1505 ;With arg, turn Transient Mark mode on if arg is positive, off otherwise.
|
|
1506 ;
|
|
1507 ;In Transient Mark mode, when the mark is active, the region is highlighted.
|
|
1508 ;Changing the buffer \"deactivates\" the mark.
|
|
1509 ;So do certain other operations that set the mark
|
|
1510 ;but whose main purpose is something else--for example,
|
|
1511 ;incremental search, \\[beginning-of-buffer], and \\[end-of-buffer]."
|
|
1512 ; (interactive "P")
|
|
1513 ; (setq transient-mark-mode
|
|
1514 ; (if (null arg)
|
|
1515 ; (not transient-mark-mode)
|
|
1516 ; (> (prefix-numeric-value arg) 0))))
|
|
1517
|
|
1518 (defun pop-global-mark ()
|
|
1519 "Pop off global mark ring and jump to the top location."
|
|
1520 (interactive)
|
|
1521 ;; Pop entries which refer to non-existent buffers.
|
|
1522 (while (and global-mark-ring (not (marker-buffer (car global-mark-ring))))
|
|
1523 (setq global-mark-ring (cdr global-mark-ring)))
|
|
1524 (or global-mark-ring
|
|
1525 (error "No global mark set"))
|
|
1526 (let* ((marker (car global-mark-ring))
|
|
1527 (buffer (marker-buffer marker))
|
|
1528 (position (marker-position marker)))
|
|
1529 (setq global-mark-ring (nconc (cdr global-mark-ring)
|
|
1530 (list (car global-mark-ring))))
|
|
1531 (set-buffer buffer)
|
|
1532 (or (and (>= position (point-min))
|
|
1533 (<= position (point-max)))
|
|
1534 (widen))
|
|
1535 (goto-char position)
|
|
1536 (switch-to-buffer buffer)))
|
|
1537
|
|
1538
|
8
|
1539 ;;; After 8 years of waiting ... -sb
|
|
1540 (defvar next-line-add-newlines nil ; XEmacs
|
0
|
1541 "*If non-nil, `next-line' inserts newline to avoid `end of buffer' error.")
|
|
1542
|
|
1543 (defun next-line (arg)
|
|
1544 "Move cursor vertically down ARG lines.
|
|
1545 If there is no character in the target line exactly under the current column,
|
|
1546 the cursor is positioned after the character in that line which spans this
|
|
1547 column, or at the end of the line if it is not long enough.
|
|
1548
|
|
1549 If there is no line in the buffer after this one, behavior depends on the
|
|
1550 value of `next-line-add-newlines'. If non-nil, it inserts a newline character
|
|
1551 to create a line, and moves the cursor to that line. Otherwise it moves the
|
|
1552 cursor to the end of the buffer.
|
|
1553
|
|
1554 The command \\[set-goal-column] can be used to create
|
|
1555 a semipermanent goal column to which this command always moves.
|
|
1556 Then it does not try to move vertically. This goal column is stored
|
|
1557 in `goal-column', which is nil when there is none.
|
|
1558
|
|
1559 If you are thinking of using this in a Lisp program, consider
|
|
1560 using `forward-line' instead. It is usually easier to use
|
|
1561 and more reliable (no dependence on goal column, etc.)."
|
4
|
1562 (interactive "_p") ; XEmacs
|
0
|
1563 (if (and next-line-add-newlines (= arg 1))
|
|
1564 (let ((opoint (point)))
|
|
1565 (end-of-line)
|
|
1566 (if (eobp)
|
|
1567 (newline 1)
|
|
1568 (goto-char opoint)
|
|
1569 (line-move arg)))
|
|
1570 (if (interactive-p)
|
|
1571 (condition-case nil
|
|
1572 (line-move arg)
|
|
1573 ((beginning-of-buffer end-of-buffer) (ding nil 'buffer-bound)))
|
|
1574 (line-move arg)))
|
|
1575 nil)
|
|
1576
|
|
1577 (defun previous-line (arg)
|
|
1578 "Move cursor vertically up ARG lines.
|
|
1579 If there is no character in the target line exactly over the current column,
|
|
1580 the cursor is positioned after the character in that line which spans this
|
|
1581 column, or at the end of the line if it is not long enough.
|
|
1582
|
|
1583 The command \\[set-goal-column] can be used to create
|
|
1584 a semipermanent goal column to which this command always moves.
|
|
1585 Then it does not try to move vertically.
|
|
1586
|
|
1587 If you are thinking of using this in a Lisp program, consider using
|
|
1588 `forward-line' with a negative argument instead. It is usually easier
|
|
1589 to use and more reliable (no dependence on goal column, etc.)."
|
4
|
1590 (interactive "_p") ; XEmacs
|
0
|
1591 (if (interactive-p)
|
|
1592 (condition-case nil
|
|
1593 (line-move (- arg))
|
|
1594 ((beginning-of-buffer end-of-buffer) (ding nil 'buffer-bound)))
|
|
1595 (line-move (- arg)))
|
|
1596 nil)
|
|
1597
|
4
|
1598 (defconst track-eol nil
|
0
|
1599 "*Non-nil means vertical motion starting at end of line keeps to ends of lines.
|
|
1600 This means moving to the end of each line moved onto.
|
|
1601 The beginning of a blank line does not count as the end of a line.")
|
|
1602
|
|
1603 (defvar goal-column nil
|
|
1604 "*Semipermanent goal column for vertical motion, as set by \\[set-goal-column], or nil.")
|
|
1605 (make-variable-buffer-local 'goal-column)
|
|
1606
|
|
1607 (defvar temporary-goal-column 0
|
|
1608 "Current goal column for vertical motion.
|
|
1609 It is the column where point was
|
|
1610 at the start of current run of vertical motion commands.
|
|
1611 When the `track-eol' feature is doing its job, the value is 9999.")
|
|
1612
|
|
1613 ;XEmacs: not yet ported, so avoid compiler warnings
|
|
1614 (eval-when-compile
|
|
1615 (defvar inhibit-point-motion-hooks))
|
|
1616
|
|
1617 (defvar line-move-ignore-invisible nil
|
|
1618 "*Non-nil means \\[next-line] and \\[previous-line] ignore invisible lines.
|
|
1619 Outline mode sets this.")
|
|
1620
|
|
1621 ;; This is the guts of next-line and previous-line.
|
|
1622 ;; Arg says how many lines to move.
|
|
1623 (defun line-move (arg)
|
|
1624 ;; Don't run any point-motion hooks, and disregard intangibility,
|
|
1625 ;; for intermediate positions.
|
|
1626 (let ((inhibit-point-motion-hooks t)
|
|
1627 (opoint (point))
|
|
1628 new)
|
|
1629 (unwind-protect
|
|
1630 (progn
|
|
1631 (if (not (or (eq last-command 'next-line)
|
|
1632 (eq last-command 'previous-line)))
|
|
1633 (setq temporary-goal-column
|
|
1634 (if (and track-eol (eolp)
|
|
1635 ;; Don't count beg of empty line as end of line
|
|
1636 ;; unless we just did explicit end-of-line.
|
|
1637 (or (not (bolp)) (eq last-command 'end-of-line)))
|
|
1638 9999
|
|
1639 (current-column))))
|
|
1640 (if (and (not (integerp selective-display))
|
|
1641 (not line-move-ignore-invisible))
|
|
1642 ;; Use just newline characters.
|
|
1643 (or (if (> arg 0)
|
|
1644 (progn (if (> arg 1) (forward-line (1- arg)))
|
|
1645 ;; This way of moving forward ARG lines
|
|
1646 ;; verifies that we have a newline after the last one.
|
|
1647 ;; It doesn't get confused by intangible text.
|
|
1648 (end-of-line)
|
|
1649 (zerop (forward-line 1)))
|
|
1650 (and (zerop (forward-line arg))
|
|
1651 (bolp)))
|
|
1652 (signal (if (< arg 0)
|
|
1653 'beginning-of-buffer
|
|
1654 'end-of-buffer)
|
|
1655 nil))
|
|
1656 ;; Move by arg lines, but ignore invisible ones.
|
|
1657 (while (> arg 0)
|
|
1658 (end-of-line)
|
|
1659 (and (zerop (vertical-motion 1))
|
|
1660 (signal 'end-of-buffer nil))
|
|
1661 ;; If the following character is currently invisible,
|
|
1662 ;; skip all characters with that same `invisible' property value.
|
|
1663 (while (and (not (eobp))
|
|
1664 (let ((prop
|
|
1665 (get-char-property (point) 'invisible)))
|
|
1666 (if (eq buffer-invisibility-spec t)
|
|
1667 prop
|
|
1668 (or (memq prop buffer-invisibility-spec)
|
|
1669 (assq prop buffer-invisibility-spec)))))
|
|
1670 (if (get-text-property (point) 'invisible)
|
|
1671 (goto-char (next-single-property-change (point) 'invisible))
|
4
|
1672 (goto-char (next-extent-change (point))))) ; XEmacs
|
0
|
1673 (setq arg (1- arg)))
|
|
1674 (while (< arg 0)
|
|
1675 (beginning-of-line)
|
|
1676 (and (zerop (vertical-motion -1))
|
|
1677 (signal 'beginning-of-buffer nil))
|
|
1678 (while (and (not (bobp))
|
|
1679 (let ((prop
|
|
1680 (get-char-property (1- (point)) 'invisible)))
|
|
1681 (if (eq buffer-invisibility-spec t)
|
|
1682 prop
|
|
1683 (or (memq prop buffer-invisibility-spec)
|
|
1684 (assq prop buffer-invisibility-spec)))))
|
|
1685 (if (get-text-property (1- (point)) 'invisible)
|
|
1686 (goto-char (previous-single-property-change (point) 'invisible))
|
4
|
1687 (goto-char (previous-extent-change (point))))) ; XEmacs
|
0
|
1688 (setq arg (1+ arg))))
|
|
1689 (move-to-column (or goal-column temporary-goal-column)))
|
|
1690 ;; Remember where we moved to, go back home,
|
|
1691 ;; then do the motion over again
|
|
1692 ;; in just one step, with intangibility and point-motion hooks
|
|
1693 ;; enabled this time.
|
|
1694 (setq new (point))
|
|
1695 (goto-char opoint)
|
|
1696 (setq inhibit-point-motion-hooks nil)
|
|
1697 (goto-char new)))
|
|
1698 nil)
|
|
1699
|
|
1700 ;;; Many people have said they rarely use this feature, and often type
|
|
1701 ;;; it by accident. Maybe it shouldn't even be on a key.
|
|
1702 (put 'set-goal-column 'disabled t)
|
|
1703
|
|
1704 (defun set-goal-column (arg)
|
|
1705 "Set the current horizontal position as a goal for \\[next-line] and \\[previous-line].
|
|
1706 Those commands will move to this position in the line moved to
|
|
1707 rather than trying to keep the same horizontal position.
|
|
1708 With a non-nil argument, clears out the goal column
|
|
1709 so that \\[next-line] and \\[previous-line] resume vertical motion.
|
|
1710 The goal column is stored in the variable `goal-column'."
|
4
|
1711 (interactive "_P") ; XEmacs
|
0
|
1712 (if arg
|
|
1713 (progn
|
|
1714 (setq goal-column nil)
|
|
1715 (message "No goal column"))
|
|
1716 (setq goal-column (current-column))
|
|
1717 (message (substitute-command-keys
|
|
1718 "Goal column %d (use \\[set-goal-column] with an arg to unset it)")
|
|
1719 goal-column))
|
|
1720 nil)
|
|
1721
|
4
|
1722 ;; deleted FSFmacs terminal randomness hscroll-point-visible stuff.
|
|
1723 ;; hscroll-step
|
|
1724 ;; hscroll-point-visible
|
|
1725 ;; hscroll-window-column
|
|
1726 ;; right-arrow
|
|
1727 ;; left-arrow
|
0
|
1728
|
|
1729 (defun scroll-other-window-down (lines)
|
|
1730 "Scroll the \"other window\" down.
|
|
1731 For more details, see the documentation for `scroll-other-window'."
|
|
1732 (interactive "P")
|
|
1733 (scroll-other-window
|
|
1734 ;; Just invert the argument's meaning.
|
|
1735 ;; We can do that without knowing which window it will be.
|
|
1736 (if (eq lines '-) nil
|
|
1737 (if (null lines) '-
|
|
1738 (- (prefix-numeric-value lines))))))
|
4
|
1739 ;(define-key esc-map [?\C-\S-v] 'scroll-other-window-down)
|
0
|
1740
|
|
1741 (defun beginning-of-buffer-other-window (arg)
|
|
1742 "Move point to the beginning of the buffer in the other window.
|
|
1743 Leave mark at previous position.
|
|
1744 With arg N, put point N/10 of the way from the true beginning."
|
|
1745 (interactive "P")
|
|
1746 (let ((orig-window (selected-window))
|
|
1747 (window (other-window-for-scrolling)))
|
|
1748 ;; We use unwind-protect rather than save-window-excursion
|
|
1749 ;; because the latter would preserve the things we want to change.
|
|
1750 (unwind-protect
|
|
1751 (progn
|
|
1752 (select-window window)
|
|
1753 ;; Set point and mark in that window's buffer.
|
|
1754 (beginning-of-buffer arg)
|
|
1755 ;; Set point accordingly.
|
|
1756 (recenter '(t)))
|
|
1757 (select-window orig-window))))
|
|
1758
|
|
1759 (defun end-of-buffer-other-window (arg)
|
|
1760 "Move point to the end of the buffer in the other window.
|
|
1761 Leave mark at previous position.
|
|
1762 With arg N, put point N/10 of the way from the true end."
|
|
1763 (interactive "P")
|
|
1764 ;; See beginning-of-buffer-other-window for comments.
|
|
1765 (let ((orig-window (selected-window))
|
|
1766 (window (other-window-for-scrolling)))
|
|
1767 (unwind-protect
|
|
1768 (progn
|
|
1769 (select-window window)
|
|
1770 (end-of-buffer arg)
|
|
1771 (recenter '(t)))
|
|
1772 (select-window orig-window))))
|
|
1773
|
|
1774 (defun transpose-chars (arg)
|
|
1775 "Interchange characters around point, moving forward one character.
|
|
1776 With prefix arg ARG, effect is to take character before point
|
|
1777 and drag it forward past ARG other characters (backward if ARG negative).
|
|
1778 If no argument and at end of line, the previous two chars are exchanged."
|
|
1779 (interactive "*P")
|
|
1780 (and (null arg) (eolp) (forward-char -1))
|
|
1781 (transpose-subr 'forward-char (prefix-numeric-value arg)))
|
|
1782
|
|
1783 (defun transpose-words (arg)
|
|
1784 "Interchange words around point, leaving point at end of them.
|
|
1785 With prefix arg ARG, effect is to take word before or around point
|
|
1786 and drag it forward past ARG other words (backward if ARG negative).
|
|
1787 If ARG is zero, the words around or after point and around or after mark
|
|
1788 are interchanged."
|
|
1789 (interactive "*p")
|
|
1790 (transpose-subr 'forward-word arg))
|
|
1791
|
|
1792 (defun transpose-sexps (arg)
|
|
1793 "Like \\[transpose-words] but applies to sexps.
|
|
1794 Does not work on a sexp that point is in the middle of
|
|
1795 if it is a list or string."
|
|
1796 (interactive "*p")
|
|
1797 (transpose-subr 'forward-sexp arg))
|
|
1798
|
|
1799 (defun transpose-lines (arg)
|
|
1800 "Exchange current line and previous line, leaving point after both.
|
|
1801 With argument ARG, takes previous line and moves it past ARG lines.
|
|
1802 With argument 0, interchanges line point is in with line mark is in."
|
|
1803 (interactive "*p")
|
|
1804 (transpose-subr #'(lambda (arg)
|
|
1805 (if (= arg 1)
|
|
1806 (progn
|
|
1807 ;; Move forward over a line,
|
|
1808 ;; but create a newline if none exists yet.
|
|
1809 (end-of-line)
|
|
1810 (if (eobp)
|
|
1811 (newline)
|
|
1812 (forward-char 1)))
|
|
1813 (forward-line arg)))
|
|
1814 arg))
|
|
1815
|
|
1816 (eval-when-compile
|
|
1817 ;; avoid byte-compiler warnings...
|
|
1818 (defvar start1)
|
|
1819 (defvar start2)
|
|
1820 (defvar end1)
|
|
1821 (defvar end2))
|
|
1822
|
|
1823 ; start[12] and end[12] used in transpose-subr-1 below
|
|
1824 (defun transpose-subr (mover arg)
|
|
1825 (let (start1 end1 start2 end2)
|
|
1826 (if (= arg 0)
|
|
1827 (progn
|
|
1828 (save-excursion
|
|
1829 (funcall mover 1)
|
|
1830 (setq end2 (point))
|
|
1831 (funcall mover -1)
|
|
1832 (setq start2 (point))
|
4
|
1833 (goto-char (mark t)) ; XEmacs
|
0
|
1834 (funcall mover 1)
|
|
1835 (setq end1 (point))
|
|
1836 (funcall mover -1)
|
|
1837 (setq start1 (point))
|
|
1838 (transpose-subr-1))
|
4
|
1839 (exchange-point-and-mark t))) ; XEmacs
|
0
|
1840 (while (> arg 0)
|
|
1841 (funcall mover -1)
|
|
1842 (setq start1 (point))
|
|
1843 (funcall mover 1)
|
|
1844 (setq end1 (point))
|
|
1845 (funcall mover 1)
|
|
1846 (setq end2 (point))
|
|
1847 (funcall mover -1)
|
|
1848 (setq start2 (point))
|
|
1849 (transpose-subr-1)
|
|
1850 (goto-char end2)
|
|
1851 (setq arg (1- arg)))
|
|
1852 (while (< arg 0)
|
|
1853 (funcall mover -1)
|
|
1854 (setq start2 (point))
|
|
1855 (funcall mover -1)
|
|
1856 (setq start1 (point))
|
|
1857 (funcall mover 1)
|
|
1858 (setq end1 (point))
|
|
1859 (funcall mover 1)
|
|
1860 (setq end2 (point))
|
|
1861 (transpose-subr-1)
|
|
1862 (setq arg (1+ arg)))))
|
|
1863
|
|
1864 ; start[12] and end[12] used free
|
|
1865 (defun transpose-subr-1 ()
|
|
1866 (if (> (min end1 end2) (max start1 start2))
|
|
1867 (error "Don't have two things to transpose"))
|
|
1868 (let ((word1 (buffer-substring start1 end1))
|
|
1869 (word2 (buffer-substring start2 end2)))
|
|
1870 (delete-region start2 end2)
|
|
1871 (goto-char start2)
|
|
1872 (insert word1)
|
|
1873 (goto-char (if (< start1 start2) start1
|
|
1874 (+ start1 (- (length word1) (length word2)))))
|
|
1875 (delete-char (length word1))
|
|
1876 (insert word2)))
|
|
1877
|
4
|
1878 (defconst comment-column 32
|
0
|
1879 "*Column to indent right-margin comments to.
|
|
1880 Setting this variable automatically makes it local to the current buffer.
|
|
1881 Each mode establishes a different default value for this variable; you
|
|
1882 can set the value for a particular mode using that mode's hook.")
|
|
1883 (make-variable-buffer-local 'comment-column)
|
|
1884
|
4
|
1885 (defconst comment-start nil
|
0
|
1886 "*String to insert to start a new comment, or nil if no comment syntax.")
|
|
1887
|
4
|
1888 (defconst comment-start-skip nil
|
0
|
1889 "*Regexp to match the start of a comment plus everything up to its body.
|
|
1890 If there are any \\(...\\) pairs, the comment delimiter text is held to begin
|
|
1891 at the place matched by the close of the first pair.")
|
|
1892
|
4
|
1893 (defconst comment-end ""
|
0
|
1894 "*String to insert to end a new comment.
|
|
1895 Should be an empty string if comments are terminated by end-of-line.")
|
|
1896
|
|
1897 (defconst comment-indent-hook nil
|
|
1898 "Obsolete variable for function to compute desired indentation for a comment.
|
|
1899 Use `comment-indent-function' instead.
|
|
1900 This function is called with no args with point at the beginning of
|
|
1901 the comment's starting delimiter.")
|
|
1902
|
4
|
1903 (defconst comment-indent-function
|
0
|
1904 ;; XEmacs - add at least one space after the end of the text on the
|
|
1905 ;; current line...
|
|
1906 #'(lambda ()
|
|
1907 (save-excursion
|
|
1908 (beginning-of-line)
|
|
1909 (let ((eol (save-excursion (end-of-line) (point))))
|
|
1910 (and comment-start-skip
|
|
1911 (re-search-forward comment-start-skip eol t)
|
|
1912 (setq eol (match-beginning 0)))
|
|
1913 (goto-char eol)
|
|
1914 (skip-chars-backward " \t")
|
|
1915 (max comment-column (1+ (current-column))))))
|
|
1916 "Function to compute desired indentation for a comment.
|
|
1917 This function is called with no args with point at the beginning of
|
|
1918 the comment's starting delimiter.")
|
|
1919
|
|
1920 (defconst block-comment-start nil
|
|
1921 "*String to insert to start a new comment on a line by itself.
|
|
1922 If nil, use `comment-start' instead.
|
|
1923 Note that the regular expression `comment-start-skip' should skip this string
|
|
1924 as well as the `comment-start' string.")
|
|
1925
|
|
1926 (defconst block-comment-end nil
|
|
1927 "*String to insert to end a new comment on a line by itself.
|
|
1928 Should be an empty string if comments are terminated by end-of-line.
|
|
1929 If nil, use `comment-end' instead.")
|
|
1930
|
|
1931 (defun indent-for-comment ()
|
|
1932 "Indent this line's comment to comment column, or insert an empty comment."
|
|
1933 (interactive "*")
|
|
1934 (let* ((empty (save-excursion (beginning-of-line)
|
|
1935 (looking-at "[ \t]*$")))
|
|
1936 (starter (or (and empty block-comment-start) comment-start))
|
|
1937 (ender (or (and empty block-comment-end) comment-end)))
|
|
1938 (if (null starter)
|
|
1939 (error "No comment syntax defined")
|
|
1940 (let* ((eolpos (save-excursion (end-of-line) (point)))
|
|
1941 cpos indent begpos)
|
|
1942 (beginning-of-line)
|
|
1943 (if (re-search-forward comment-start-skip eolpos 'move)
|
|
1944 (progn (setq cpos (point-marker))
|
|
1945 ;; Find the start of the comment delimiter.
|
|
1946 ;; If there were paren-pairs in comment-start-skip,
|
|
1947 ;; position at the end of the first pair.
|
|
1948 (if (match-end 1)
|
|
1949 (goto-char (match-end 1))
|
|
1950 ;; If comment-start-skip matched a string with
|
|
1951 ;; internal whitespace (not final whitespace) then
|
|
1952 ;; the delimiter start at the end of that
|
|
1953 ;; whitespace. Otherwise, it starts at the
|
|
1954 ;; beginning of what was matched.
|
|
1955 (skip-syntax-backward " " (match-beginning 0))
|
|
1956 (skip-syntax-backward "^ " (match-beginning 0)))))
|
|
1957 (setq begpos (point))
|
|
1958 ;; Compute desired indent.
|
|
1959 (if (= (current-column)
|
|
1960 (setq indent (if comment-indent-hook
|
|
1961 (funcall comment-indent-hook)
|
|
1962 (funcall comment-indent-function))))
|
|
1963 (goto-char begpos)
|
|
1964 ;; If that's different from current, change it.
|
|
1965 (skip-chars-backward " \t")
|
|
1966 (delete-region (point) begpos)
|
|
1967 (indent-to indent))
|
|
1968 ;; An existing comment?
|
|
1969 (if cpos
|
|
1970 (progn (goto-char cpos)
|
|
1971 (set-marker cpos nil))
|
|
1972 ;; No, insert one.
|
|
1973 (insert starter)
|
|
1974 (save-excursion
|
|
1975 (insert ender)))))))
|
|
1976
|
|
1977 (defun set-comment-column (arg)
|
|
1978 "Set the comment column based on point.
|
|
1979 With no arg, set the comment column to the current column.
|
|
1980 With just minus as arg, kill any comment on this line.
|
|
1981 With any other arg, set comment column to indentation of the previous comment
|
|
1982 and then align or create a comment on this line at that column."
|
|
1983 (interactive "P")
|
|
1984 (if (eq arg '-)
|
|
1985 (kill-comment nil)
|
|
1986 (if arg
|
|
1987 (progn
|
|
1988 (save-excursion
|
|
1989 (beginning-of-line)
|
|
1990 (re-search-backward comment-start-skip)
|
|
1991 (beginning-of-line)
|
|
1992 (re-search-forward comment-start-skip)
|
|
1993 (goto-char (match-beginning 0))
|
|
1994 (setq comment-column (current-column))
|
|
1995 (message "Comment column set to %d" comment-column))
|
|
1996 (indent-for-comment))
|
|
1997 (setq comment-column (current-column))
|
|
1998 (message "Comment column set to %d" comment-column))))
|
|
1999
|
|
2000 (defun kill-comment (arg)
|
|
2001 "Kill the comment on this line, if any.
|
|
2002 With argument, kill comments on that many lines starting with this one."
|
|
2003 ;; this function loses in a lot of situations. it incorrectly recognises
|
|
2004 ;; comment delimiters sometimes (ergo, inside a string), doesn't work
|
|
2005 ;; with multi-line comments, can kill extra whitespace if comment wasn't
|
|
2006 ;; through end-of-line, et cetera.
|
|
2007 (interactive "*P")
|
|
2008 (or comment-start-skip (error "No comment syntax defined"))
|
|
2009 (let ((count (prefix-numeric-value arg)) endc)
|
|
2010 (while (> count 0)
|
|
2011 (save-excursion
|
|
2012 (end-of-line)
|
|
2013 (setq endc (point))
|
|
2014 (beginning-of-line)
|
|
2015 (and (string< "" comment-end)
|
|
2016 (setq endc
|
|
2017 (progn
|
|
2018 (re-search-forward (regexp-quote comment-end) endc 'move)
|
|
2019 (skip-chars-forward " \t")
|
|
2020 (point))))
|
|
2021 (beginning-of-line)
|
|
2022 (if (re-search-forward comment-start-skip endc t)
|
|
2023 (progn
|
|
2024 (goto-char (match-beginning 0))
|
|
2025 (skip-chars-backward " \t")
|
|
2026 (kill-region (point) endc)
|
|
2027 ;; to catch comments a line beginnings
|
|
2028 (indent-according-to-mode))))
|
|
2029 (if arg (forward-line 1))
|
|
2030 (setq count (1- count)))))
|
|
2031
|
|
2032 (defun comment-region (beg end &optional arg)
|
|
2033 "Comment or uncomment each line in the region.
|
|
2034 With just C-u prefix arg, uncomment each line in region.
|
|
2035 Numeric prefix arg ARG means use ARG comment characters.
|
|
2036 If ARG is negative, delete that many comment characters instead.
|
|
2037 Comments are terminated on each line, even for syntax in which newline does
|
|
2038 not end the comment. Blank lines do not get comments."
|
|
2039 ;; if someone wants it to only put a comment-start at the beginning and
|
|
2040 ;; comment-end at the end then typing it, C-x C-x, closing it, C-x C-x
|
|
2041 ;; is easy enough. No option is made here for other than commenting
|
|
2042 ;; every line.
|
|
2043 (interactive "r\nP")
|
|
2044 (or comment-start (error "No comment syntax is defined"))
|
|
2045 (if (> beg end) (let (mid) (setq mid beg beg end end mid)))
|
|
2046 (save-excursion
|
|
2047 (save-restriction
|
|
2048 (let ((cs comment-start) (ce comment-end)
|
|
2049 numarg)
|
|
2050 (if (consp arg) (setq numarg t)
|
|
2051 (setq numarg (prefix-numeric-value arg))
|
|
2052 ;; For positive arg > 1, replicate the comment delims now,
|
|
2053 ;; then insert the replicated strings just once.
|
|
2054 (while (> numarg 1)
|
|
2055 (setq cs (concat cs comment-start)
|
|
2056 ce (concat ce comment-end))
|
|
2057 (setq numarg (1- numarg))))
|
|
2058 ;; Loop over all lines from BEG to END.
|
|
2059 (narrow-to-region beg end)
|
|
2060 (goto-char beg)
|
|
2061 (while (not (eobp))
|
|
2062 (if (or (eq numarg t) (< numarg 0))
|
|
2063 (progn
|
|
2064 ;; Delete comment start from beginning of line.
|
|
2065 (if (eq numarg t)
|
|
2066 (while (looking-at (regexp-quote cs))
|
|
2067 (delete-char (length cs)))
|
|
2068 (let ((count numarg))
|
|
2069 (while (and (> 1 (setq count (1+ count)))
|
|
2070 (looking-at (regexp-quote cs)))
|
|
2071 (delete-char (length cs)))))
|
|
2072 ;; Delete comment end from end of line.
|
|
2073 (if (string= "" ce)
|
|
2074 nil
|
|
2075 (if (eq numarg t)
|
|
2076 (progn
|
|
2077 (end-of-line)
|
|
2078 ;; This is questionable if comment-end ends in
|
|
2079 ;; whitespace. That is pretty brain-damaged,
|
|
2080 ;; though.
|
|
2081 (skip-chars-backward " \t")
|
|
2082 (if (and (>= (- (point) (point-min)) (length ce))
|
|
2083 (save-excursion
|
|
2084 (backward-char (length ce))
|
|
2085 (looking-at (regexp-quote ce))))
|
|
2086 (delete-char (- (length ce)))))
|
|
2087 (let ((count numarg))
|
|
2088 (while (> 1 (setq count (1+ count)))
|
|
2089 (end-of-line)
|
|
2090 ;; This is questionable if comment-end ends in
|
|
2091 ;; whitespace. That is pretty brain-damaged though
|
|
2092 (skip-chars-backward " \t")
|
|
2093 (save-excursion
|
|
2094 (backward-char (length ce))
|
|
2095 (if (looking-at (regexp-quote ce))
|
|
2096 (delete-char (length ce))))))))
|
|
2097 (forward-line 1))
|
|
2098 ;; Insert at beginning and at end.
|
|
2099 (if (looking-at "[ \t]*$") ()
|
|
2100 (insert cs)
|
|
2101 (if (string= "" ce) ()
|
|
2102 (end-of-line)
|
|
2103 (insert ce)))
|
|
2104 (search-forward "\n" nil 'move)))))))
|
|
2105
|
4
|
2106 ;; XEmacs
|
0
|
2107 (defun prefix-region (prefix)
|
|
2108 "Add a prefix string to each line between mark and point."
|
|
2109 (interactive "sPrefix string: ")
|
|
2110 (if prefix
|
|
2111 (let ((count (count-lines (mark) (point))))
|
|
2112 (goto-char (min (mark) (point)))
|
|
2113 (while (> count 0)
|
|
2114 (setq count (1- count))
|
|
2115 (beginning-of-line 1)
|
|
2116 (insert prefix)
|
|
2117 (end-of-line 1)
|
|
2118 (forward-char 1)))))
|
|
2119
|
|
2120
|
4
|
2121 ;; XEmacs - extra parameter
|
0
|
2122 (defun backward-word (arg &optional buffer)
|
|
2123 "Move backward until encountering the end of a word.
|
|
2124 With argument, do this that many times.
|
|
2125 In programs, it is faster to call `forward-word' with negative arg."
|
4
|
2126 (interactive "_p") ; XEmacs
|
0
|
2127 (forward-word (- arg) buffer))
|
|
2128
|
|
2129 (defun mark-word (arg)
|
|
2130 "Set mark arg words away from point."
|
|
2131 (interactive "p")
|
|
2132 (mark-something 'mark-word 'forward-word arg))
|
|
2133
|
4
|
2134 ;; XEmacs modified
|
0
|
2135 (defun kill-word (arg)
|
|
2136 "Kill characters forward until encountering the end of a word.
|
|
2137 With argument, do this that many times."
|
|
2138 (interactive "*p")
|
|
2139 (kill-region (point) (save-excursion (forward-word arg) (point))))
|
|
2140
|
|
2141 (defun backward-kill-word (arg)
|
|
2142 "Kill characters backward until encountering the end of a word.
|
|
2143 With argument, do this that many times."
|
4
|
2144 (interactive "*p") ; XEmacs
|
0
|
2145 (kill-word (- arg)))
|
|
2146
|
|
2147 (defun current-word (&optional strict)
|
|
2148 "Return the word point is on (or a nearby word) as a string.
|
|
2149 If optional arg STRICT is non-nil, return nil unless point is within
|
|
2150 or adjacent to a word.
|
|
2151 If point is not between two word-constituent characters, but immediately
|
|
2152 follows one, move back first.
|
|
2153 Otherwise, if point precedes a word constituent, move forward first.
|
|
2154 Otherwise, move backwards until a word constituent is found and get that word;
|
|
2155 if you a newlines is reached first, move forward instead."
|
|
2156 (save-excursion
|
|
2157 (let ((oldpoint (point)) (start (point)) (end (point)))
|
|
2158 (skip-syntax-backward "w_") (setq start (point))
|
|
2159 (goto-char oldpoint)
|
|
2160 (skip-syntax-forward "w_") (setq end (point))
|
|
2161 (if (and (eq start oldpoint) (eq end oldpoint))
|
|
2162 ;; Point is neither within nor adjacent to a word.
|
|
2163 (and (not strict)
|
|
2164 (progn
|
|
2165 ;; Look for preceding word in same line.
|
|
2166 (skip-syntax-backward "^w_"
|
|
2167 (save-excursion
|
|
2168 (beginning-of-line) (point)))
|
|
2169 (if (bolp)
|
|
2170 ;; No preceding word in same line.
|
|
2171 ;; Look for following word in same line.
|
|
2172 (progn
|
|
2173 (skip-syntax-forward "^w_"
|
|
2174 (save-excursion
|
|
2175 (end-of-line) (point)))
|
|
2176 (setq start (point))
|
|
2177 (skip-syntax-forward "w_")
|
|
2178 (setq end (point)))
|
|
2179 (setq end (point))
|
|
2180 (skip-syntax-backward "w_")
|
|
2181 (setq start (point)))
|
|
2182 (buffer-substring start end)))
|
|
2183 (buffer-substring start end)))))
|
|
2184
|
4
|
2185 (defconst fill-prefix nil
|
0
|
2186 "*String for filling to insert at front of new line, or nil for none.
|
|
2187 Setting this variable automatically makes it local to the current buffer.")
|
|
2188 (make-variable-buffer-local 'fill-prefix)
|
|
2189
|
4
|
2190 (defconst auto-fill-inhibit-regexp nil
|
0
|
2191 "*Regexp to match lines which should not be auto-filled.")
|
|
2192
|
4
|
2193 ;; This function is the auto-fill-function of a buffer
|
|
2194 ;; when Auto-Fill mode is enabled.
|
|
2195 ;; It returns t if it really did any work.
|
|
2196 ;; XEmacs: This function is totally different.
|
0
|
2197 (defun do-auto-fill ()
|
|
2198 (let (give-up)
|
|
2199 (or (and auto-fill-inhibit-regexp
|
|
2200 (save-excursion (beginning-of-line)
|
|
2201 (looking-at auto-fill-inhibit-regexp)))
|
|
2202 (while (and (not give-up) (> (current-column) fill-column))
|
|
2203 ;; Determine where to split the line.
|
|
2204 (let ((fill-prefix fill-prefix)
|
|
2205 (fill-point
|
|
2206 (let ((opoint (point))
|
|
2207 bounce
|
|
2208 (first t))
|
|
2209 (save-excursion
|
|
2210 (move-to-column (1+ fill-column))
|
|
2211 ;; Move back to a word boundary.
|
|
2212 (while (or first
|
|
2213 ;; If this is after period and a single space,
|
|
2214 ;; move back once more--we don't want to break
|
|
2215 ;; the line there and make it look like a
|
|
2216 ;; sentence end.
|
|
2217 (and (not (bobp))
|
|
2218 (not bounce)
|
|
2219 sentence-end-double-space
|
|
2220 (save-excursion (forward-char -1)
|
|
2221 (and (looking-at "\\. ")
|
|
2222 (not (looking-at "\\. "))))))
|
|
2223 (setq first nil)
|
|
2224 (skip-chars-backward "^ \t\n")
|
|
2225 ;; If we find nowhere on the line to break it,
|
|
2226 ;; break after one word. Set bounce to t
|
|
2227 ;; so we will not keep going in this while loop.
|
|
2228 (if (bolp)
|
|
2229 (progn
|
|
2230 (re-search-forward "[ \t]" opoint t)
|
|
2231 (setq bounce t)))
|
|
2232 (skip-chars-backward " \t"))
|
|
2233 ;; Let fill-point be set to the place where we end up.
|
|
2234 (point)))))
|
|
2235
|
|
2236 ;; I'm not sure why Stig made this change but it breaks
|
|
2237 ;; auto filling in at least C mode so I'm taking it back
|
|
2238 ;; out. --cet
|
|
2239 ;; XEmacs - adaptive fill.
|
|
2240 ;;(maybe-adapt-fill-prefix
|
|
2241 ;; (or from (setq from (save-excursion (beginning-of-line)
|
|
2242 ;; (point))))
|
|
2243 ;; (or to (setq to (save-excursion (beginning-of-line 2)
|
|
2244 ;; (point))))
|
|
2245 ;; t)
|
|
2246
|
|
2247 ;; If that place is not the beginning of the line,
|
|
2248 ;; break the line there.
|
|
2249 (if (save-excursion
|
|
2250 (goto-char fill-point)
|
|
2251 (not (bolp)))
|
|
2252 (let ((prev-column (current-column)))
|
|
2253 ;; If point is at the fill-point, do not `save-excursion'.
|
|
2254 ;; Otherwise, if a comment prefix or fill-prefix is inserted,
|
|
2255 ;; point will end up before it rather than after it.
|
|
2256 (if (save-excursion
|
|
2257 (skip-chars-backward " \t")
|
|
2258 (= (point) fill-point))
|
|
2259 (indent-new-comment-line)
|
|
2260 (save-excursion
|
|
2261 (goto-char fill-point)
|
|
2262 (indent-new-comment-line)))
|
|
2263 ;; If making the new line didn't reduce the hpos of
|
|
2264 ;; the end of the line, then give up now;
|
|
2265 ;; trying again will not help.
|
|
2266 (if (>= (current-column) prev-column)
|
|
2267 (setq give-up t)))
|
|
2268 ;; No place to break => stop trying.
|
|
2269 (setq give-up t)))))))
|
|
2270
|
4
|
2271 ;; Put FSF one in until I can one or the other working properly, then the
|
|
2272 ;; other one is history.
|
|
2273 (defun fsf:do-auto-fill ()
|
|
2274 (let (fc justify bol give-up
|
|
2275 (fill-prefix fill-prefix))
|
|
2276 (if (or (not (setq justify (current-justification)))
|
|
2277 (null (setq fc (current-fill-column)))
|
|
2278 (and (eq justify 'left)
|
|
2279 (<= (current-column) fc))
|
|
2280 (save-excursion (beginning-of-line)
|
|
2281 (setq bol (point))
|
|
2282 (and auto-fill-inhibit-regexp
|
|
2283 (looking-at auto-fill-inhibit-regexp))))
|
|
2284 nil ;; Auto-filling not required
|
|
2285 (if (memq justify '(full center right))
|
|
2286 (save-excursion (unjustify-current-line)))
|
|
2287
|
|
2288 ;; Choose a fill-prefix automatically.
|
|
2289 (if (and adaptive-fill-mode
|
|
2290 (or (null fill-prefix) (string= fill-prefix "")))
|
|
2291 (let ((prefix
|
|
2292 (fill-context-prefix
|
|
2293 (save-excursion (backward-paragraph 1) (point))
|
|
2294 (save-excursion (forward-paragraph 1) (point))
|
|
2295 ;; Don't accept a non-whitespace fill prefix
|
|
2296 ;; from the first line of a paragraph.
|
|
2297 "^[ \t]*$")))
|
|
2298 (and prefix (not (equal prefix ""))
|
|
2299 (setq fill-prefix prefix))))
|
|
2300
|
|
2301 (while (and (not give-up) (> (current-column) fc))
|
|
2302 ;; Determine where to split the line.
|
|
2303 (let ((fill-point
|
|
2304 (let ((opoint (point))
|
|
2305 bounce
|
|
2306 (first t))
|
|
2307 (save-excursion
|
|
2308 (move-to-column (1+ fc))
|
|
2309 ;; Move back to a word boundary.
|
|
2310 (while (or first
|
|
2311 ;; If this is after period and a single space,
|
|
2312 ;; move back once more--we don't want to break
|
|
2313 ;; the line there and make it look like a
|
|
2314 ;; sentence end.
|
|
2315 (and (not (bobp))
|
|
2316 (not bounce)
|
|
2317 sentence-end-double-space
|
|
2318 (save-excursion (forward-char -1)
|
|
2319 (and (looking-at "\\. ")
|
|
2320 (not (looking-at "\\. "))))))
|
|
2321 (setq first nil)
|
|
2322 (skip-chars-backward "^ \t\n")
|
|
2323 ;; If we find nowhere on the line to break it,
|
|
2324 ;; break after one word. Set bounce to t
|
|
2325 ;; so we will not keep going in this while loop.
|
|
2326 (if (bolp)
|
|
2327 (progn
|
|
2328 (re-search-forward "[ \t]" opoint t)
|
|
2329 (setq bounce t)))
|
|
2330 (skip-chars-backward " \t"))
|
|
2331 ;; Let fill-point be set to the place where we end up.
|
|
2332 (point)))))
|
|
2333 ;; If that place is not the beginning of the line,
|
|
2334 ;; break the line there.
|
|
2335 (if (save-excursion
|
|
2336 (goto-char fill-point)
|
|
2337 (not (bolp)))
|
|
2338 (let ((prev-column (current-column)))
|
|
2339 ;; If point is at the fill-point, do not `save-excursion'.
|
|
2340 ;; Otherwise, if a comment prefix or fill-prefix is inserted,
|
|
2341 ;; point will end up before it rather than after it.
|
|
2342 (if (save-excursion
|
|
2343 (skip-chars-backward " \t")
|
|
2344 (= (point) fill-point))
|
|
2345 (indent-new-comment-line t)
|
|
2346 (save-excursion
|
|
2347 (goto-char fill-point)
|
|
2348 (indent-new-comment-line t)))
|
|
2349 ;; Now do justification, if required
|
|
2350 (if (not (eq justify 'left))
|
|
2351 (save-excursion
|
|
2352 (end-of-line 0)
|
|
2353 (justify-current-line justify nil t)))
|
|
2354 ;; If making the new line didn't reduce the hpos of
|
|
2355 ;; the end of the line, then give up now;
|
|
2356 ;; trying again will not help.
|
|
2357 (if (>= (current-column) prev-column)
|
|
2358 (setq give-up t)))
|
|
2359 ;; No place to break => stop trying.
|
|
2360 (setq give-up t))))
|
|
2361 ;; Justify last line.
|
|
2362 (justify-current-line justify t t)
|
|
2363 t)))
|
|
2364
|
|
2365 (defvar normal-auto-fill-function 'do-auto-fill
|
|
2366 "The function to use for `auto-fill-function' if Auto Fill mode is turned on.
|
|
2367 Some major modes set this.")
|
|
2368
|
|
2369 (defun auto-fill-mode (&optional arg)
|
|
2370 "Toggle auto-fill mode.
|
|
2371 With arg, turn auto-fill mode on if and only if arg is positive.
|
|
2372 In Auto-Fill mode, inserting a space at a column beyond `current-fill-column'
|
|
2373 automatically breaks the line at a previous space.
|
|
2374
|
|
2375 The value of `normal-auto-fill-function' specifies the function to use
|
|
2376 for `auto-fill-function' when turning Auto Fill mode on."
|
|
2377 (interactive "P")
|
|
2378 (prog1 (setq auto-fill-function
|
|
2379 (if (if (null arg)
|
|
2380 (not auto-fill-function)
|
|
2381 (> (prefix-numeric-value arg) 0))
|
|
2382 normal-auto-fill-function
|
|
2383 nil))
|
|
2384 (redraw-modeline)))
|
|
2385
|
|
2386 ;; This holds a document string used to document auto-fill-mode.
|
|
2387 (defun auto-fill-function ()
|
|
2388 "Automatically break line at a previous space, in insertion of text."
|
|
2389 nil)
|
|
2390
|
|
2391 (defun turn-on-auto-fill ()
|
|
2392 "Unconditionally turn on Auto Fill mode."
|
|
2393 (auto-fill-mode 1))
|
|
2394
|
|
2395 (defun set-fill-column (arg)
|
|
2396 "Set `fill-column' to current column, or to argument if given.
|
|
2397 The variable `fill-column' has a separate value for each buffer."
|
|
2398 (interactive "_P") ; XEmacs
|
|
2399 (cond ((integerp arg)
|
|
2400 (setq fill-column arg))
|
|
2401 ((consp arg)
|
|
2402 (setq fill-column (current-column)))
|
|
2403 ;; Disallow missing argument; it's probably a typo for C-x C-f.
|
|
2404 (t
|
|
2405 (error "set-fill-column requires an explicit argument")))
|
|
2406 (message "fill-column set to %d" fill-column))
|
|
2407
|
0
|
2408 (defvar comment-multi-line t ; XEmacs - this works well with adaptive fill
|
|
2409 "*Non-nil means \\[indent-new-comment-line] should continue same comment
|
|
2410 on new line, with no new terminator or starter.
|
|
2411 This is obsolete because you might as well use \\[newline-and-indent].")
|
|
2412
|
|
2413 (defun indent-new-comment-line (&optional soft)
|
|
2414 "Break line at point and indent, continuing comment if within one.
|
|
2415 This indents the body of the continued comment
|
|
2416 under the previous comment line.
|
|
2417
|
|
2418 This command is intended for styles where you write a comment per line,
|
|
2419 starting a new comment (and terminating it if necessary) on each line.
|
|
2420 If you want to continue one comment across several lines, use \\[newline-and-indent].
|
|
2421
|
|
2422 If a fill column is specified, it overrides the use of the comment column
|
|
2423 or comment indentation.
|
|
2424
|
|
2425 The inserted newline is marked hard if `use-hard-newlines' is true,
|
|
2426 unless optional argument SOFT is non-nil."
|
|
2427 (interactive)
|
|
2428 (let (comcol comstart)
|
|
2429 (skip-chars-backward " \t")
|
|
2430 (delete-region (point)
|
|
2431 (progn (skip-chars-forward " \t")
|
|
2432 (point)))
|
|
2433 (if soft (insert ?\n) (newline 1))
|
|
2434 (if fill-prefix
|
|
2435 (progn
|
|
2436 (indent-to-left-margin)
|
|
2437 (insert fill-prefix))
|
|
2438 ;; #### - Eric Eide reverts to v18 semantics for this function in
|
|
2439 ;; fa-extras, which I'm not gonna do. His changes are to (1) execute
|
|
2440 ;; the save-excursion below unconditionally, and (2) uncomment the check
|
|
2441 ;; for (not comment-multi-line) further below. --Stig
|
|
2442 (if (not comment-multi-line)
|
|
2443 (save-excursion
|
|
2444 (if (and comment-start-skip
|
|
2445 (let ((opoint (point)))
|
|
2446 (forward-line -1)
|
|
2447 (re-search-forward comment-start-skip opoint t)))
|
|
2448 ;; The old line is a comment.
|
|
2449 ;; Set WIN to the pos of the comment-start.
|
|
2450 ;; But if the comment is empty, look at preceding lines
|
|
2451 ;; to find one that has a nonempty comment.
|
|
2452
|
|
2453 ;; If comment-start-skip contains a \(...\) pair,
|
|
2454 ;; the real comment delimiter starts at the end of that pair.
|
|
2455 (let ((win (or (match-end 1) (match-beginning 0))))
|
|
2456 (while (and (eolp) (not (bobp))
|
|
2457 (let (opoint)
|
|
2458 (beginning-of-line)
|
|
2459 (setq opoint (point))
|
|
2460 (forward-line -1)
|
|
2461 (re-search-forward comment-start-skip opoint t)))
|
|
2462 (setq win (or (match-end 1) (match-beginning 0))))
|
|
2463 ;; Indent this line like what we found.
|
|
2464 (goto-char win)
|
|
2465 (setq comcol (current-column))
|
|
2466 (setq comstart
|
|
2467 (buffer-substring (point) (match-end 0)))))))
|
|
2468 (if (and comcol (not fill-prefix)) ; XEmacs - (ENE) from fa-extras.
|
|
2469 (let ((comment-column comcol)
|
|
2470 (comment-start comstart)
|
|
2471 (comment-end comment-end))
|
|
2472 (and comment-end (not (equal comment-end ""))
|
|
2473 ; (if (not comment-multi-line)
|
|
2474 (progn
|
|
2475 (forward-char -1)
|
|
2476 (insert comment-end)
|
|
2477 (forward-char 1))
|
|
2478 ; (setq comment-column (+ comment-column (length comment-start))
|
|
2479 ; comment-start "")
|
|
2480 ; )
|
|
2481 )
|
|
2482 (if (not (eolp))
|
|
2483 (setq comment-end ""))
|
|
2484 (insert ?\n)
|
|
2485 (forward-char -1)
|
|
2486 (indent-for-comment)
|
|
2487 (save-excursion
|
|
2488 ;; Make sure we delete the newline inserted above.
|
|
2489 (end-of-line)
|
|
2490 (delete-char 1)))
|
|
2491 (indent-according-to-mode)))))
|
|
2492
|
|
2493
|
|
2494 (defun set-selective-display (arg)
|
|
2495 "Set `selective-display' to ARG; clear it if no arg.
|
|
2496 When the value of `selective-display' is a number > 0,
|
|
2497 lines whose indentation is >= that value are not displayed.
|
|
2498 The variable `selective-display' has a separate value for each buffer."
|
|
2499 (interactive "P")
|
|
2500 (if (eq selective-display t)
|
|
2501 (error "selective-display already in use for marked lines"))
|
|
2502 (let ((current-vpos
|
|
2503 (save-restriction
|
|
2504 (narrow-to-region (point-min) (point))
|
|
2505 (goto-char (window-start))
|
|
2506 (vertical-motion (window-height)))))
|
|
2507 (setq selective-display
|
|
2508 (and arg (prefix-numeric-value arg)))
|
|
2509 (recenter current-vpos))
|
|
2510 (set-window-start (selected-window) (window-start (selected-window)))
|
|
2511 ;; #### doesn't localize properly:
|
|
2512 (princ "selective-display set to " t)
|
|
2513 (prin1 selective-display t)
|
|
2514 (princ "." t))
|
|
2515
|
4
|
2516 ;; XEmacs
|
0
|
2517 (defun nuke-selective-display ()
|
|
2518 "Ensure that the buffer is not in selective-display mode.
|
|
2519 If `selective-display' is t, then restore the buffer text to it's original
|
|
2520 state before disabling selective display."
|
|
2521 ;; by Stig@hackvan.com
|
|
2522 (interactive)
|
|
2523 (and (eq t selective-display)
|
|
2524 (save-excursion
|
|
2525 (save-restriction
|
|
2526 (widen)
|
|
2527 (goto-char (point-min))
|
|
2528 (let ((mod-p (buffer-modified-p))
|
|
2529 (buffer-read-only nil))
|
|
2530 (while (search-forward "\r" nil t)
|
|
2531 (delete-char -1)
|
|
2532 (insert "\n"))
|
|
2533 (set-buffer-modified-p mod-p)
|
|
2534 ))))
|
|
2535 (setq selective-display nil))
|
|
2536
|
|
2537 (add-hook 'change-major-mode-hook 'nuke-selective-display)
|
|
2538
|
4
|
2539 (defconst overwrite-mode-textual (purecopy " Ovwrt")
|
|
2540 "The string displayed in the mode line when in overwrite mode.")
|
|
2541 (defconst overwrite-mode-binary (purecopy " Bin Ovwrt")
|
|
2542 "The string displayed in the mode line when in binary overwrite mode.")
|
0
|
2543
|
|
2544 (defun overwrite-mode (arg)
|
|
2545 "Toggle overwrite mode.
|
|
2546 With arg, turn overwrite mode on iff arg is positive.
|
|
2547 In overwrite mode, printing characters typed in replace existing text
|
|
2548 on a one-for-one basis, rather than pushing it to the right. At the
|
|
2549 end of a line, such characters extend the line. Before a tab,
|
|
2550 such characters insert until the tab is filled in.
|
|
2551 \\[quoted-insert] still inserts characters in overwrite mode; this
|
|
2552 is supposed to make it easier to insert characters when necessary."
|
|
2553 (interactive "P")
|
|
2554 (setq overwrite-mode
|
|
2555 (if (if (null arg) (not overwrite-mode)
|
|
2556 (> (prefix-numeric-value arg) 0))
|
|
2557 'overwrite-mode-textual))
|
|
2558 (redraw-modeline))
|
|
2559
|
|
2560 (defun binary-overwrite-mode (arg)
|
|
2561 "Toggle binary overwrite mode.
|
|
2562 With arg, turn binary overwrite mode on iff arg is positive.
|
|
2563 In binary overwrite mode, printing characters typed in replace
|
|
2564 existing text. Newlines are not treated specially, so typing at the
|
|
2565 end of a line joins the line to the next, with the typed character
|
|
2566 between them. Typing before a tab character simply replaces the tab
|
|
2567 with the character typed.
|
|
2568 \\[quoted-insert] replaces the text at the cursor, just as ordinary
|
|
2569 typing characters do.
|
|
2570
|
|
2571 Note that binary overwrite mode is not its own minor mode; it is a
|
|
2572 specialization of overwrite-mode, entered by setting the
|
|
2573 `overwrite-mode' variable to `overwrite-mode-binary'."
|
|
2574 (interactive "P")
|
|
2575 (setq overwrite-mode
|
|
2576 (if (if (null arg)
|
|
2577 (not (eq overwrite-mode 'overwrite-mode-binary))
|
|
2578 (> (prefix-numeric-value arg) 0))
|
|
2579 'overwrite-mode-binary))
|
|
2580 (redraw-modeline))
|
|
2581
|
|
2582 (defvar line-number-mode nil
|
|
2583 "*Non-nil means display line number in modeline.")
|
|
2584
|
|
2585 (defun line-number-mode (arg)
|
|
2586 "Toggle Line Number mode.
|
|
2587 With arg, turn Line Number mode on iff arg is positive.
|
|
2588 When Line Number mode is enabled, the line number appears
|
4
|
2589 in the mode line."
|
0
|
2590 (interactive "P")
|
|
2591 (setq line-number-mode
|
|
2592 (if (null arg) (not line-number-mode)
|
|
2593 (> (prefix-numeric-value arg) 0)))
|
|
2594 (redraw-modeline))
|
|
2595
|
|
2596 (defvar column-number-mode nil
|
4
|
2597 "*Non-nil means display column number in mode line.")
|
0
|
2598
|
|
2599 (defun column-number-mode (arg)
|
|
2600 "Toggle Column Number mode.
|
|
2601 With arg, turn Column Number mode on iff arg is positive.
|
|
2602 When Column Number mode is enabled, the column number appears
|
4
|
2603 in the mode line."
|
0
|
2604 (interactive "P")
|
|
2605 (setq column-number-mode
|
|
2606 (if (null arg) (not column-number-mode)
|
|
2607 (> (prefix-numeric-value arg) 0)))
|
|
2608 (redraw-modeline))
|
|
2609
|
|
2610
|
|
2611 (defvar blink-matching-paren t
|
|
2612 "*Non-nil means show matching open-paren when close-paren is inserted.")
|
|
2613
|
4
|
2614 (defvar blink-matching-paren-on-screen t
|
|
2615 "*Non-nil means show matching open-paren when it is on screen.
|
|
2616 nil means don't show it (but the open-paren can still be shown
|
|
2617 when it is off screen.")
|
|
2618
|
|
2619 (defconst blink-matching-paren-distance 12000
|
0
|
2620 "*If non-nil, is maximum distance to search for matching open-paren.")
|
|
2621
|
|
2622 (defconst blink-matching-delay 1
|
|
2623 "*The number of seconds that `blink-matching-open' will delay at a match.")
|
|
2624
|
|
2625 (defconst blink-matching-paren-dont-ignore-comments nil
|
|
2626 "*Non-nil means `blink-matching-paren' should not ignore comments.")
|
|
2627
|
|
2628 (defun blink-matching-open ()
|
|
2629 "Move cursor momentarily to the beginning of the sexp before point."
|
4
|
2630 (interactive "_") ; XEmacs
|
0
|
2631 (and (> (point) (1+ (point-min)))
|
|
2632 blink-matching-paren
|
|
2633 ;; Verify an even number of quoting characters precede the close.
|
|
2634 (= 1 (logand 1 (- (point)
|
|
2635 (save-excursion
|
|
2636 (forward-char -1)
|
|
2637 (skip-syntax-backward "/\\")
|
|
2638 (point)))))
|
|
2639 (let* ((oldpos (point))
|
|
2640 (parse-sexp-ignore-comments t) ; to avoid C++ lossage
|
|
2641 (blinkpos)
|
|
2642 (mismatch))
|
|
2643 (save-excursion
|
|
2644 (save-restriction
|
|
2645 (if blink-matching-paren-distance
|
|
2646 (narrow-to-region (max (point-min)
|
|
2647 (- (point) blink-matching-paren-distance))
|
|
2648 oldpos))
|
|
2649 (condition-case ()
|
|
2650 (let ((parse-sexp-ignore-comments
|
|
2651 (and parse-sexp-ignore-comments
|
|
2652 (not blink-matching-paren-dont-ignore-comments))))
|
|
2653 (setq blinkpos (scan-sexps oldpos -1)))
|
|
2654 (error nil)))
|
|
2655 (and blinkpos
|
|
2656 (/= (char-syntax (char-after blinkpos))
|
|
2657 ?\$)
|
|
2658 (setq mismatch
|
|
2659 (or (null (matching-paren (char-after blinkpos)))
|
|
2660 (/= (char-after (1- oldpos))
|
|
2661 (matching-paren (char-after blinkpos))))))
|
|
2662 (if mismatch (setq blinkpos nil))
|
|
2663 (if blinkpos
|
|
2664 (progn
|
|
2665 (goto-char blinkpos)
|
|
2666 (if (pos-visible-in-window-p)
|
4
|
2667 (and blink-matching-paren-on-screen
|
|
2668 (sit-for blink-matching-delay))
|
0
|
2669 (goto-char blinkpos)
|
|
2670 (message
|
|
2671 "Matches %s"
|
|
2672 ;; Show what precedes the open in its line, if anything.
|
|
2673 (if (save-excursion
|
|
2674 (skip-chars-backward " \t")
|
|
2675 (not (bolp)))
|
|
2676 (buffer-substring (progn (beginning-of-line) (point))
|
|
2677 (1+ blinkpos))
|
|
2678 ;; Show what follows the open in its line, if anything.
|
|
2679 (if (save-excursion
|
|
2680 (forward-char 1)
|
|
2681 (skip-chars-forward " \t")
|
|
2682 (not (eolp)))
|
4
|
2683 (buffer-substring blinkpos
|
|
2684 (progn (end-of-line) (point)))
|
0
|
2685 ;; Otherwise show the previous nonblank line,
|
|
2686 ;; if there is one.
|
|
2687 (if (save-excursion
|
|
2688 (skip-chars-backward "\n \t")
|
|
2689 (not (bobp)))
|
|
2690 (concat
|
|
2691 (buffer-substring (progn
|
|
2692 (skip-chars-backward "\n \t")
|
|
2693 (beginning-of-line)
|
|
2694 (point))
|
|
2695 (progn (end-of-line)
|
|
2696 (skip-chars-backward " \t")
|
|
2697 (point)))
|
|
2698 ;; Replace the newline and other whitespace with `...'.
|
|
2699 "..."
|
|
2700 (buffer-substring blinkpos (1+ blinkpos)))
|
|
2701 ;; There is nothing to show except the char itself.
|
|
2702 (buffer-substring blinkpos (1+ blinkpos))))))))
|
|
2703 (cond (mismatch
|
|
2704 (message "Mismatched parentheses"))
|
|
2705 ((not blink-matching-paren-distance)
|
|
2706 (message "Unmatched parenthesis"))))))))
|
|
2707
|
|
2708 ;Turned off because it makes dbx bomb out.
|
|
2709 (setq blink-paren-function 'blink-matching-open)
|
|
2710
|
|
2711 (eval-when-compile (defvar myhelp)) ; suppress compiler warning
|
|
2712
|
4
|
2713 ;; XEmacs: Some functions moved to cmdloop.el:
|
|
2714 ;; keyboard-quit
|
|
2715 ;; buffer-quit-function
|
|
2716 ;; keyboard-escape-quit
|
|
2717
|
0
|
2718 (defun set-variable (var val)
|
|
2719 "Set VARIABLE to VALUE. VALUE is a Lisp object.
|
|
2720 When using this interactively, supply a Lisp expression for VALUE.
|
|
2721 If you want VALUE to be a string, you must surround it with doublequotes.
|
|
2722
|
|
2723 If VARIABLE has a `variable-interactive' property, that is used as if
|
|
2724 it were the arg to `interactive' (which see) to interactively read the value."
|
|
2725 (interactive
|
|
2726 (let* ((var (read-variable "Set variable: "))
|
|
2727 ;; #### - yucky code replication here. This should use something
|
|
2728 ;; from help.el or hyper-apropos.el
|
|
2729 (minibuffer-help-form
|
|
2730 '(funcall myhelp))
|
|
2731 (myhelp
|
|
2732 #'(lambda ()
|
|
2733 (with-output-to-temp-buffer "*Help*"
|
|
2734 (prin1 var)
|
|
2735 (princ "\nDocumentation:\n")
|
|
2736 (princ (substring (documentation-property var 'variable-documentation)
|
|
2737 1))
|
|
2738 (if (boundp var)
|
|
2739 (let ((print-length 20))
|
|
2740 (princ "\n\nCurrent value: ")
|
|
2741 (prin1 (symbol-value var))))
|
|
2742 (save-excursion
|
|
2743 (set-buffer standard-output)
|
|
2744 (help-mode))
|
|
2745 nil))))
|
|
2746 (list var
|
|
2747 (let ((prop (get var 'variable-interactive)))
|
|
2748 (if prop
|
|
2749 ;; Use VAR's `variable-interactive' property
|
|
2750 ;; as an interactive spec for prompting.
|
|
2751 (call-interactively (list 'lambda '(arg)
|
|
2752 (list 'interactive prop)
|
|
2753 'arg))
|
|
2754 (eval-minibuffer (format "Set %s to value: " var)))))))
|
|
2755 (set var val))
|
|
2756
|
4
|
2757 ;; XEmacs
|
0
|
2758 (defun activate-region ()
|
|
2759 "Activate the region, if `zmacs-regions' is true.
|
|
2760 Setting `zmacs-regions' to true causes LISPM-style active regions to be used.
|
|
2761 This function has no effect if `zmacs-regions' is false."
|
|
2762 (interactive)
|
|
2763 (and zmacs-regions (zmacs-activate-region)))
|
|
2764
|
4
|
2765 ;; XEmacs
|
0
|
2766 (defsubst region-exists-p ()
|
|
2767 "Non-nil iff the region exists.
|
|
2768 If active regions are in use (i.e. `zmacs-regions' is true), this means that
|
|
2769 the region is active. Otherwise, this means that the user has pushed
|
|
2770 a mark in this buffer at some point in the past.
|
|
2771 The functions `region-beginning' and `region-end' can be used to find the
|
|
2772 limits of the region."
|
|
2773 (not (null (mark))))
|
|
2774
|
4
|
2775 ;; XEmacs
|
0
|
2776 (defun region-active-p ()
|
|
2777 "Non-nil iff the region is active.
|
|
2778 If `zmacs-regions' is true, this is equivalent to `region-exists-p'.
|
|
2779 Otherwise, this function always returns false."
|
|
2780 (and zmacs-regions zmacs-region-extent))
|
|
2781
|
4
|
2782 ;; A bunch of stuff was moved elsewhere:
|
|
2783 ;; completion-list-mode-map
|
|
2784 ;; completion-reference-buffer
|
|
2785 ;; completion-base-size
|
|
2786 ;; delete-completion-window
|
|
2787 ;; previous-completion
|
|
2788 ;; next-completion
|
|
2789 ;; choose-completion
|
|
2790 ;; choose-completion-delete-max-match
|
|
2791 ;; choose-completion-string
|
|
2792 ;; completion-list-mode
|
|
2793 ;; completion-fixup-function
|
|
2794 ;; completion-setup-function
|
|
2795 ;; switch-to-completions
|
|
2796 ;; event stuffs
|
|
2797 ;; keypad stuffs
|
|
2798
|
|
2799 ;; The rest of this file is not in Lisp in FSF
|
0
|
2800 (defun capitalize-region-or-word (arg)
|
|
2801 "Capitalize the selected region or the following word (or ARG words)."
|
|
2802 (interactive "p")
|
|
2803 (if (region-active-p) (capitalize-region (region-beginning) (region-end))
|
|
2804 (capitalize-word arg)))
|
|
2805
|
|
2806 (defun upcase-region-or-word (arg)
|
|
2807 "Upcase the selected region or the following word (or ARG words)."
|
|
2808 (interactive "p")
|
|
2809 (if (region-active-p) (upcase-region (region-beginning) (region-end))
|
|
2810 (upcase-word arg)))
|
|
2811
|
|
2812 (defun downcase-region-or-word (arg)
|
|
2813 "Downcase the selected region or the following word (or ARG words)."
|
|
2814 (interactive "p")
|
|
2815 (if (region-active-p) (downcase-region (region-beginning) (region-end))
|
|
2816 (downcase-word arg)))
|
|
2817
|
|
2818 ;;;
|
|
2819 ;;; Most of the zmacs code is now in elisp. The only thing left in C
|
|
2820 ;;; are the variables zmacs-regions, zmacs-region-active-p and
|
|
2821 ;;; zmacs-region-stays plus the function zmacs_update_region which
|
|
2822 ;;; calls the lisp level zmacs-update-region. It must remain since it
|
|
2823 ;;; must be called by core C code.
|
|
2824 ;;;
|
|
2825
|
|
2826 (defvar zmacs-activate-region-hook nil
|
|
2827 "Function or functions called when the region becomes active;
|
|
2828 see the variable `zmacs-regions'.")
|
|
2829
|
|
2830 (defvar zmacs-deactivate-region-hook nil
|
|
2831 "Function or functions called when the region becomes inactive;
|
|
2832 see the variable `zmacs-regions'.")
|
|
2833
|
|
2834 (defvar zmacs-update-region-hook nil
|
|
2835 "Function or functions called when the active region changes.
|
|
2836 This is called after each command that sets `zmacs-region-stays' to t.
|
|
2837 See the variable `zmacs-regions'.")
|
|
2838
|
|
2839 (defvar zmacs-region-extent nil
|
|
2840 "The extent of the zmacs region; don't use this.")
|
|
2841
|
|
2842 (defvar zmacs-region-rectangular-p nil
|
|
2843 "Whether the zmacs region is a rectangle; don't use this.")
|
|
2844
|
|
2845 (defun zmacs-make-extent-for-region (region)
|
|
2846 ;; Given a region, this makes an extent in the buffer which holds that
|
|
2847 ;; region, for highlighting purposes. If the region isn't associated
|
|
2848 ;; with a buffer, this does nothing.
|
|
2849 (let ((buffer nil)
|
|
2850 (valid (and (extentp zmacs-region-extent)
|
|
2851 (extent-object zmacs-region-extent)
|
|
2852 (buffer-live-p (extent-object zmacs-region-extent))))
|
|
2853 start end)
|
|
2854 (cond ((consp region)
|
|
2855 (setq start (min (car region) (cdr region))
|
|
2856 end (max (car region) (cdr region))
|
|
2857 valid (and valid
|
|
2858 (eq (marker-buffer (car region))
|
|
2859 (extent-object zmacs-region-extent)))
|
|
2860 buffer (marker-buffer (car region))))
|
|
2861 (t
|
|
2862 (signal 'error (list "invalid region" region))))
|
|
2863
|
|
2864 (if valid
|
|
2865 nil
|
|
2866 ;; The condition case is in case any of the extents are dead or
|
|
2867 ;; otherwise incapacitated.
|
|
2868 (condition-case ()
|
|
2869 (if (listp zmacs-region-extent)
|
|
2870 (mapcar 'delete-extent zmacs-region-extent)
|
|
2871 (delete-extent zmacs-region-extent))
|
|
2872 (error nil)))
|
|
2873
|
|
2874 (if valid
|
|
2875 (set-extent-endpoints zmacs-region-extent start end)
|
|
2876 (setq zmacs-region-extent (make-extent start end buffer))
|
|
2877
|
|
2878 ;; Make the extent be closed on the right, which means that if
|
|
2879 ;; characters are inserted exactly at the end of the extent, the
|
|
2880 ;; extent will grow to cover them. This is important for shell
|
|
2881 ;; buffers - suppose one makes a region, and one end is at point-max.
|
|
2882 ;; If the shell produces output, that marker will remain at point-max
|
|
2883 ;; (its position will increase). So it's important that the extent
|
|
2884 ;; exhibit the same behavior, lest the region covered by the extent
|
|
2885 ;; (the visual indication), and the region between point and mark
|
|
2886 ;; (the actual region value) become different!
|
|
2887 (set-extent-property zmacs-region-extent 'end-open nil)
|
|
2888
|
|
2889 ;; use same priority as mouse-highlighting so that conflicts between
|
|
2890 ;; the region extent and a mouse-highlighted extent are resolved by
|
|
2891 ;; the usual size-and-endpoint-comparison method.
|
|
2892 (set-extent-priority zmacs-region-extent mouse-highlight-priority)
|
|
2893 (set-extent-face zmacs-region-extent 'zmacs-region)
|
|
2894
|
|
2895 ;; #### It might be better to actually break
|
|
2896 ;; default-mouse-track-next-move-rect out of mouse.el so that we
|
|
2897 ;; can use its logic here.
|
|
2898 (cond
|
|
2899 (zmacs-region-rectangular-p
|
|
2900 (setq zmacs-region-extent (list zmacs-region-extent))
|
|
2901 (default-mouse-track-next-move-rect start end zmacs-region-extent)
|
|
2902 ))
|
|
2903
|
|
2904 zmacs-region-extent)))
|
|
2905
|
|
2906 (defun zmacs-region-buffer ()
|
|
2907 "Return the buffer containing the zmacs region, or nil."
|
|
2908 ;; #### this is horrible and kludgy! This stuff needs to be rethought.
|
|
2909 (and zmacs-regions zmacs-region-active-p
|
|
2910 (or (marker-buffer (mark-marker t))
|
|
2911 (and (extent-live-p zmacs-region-extent)
|
|
2912 (buffer-live-p (extent-object zmacs-region-extent))
|
|
2913 (extent-object zmacs-region-extent)))))
|
|
2914
|
|
2915 (defun zmacs-activate-region ()
|
|
2916 "Make the region between `point' and `mark' be active (highlighted),
|
|
2917 if `zmacs-regions' is true. Only a very small number of commands
|
|
2918 should ever do this. Calling this function will call the hook
|
|
2919 `zmacs-activate-region-hook', if the region was previously inactive.
|
|
2920 Calling this function ensures that the region stays active after the
|
|
2921 current command terminates, even if `zmacs-region-stays' is not set.
|
|
2922 Returns t if the region was activated (i.e. if `zmacs-regions' if t)."
|
|
2923 (if (not zmacs-regions)
|
|
2924 nil
|
|
2925 (setq zmacs-region-active-p t
|
|
2926 zmacs-region-stays t
|
|
2927 zmacs-region-rectangular-p (and (boundp 'mouse-track-rectangle-p)
|
|
2928 mouse-track-rectangle-p))
|
|
2929 (if (marker-buffer (mark-marker t))
|
|
2930 (zmacs-make-extent-for-region (cons (point-marker t) (mark-marker t))))
|
|
2931 (run-hooks 'zmacs-activate-region-hook)
|
|
2932 t))
|
|
2933
|
|
2934 (defun zmacs-deactivate-region ()
|
|
2935 "Make the region between `point' and `mark' no longer be active,
|
|
2936 if `zmacs-regions' is true. You shouldn't need to call this; the
|
|
2937 command loop calls it when appropriate. Calling this function will
|
|
2938 call the hook `zmacs-deactivate-region-hook', if the region was
|
|
2939 previously active. Returns t if the region had been active, nil
|
|
2940 otherwise."
|
|
2941 (if (not zmacs-region-active-p)
|
|
2942 nil
|
|
2943 (setq zmacs-region-active-p nil
|
|
2944 zmacs-region-stays nil
|
|
2945 zmacs-region-rectangular-p nil)
|
|
2946 (if zmacs-region-extent
|
|
2947 (let ((inhibit-quit t))
|
|
2948 (if (listp zmacs-region-extent)
|
|
2949 (mapcar 'delete-extent zmacs-region-extent)
|
|
2950 (delete-extent zmacs-region-extent))
|
|
2951 (setq zmacs-region-extent nil)))
|
|
2952 (run-hooks 'zmacs-deactivate-region-hook)
|
|
2953 t))
|
|
2954
|
|
2955 (defun zmacs-update-region ()
|
|
2956 "Update the highlighted region between `point' and `mark'.
|
|
2957 You shouldn't need to call this; the command loop calls it
|
|
2958 when appropriate. Calling this function will call the hook
|
|
2959 `zmacs-update-region-hook', if the region is active."
|
|
2960 (if zmacs-region-active-p
|
|
2961 (progn
|
|
2962 (if (marker-buffer (mark-marker t))
|
|
2963 (zmacs-make-extent-for-region (cons (point-marker t)
|
|
2964 (mark-marker t))))
|
|
2965 (run-hooks 'zmacs-update-region-hook))))
|
|
2966
|
|
2967 ;;;;;;
|
|
2968 ;;;;;; echo area stuff
|
|
2969 ;;;;;;
|
|
2970
|
|
2971 ;;; The `message-stack' is an alist of labels with messages; the first
|
|
2972 ;;; message in this list is always in the echo area. A call to
|
|
2973 ;;; `display-message' inserts a label/message pair at the head of the
|
|
2974 ;;; list, and removes any other pairs with that label. Calling
|
|
2975 ;;; `clear-message' causes any pair with matching label to be removed,
|
|
2976 ;;; and this may cause the displayed message to change or vanish. If
|
|
2977 ;;; the label arg is nil, the entire message stack is cleared.
|
|
2978 ;;;
|
|
2979 ;;; Message/error filtering will be a little tricker to implement than
|
|
2980 ;;; logging, since messages can be built up incrementally
|
|
2981 ;;; using clear-message followed by repeated calls to append-message
|
|
2982 ;;; (this happens with error messages). For messages which aren't
|
|
2983 ;;; created this way, filtering could be implemented at display-message
|
|
2984 ;;; very easily.
|
|
2985 ;;;
|
|
2986 ;;; Bits of the logging code are borrowed from log-messages.el by
|
|
2987 ;;; Robert Potter (rpotter@grip.cis.upenn.edu).
|
|
2988
|
|
2989 ;; need this to terminate the currently-displayed message
|
|
2990 ;; ("Loading simple ...")
|
4
|
2991 (when (and
|
|
2992 (not (fboundp 'display-message))
|
|
2993 (not (featurep 'debug)))
|
|
2994 (send-string-to-terminal "\n"))
|
0
|
2995
|
|
2996 (defvar message-stack nil
|
|
2997 "An alist of label/string pairs representing active echo-area messages.
|
|
2998 The first element in the list is currently displayed in the echo area.
|
|
2999 Do not modify this directly--use the `message' or
|
|
3000 `display-message'/`clear-message' functions.")
|
|
3001
|
|
3002 (defvar remove-message-hook 'log-message
|
|
3003 "A function or list of functions to be called when a message is removed
|
|
3004 from the echo area at the bottom of the frame. The label of the removed
|
|
3005 message is passed as the first argument, and the text of the message
|
|
3006 as the second argument.")
|
|
3007
|
|
3008 (defvar log-message-max-size 50000
|
|
3009 "Maximum size of the \" *Message-Log*\" buffer. See `log-message'.")
|
|
3010
|
|
3011 (defvar log-message-ignore-regexps
|
|
3012 '("^Mark set$"
|
|
3013 "^Undo!$"
|
|
3014 "^Quit$"
|
|
3015 "^\\(Beginning\\|End\\) of buffer$"
|
|
3016 "^Fontifying"
|
|
3017 "^\\(Failing \\)?\\([Ww]rapped \\)?\\([Rr]egexp \\)?I-search\\( backward\\)?:"
|
|
3018 "^Mark saved where search started$"
|
|
3019 "^Making completion list"
|
|
3020 "^Matches " ; paren-matching message
|
|
3021 "^Type .* to \\(remove help\\|restore the other\\) window."
|
|
3022 "^M-x .* (bound to key" ; teach-extended-commands
|
|
3023 "^(No changes need to be saved)$"
|
|
3024 "^(No files need saving)$"
|
|
3025 "^\\(Parsing messages\\|Reading attributes\\|Generating summary\\|Building threads\\|Converting\\)\\.\\.\\. [0-9]+$" ; vm
|
|
3026 "^End of message \d+" ; vm
|
|
3027 "^Parsing error messages\\.\\.\\.[0-9]+" ; compile
|
|
3028 "^Parsed [0-9]+ of [0-9]+ ([0-9]+%)$" ; w3
|
|
3029 "^\\(Formatting Summary\\|Reading active file\\|Checking new news\\|Looking for crossposts\\|Marking crossposts\\|MHSPOOL:\\|NNSPOOL:\\|NNTP:\\|\\(Uns\\|S\\)ubscribing new newsgroups\\)\\.\\.\\. *[0-9]+%$" ; gnus
|
|
3030 "^Adding glyphs\\.\\.\\. ([0-9]+%)\\( done\\)?$" ; outl-mouse
|
|
3031 "^->" ; bbdb prompt
|
|
3032 )
|
|
3033 "List of regular expressions matching messages which shouldn't be logged.
|
|
3034 See `log-message'.
|
|
3035
|
|
3036 Ideally, packages which generate messages which might need to be ignored
|
|
3037 should label them with 'progress, 'prompt, or 'no-log, so they can be
|
|
3038 filtered by the log-message-ignore-labels.")
|
|
3039
|
|
3040 (defvar log-message-ignore-labels
|
|
3041 '(help-echo command progress prompt no-log garbage-collecting auto-saving)
|
|
3042 "List of symbols indicating labels of messages which shouldn't be logged.
|
|
3043 See `display-message' for some common labels. See also `log-message'.")
|
|
3044
|
|
3045 ;Subsumed by view-lossage
|
|
3046 ;(defun show-message-log ()
|
|
3047 ; "Show the \" *Message-Log*\" buffer, which contains old messages and errors."
|
|
3048 ; (interactive)
|
|
3049 ; (pop-to-buffer " *Message-Log*"))
|
|
3050
|
|
3051 (defvar log-message-filter-function 'log-message-filter
|
|
3052 "Value must be a function of two arguments: a symbol (label) and
|
|
3053 a string (messsage). It should return non-nil to indicate a message
|
|
3054 should be logged. Possible values include 'log-message-filter and
|
|
3055 'log-message-filter-errors-only.")
|
|
3056
|
|
3057 (defun log-message-filter (label message)
|
|
3058 "Default value of log-message-filter-function.
|
|
3059 Mesages whose text matches one of the log-message-ignore-regexps
|
|
3060 or whose label appears in log-message-ignore-labels are not saved."
|
|
3061 (let ((r log-message-ignore-regexps)
|
|
3062 (ok (not (memq label log-message-ignore-labels))))
|
|
3063 (while (and r ok)
|
|
3064 (if (save-match-data (string-match (car r) message))
|
|
3065 (setq ok nil))
|
|
3066 (setq r (cdr r)))
|
|
3067 ok))
|
|
3068
|
|
3069 (defun log-message-filter-errors-only (label message)
|
|
3070 "For use as the log-message-filter-function. Only logs error messages."
|
|
3071 (eq label 'error))
|
|
3072
|
|
3073 (defun log-message (label message)
|
|
3074 "Stuff a copy of the message into the \" *Message-Log*\" buffer,
|
|
3075 if it satisfies the log-message-filter-function.
|
|
3076
|
|
3077 For use on remove-message-hook."
|
|
3078 (if (and (not noninteractive)
|
|
3079 (funcall log-message-filter-function label message))
|
|
3080 (save-excursion
|
|
3081 (set-buffer (get-buffer-create " *Message-Log*"))
|
|
3082 (goto-char (point-max))
|
|
3083 ;; (insert (concat (upcase (symbol-name label)) ": " message "\n"))
|
|
3084 (insert message "\n")
|
|
3085 (if (> (point-max) (max log-message-max-size (point-min)))
|
|
3086 (progn
|
|
3087 ;; trim log to ~90% of max size
|
|
3088 (goto-char (max (- (point-max)
|
|
3089 (truncate (* 0.9 log-message-max-size)))
|
|
3090 (point-min)))
|
|
3091 (forward-line 1)
|
|
3092 (delete-region (point-min) (point)))))))
|
|
3093
|
|
3094 (defun message-displayed-p (&optional return-string frame)
|
|
3095 "Return a non-nil value if a message is presently displayed in the\n\
|
|
3096 minibuffer's echo area. If optional argument RETURN-STRING is non-nil,\n\
|
|
3097 return a string containing the message, otherwise just return t."
|
|
3098 ;; by definition, a message is displayed if the echo area buffer is
|
|
3099 ;; non-empty (see also echo_area_active()). It had better also
|
|
3100 ;; be the case that message-stack is nil exactly when the echo area
|
|
3101 ;; is non-empty.
|
|
3102 (let ((buffer (get-buffer " *Echo Area*")))
|
|
3103 (and (< (point-min buffer) (point-max buffer))
|
|
3104 (if return-string
|
|
3105 (buffer-substring nil nil buffer)
|
|
3106 t))))
|
|
3107
|
|
3108 ;;; Returns the string which remains in the echo area, or nil if none.
|
|
3109 ;;; If label is nil, the whole message stack is cleared.
|
|
3110 (defun clear-message (&optional label frame stdout-p no-restore)
|
|
3111 "Remove any message with the given LABEL from the message-stack,
|
|
3112 erasing it from the echo area if it's currently displayed there.
|
|
3113 If a message remains at the head of the message-stack and NO-RESTORE
|
|
3114 is nil, it will be displayed. The string which remains in the echo
|
|
3115 area will be returned, or nil if the message-stack is now empty.
|
|
3116 If LABEL is nil, the entire message-stack is cleared.
|
|
3117
|
4
|
3118 Unless you need the return value or you need to specify a label,
|
0
|
3119 you should just use (message nil)."
|
|
3120 (or frame (setq frame (selected-frame)))
|
|
3121 (let ((clear-stream (and message-stack (eq 'stream (frame-type frame)))))
|
|
3122 (remove-message label frame)
|
|
3123 (let ((buffer (get-buffer " *Echo Area*"))
|
|
3124 (zmacs-region-stays zmacs-region-stays)) ; preserve from change
|
|
3125 (erase-buffer buffer))
|
|
3126 (if clear-stream
|
|
3127 (send-string-to-terminal ?\n stdout-p))
|
|
3128 (if no-restore
|
|
3129 nil ; just preparing to put another msg up
|
|
3130 (if message-stack
|
|
3131 (let ((oldmsg (cdr (car message-stack))))
|
|
3132 (raw-append-message oldmsg frame stdout-p)
|
|
3133 oldmsg)
|
|
3134 ;; ### should we (redisplay-echo-area) here? messes some things up.
|
|
3135 nil))))
|
|
3136
|
|
3137 (defun remove-message (&optional label frame)
|
|
3138 ;; If label is nil, we want to remove all matching messages.
|
|
3139 ;; Must reverse the stack first to log them in the right order.
|
|
3140 (let ((log nil))
|
|
3141 (while (and message-stack
|
|
3142 (or (null label) ; null label means clear whole stack
|
|
3143 (eq label (car (car message-stack)))))
|
|
3144 (setq log (cons (car message-stack) log))
|
|
3145 (setq message-stack (cdr message-stack)))
|
|
3146 (let ((s message-stack))
|
|
3147 (while (cdr s)
|
|
3148 (let ((msg (car (cdr s))))
|
|
3149 (if (eq label (car msg))
|
|
3150 (progn
|
|
3151 (setq log (cons msg log))
|
|
3152 (setcdr s (cdr (cdr s))))
|
|
3153 (setq s (cdr s))))))
|
|
3154 ;; (possibly) log each removed message
|
|
3155 (while log
|
|
3156 (condition-case e
|
|
3157 (run-hook-with-args 'remove-message-hook
|
|
3158 (car (car log)) (cdr (car log)))
|
|
3159 (error (setq remove-message-hook nil)
|
|
3160 (message "remove-message-hook error: %s" e)
|
|
3161 (sit-for 2)
|
|
3162 (erase-buffer (get-buffer " *Echo Area*"))
|
|
3163 (signal (car e) (cdr e))))
|
|
3164 (setq log (cdr log)))))
|
|
3165
|
|
3166 (defun append-message (label message &optional frame stdout-p)
|
|
3167 (or frame (setq frame (selected-frame)))
|
|
3168 ;; add a new entry to the message-stack, or modify an existing one
|
|
3169 (let ((top (car message-stack)))
|
|
3170 (if (eq label (car top))
|
|
3171 (setcdr top (concat (cdr top) message))
|
|
3172 (setq message-stack (cons (cons label message) message-stack))))
|
|
3173 (raw-append-message message frame stdout-p))
|
|
3174
|
|
3175 ;; really append the message to the echo area. no fiddling with message-stack.
|
|
3176 (defun raw-append-message (message &optional frame stdout-p)
|
|
3177 (if (eq message "") nil
|
|
3178 (let ((buffer (get-buffer " *Echo Area*"))
|
|
3179 (zmacs-region-stays zmacs-region-stays)) ; preserve from change
|
|
3180 (save-excursion
|
|
3181 (set-buffer buffer)
|
|
3182 (insert message))
|
|
3183 ;; Conditionalizing on the device type in this way is not that clean,
|
|
3184 ;; but neither is having a device method, as I originally implemented
|
|
3185 ;; it: all non-stream devices behave in the same way. Perhaps
|
|
3186 ;; the cleanest way is to make the concept of a "redisplayable"
|
|
3187 ;; device, which stream devices are not. Look into this more if
|
|
3188 ;; we ever create another non-redisplayable device type (e.g.
|
|
3189 ;; processes? printers?).
|
|
3190
|
|
3191 ;; Don't redisplay the echo area if we are executing a macro.
|
|
3192 (if (not executing-kbd-macro)
|
|
3193 (if (eq 'stream (frame-type frame))
|
|
3194 (send-string-to-terminal message stdout-p)
|
|
3195 (redisplay-echo-area))))))
|
|
3196
|
|
3197 (defun display-message (label message &optional frame stdout-p)
|
|
3198 "Print a one-line message at the bottom of the frame. First argument
|
|
3199 LABEL is an identifier for this message. MESSAGE is the string to display.
|
|
3200 Use `clear-message' to remove a labelled message.
|
|
3201
|
|
3202 Here are some standard labels (those marked with `*' are not logged
|
|
3203 by default--see the `log-message-ignore-labels' variable):
|
|
3204 message default label used by the `message' function
|
|
3205 error default label used for reporting errors
|
|
3206 * progress progress indicators like \"Converting... 45%\"
|
|
3207 * prompt prompt-like messages like \"I-search: foo\"
|
|
3208 * no-log messages that should never be logged"
|
|
3209 (clear-message label frame stdout-p t)
|
|
3210 (append-message label message frame stdout-p))
|
|
3211
|
|
3212 ;;; may eventually be frame-dependent
|
|
3213 (defun current-message-label (frame)
|
|
3214 (if message-stack
|
|
3215 (car (car message-stack))
|
|
3216 nil))
|
|
3217
|
|
3218 (defun message (fmt &rest args)
|
|
3219 "Print a one-line message at the bottom of the frame.
|
|
3220 The arguments are the same as to `format'.
|
|
3221
|
|
3222 If the only argument is nil, clear any existing message; let the
|
|
3223 minibuffer contents show."
|
|
3224 ;; questionable junk in the C code
|
|
3225 ;; (if (framep default-minibuffer-frame)
|
|
3226 ;; (make-frame-visible default-minibuffer-frame))
|
|
3227 (if (and (null fmt) (null args))
|
|
3228 (progn
|
|
3229 (clear-message nil)
|
|
3230 nil)
|
|
3231 (let ((str (apply 'format fmt args)))
|
|
3232 (display-message 'message str)
|
|
3233 str)))
|
|
3234
|
|
3235 ;;;;;;
|
|
3236 ;;;;;; warning stuff
|
|
3237 ;;;;;;
|
|
3238
|
|
3239 (defvar log-warning-minimum-level 'info
|
|
3240 "Minimum level of warnings that should be logged.
|
|
3241 The warnings in levels below this are completely ignored, as if they never
|
|
3242 happened.
|
|
3243
|
|
3244 The recognized warning levels, in decreasing order of priority, are
|
|
3245 'emergency, 'alert, 'critical, 'error, 'warning, 'notice, 'info, and
|
|
3246 'debug.
|
|
3247
|
|
3248 See also `display-warning-minimum-level'.
|
|
3249
|
|
3250 You can also control which warnings are displayed on a class-by-class
|
|
3251 basis. See `display-warning-suppressed-classes' and
|
|
3252 `log-warning-suppressed-classes'.")
|
|
3253
|
|
3254 (defvar display-warning-minimum-level 'info
|
|
3255 "Minimum level of warnings that should be displayed.
|
|
3256 The warnings in levels below this are completely ignored, as if they never
|
|
3257 happened.
|
|
3258
|
|
3259 The recognized warning levels, in decreasing order of priority, are
|
|
3260 'emergency, 'alert, 'critical, 'error, 'warning, 'notice, 'info, and
|
|
3261 'debug.
|
|
3262
|
|
3263 See also `log-warning-minimum-level'.
|
|
3264
|
|
3265 You can also control which warnings are displayed on a class-by-class
|
|
3266 basis. See `display-warning-suppressed-classes' and
|
|
3267 `log-warning-suppressed-classes'.")
|
|
3268
|
|
3269 (defvar log-warning-suppressed-classes nil
|
|
3270 "List of classes of warnings that shouldn't be logged or displayed.
|
|
3271 If any of the CLASS symbols associated with a warning is the same as
|
|
3272 any of the symbols listed here, the warning will be completely ignored,
|
|
3273 as it they never happened.
|
|
3274
|
|
3275 NOTE: In most circumstances, you should *not* set this variable.
|
|
3276 Set `display-warning-suppressed-classes' instead. That way the suppressed
|
|
3277 warnings are not displayed but are still unobtrusively logged.
|
|
3278
|
|
3279 See also `log-warning-minimum-level' and `display-warning-minimum-level'.")
|
|
3280
|
|
3281 (defvar display-warning-suppressed-classes nil
|
|
3282 "List of classes of warnings that shouldn't be displayed.
|
|
3283 If any of the CLASS symbols associated with a warning is the same as
|
|
3284 any of the symbols listed here, the warning will not be displayed.
|
|
3285 The warning will still logged in the *Warnings* buffer (unless also
|
|
3286 contained in `log-warning-suppressed-classes'), but the buffer will
|
|
3287 not be automatically popped up.
|
|
3288
|
|
3289 See also `log-warning-minimum-level' and `display-warning-minimum-level'.")
|
|
3290
|
|
3291 (defvar warning-count 0
|
|
3292 "Count of the number of warning messages displayed so far.")
|
|
3293
|
|
3294 (defconst warning-level-alist '((emergency . 8)
|
|
3295 (alert . 7)
|
|
3296 (critical . 6)
|
|
3297 (error . 5)
|
|
3298 (warning . 4)
|
|
3299 (notice . 3)
|
|
3300 (info . 2)
|
|
3301 (debug . 1)))
|
|
3302
|
|
3303 (defun warning-level-p (level)
|
|
3304 "Non-nil if LEVEL specifies a warning level."
|
|
3305 (and (symbolp level) (assq level warning-level-alist)))
|
|
3306
|
|
3307 ;; If you're interested in rewriting this function, be aware that it
|
|
3308 ;; could be called at arbitrary points in a Lisp program (when a
|
|
3309 ;; built-in function wants to issue a warning, it will call out to
|
|
3310 ;; this function the next time some Lisp code is evaluated). Therefore,
|
|
3311 ;; this function *must* not permanently modify any global variables
|
|
3312 ;; (e.g. the current buffer) except those that specifically apply
|
|
3313 ;; to the warning system.
|
|
3314
|
|
3315 (defvar before-init-deferred-warnings nil)
|
|
3316
|
|
3317 (defun after-init-display-warnings ()
|
|
3318 "Display warnings deferred till after the init file is run.
|
|
3319 Warnings that occur before then are deferred so that warning
|
|
3320 suppression in the .emacs file will be honored."
|
|
3321 (while before-init-deferred-warnings
|
|
3322 (apply 'display-warning (car before-init-deferred-warnings))
|
|
3323 (setq before-init-deferred-warnings
|
|
3324 (cdr before-init-deferred-warnings))))
|
|
3325
|
|
3326 (add-hook 'after-init-hook 'after-init-display-warnings)
|
|
3327
|
|
3328 (defun display-warning (class message &optional level)
|
|
3329 "Display a warning message.
|
|
3330 CLASS should be a symbol describing what sort of warning this is, such
|
|
3331 as `resource' or `key-mapping'. A list of such symbols is also
|
|
3332 accepted. (Individual classes can be suppressed; see
|
|
3333 `display-warning-suppressed-classes'.) Optional argument LEVEL can
|
|
3334 be used to specify a priority for the warning, other than default priority
|
|
3335 `warning'. (See `display-warning-minimum-level'). The message is
|
|
3336 inserted into the *Warnings* buffer, which is made visible at appropriate
|
|
3337 times."
|
|
3338 (or level (setq level 'warning))
|
|
3339 (or (listp class) (setq class (list class)))
|
|
3340 (check-argument-type 'warning-level-p level)
|
|
3341 (if (not init-file-loaded)
|
|
3342 (setq before-init-deferred-warnings
|
|
3343 (cons (list class message level) before-init-deferred-warnings))
|
|
3344 (catch 'ignored
|
|
3345 (let ((display-p t)
|
|
3346 (level-num (cdr (assq level warning-level-alist))))
|
|
3347 (if (< level-num (cdr (assq log-warning-minimum-level
|
|
3348 warning-level-alist)))
|
|
3349 (throw 'ignored nil))
|
|
3350 (if (intersection class log-warning-suppressed-classes)
|
|
3351 (throw 'ignored nil))
|
|
3352
|
|
3353 (if (< level-num (cdr (assq display-warning-minimum-level
|
|
3354 warning-level-alist)))
|
|
3355 (setq display-p nil))
|
|
3356 (if (and display-p
|
|
3357 (intersection class display-warning-suppressed-classes))
|
|
3358 (setq display-p nil))
|
|
3359 (save-excursion
|
|
3360 (let ((buffer (get-buffer-create "*Warnings*")))
|
|
3361 (if display-p
|
|
3362 ;; The C code looks at display-warning-tick to determine
|
|
3363 ;; when it should call `display-warning-buffer'. Change it
|
|
3364 ;; to get the C code's attention.
|
|
3365 (setq display-warning-tick (1+ display-warning-tick)))
|
|
3366 (set-buffer buffer)
|
|
3367 (goto-char (point-max))
|
|
3368 (setq warning-count (1+ warning-count))
|
|
3369 (princ (format "(%d) (%s/%s) "
|
|
3370 warning-count
|
|
3371 (mapconcat 'symbol-name class ",")
|
|
3372 level) buffer)
|
|
3373 (princ message buffer)
|
|
3374 (terpri buffer)
|
|
3375 (terpri buffer)))))))
|
|
3376
|
|
3377 (defun warn (&rest args)
|
|
3378 "Display a warning message.
|
|
3379 The message is constructed by passing all args to `format'. The message
|
|
3380 is placed in the *Warnings* buffer, which will be popped up at the next
|
|
3381 redisplay. The class of the warning is `warning'. See also
|
|
3382 `display-warning'."
|
|
3383 (display-warning 'warning (apply 'format args)))
|
|
3384
|
|
3385 (defvar warning-marker nil)
|
|
3386
|
|
3387 ;; When this function is called by the C code, all non-local exits are
|
|
3388 ;; trapped and C-g is inhibited; therefore, it would be a very, very
|
|
3389 ;; bad idea for this function to get into an infinite loop.
|
|
3390
|
|
3391 (defun display-warning-buffer ()
|
|
3392 "Make the buffer that contains the warnings be visible.
|
|
3393 The C code calls this periodically, right before redisplay."
|
|
3394 (let ((buffer (get-buffer-create "*Warnings*")))
|
|
3395 (if (or (not warning-marker) (not (eq (marker-buffer warning-marker)
|
|
3396 buffer)))
|
|
3397 (progn
|
|
3398 (setq warning-marker (make-marker))
|
|
3399 (set-marker warning-marker 1 buffer)))
|
|
3400 (set-window-start (display-buffer buffer) warning-marker)
|
|
3401 (set-marker warning-marker (point-max buffer) buffer)))
|
4
|
3402
|
|
3403 ;;; simple.el ends here
|