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