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