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