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