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