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