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