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