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