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