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