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