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