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