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