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;
|
843
|
1227 nil means appending to an \"old\" kill.
|
|
1228
|
|
1229 One reasonable choice is `own-clipboard' (the default)."
|
442
|
1230 :type '(radio (function-item :tag "Send to Clipboard"
|
|
1231 :format "%t\n"
|
|
1232 own-clipboard)
|
|
1233 (const :tag "None" nil)
|
|
1234 (function :tag "Other"))
|
|
1235 :group 'killing)
|
|
1236
|
843
|
1237 (defcustom interprogram-paste-function 'get-clipboard-foreign
|
428
|
1238 "Function to call to get text cut from other programs.
|
|
1239
|
|
1240 Most window systems provide some sort of facility for cutting and
|
|
1241 pasting text between the windows of different programs.
|
|
1242 This variable holds a function that Emacs calls to obtain
|
|
1243 text that other programs have provided for pasting.
|
|
1244
|
|
1245 The function should be called with no arguments. If the function
|
|
1246 returns nil, then no other program has provided such text, and the top
|
|
1247 of the Emacs kill ring should be used. If the function returns a
|
|
1248 string, that string should be put in the kill ring as the latest kill.
|
|
1249
|
|
1250 Note that the function should return a string only if a program other
|
|
1251 than Emacs has provided a string for pasting; if Emacs provided the
|
|
1252 most recent string, the function should return nil. If it is
|
|
1253 difficult to tell whether Emacs or some other program provided the
|
|
1254 current string, it is probably good enough to return nil if the string
|
843
|
1255 is equal (according to `string=') to the last text Emacs provided.
|
|
1256
|
|
1257 Reasonable choices include `get-clipboard-foreign' (the default), and
|
|
1258 functions calling `get-selection-foreign' (q.v.)."
|
442
|
1259 :type '(radio (function-item :tag "Get from Clipboard"
|
|
1260 :format "%t\n"
|
843
|
1261 get-clipboard-foreign)
|
442
|
1262 (const :tag "None" nil)
|
|
1263 (function :tag "Other"))
|
|
1264 :group 'killing)
|
428
|
1265
|
|
1266
|
|
1267 ;;;; The kill ring data structure.
|
|
1268
|
|
1269 (defvar kill-ring nil
|
|
1270 "List of killed text sequences.
|
|
1271 Since the kill ring is supposed to interact nicely with cut-and-paste
|
|
1272 facilities offered by window systems, use of this variable should
|
|
1273 interact nicely with `interprogram-cut-function' and
|
|
1274 `interprogram-paste-function'. The functions `kill-new',
|
|
1275 `kill-append', and `current-kill' are supposed to implement this
|
|
1276 interaction; you may want to use them instead of manipulating the kill
|
|
1277 ring directly.")
|
|
1278
|
829
|
1279 (defcustom kill-ring-max 60
|
428
|
1280 "*Maximum length of kill ring before oldest elements are thrown away."
|
|
1281 :type 'integer
|
|
1282 :group 'killing)
|
|
1283
|
|
1284 (defvar kill-ring-yank-pointer nil
|
|
1285 "The tail of the kill ring whose car is the last thing yanked.")
|
|
1286
|
|
1287 (defun kill-new (string &optional replace)
|
|
1288 "Make STRING the latest kill in the kill ring.
|
444
|
1289 Set `kill-ring-yank-pointer' to point to it.
|
829
|
1290 If `interprogram-cut-function' is non-nil, apply it to STRING.
|
428
|
1291 Run `kill-hooks'.
|
|
1292 Optional second argument REPLACE non-nil means that STRING will replace
|
|
1293 the front of the kill ring, rather than being added to the list."
|
|
1294 ; (and (fboundp 'menu-bar-update-yank-menu)
|
|
1295 ; (menu-bar-update-yank-menu string (and replace (car kill-ring))))
|
829
|
1296 (if (and replace kill-ring)
|
428
|
1297 (setcar kill-ring string)
|
|
1298 (setq kill-ring (cons string kill-ring))
|
|
1299 (if (> (length kill-ring) kill-ring-max)
|
|
1300 (setcdr (nthcdr (1- kill-ring-max) kill-ring) nil)))
|
|
1301 (setq kill-ring-yank-pointer kill-ring)
|
|
1302 (if interprogram-cut-function
|
|
1303 (funcall interprogram-cut-function string (not replace)))
|
|
1304 (run-hook-with-args 'kill-hooks string))
|
|
1305
|
|
1306 (defun kill-append (string before-p)
|
|
1307 "Append STRING to the end of the latest kill in the kill ring.
|
|
1308 If BEFORE-P is non-nil, prepend STRING to the kill.
|
|
1309 Run `kill-hooks'."
|
|
1310 (kill-new (if before-p
|
|
1311 (concat string (car kill-ring))
|
|
1312 (concat (car kill-ring) string)) t))
|
|
1313
|
|
1314 (defun current-kill (n &optional do-not-move)
|
|
1315 "Rotate the yanking point by N places, and then return that kill.
|
|
1316 If N is zero, `interprogram-paste-function' is set, and calling it
|
|
1317 returns a string, then that string is added to the front of the
|
|
1318 kill ring and returned as the latest kill.
|
|
1319 If optional arg DO-NOT-MOVE is non-nil, then don't actually move the
|
|
1320 yanking point\; just return the Nth kill forward."
|
|
1321 (let ((interprogram-paste (and (= n 0)
|
|
1322 interprogram-paste-function
|
|
1323 (funcall interprogram-paste-function))))
|
|
1324 (if interprogram-paste
|
|
1325 (progn
|
|
1326 ;; Disable the interprogram cut function when we add the new
|
|
1327 ;; text to the kill ring, so Emacs doesn't try to own the
|
|
1328 ;; selection, with identical text.
|
|
1329 (let ((interprogram-cut-function nil))
|
|
1330 (kill-new interprogram-paste))
|
|
1331 interprogram-paste)
|
|
1332 (or kill-ring (error "Kill ring is empty"))
|
|
1333 (let* ((tem (nthcdr (mod (- n (length kill-ring-yank-pointer))
|
|
1334 (length kill-ring))
|
|
1335 kill-ring)))
|
|
1336 (or do-not-move
|
|
1337 (setq kill-ring-yank-pointer tem))
|
|
1338 (car tem)))))
|
|
1339
|
|
1340
|
|
1341
|
|
1342 ;;;; Commands for manipulating the kill ring.
|
|
1343
|
|
1344 ;; In FSF killing read-only text just pastes it into kill-ring. Which
|
|
1345 ;; is a very bad idea -- see Jamie's comment below.
|
|
1346
|
|
1347 ;(defvar kill-read-only-ok nil
|
|
1348 ; "*Non-nil means don't signal an error for killing read-only text.")
|
|
1349
|
444
|
1350 (defun kill-region (start end &optional verbose) ; verbose is XEmacs addition
|
428
|
1351 "Kill between point and mark.
|
|
1352 The text is deleted but saved in the kill ring.
|
|
1353 The command \\[yank] can retrieve it from there.
|
|
1354 \(If you want to kill and then yank immediately, use \\[copy-region-as-kill].)
|
|
1355
|
|
1356 This is the primitive for programs to kill text (as opposed to deleting it).
|
|
1357 Supply two arguments, character numbers indicating the stretch of text
|
|
1358 to be killed.
|
|
1359 Any command that calls this function is a \"kill command\".
|
|
1360 If the previous command was also a kill command,
|
|
1361 the text killed this time appends to the text killed last time
|
|
1362 to make one entry in the kill ring."
|
|
1363 (interactive "*r\np")
|
|
1364 ; (interactive
|
|
1365 ; (let ((region-hack (and zmacs-regions (eq last-command 'yank))))
|
|
1366 ; ;; This lets "^Y^W" work. I think this is dumb, but zwei did it.
|
|
1367 ; (if region-hack (zmacs-activate-region))
|
|
1368 ; (prog1
|
|
1369 ; (list (point) (mark) current-prefix-arg)
|
|
1370 ; (if region-hack (zmacs-deactivate-region)))))
|
444
|
1371 ;; start and end can be markers but the rest of this function is
|
428
|
1372 ;; written as if they are only integers
|
444
|
1373 (if (markerp start) (setq start (marker-position start)))
|
428
|
1374 (if (markerp end) (setq end (marker-position end)))
|
444
|
1375 (or (and start end) (if zmacs-regions ;; rewritten for I18N3 snarfing
|
428
|
1376 (error "The region is not active now")
|
|
1377 (error "The mark is not set now")))
|
|
1378 (if verbose (if buffer-read-only
|
|
1379 (lmessage 'command "Copying %d characters"
|
444
|
1380 (- (max start end) (min start end)))
|
428
|
1381 (lmessage 'command "Killing %d characters"
|
444
|
1382 (- (max start end) (min start end)))))
|
428
|
1383 (cond
|
|
1384
|
|
1385 ;; I don't like this large change in behavior -- jwz
|
|
1386 ;; Read-Only text means it shouldn't be deleted, so I'm restoring
|
|
1387 ;; this code, but only for text-properties and not full extents. -sb
|
|
1388 ;; If the buffer is read-only, we should beep, in case the person
|
|
1389 ;; just isn't aware of this. However, there's no harm in putting
|
|
1390 ;; the region's text in the kill ring, anyway.
|
|
1391 ((or (and buffer-read-only (not inhibit-read-only))
|
444
|
1392 (text-property-not-all (min start end) (max start end) 'read-only nil))
|
428
|
1393 ;; This is redundant.
|
|
1394 ;; (if verbose (message "Copying %d characters"
|
444
|
1395 ;; (- (max start end) (min start end))))
|
|
1396 (copy-region-as-kill start end)
|
428
|
1397 ;; ;; This should always barf, and give us the correct error.
|
|
1398 ;; (if kill-read-only-ok
|
|
1399 ;; (message "Read only text copied to kill ring")
|
|
1400 (setq this-command 'kill-region)
|
|
1401 (barf-if-buffer-read-only)
|
|
1402 (signal 'buffer-read-only (list (current-buffer))))
|
|
1403
|
|
1404 ;; In certain cases, we can arrange for the undo list and the kill
|
|
1405 ;; ring to share the same string object. This code does that.
|
|
1406 ((not (or (eq buffer-undo-list t)
|
|
1407 (eq last-command 'kill-region)
|
|
1408 ;; Use = since positions may be numbers or markers.
|
444
|
1409 (= start end)))
|
428
|
1410 ;; Don't let the undo list be truncated before we can even access it.
|
|
1411 ;; FSF calls this `undo-strong-limit'
|
444
|
1412 (let ((undo-high-threshold (+ (- end start) 100))
|
428
|
1413 ;(old-list buffer-undo-list)
|
|
1414 tail)
|
444
|
1415 (delete-region start end)
|
428
|
1416 ;; Search back in buffer-undo-list for this string,
|
|
1417 ;; in case a change hook made property changes.
|
|
1418 (setq tail buffer-undo-list)
|
|
1419 (while (and tail
|
|
1420 (not (stringp (car-safe (car-safe tail))))) ; XEmacs
|
|
1421 (pop tail))
|
|
1422 ;; Take the same string recorded for undo
|
|
1423 ;; and put it in the kill-ring.
|
|
1424 (and tail
|
|
1425 (kill-new (car (car tail))))))
|
|
1426
|
|
1427 (t
|
|
1428 ;; if undo is not kept, grab the string then delete it (which won't
|
|
1429 ;; add another string to the undo list).
|
444
|
1430 (copy-region-as-kill start end)
|
|
1431 (delete-region start end)))
|
428
|
1432 (setq this-command 'kill-region))
|
|
1433
|
|
1434 ;; copy-region-as-kill no longer sets this-command, because it's confusing
|
|
1435 ;; to get two copies of the text when the user accidentally types M-w and
|
|
1436 ;; then corrects it with the intended C-w.
|
444
|
1437 (defun copy-region-as-kill (start end)
|
428
|
1438 "Save the region as if killed, but don't kill it.
|
|
1439 Run `kill-hooks'."
|
|
1440 (interactive "r")
|
|
1441 (if (eq last-command 'kill-region)
|
444
|
1442 (kill-append (buffer-substring start end) (< end start))
|
|
1443 (kill-new (buffer-substring start end)))
|
428
|
1444 nil)
|
|
1445
|
444
|
1446 (defun kill-ring-save (start end)
|
428
|
1447 "Save the region as if killed, but don't kill it.
|
|
1448 This command is similar to `copy-region-as-kill', except that it gives
|
|
1449 visual feedback indicating the extent of the region being copied."
|
|
1450 (interactive "r")
|
444
|
1451 (copy-region-as-kill start end)
|
428
|
1452 ;; copy before delay, for xclipboard's benefit
|
|
1453 (if (interactive-p)
|
444
|
1454 (let ((other-end (if (= (point) start) end start))
|
428
|
1455 (opoint (point))
|
|
1456 ;; Inhibit quitting so we can make a quit here
|
|
1457 ;; look like a C-g typed as a command.
|
|
1458 (inhibit-quit t))
|
|
1459 (if (pos-visible-in-window-p other-end (selected-window))
|
|
1460 (progn
|
|
1461 ;; FSF (I'm not sure what this does -sb)
|
|
1462 ; ;; Swap point and mark.
|
|
1463 ; (set-marker (mark-marker) (point) (current-buffer))
|
|
1464 (goto-char other-end)
|
|
1465 (sit-for 1)
|
|
1466 ; ;; Swap back.
|
|
1467 ; (set-marker (mark-marker) other-end (current-buffer))
|
|
1468 (goto-char opoint)
|
|
1469 ;; If user quit, deactivate the mark
|
|
1470 ;; as C-g would as a command.
|
|
1471 (and quit-flag (mark)
|
|
1472 (zmacs-deactivate-region)))
|
|
1473 ;; too noisy. -- jwz
|
|
1474 ; (let* ((killed-text (current-kill 0))
|
|
1475 ; (message-len (min (length killed-text) 40)))
|
444
|
1476 ; (if (= (point) start)
|
428
|
1477 ; ;; Don't say "killed"; that is misleading.
|
|
1478 ; (message "Saved text until \"%s\""
|
|
1479 ; (substring killed-text (- message-len)))
|
|
1480 ; (message "Saved text from \"%s\""
|
|
1481 ; (substring killed-text 0 message-len))))
|
|
1482 ))))
|
|
1483
|
|
1484 (defun append-next-kill ()
|
|
1485 "Cause following command, if it kills, to append to previous kill."
|
|
1486 ;; XEmacs
|
|
1487 (interactive "_")
|
|
1488 (if (interactive-p)
|
|
1489 (progn
|
|
1490 (setq this-command 'kill-region)
|
|
1491 (display-message 'command
|
|
1492 "If the next command is a kill, it will append"))
|
|
1493 (setq last-command 'kill-region)))
|
|
1494
|
|
1495 (defun yank-pop (arg)
|
|
1496 "Replace just-yanked stretch of killed text with a different stretch.
|
|
1497 This command is allowed only immediately after a `yank' or a `yank-pop'.
|
|
1498 At such a time, the region contains a stretch of reinserted
|
|
1499 previously-killed text. `yank-pop' deletes that text and inserts in its
|
|
1500 place a different stretch of killed text.
|
|
1501
|
|
1502 With no argument, the previous kill is inserted.
|
|
1503 With argument N, insert the Nth previous kill.
|
|
1504 If N is negative, this is a more recent kill.
|
|
1505
|
|
1506 The sequence of kills wraps around, so that after the oldest one
|
|
1507 comes the newest one."
|
|
1508 (interactive "*p")
|
|
1509 (if (not (eq last-command 'yank))
|
|
1510 (error "Previous command was not a yank"))
|
|
1511 (setq this-command 'yank)
|
|
1512 (let ((inhibit-read-only t)
|
|
1513 (before (< (point) (mark t))))
|
|
1514 (delete-region (point) (mark t))
|
|
1515 ;;(set-marker (mark-marker) (point) (current-buffer))
|
|
1516 (set-mark (point))
|
|
1517 (insert (current-kill arg))
|
|
1518 (if before
|
|
1519 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
|
|
1520 ;; It is cleaner to avoid activation, even though the command
|
|
1521 ;; loop would deactivate the mark because we inserted text.
|
|
1522 (goto-char (prog1 (mark t)
|
|
1523 (set-marker (mark-marker t) (point) (current-buffer))))))
|
|
1524 nil)
|
|
1525
|
|
1526
|
|
1527 (defun yank (&optional arg)
|
|
1528 "Reinsert the last stretch of killed text.
|
|
1529 More precisely, reinsert the stretch of killed text most recently
|
|
1530 killed OR yanked. Put point at end, and set mark at beginning.
|
|
1531 With just C-u as argument, same but put point at beginning (and mark at end).
|
|
1532 With argument N, reinsert the Nth most recently killed stretch of killed
|
|
1533 text.
|
|
1534 See also the command \\[yank-pop]."
|
|
1535 (interactive "*P")
|
|
1536 ;; If we don't get all the way through, make last-command indicate that
|
|
1537 ;; for the following command.
|
|
1538 (setq this-command t)
|
|
1539 (push-mark (point))
|
|
1540 (insert (current-kill (cond
|
|
1541 ((listp arg) 0)
|
|
1542 ((eq arg '-) -1)
|
|
1543 (t (1- arg)))))
|
|
1544 (if (consp arg)
|
|
1545 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
|
|
1546 ;; It is cleaner to avoid activation, even though the command
|
|
1547 ;; loop would deactivate the mark because we inserted text.
|
|
1548 ;; (But it's an unnecessary kludge in XEmacs.)
|
|
1549 ;(goto-char (prog1 (mark t)
|
|
1550 ;(set-marker (mark-marker) (point) (current-buffer)))))
|
|
1551 (exchange-point-and-mark t))
|
|
1552 ;; If we do get all the way thru, make this-command indicate that.
|
|
1553 (setq this-command 'yank)
|
|
1554 nil)
|
|
1555
|
|
1556 (defun rotate-yank-pointer (arg)
|
|
1557 "Rotate the yanking point in the kill ring.
|
|
1558 With argument, rotate that many kills forward (or backward, if negative)."
|
|
1559 (interactive "p")
|
|
1560 (current-kill arg))
|
|
1561
|
|
1562
|
|
1563 (defun insert-buffer (buffer)
|
|
1564 "Insert after point the contents of BUFFER.
|
|
1565 Puts mark after the inserted text.
|
|
1566 BUFFER may be a buffer or a buffer name."
|
|
1567 (interactive
|
|
1568 (list
|
|
1569 (progn
|
|
1570 (barf-if-buffer-read-only)
|
|
1571 (read-buffer "Insert buffer: "
|
|
1572 ;; XEmacs: we have different args
|
|
1573 (other-buffer (current-buffer) nil t)
|
|
1574 t))))
|
|
1575 (or (bufferp buffer)
|
|
1576 (setq buffer (get-buffer buffer)))
|
|
1577 (let (start end newmark)
|
|
1578 (save-excursion
|
|
1579 (save-excursion
|
|
1580 (set-buffer buffer)
|
|
1581 (setq start (point-min) end (point-max)))
|
|
1582 (insert-buffer-substring buffer start end)
|
|
1583 (setq newmark (point)))
|
|
1584 (push-mark newmark))
|
|
1585 nil)
|
|
1586
|
|
1587 (defun append-to-buffer (buffer start end)
|
|
1588 "Append to specified buffer the text of the region.
|
|
1589 It is inserted into that buffer before its point.
|
|
1590
|
|
1591 When calling from a program, give three arguments:
|
|
1592 BUFFER (or buffer name), START and END.
|
|
1593 START and END specify the portion of the current buffer to be copied."
|
|
1594 (interactive
|
|
1595 ;; XEmacs: we have different args to other-buffer
|
|
1596 (list (read-buffer "Append to buffer: " (other-buffer (current-buffer)
|
|
1597 nil t))
|
|
1598 (region-beginning) (region-end)))
|
|
1599 (let ((oldbuf (current-buffer)))
|
|
1600 (save-excursion
|
|
1601 (set-buffer (get-buffer-create buffer))
|
|
1602 (insert-buffer-substring oldbuf start end))))
|
|
1603
|
|
1604 (defun prepend-to-buffer (buffer start end)
|
|
1605 "Prepend to specified buffer the text of the region.
|
|
1606 It is inserted into that buffer after its point.
|
|
1607
|
|
1608 When calling from a program, give three arguments:
|
|
1609 BUFFER (or buffer name), START and END.
|
|
1610 START and END specify the portion of the current buffer to be copied."
|
|
1611 (interactive "BPrepend to buffer: \nr")
|
|
1612 (let ((oldbuf (current-buffer)))
|
|
1613 (save-excursion
|
|
1614 (set-buffer (get-buffer-create buffer))
|
|
1615 (save-excursion
|
|
1616 (insert-buffer-substring oldbuf start end)))))
|
|
1617
|
|
1618 (defun copy-to-buffer (buffer start end)
|
|
1619 "Copy to specified buffer the text of the region.
|
|
1620 It is inserted into that buffer, replacing existing text there.
|
|
1621
|
|
1622 When calling from a program, give three arguments:
|
|
1623 BUFFER (or buffer name), START and END.
|
|
1624 START and END specify the portion of the current buffer to be copied."
|
|
1625 (interactive "BCopy to buffer: \nr")
|
|
1626 (let ((oldbuf (current-buffer)))
|
|
1627 (save-excursion
|
|
1628 (set-buffer (get-buffer-create buffer))
|
|
1629 (erase-buffer)
|
|
1630 (save-excursion
|
|
1631 (insert-buffer-substring oldbuf start end)))))
|
|
1632
|
|
1633 ;FSFmacs
|
|
1634 ;(put 'mark-inactive 'error-conditions '(mark-inactive error))
|
|
1635 ;(put 'mark-inactive 'error-message "The mark is not active now")
|
|
1636
|
|
1637 (defun mark (&optional force buffer)
|
|
1638 "Return this buffer's mark value as integer, or nil if no mark.
|
|
1639
|
|
1640 If `zmacs-regions' is true, then this returns nil unless the region is
|
|
1641 currently in the active (highlighted) state. With an argument of t, this
|
|
1642 returns the mark (if there is one) regardless of the active-region state.
|
|
1643 You should *generally* not use the mark unless the region is active, if
|
|
1644 the user has expressed a preference for the active-region model.
|
|
1645
|
|
1646 If you are using this in an editing command, you are most likely making
|
|
1647 a mistake; see the documentation of `set-mark'."
|
|
1648 (setq buffer (decode-buffer buffer))
|
|
1649 ;FSFmacs version:
|
|
1650 ; (if (or force (not transient-mark-mode) mark-active mark-even-if-inactive)
|
|
1651 ; (marker-position (mark-marker))
|
|
1652 ; (signal 'mark-inactive nil)))
|
|
1653 (let ((m (mark-marker force buffer)))
|
|
1654 (and m (marker-position m))))
|
|
1655
|
|
1656 ;;;#### FSFmacs
|
|
1657 ;;; Many places set mark-active directly, and several of them failed to also
|
|
1658 ;;; run deactivate-mark-hook. This shorthand should simplify.
|
|
1659 ;(defsubst deactivate-mark ()
|
|
1660 ; "Deactivate the mark by setting `mark-active' to nil.
|
|
1661 ;\(That makes a difference only in Transient Mark mode.)
|
|
1662 ;Also runs the hook `deactivate-mark-hook'."
|
|
1663 ; (if transient-mark-mode
|
|
1664 ; (progn
|
|
1665 ; (setq mark-active nil)
|
|
1666 ; (run-hooks 'deactivate-mark-hook))))
|
|
1667
|
|
1668 (defun set-mark (pos &optional buffer)
|
|
1669 "Set this buffer's mark to POS. Don't use this function!
|
|
1670 That is to say, don't use this function unless you want
|
|
1671 the user to see that the mark has moved, and you want the previous
|
|
1672 mark position to be lost.
|
|
1673
|
|
1674 Normally, when a new mark is set, the old one should go on the stack.
|
444
|
1675 This is why most applications should use `push-mark', not `set-mark'.
|
428
|
1676
|
|
1677 Novice Emacs Lisp programmers often try to use the mark for the wrong
|
|
1678 purposes. The mark saves a location for the user's convenience.
|
|
1679 Most editing commands should not alter the mark.
|
|
1680 To remember a location for internal use in the Lisp program,
|
|
1681 store it in a Lisp variable. Example:
|
|
1682
|
444
|
1683 (let ((start (point))) (forward-line 1) (delete-region start (point)))."
|
428
|
1684
|
|
1685 (setq buffer (decode-buffer buffer))
|
|
1686 (set-marker (mark-marker t buffer) pos buffer))
|
|
1687 ;; FSF
|
|
1688 ; (if pos
|
|
1689 ; (progn
|
|
1690 ; (setq mark-active t)
|
|
1691 ; (run-hooks 'activate-mark-hook)
|
|
1692 ; (set-marker (mark-marker) pos (current-buffer)))
|
|
1693 ; ;; Normally we never clear mark-active except in Transient Mark mode.
|
|
1694 ; ;; But when we actually clear out the mark value too,
|
|
1695 ; ;; we must clear mark-active in any mode.
|
|
1696 ; (setq mark-active nil)
|
|
1697 ; (run-hooks 'deactivate-mark-hook)
|
|
1698 ; (set-marker (mark-marker) nil)))
|
|
1699
|
|
1700 (defvar mark-ring nil
|
442
|
1701 "The list of former marks of the current buffer, most recent first.
|
|
1702 This variable is automatically buffer-local.")
|
428
|
1703 (make-variable-buffer-local 'mark-ring)
|
|
1704 (put 'mark-ring 'permanent-local t)
|
|
1705
|
442
|
1706 (defvar dont-record-current-mark nil
|
|
1707 "If set to t, the current mark value should not be recorded on the mark ring.
|
|
1708 This is set by commands that manipulate the mark incidentally, to avoid
|
|
1709 cluttering the mark ring unnecessarily. Under most circumstances, you do
|
|
1710 not need to set this directly; it is automatically reset each time
|
|
1711 `push-mark' is called, according to `mark-ring-unrecorded-commands'. This
|
|
1712 variable is automatically buffer-local.")
|
|
1713 (make-variable-buffer-local 'dont-record-current-mark)
|
|
1714 (put 'dont-record-current-mark 'permanent-local t)
|
|
1715
|
|
1716 ;; a conspiracy between push-mark and handle-pre-motion-command
|
|
1717 (defvar in-shifted-motion-command nil)
|
|
1718
|
|
1719 (defcustom mark-ring-unrecorded-commands '(shifted-motion-commands
|
|
1720 yank
|
|
1721 mark-beginning-of-buffer
|
|
1722 mark-bob
|
|
1723 mark-defun
|
|
1724 mark-end-of-buffer
|
|
1725 mark-end-of-line
|
|
1726 mark-end-of-sentence
|
|
1727 mark-eob
|
|
1728 mark-marker
|
|
1729 mark-page
|
|
1730 mark-paragraph
|
|
1731 mark-sexp
|
|
1732 mark-whole-buffer
|
|
1733 mark-word)
|
|
1734 "*List of commands whose marks should not be recorded on the mark stack.
|
|
1735 Many commands set the mark as part of their action. Normally, all such
|
|
1736 marks get recorded onto the mark stack. However, this tends to clutter up
|
|
1737 the mark stack unnecessarily. You can control this by putting a command
|
|
1738 onto this list. Then, any marks set by the function will not be recorded.
|
|
1739
|
|
1740 The special value `shifted-motion-commands' causes marks set as a result
|
|
1741 of selection using any shifted motion commands to not be recorded.
|
|
1742
|
|
1743 The value `yank' affects all yank-like commands, as well as just `yank'."
|
|
1744 :type '(repeat (choice (const :tag "shifted motion commands"
|
462
|
1745 shifted-motion-commands)
|
442
|
1746 (const :tag "functions that select text"
|
|
1747 :inline t
|
462
|
1748 (mark-beginning-of-buffer
|
|
1749 mark-bob
|
|
1750 mark-defun
|
|
1751 mark-end-of-buffer
|
|
1752 mark-end-of-line
|
|
1753 mark-end-of-sentence
|
|
1754 mark-eob
|
|
1755 mark-marker
|
|
1756 mark-page
|
|
1757 mark-paragraph
|
|
1758 mark-sexp
|
|
1759 mark-whole-buffer
|
|
1760 mark-word))
|
442
|
1761 (const :tag "functions that paste text"
|
462
|
1762 yank)
|
442
|
1763 function))
|
|
1764 :group 'killing)
|
|
1765
|
428
|
1766 (defcustom mark-ring-max 16
|
|
1767 "*Maximum size of mark ring. Start discarding off end if gets this big."
|
|
1768 :type 'integer
|
|
1769 :group 'killing)
|
|
1770
|
|
1771 (defvar global-mark-ring nil
|
|
1772 "The list of saved global marks, most recent first.")
|
|
1773
|
|
1774 (defcustom global-mark-ring-max 16
|
|
1775 "*Maximum size of global mark ring. \
|
|
1776 Start discarding off end if gets this big."
|
|
1777 :type 'integer
|
|
1778 :group 'killing)
|
|
1779
|
|
1780 (defun set-mark-command (arg)
|
|
1781 "Set mark at where point is, or jump to mark.
|
|
1782 With no prefix argument, set mark, push old mark position on local mark
|
|
1783 ring, and push mark on global mark ring.
|
|
1784 With argument, jump to mark, and pop a new position for mark off the ring
|
|
1785 \(does not affect global mark ring\).
|
|
1786
|
442
|
1787 The mark ring is a per-buffer stack of marks, most recent first. Its
|
|
1788 maximum length is controlled by `mark-ring-max'. Generally, when new
|
|
1789 marks are set, the current mark is pushed onto the stack. You can pop
|
|
1790 marks off the stack using \\[universal-argument] \\[set-mark-command]. The term \"ring\" is used because when
|
|
1791 you pop a mark off the stack, the current mark value is pushed onto the
|
|
1792 far end of the stack. If this is confusing, just think of the mark ring
|
|
1793 as a stack.
|
|
1794
|
428
|
1795 Novice Emacs Lisp programmers often try to use the mark for the wrong
|
|
1796 purposes. See the documentation of `set-mark' for more information."
|
|
1797 (interactive "P")
|
|
1798 (if (null arg)
|
|
1799 (push-mark nil nil t)
|
|
1800 (if (null (mark t))
|
|
1801 (error "No mark set in this buffer")
|
442
|
1802 (if dont-record-current-mark (pop-mark))
|
428
|
1803 (goto-char (mark t))
|
|
1804 (pop-mark))))
|
|
1805
|
|
1806 ;; XEmacs: Extra parameter
|
|
1807 (defun push-mark (&optional location nomsg activate-region buffer)
|
|
1808 "Set mark at LOCATION (point, by default) and push old mark on mark ring.
|
|
1809 If the last global mark pushed was not in the current buffer,
|
|
1810 also push LOCATION on the global mark ring.
|
|
1811 Display `Mark set' unless the optional second arg NOMSG is non-nil.
|
|
1812 Activate mark if optional third arg ACTIVATE-REGION non-nil.
|
|
1813
|
|
1814 Novice Emacs Lisp programmers often try to use the mark for the wrong
|
|
1815 purposes. See the documentation of `set-mark' for more information."
|
|
1816 (setq buffer (decode-buffer buffer)) ; XEmacs
|
442
|
1817 (if (or dont-record-current-mark (null (mark t buffer))) ; XEmacs
|
428
|
1818 nil
|
|
1819 ;; The save-excursion / set-buffer is necessary because mark-ring
|
|
1820 ;; is a buffer local variable
|
|
1821 (save-excursion
|
|
1822 (set-buffer buffer)
|
|
1823 (setq mark-ring (cons (copy-marker (mark-marker t buffer)) mark-ring))
|
|
1824 (if (> (length mark-ring) mark-ring-max)
|
|
1825 (progn
|
|
1826 (move-marker (car (nthcdr mark-ring-max mark-ring)) nil buffer)
|
|
1827 (setcdr (nthcdr (1- mark-ring-max) mark-ring) nil)))))
|
|
1828 (set-mark (or location (point buffer)) buffer)
|
|
1829 ; (set-marker (mark-marker) (or location (point)) (current-buffer)) ; FSF
|
|
1830 ;; Now push the mark on the global mark ring.
|
442
|
1831 (if (and (not dont-record-current-mark)
|
|
1832 (or (null global-mark-ring)
|
|
1833 (not (eq (marker-buffer (car global-mark-ring)) buffer))))
|
428
|
1834 ;; The last global mark pushed wasn't in this same buffer.
|
|
1835 (progn
|
|
1836 (setq global-mark-ring (cons (copy-marker (mark-marker t buffer))
|
|
1837 global-mark-ring))
|
|
1838 (if (> (length global-mark-ring) global-mark-ring-max)
|
|
1839 (progn
|
|
1840 (move-marker (car (nthcdr global-mark-ring-max global-mark-ring))
|
|
1841 nil buffer)
|
|
1842 (setcdr (nthcdr (1- global-mark-ring-max) global-mark-ring) nil)))))
|
442
|
1843 (setq dont-record-current-mark
|
|
1844 (not (not (or (and in-shifted-motion-command
|
|
1845 (memq 'shifted-motion-commands
|
|
1846 mark-ring-unrecorded-commands))
|
|
1847 (memq this-command mark-ring-unrecorded-commands)))))
|
|
1848 (or dont-record-current-mark nomsg executing-kbd-macro
|
|
1849 (> (minibuffer-depth) 0)
|
428
|
1850 (display-message 'command "Mark set"))
|
|
1851 (if activate-region
|
|
1852 (progn
|
|
1853 (setq zmacs-region-stays t)
|
|
1854 (zmacs-activate-region)))
|
|
1855 ; (if (or activate (not transient-mark-mode)) ; FSF
|
|
1856 ; (set-mark (mark t))) ; FSF
|
|
1857 nil)
|
|
1858
|
|
1859 (defun pop-mark ()
|
|
1860 "Pop off mark ring into the buffer's actual mark.
|
|
1861 Does not set point. Does nothing if mark ring is empty."
|
|
1862 (if mark-ring
|
|
1863 (progn
|
|
1864 (setq mark-ring (nconc mark-ring (list (copy-marker (mark-marker t)))))
|
|
1865 (set-mark (car mark-ring))
|
|
1866 (move-marker (car mark-ring) nil)
|
|
1867 (if (null (mark t)) (ding))
|
|
1868 (setq mark-ring (cdr mark-ring)))))
|
|
1869
|
|
1870 (define-function 'exchange-dot-and-mark 'exchange-point-and-mark)
|
|
1871 (defun exchange-point-and-mark (&optional dont-activate-region)
|
|
1872 "Put the mark where point is now, and point where the mark is now.
|
|
1873 The mark is activated unless DONT-ACTIVATE-REGION is non-nil."
|
|
1874 (interactive nil)
|
|
1875 (let ((omark (mark t)))
|
|
1876 (if (null omark)
|
|
1877 (error "No mark set in this buffer"))
|
|
1878 (set-mark (point))
|
|
1879 (goto-char omark)
|
|
1880 (or dont-activate-region (zmacs-activate-region)) ; XEmacs
|
|
1881 nil))
|
|
1882
|
|
1883 ;; XEmacs
|
|
1884 (defun mark-something (mark-fn movement-fn arg)
|
|
1885 "internal function used by mark-sexp, mark-word, etc."
|
|
1886 (let (newmark (pushp t))
|
|
1887 (save-excursion
|
|
1888 (if (and (eq last-command mark-fn) (mark))
|
|
1889 ;; Extend the previous state in the same direction:
|
|
1890 (progn
|
|
1891 (if (< (mark) (point)) (setq arg (- arg)))
|
|
1892 (goto-char (mark))
|
|
1893 (setq pushp nil)))
|
|
1894 (funcall movement-fn arg)
|
|
1895 (setq newmark (point)))
|
|
1896 (if pushp
|
|
1897 (push-mark newmark nil t)
|
|
1898 ;; Do not mess with the mark stack, but merely adjust the previous state:
|
|
1899 (set-mark newmark)
|
|
1900 (activate-region))))
|
|
1901
|
|
1902 ;(defun transient-mark-mode (arg)
|
|
1903 ; "Toggle Transient Mark mode.
|
|
1904 ;With arg, turn Transient Mark mode on if arg is positive, off otherwise.
|
|
1905 ;
|
|
1906 ;In Transient Mark mode, when the mark is active, the region is highlighted.
|
|
1907 ;Changing the buffer \"deactivates\" the mark.
|
|
1908 ;So do certain other operations that set the mark
|
|
1909 ;but whose main purpose is something else--for example,
|
|
1910 ;incremental search, \\[beginning-of-buffer], and \\[end-of-buffer]."
|
|
1911 ; (interactive "P")
|
|
1912 ; (setq transient-mark-mode
|
|
1913 ; (if (null arg)
|
|
1914 ; (not transient-mark-mode)
|
|
1915 ; (> (prefix-numeric-value arg) 0))))
|
|
1916
|
|
1917 (defun pop-global-mark ()
|
|
1918 "Pop off global mark ring and jump to the top location."
|
|
1919 (interactive)
|
|
1920 ;; Pop entries which refer to non-existent buffers.
|
|
1921 (while (and global-mark-ring (not (marker-buffer (car global-mark-ring))))
|
|
1922 (setq global-mark-ring (cdr global-mark-ring)))
|
|
1923 (or global-mark-ring
|
|
1924 (error "No global mark set"))
|
|
1925 (let* ((marker (car global-mark-ring))
|
|
1926 (buffer (marker-buffer marker))
|
|
1927 (position (marker-position marker)))
|
|
1928 (setq global-mark-ring (nconc (cdr global-mark-ring)
|
|
1929 (list (car global-mark-ring))))
|
|
1930 (set-buffer buffer)
|
|
1931 (or (and (>= position (point-min))
|
|
1932 (<= position (point-max)))
|
|
1933 (widen))
|
|
1934 (goto-char position)
|
|
1935 (switch-to-buffer buffer)))
|
|
1936
|
|
1937
|
|
1938 (defcustom signal-error-on-buffer-boundary t
|
462
|
1939 "*If Non-nil, beep or signal an error when moving past buffer boundary.
|
428
|
1940 The commands that honor this variable are
|
|
1941
|
|
1942 forward-char-command
|
|
1943 backward-char-command
|
|
1944 next-line
|
|
1945 previous-line
|
|
1946 scroll-up-command
|
|
1947 scroll-down-command"
|
|
1948 :type 'boolean
|
|
1949 :group 'editing-basics)
|
|
1950
|
|
1951 ;;; After 8 years of waiting ... -sb
|
|
1952 (defcustom next-line-add-newlines nil ; XEmacs
|
|
1953 "*If non-nil, `next-line' inserts newline when the point is at end of buffer.
|
|
1954 This behavior used to be the default, and is still default in FSF Emacs.
|
|
1955 We think it is an unnecessary and unwanted side-effect."
|
|
1956 :type 'boolean
|
|
1957 :group 'editing-basics)
|
|
1958
|
442
|
1959 (defcustom shifted-motion-keys-select-region t
|
|
1960 "*If non-nil, shifted motion keys select text, like in MS Windows.
|
462
|
1961
|
|
1962 More specifically, if a keystroke that matches one of the key
|
|
1963 specifications in `motion-keys-for-shifted-motion' is pressed along
|
|
1964 with the Shift key, and the command invoked moves the cursor and
|
|
1965 preserves the active region (see `zmacs-region-stays'), the
|
|
1966 intervening text will be added to the active region.
|
|
1967
|
|
1968 When the region has been enabled or augmented as a result of a shifted
|
|
1969 motion key, an unshifted motion key will normally deselect the region.
|
|
1970 However, if `unshifted-motion-keys-deselect-region' is t, the region
|
|
1971 will remain active, augmented by the characters moved over by this
|
|
1972 motion key.
|
|
1973
|
|
1974 This functionality is specifically interpreted in terms of keys, and
|
|
1975 *NOT* in terms of particular commands, because that produces the most
|
|
1976 intuitive behavior: `forward-char' will work with shifted motion
|
|
1977 when invoked by `right' but not `C-f', and user-written motion commands
|
|
1978 bound to motion keys will automatically work with shifted motion."
|
442
|
1979 :type 'boolean
|
|
1980 :group 'editing-basics)
|
|
1981
|
|
1982 (defcustom unshifted-motion-keys-deselect-region t
|
|
1983 "*If non-nil, unshifted motion keys deselect a shifted-motion region.
|
462
|
1984 This only occurs after a region has been selected or augmented using
|
|
1985 shifted motion keys (not when using the traditional set-mark-then-move
|
|
1986 method), and has no effect if `shifted-motion-keys-select-region' is
|
|
1987 nil."
|
442
|
1988 :type 'boolean
|
|
1989 :group 'editing-basics)
|
|
1990
|
462
|
1991 (defcustom motion-keys-for-shifted-motion
|
|
1992 '(left right up down home end prior next
|
|
1993 kp-left kp-right kp-up kp-down kp-home kp-end kp-prior kp-next)
|
|
1994 "*List of keys considered motion keys for the purpose of shifted selection.
|
|
1995 When one of these keys is pressed along with the Shift key, and the
|
|
1996 command invoked moves the cursor and preserves the active region (see
|
|
1997 `zmacs-region-stays'), the intervening text will be added to the active
|
|
1998 region. See `shifted-motion-keys-select-region' for more details.
|
|
1999
|
|
2000 Each entry should be a keysym or a list (MODIFIERS ... KEYSYM),
|
|
2001 i.e. zero or more modifiers followed by a keysym. When a keysym alone
|
|
2002 is given, a keystroke consisting of that keysym, with or without any
|
|
2003 modifiers, is considered a motion key. When the list form is given,
|
|
2004 only a keystroke with exactly those modifiers and no others (with the
|
|
2005 exception of the Shift key) is considered a motion key.
|
|
2006
|
|
2007 NOTE: Currently, the keysym cannot be a non-alphabetic character key
|
|
2008 such as the `=/+' key. In any case, the shifted-motion paradigm does
|
|
2009 not make much sense with those keys. The keysym can, however, be an
|
|
2010 alphabetic key without problem, and you can specify the key using
|
|
2011 either a character or a symbol, uppercase or lowercase."
|
|
2012 :type '(repeat (choice (const :tag "normal cursor-pad (\"gray\") keys"
|
|
2013 :inline t
|
|
2014 (left right up down home end prior next))
|
|
2015 (const :tag "keypad motion keys"
|
|
2016 :inline t
|
|
2017 (kp-left kp-right kp-up kp-down
|
|
2018 kp-home kp-end kp-prior kp-next))
|
|
2019 (const :tag "alphabetic motion keys"
|
|
2020 :inline t
|
|
2021 ((control b) (control f)
|
|
2022 (control p) (control n)
|
|
2023 (control a) (control e)
|
|
2024 (control v) (meta v)
|
|
2025 (meta b) (meta f)
|
|
2026 (meta a) (meta e)
|
|
2027 (meta m) ; back-to-indentation
|
|
2028 (meta r) ; move-to-window-line
|
|
2029 (meta control b) (meta control f)
|
|
2030 (meta control p) (meta control n)
|
|
2031 (meta control a) (meta control e)
|
|
2032 (meta control d) ;; down-list
|
|
2033 (meta control u) ;; backward-up-list
|
|
2034 ))
|
|
2035 symbol))
|
|
2036 :group 'editing-basics)
|
|
2037
|
442
|
2038 (defun handle-pre-motion-command-current-command-is-motion ()
|
|
2039 (and (key-press-event-p last-input-event)
|
462
|
2040 (let ((key (event-key last-input-event))
|
|
2041 (mods (delq 'shift (event-modifiers last-input-event))))
|
|
2042 ;(princ (format "key: %s mods: %s\n" key mods) 'external-debugging-output)
|
|
2043 (catch 'handle-pre-motion-command-current-command-is-motion
|
|
2044 (flet ((keysyms-equal (a b)
|
|
2045 (if (characterp a)
|
|
2046 (setq a (intern (char-to-string (downcase a)))))
|
|
2047 (if (characterp b)
|
|
2048 (setq b (intern (char-to-string (downcase b)))))
|
|
2049 (eq a b)))
|
|
2050 (mapc #'(lambda (keysym)
|
|
2051 (when (if (listp keysym)
|
|
2052 (and (equal mods (butlast keysym))
|
|
2053 (keysyms-equal key (car (last keysym))))
|
|
2054 (keysyms-equal key keysym))
|
|
2055 (throw
|
|
2056 'handle-pre-motion-command-current-command-is-motion
|
|
2057 t)))
|
|
2058 motion-keys-for-shifted-motion)
|
|
2059 nil)))))
|
444
|
2060
|
442
|
2061 (defun handle-pre-motion-command ()
|
462
|
2062 (if (and
|
442
|
2063 (handle-pre-motion-command-current-command-is-motion)
|
|
2064 zmacs-regions
|
|
2065 shifted-motion-keys-select-region
|
|
2066 (not (region-active-p))
|
462
|
2067 ;; Special-case alphabetic keysyms, because the `shift'
|
|
2068 ;; modifier does not appear on them. (Unfortunately, we have no
|
|
2069 ;; way of determining Shift-key status on non-alphabetic ASCII
|
|
2070 ;; keysyms. However, in this case, using Shift will invoke a
|
|
2071 ;; separate command from the non-shifted version, so the
|
|
2072 ;; "shifted motion" paradigm makes no sense.)
|
|
2073 (or (memq 'shift (event-modifiers last-input-event))
|
|
2074 (let ((key (event-key last-input-event)))
|
|
2075 (and (characterp key)
|
|
2076 (not (eq key (downcase key)))))))
|
442
|
2077 (let ((in-shifted-motion-command t))
|
|
2078 (push-mark nil nil t))))
|
|
2079
|
|
2080 (defun handle-post-motion-command ()
|
|
2081 (if
|
|
2082 (and
|
|
2083 (handle-pre-motion-command-current-command-is-motion)
|
|
2084 zmacs-regions
|
|
2085 (region-active-p))
|
462
|
2086 ;; Special-case alphabetic keysyms, because the `shift'
|
|
2087 ;; modifier does not appear on them. See above.
|
|
2088 (cond ((or (memq 'shift (event-modifiers last-input-event))
|
|
2089 (let ((key (event-key last-input-event)))
|
|
2090 (and (characterp key)
|
|
2091 (not (eq key (downcase key))))))
|
442
|
2092 (if shifted-motion-keys-select-region
|
|
2093 (putf this-command-properties 'shifted-motion-command t))
|
|
2094 (setq zmacs-region-stays t))
|
|
2095 ((and (getf last-command-properties 'shifted-motion-command)
|
|
2096 unshifted-motion-keys-deselect-region)
|
487
|
2097 (setq zmacs-region-stays nil)))))
|
442
|
2098
|
428
|
2099 (defun forward-char-command (&optional arg buffer)
|
|
2100 "Move point right ARG characters (left if ARG negative) in BUFFER.
|
|
2101 On attempt to pass end of buffer, stop and signal `end-of-buffer'.
|
|
2102 On attempt to pass beginning of buffer, stop and signal `beginning-of-buffer'.
|
|
2103 Error signaling is suppressed if `signal-error-on-buffer-boundary'
|
462
|
2104 is nil. If BUFFER is nil, the current buffer is assumed.
|
|
2105
|
|
2106 The characters that are moved over may be added to the current selection
|
|
2107 \(i.e. active region) if the Shift key is held down, a motion key is used
|
|
2108 to invoke this command, and `shifted-motion-keys-select-region' is t; see
|
|
2109 the documentation for this variable for more details."
|
428
|
2110 (interactive "_p")
|
|
2111 (if signal-error-on-buffer-boundary
|
|
2112 (forward-char arg buffer)
|
|
2113 (condition-case nil
|
|
2114 (forward-char arg buffer)
|
|
2115 (beginning-of-buffer nil)
|
|
2116 (end-of-buffer nil))))
|
|
2117
|
|
2118 (defun backward-char-command (&optional arg buffer)
|
|
2119 "Move point left ARG characters (right if ARG negative) in BUFFER.
|
|
2120 On attempt to pass end of buffer, stop and signal `end-of-buffer'.
|
|
2121 On attempt to pass beginning of buffer, stop and signal `beginning-of-buffer'.
|
|
2122 Error signaling is suppressed if `signal-error-on-buffer-boundary'
|
462
|
2123 is nil. If BUFFER is nil, the current buffer is assumed.
|
|
2124
|
|
2125 The characters that are moved over may be added to the current selection
|
|
2126 \(i.e. active region) if the Shift key is held down, a motion key is used
|
|
2127 to invoke this command, and `shifted-motion-keys-select-region' is t; see
|
|
2128 the documentation for this variable for more details."
|
428
|
2129 (interactive "_p")
|
|
2130 (if signal-error-on-buffer-boundary
|
|
2131 (backward-char arg buffer)
|
|
2132 (condition-case nil
|
|
2133 (backward-char arg buffer)
|
|
2134 (beginning-of-buffer nil)
|
|
2135 (end-of-buffer nil))))
|
|
2136
|
442
|
2137 (defun scroll-up-one ()
|
|
2138 "Scroll text of current window upward one line.
|
|
2139 On attempt to scroll past end of buffer, `end-of-buffer' is signaled.
|
|
2140 On attempt to scroll past beginning of buffer, `beginning-of-buffer' is
|
|
2141 signaled.
|
|
2142
|
|
2143 If `signal-error-on-buffer-boundary' is nil, attempts to scroll past buffer
|
|
2144 boundaries do not cause an error to be signaled."
|
|
2145 (interactive "_")
|
|
2146 (scroll-up-command 1))
|
|
2147
|
428
|
2148 (defun scroll-up-command (&optional n)
|
444
|
2149 "Scroll current window upward N lines; or near full screen if N is nil.
|
428
|
2150 A near full screen is `next-screen-context-lines' less than a full screen.
|
444
|
2151 Negative N means scroll downward.
|
428
|
2152 When calling from a program, supply a number as argument or nil.
|
|
2153 On attempt to scroll past end of buffer, `end-of-buffer' is signaled.
|
|
2154 On attempt to scroll past beginning of buffer, `beginning-of-buffer' is
|
|
2155 signaled.
|
|
2156
|
462
|
2157 The characters that are moved over may be added to the current selection
|
|
2158 \(i.e. active region) if the Shift key is held down, a motion key is used
|
|
2159 to invoke this command, and `shifted-motion-keys-select-region' is t; see
|
|
2160 the documentation for this variable for more details.
|
|
2161
|
428
|
2162 If `signal-error-on-buffer-boundary' is nil, attempts to scroll past buffer
|
|
2163 boundaries do not cause an error to be signaled."
|
|
2164 (interactive "_P")
|
|
2165 (if signal-error-on-buffer-boundary
|
|
2166 (scroll-up n)
|
|
2167 (condition-case nil
|
|
2168 (scroll-up n)
|
|
2169 (beginning-of-buffer nil)
|
|
2170 (end-of-buffer nil))))
|
|
2171
|
442
|
2172 (defun scroll-down-one ()
|
|
2173 "Scroll text of current window downward one line.
|
|
2174 On attempt to scroll past end of buffer, `end-of-buffer' is signaled.
|
|
2175 On attempt to scroll past beginning of buffer, `beginning-of-buffer' is
|
|
2176 signaled.
|
|
2177
|
|
2178 If `signal-error-on-buffer-boundary' is nil, attempts to scroll past buffer
|
|
2179 boundaries do not cause an error to be signaled."
|
|
2180 (interactive "_")
|
|
2181 (scroll-down-command 1))
|
|
2182
|
428
|
2183 (defun scroll-down-command (&optional n)
|
444
|
2184 "Scroll current window downward N lines; or near full screen if N is nil.
|
428
|
2185 A near full screen is `next-screen-context-lines' less than a full screen.
|
444
|
2186 Negative N means scroll upward.
|
428
|
2187 When calling from a program, supply a number as argument or nil.
|
|
2188 On attempt to scroll past end of buffer, `end-of-buffer' is signaled.
|
|
2189 On attempt to scroll past beginning of buffer, `beginning-of-buffer' is
|
|
2190 signaled.
|
|
2191
|
|
2192 If `signal-error-on-buffer-boundary' is nil, attempts to scroll past buffer
|
462
|
2193 boundaries do not cause an error to be signaled.
|
|
2194
|
|
2195 The characters that are moved over may be added to the current selection
|
|
2196 \(i.e. active region) if the Shift key is held down, a motion key is used
|
|
2197 to invoke this command, and `shifted-motion-keys-select-region' is t; see
|
|
2198 the documentation for this variable for more details."
|
428
|
2199 (interactive "_P")
|
|
2200 (if signal-error-on-buffer-boundary
|
|
2201 (scroll-down n)
|
|
2202 (condition-case nil
|
|
2203 (scroll-down n)
|
|
2204 (beginning-of-buffer nil)
|
|
2205 (end-of-buffer nil))))
|
|
2206
|
444
|
2207 (defun next-line (count)
|
|
2208 "Move cursor vertically down COUNT lines.
|
428
|
2209 If there is no character in the target line exactly under the current column,
|
|
2210 the cursor is positioned after the character in that line which spans this
|
|
2211 column, or at the end of the line if it is not long enough.
|
|
2212
|
|
2213 If there is no line in the buffer after this one, behavior depends on the
|
|
2214 value of `next-line-add-newlines'. If non-nil, it inserts a newline character
|
|
2215 to create a line, and moves the cursor to that line. Otherwise it moves the
|
|
2216 cursor to the end of the buffer.
|
|
2217
|
|
2218 The command \\[set-goal-column] can be used to create
|
|
2219 a semipermanent goal column to which this command always moves.
|
|
2220 Then it does not try to move vertically. This goal column is stored
|
|
2221 in `goal-column', which is nil when there is none.
|
|
2222
|
462
|
2223 The characters that are moved over may be added to the current selection
|
|
2224 \(i.e. active region) if the Shift key is held down, a motion key is used
|
|
2225 to invoke this command, and `shifted-motion-keys-select-region' is t; see
|
|
2226 the documentation for this variable for more details.
|
|
2227
|
428
|
2228 If you are thinking of using this in a Lisp program, consider
|
|
2229 using `forward-line' instead. It is usually easier to use
|
|
2230 and more reliable (no dependence on goal column, etc.)."
|
442
|
2231 (interactive "_p")
|
444
|
2232 (if (and next-line-add-newlines (= count 1))
|
428
|
2233 (let ((opoint (point)))
|
|
2234 (end-of-line)
|
|
2235 (if (eobp)
|
|
2236 (newline 1)
|
|
2237 (goto-char opoint)
|
444
|
2238 (line-move count)))
|
428
|
2239 (if (interactive-p)
|
|
2240 ;; XEmacs: Not sure what to do about this. It's inconsistent. -sb
|
|
2241 (condition-case nil
|
444
|
2242 (line-move count)
|
428
|
2243 ((beginning-of-buffer end-of-buffer)
|
|
2244 (when signal-error-on-buffer-boundary
|
|
2245 (ding nil 'buffer-bound))))
|
444
|
2246 (line-move count)))
|
428
|
2247 nil)
|
|
2248
|
444
|
2249 (defun previous-line (count)
|
|
2250 "Move cursor vertically up COUNT lines.
|
428
|
2251 If there is no character in the target line exactly over the current column,
|
|
2252 the cursor is positioned after the character in that line which spans this
|
|
2253 column, or at the end of the line if it is not long enough.
|
|
2254
|
|
2255 The command \\[set-goal-column] can be used to create
|
|
2256 a semipermanent goal column to which this command always moves.
|
|
2257 Then it does not try to move vertically.
|
|
2258
|
462
|
2259 The characters that are moved over may be added to the current selection
|
|
2260 \(i.e. active region) if the Shift key is held down, a motion key is used
|
|
2261 to invoke this command, and `shifted-motion-keys-select-region' is t; see
|
|
2262 the documentation for this variable for more details.
|
|
2263
|
428
|
2264 If you are thinking of using this in a Lisp program, consider using
|
|
2265 `forward-line' with a negative argument instead. It is usually easier
|
|
2266 to use and more reliable (no dependence on goal column, etc.)."
|
442
|
2267 (interactive "_p")
|
428
|
2268 (if (interactive-p)
|
|
2269 (condition-case nil
|
444
|
2270 (line-move (- count))
|
428
|
2271 ((beginning-of-buffer end-of-buffer)
|
|
2272 (when signal-error-on-buffer-boundary ; XEmacs
|
|
2273 (ding nil 'buffer-bound))))
|
444
|
2274 (line-move (- count)))
|
428
|
2275 nil)
|
|
2276
|
442
|
2277 (defcustom block-movement-size 6
|
|
2278 "*Number of lines that \"block movement\" commands (\\[forward-block-of-lines], \\[backward-block-of-lines]) move by."
|
|
2279 :type 'integer
|
|
2280 :group 'editing-basics)
|
|
2281
|
|
2282 (defun backward-block-of-lines ()
|
|
2283 "Move backward by one \"block\" of lines.
|
|
2284 The number of lines that make up a block is controlled by
|
462
|
2285 `block-movement-size', which defaults to 6.
|
|
2286
|
|
2287 The characters that are moved over may be added to the current selection
|
|
2288 \(i.e. active region) if the Shift key is held down, a motion key is used
|
|
2289 to invoke this command, and `shifted-motion-keys-select-region' is t; see
|
|
2290 the documentation for this variable for more details."
|
442
|
2291 (interactive "_")
|
|
2292 (forward-line (- block-movement-size)))
|
|
2293
|
|
2294 (defun forward-block-of-lines ()
|
|
2295 "Move forward by one \"block\" of lines.
|
|
2296 The number of lines that make up a block is controlled by
|
462
|
2297 `block-movement-size', which defaults to 6.
|
|
2298
|
|
2299 The characters that are moved over may be added to the current selection
|
|
2300 \(i.e. active region) if the Shift key is held down, a motion key is used
|
|
2301 to invoke this command, and `shifted-motion-keys-select-region' is t; see
|
|
2302 the documentation for this variable for more details."
|
442
|
2303 (interactive "_")
|
|
2304 (forward-line block-movement-size))
|
|
2305
|
428
|
2306 (defcustom track-eol nil
|
|
2307 "*Non-nil means vertical motion starting at end of line keeps to ends of lines.
|
|
2308 This means moving to the end of each line moved onto.
|
|
2309 The beginning of a blank line does not count as the end of a line."
|
|
2310 :type 'boolean
|
|
2311 :group 'editing-basics)
|
|
2312
|
|
2313 (defcustom goal-column nil
|
|
2314 "*Semipermanent goal column for vertical motion, as set by \\[set-goal-column], or nil."
|
|
2315 :type '(choice integer (const :tag "None" nil))
|
|
2316 :group 'editing-basics)
|
|
2317 (make-variable-buffer-local 'goal-column)
|
|
2318
|
|
2319 (defvar temporary-goal-column 0
|
|
2320 "Current goal column for vertical motion.
|
|
2321 It is the column where point was
|
|
2322 at the start of current run of vertical motion commands.
|
|
2323 When the `track-eol' feature is doing its job, the value is 9999.")
|
|
2324 (make-variable-buffer-local 'temporary-goal-column)
|
|
2325
|
|
2326 ;XEmacs: not yet ported, so avoid compiler warnings
|
|
2327 (eval-when-compile
|
|
2328 (defvar inhibit-point-motion-hooks))
|
|
2329
|
|
2330 (defcustom line-move-ignore-invisible nil
|
|
2331 "*Non-nil means \\[next-line] and \\[previous-line] ignore invisible lines.
|
|
2332 Use with care, as it slows down movement significantly. Outline mode sets this."
|
|
2333 :type 'boolean
|
|
2334 :group 'editing-basics)
|
|
2335
|
|
2336 ;; This is the guts of next-line and previous-line.
|
444
|
2337 ;; Count says how many lines to move.
|
|
2338 (defun line-move (count)
|
428
|
2339 ;; Don't run any point-motion hooks, and disregard intangibility,
|
|
2340 ;; for intermediate positions.
|
|
2341 (let ((inhibit-point-motion-hooks t)
|
|
2342 (opoint (point))
|
|
2343 new)
|
|
2344 (unwind-protect
|
|
2345 (progn
|
|
2346 (if (not (or (eq last-command 'next-line)
|
|
2347 (eq last-command 'previous-line)))
|
|
2348 (setq temporary-goal-column
|
|
2349 (if (and track-eol (eolp)
|
444
|
2350 ;; Don't count start of empty line as end of line
|
428
|
2351 ;; unless we just did explicit end-of-line.
|
|
2352 (or (not (bolp)) (eq last-command 'end-of-line)))
|
|
2353 9999
|
|
2354 (current-column))))
|
|
2355 (if (and (not (integerp selective-display))
|
|
2356 (not line-move-ignore-invisible))
|
|
2357 ;; Use just newline characters.
|
444
|
2358 (or (if (> count 0)
|
|
2359 (progn (if (> count 1) (forward-line (1- count)))
|
|
2360 ;; This way of moving forward COUNT lines
|
428
|
2361 ;; verifies that we have a newline after the last one.
|
|
2362 ;; It doesn't get confused by intangible text.
|
|
2363 (end-of-line)
|
|
2364 (zerop (forward-line 1)))
|
444
|
2365 (and (zerop (forward-line count))
|
428
|
2366 (bolp)))
|
444
|
2367 (signal (if (< count 0)
|
428
|
2368 'beginning-of-buffer
|
|
2369 'end-of-buffer)
|
|
2370 nil))
|
444
|
2371 ;; Move by count lines, but ignore invisible ones.
|
|
2372 (while (> count 0)
|
428
|
2373 (end-of-line)
|
|
2374 (and (zerop (vertical-motion 1))
|
|
2375 (signal 'end-of-buffer nil))
|
|
2376 ;; If the following character is currently invisible,
|
|
2377 ;; skip all characters with that same `invisible' property value.
|
|
2378 (while (and (not (eobp))
|
|
2379 (let ((prop
|
|
2380 (get-char-property (point) 'invisible)))
|
|
2381 (if (eq buffer-invisibility-spec t)
|
|
2382 prop
|
|
2383 (or (memq prop buffer-invisibility-spec)
|
|
2384 (assq prop buffer-invisibility-spec)))))
|
|
2385 (if (get-text-property (point) 'invisible)
|
|
2386 (goto-char (next-single-property-change (point) 'invisible))
|
|
2387 (goto-char (next-extent-change (point))))) ; XEmacs
|
444
|
2388 (setq count (1- count)))
|
|
2389 (while (< count 0)
|
428
|
2390 (beginning-of-line)
|
|
2391 (and (zerop (vertical-motion -1))
|
|
2392 (signal 'beginning-of-buffer nil))
|
|
2393 (while (and (not (bobp))
|
|
2394 (let ((prop
|
|
2395 (get-char-property (1- (point)) 'invisible)))
|
|
2396 (if (eq buffer-invisibility-spec t)
|
|
2397 prop
|
|
2398 (or (memq prop buffer-invisibility-spec)
|
|
2399 (assq prop buffer-invisibility-spec)))))
|
|
2400 (if (get-text-property (1- (point)) 'invisible)
|
|
2401 (goto-char (previous-single-property-change (point) 'invisible))
|
|
2402 (goto-char (previous-extent-change (point))))) ; XEmacs
|
444
|
2403 (setq count (1+ count))))
|
428
|
2404 (move-to-column (or goal-column temporary-goal-column)))
|
|
2405 ;; Remember where we moved to, go back home,
|
|
2406 ;; then do the motion over again
|
|
2407 ;; in just one step, with intangibility and point-motion hooks
|
|
2408 ;; enabled this time.
|
|
2409 (setq new (point))
|
|
2410 (goto-char opoint)
|
|
2411 (setq inhibit-point-motion-hooks nil)
|
|
2412 (goto-char new)))
|
|
2413 nil)
|
|
2414
|
|
2415 ;;; Many people have said they rarely use this feature, and often type
|
|
2416 ;;; it by accident. Maybe it shouldn't even be on a key.
|
|
2417 ;; It's not on a key, as of 20.2. So no need for this.
|
|
2418 ;(put 'set-goal-column 'disabled t)
|
|
2419
|
444
|
2420 (defun set-goal-column (column)
|
428
|
2421 "Set the current horizontal position as a goal for \\[next-line] and \\[previous-line].
|
|
2422 Those commands will move to this position in the line moved to
|
|
2423 rather than trying to keep the same horizontal position.
|
|
2424 With a non-nil argument, clears out the goal column
|
|
2425 so that \\[next-line] and \\[previous-line] resume vertical motion.
|
|
2426 The goal column is stored in the variable `goal-column'."
|
|
2427 (interactive "_P") ; XEmacs
|
444
|
2428 (if column
|
428
|
2429 (progn
|
|
2430 (setq goal-column nil)
|
|
2431 (display-message 'command "No goal column"))
|
|
2432 (setq goal-column (current-column))
|
|
2433 (lmessage 'command
|
444
|
2434 "Goal column %d (use %s with a prefix arg to unset it)"
|
428
|
2435 goal-column
|
|
2436 (substitute-command-keys "\\[set-goal-column]")))
|
|
2437 nil)
|
|
2438
|
|
2439 ;; deleted FSFmacs terminal randomness hscroll-point-visible stuff.
|
|
2440 ;; hscroll-step
|
|
2441 ;; hscroll-point-visible
|
|
2442 ;; hscroll-window-column
|
|
2443 ;; right-arrow
|
|
2444 ;; left-arrow
|
|
2445
|
|
2446 (defun scroll-other-window-down (lines)
|
|
2447 "Scroll the \"other window\" down.
|
|
2448 For more details, see the documentation for `scroll-other-window'."
|
|
2449 (interactive "P")
|
|
2450 (scroll-other-window
|
|
2451 ;; Just invert the argument's meaning.
|
|
2452 ;; We can do that without knowing which window it will be.
|
|
2453 (if (eq lines '-) nil
|
|
2454 (if (null lines) '-
|
|
2455 (- (prefix-numeric-value lines))))))
|
|
2456 ;(define-key esc-map [?\C-\S-v] 'scroll-other-window-down)
|
|
2457
|
|
2458 (defun beginning-of-buffer-other-window (arg)
|
|
2459 "Move point to the beginning of the buffer in the other window.
|
|
2460 Leave mark at previous position.
|
|
2461 With arg N, put point N/10 of the way from the true beginning."
|
|
2462 (interactive "P")
|
|
2463 (let ((orig-window (selected-window))
|
|
2464 (window (other-window-for-scrolling)))
|
|
2465 ;; We use unwind-protect rather than save-window-excursion
|
|
2466 ;; because the latter would preserve the things we want to change.
|
|
2467 (unwind-protect
|
|
2468 (progn
|
|
2469 (select-window window)
|
|
2470 ;; Set point and mark in that window's buffer.
|
|
2471 (beginning-of-buffer arg)
|
|
2472 ;; Set point accordingly.
|
|
2473 (recenter '(t)))
|
|
2474 (select-window orig-window))))
|
|
2475
|
|
2476 (defun end-of-buffer-other-window (arg)
|
|
2477 "Move point to the end of the buffer in the other window.
|
|
2478 Leave mark at previous position.
|
|
2479 With arg N, put point N/10 of the way from the true end."
|
|
2480 (interactive "P")
|
|
2481 ;; See beginning-of-buffer-other-window for comments.
|
|
2482 (let ((orig-window (selected-window))
|
|
2483 (window (other-window-for-scrolling)))
|
|
2484 (unwind-protect
|
|
2485 (progn
|
|
2486 (select-window window)
|
|
2487 (end-of-buffer arg)
|
|
2488 (recenter '(t)))
|
|
2489 (select-window orig-window))))
|
|
2490
|
|
2491 (defun transpose-chars (arg)
|
|
2492 "Interchange characters around point, moving forward one character.
|
|
2493 With prefix arg ARG, effect is to take character before point
|
|
2494 and drag it forward past ARG other characters (backward if ARG negative).
|
|
2495 If no argument and at end of line, the previous two chars are exchanged."
|
|
2496 (interactive "*P")
|
446
|
2497 (and (null arg) (eolp) (backward-char 1))
|
428
|
2498 (transpose-subr 'forward-char (prefix-numeric-value arg)))
|
|
2499
|
|
2500 ;;; A very old implementation of transpose-chars from the old days ...
|
|
2501 (defun transpose-preceding-chars (arg)
|
|
2502 "Interchange characters before point.
|
|
2503 With prefix arg ARG, effect is to take character before point
|
|
2504 and drag it forward past ARG other characters (backward if ARG negative).
|
|
2505 If no argument and not at start of line, the previous two chars are exchanged."
|
|
2506 (interactive "*P")
|
446
|
2507 (and (null arg) (not (bolp)) (backward-char 1))
|
428
|
2508 (transpose-subr 'forward-char (prefix-numeric-value arg)))
|
|
2509
|
|
2510
|
|
2511 (defun transpose-words (arg)
|
|
2512 "Interchange words around point, leaving point at end of them.
|
|
2513 With prefix arg ARG, effect is to take word before or around point
|
|
2514 and drag it forward past ARG other words (backward if ARG negative).
|
|
2515 If ARG is zero, the words around or after point and around or after mark
|
|
2516 are interchanged."
|
|
2517 (interactive "*p")
|
|
2518 (transpose-subr 'forward-word arg))
|
|
2519
|
|
2520 (defun transpose-sexps (arg)
|
|
2521 "Like \\[transpose-words] but applies to sexps.
|
|
2522 Does not work on a sexp that point is in the middle of
|
|
2523 if it is a list or string."
|
|
2524 (interactive "*p")
|
|
2525 (transpose-subr 'forward-sexp arg))
|
|
2526
|
613
|
2527 (defun Simple-forward-line-creating-newline ()
|
|
2528 ;; Move forward over a line,
|
|
2529 ;; but create a newline if none exists yet.
|
|
2530 (end-of-line)
|
|
2531 (if (eobp)
|
|
2532 (newline)
|
|
2533 (forward-char 1)))
|
|
2534
|
|
2535 (defun Simple-transpose-lines-mover (arg)
|
|
2536 (if (= arg 1)
|
|
2537 (Simple-forward-line-creating-newline)
|
|
2538 (forward-line arg)))
|
|
2539
|
428
|
2540 (defun transpose-lines (arg)
|
|
2541 "Exchange current line and previous line, leaving point after both.
|
|
2542 With argument ARG, takes previous line and moves it past ARG lines.
|
|
2543 With argument 0, interchanges line point is in with line mark is in."
|
|
2544 (interactive "*p")
|
613
|
2545 (transpose-subr 'Simple-transpose-lines-mover arg))
|
428
|
2546
|
442
|
2547 (defun transpose-line-up (arg)
|
|
2548 "Move current line one line up, leaving point at beginning of that line.
|
613
|
2549 With argument ARG, move it ARG lines up. This can be run repeatedly
|
|
2550 to move the current line up a number of lines.
|
|
2551
|
|
2552 If the region is active, move the region up one line (or ARG lines,
|
|
2553 if specified). The region will not be selected afterwards, but this
|
|
2554 command can still be run repeatedly to move the region up a number
|
|
2555 of lines."
|
442
|
2556 (interactive "*p")
|
613
|
2557 (transpose-line-down (- arg)))
|
442
|
2558
|
|
2559 (defun transpose-line-down (arg)
|
|
2560 "Move current line one line down, leaving point at beginning of that line.
|
613
|
2561 With argument ARG, move it ARG lines down. This can be run repeatedly
|
|
2562 to move the current line down a number of lines.
|
|
2563
|
|
2564 If the region is active, move the region down one line (or ARG lines,
|
|
2565 if specified). The region will not be selected afterwards, but this
|
|
2566 command can still be run repeatedly to move the region down a number
|
|
2567 of lines."
|
442
|
2568 (interactive "*p")
|
613
|
2569 (if (or (region-active-p)
|
|
2570 (getf last-command-properties 'transpose-region-by-line-command))
|
|
2571 (progn
|
|
2572 (transpose-subr 'Simple-transpose-lines-mover arg t)
|
|
2573 (putf this-command-properties 'transpose-region-by-line-command t))
|
|
2574 (Simple-forward-line-creating-newline)
|
|
2575 (transpose-subr 'Simple-transpose-lines-mover arg)
|
|
2576 (forward-line -1)))
|
|
2577
|
|
2578 (defun transpose-subr (mover arg &optional move-region)
|
428
|
2579 (let (start1 end1 start2 end2)
|
442
|
2580 ;; XEmacs -- use flet instead of defining a separate function and
|
613
|
2581 ;; relying on dynamic scope; use (mark t) etc; add code to support
|
|
2582 ;; the new MOVE-REGION arg.
|
442
|
2583 (flet ((transpose-subr-1 ()
|
|
2584 (if (> (min end1 end2) (max start1 start2))
|
|
2585 (error "Don't have two things to transpose"))
|
|
2586 (let ((word1 (buffer-substring start1 end1))
|
|
2587 (word2 (buffer-substring start2 end2)))
|
|
2588 (delete-region start2 end2)
|
|
2589 (goto-char start2)
|
|
2590 (insert word1)
|
|
2591 (goto-char (if (< start1 start2) start1
|
|
2592 (+ start1 (- (length word1) (length word2)))))
|
|
2593 (delete-char (length word1))
|
|
2594 (insert word2))))
|
|
2595 (if (= arg 0)
|
|
2596 (progn
|
|
2597 (save-excursion
|
|
2598 (funcall mover 1)
|
|
2599 (setq end2 (point))
|
|
2600 (funcall mover -1)
|
|
2601 (setq start2 (point))
|
613
|
2602 (goto-char (mark t))
|
442
|
2603 (funcall mover 1)
|
|
2604 (setq end1 (point))
|
|
2605 (funcall mover -1)
|
|
2606 (setq start1 (point))
|
|
2607 (transpose-subr-1))
|
613
|
2608 (exchange-point-and-mark t)))
|
|
2609 (if move-region
|
|
2610 (let ((rbeg (region-beginning))
|
|
2611 (rend (region-end)))
|
|
2612 (while (> arg 0)
|
|
2613 (goto-char rend)
|
|
2614 (funcall mover 1)
|
|
2615 (setq end2 (point))
|
|
2616 (funcall mover -1)
|
|
2617 (setq start2 (point))
|
|
2618 (setq start1 rbeg end1 rend)
|
|
2619 (transpose-subr-1)
|
|
2620 (incf rbeg (- end2 start2))
|
|
2621 (incf rend (- end2 start2))
|
|
2622 (setq arg (1- arg)))
|
|
2623 (while (< arg 0)
|
|
2624 (goto-char rbeg)
|
|
2625 (funcall mover -1)
|
|
2626 (setq start1 (point))
|
|
2627 (funcall mover 1)
|
|
2628 (setq end1 (point))
|
|
2629 (setq start2 rbeg end2 rend)
|
|
2630 (transpose-subr-1)
|
|
2631 (decf rbeg (- end1 start1))
|
|
2632 (decf rend (- end1 start1))
|
|
2633 (setq arg (1+ arg)))
|
|
2634 (set-mark rbeg)
|
|
2635 (goto-char rend))
|
|
2636 (while (> arg 0)
|
|
2637 (funcall mover -1)
|
|
2638 (setq start1 (point))
|
|
2639 (funcall mover 1)
|
|
2640 (setq end1 (point))
|
|
2641 (funcall mover 1)
|
|
2642 (setq end2 (point))
|
|
2643 (funcall mover -1)
|
|
2644 (setq start2 (point))
|
|
2645 (transpose-subr-1)
|
|
2646 (goto-char end2)
|
|
2647 (setq arg (1- arg)))
|
|
2648 (while (< arg 0)
|
|
2649 (funcall mover -1)
|
|
2650 (setq start2 (point))
|
|
2651 (funcall mover -1)
|
|
2652 (setq start1 (point))
|
|
2653 (funcall mover 1)
|
|
2654 (setq end1 (point))
|
|
2655 (funcall mover 1)
|
|
2656 (setq end2 (point))
|
|
2657 (transpose-subr-1)
|
|
2658 (setq arg (1+ arg)))))))
|
442
|
2659
|
428
|
2660
|
|
2661 (defcustom comment-column 32
|
|
2662 "*Column to indent right-margin comments to.
|
|
2663 Setting this variable automatically makes it local to the current buffer.
|
|
2664 Each mode establishes a different default value for this variable; you
|
|
2665 can set the value for a particular mode using that mode's hook."
|
|
2666 :type 'integer
|
|
2667 :group 'fill-comments)
|
|
2668 (make-variable-buffer-local 'comment-column)
|
|
2669
|
|
2670 (defcustom comment-start nil
|
|
2671 "*String to insert to start a new comment, or nil if no comment syntax."
|
|
2672 :type '(choice (const :tag "None" nil)
|
|
2673 string)
|
|
2674 :group 'fill-comments)
|
|
2675
|
|
2676 (defcustom comment-start-skip nil
|
|
2677 "*Regexp to match the start of a comment plus everything up to its body.
|
|
2678 If there are any \\(...\\) pairs, the comment delimiter text is held to begin
|
|
2679 at the place matched by the close of the first pair."
|
|
2680 :type '(choice (const :tag "None" nil)
|
|
2681 regexp)
|
|
2682 :group 'fill-comments)
|
|
2683
|
|
2684 (defcustom comment-end ""
|
|
2685 "*String to insert to end a new comment.
|
|
2686 Should be an empty string if comments are terminated by end-of-line."
|
|
2687 :type 'string
|
|
2688 :group 'fill-comments)
|
|
2689
|
|
2690 (defconst comment-indent-hook nil
|
|
2691 "Obsolete variable for function to compute desired indentation for a comment.
|
|
2692 Use `comment-indent-function' instead.
|
|
2693 This function is called with no args with point at the beginning of
|
|
2694 the comment's starting delimiter.")
|
|
2695
|
|
2696 (defconst comment-indent-function
|
|
2697 ;; XEmacs - add at least one space after the end of the text on the
|
|
2698 ;; current line...
|
|
2699 (lambda ()
|
|
2700 (save-excursion
|
|
2701 (beginning-of-line)
|
|
2702 (let ((eol (save-excursion (end-of-line) (point))))
|
|
2703 (and comment-start-skip
|
|
2704 (re-search-forward comment-start-skip eol t)
|
|
2705 (setq eol (match-beginning 0)))
|
|
2706 (goto-char eol)
|
|
2707 (skip-chars-backward " \t")
|
|
2708 (max comment-column (1+ (current-column))))))
|
|
2709 "Function to compute desired indentation for a comment.
|
|
2710 This function is called with no args with point at the beginning of
|
|
2711 the comment's starting delimiter.")
|
|
2712
|
|
2713 (defcustom block-comment-start nil
|
|
2714 "*String to insert to start a new comment on a line by itself.
|
|
2715 If nil, use `comment-start' instead.
|
|
2716 Note that the regular expression `comment-start-skip' should skip this string
|
|
2717 as well as the `comment-start' string."
|
|
2718 :type '(choice (const :tag "Use `comment-start'" nil)
|
|
2719 string)
|
|
2720 :group 'fill-comments)
|
|
2721
|
|
2722 (defcustom block-comment-end nil
|
|
2723 "*String to insert to end a new comment on a line by itself.
|
|
2724 Should be an empty string if comments are terminated by end-of-line.
|
|
2725 If nil, use `comment-end' instead."
|
|
2726 :type '(choice (const :tag "Use `comment-end'" nil)
|
|
2727 string)
|
|
2728 :group 'fill-comments)
|
|
2729
|
|
2730 (defun indent-for-comment ()
|
448
|
2731 "Indent this line's comment to comment column, or insert an empty
|
|
2732 comment. Comments starting in column 0 are not moved."
|
428
|
2733 (interactive "*")
|
|
2734 (let* ((empty (save-excursion (beginning-of-line)
|
|
2735 (looking-at "[ \t]*$")))
|
|
2736 (starter (or (and empty block-comment-start) comment-start))
|
|
2737 (ender (or (and empty block-comment-end) comment-end)))
|
|
2738 (if (null starter)
|
|
2739 (error "No comment syntax defined")
|
|
2740 (let* ((eolpos (save-excursion (end-of-line) (point)))
|
|
2741 cpos indent begpos)
|
|
2742 (beginning-of-line)
|
|
2743 (if (re-search-forward comment-start-skip eolpos 'move)
|
|
2744 (progn (setq cpos (point-marker))
|
|
2745 ;; Find the start of the comment delimiter.
|
|
2746 ;; If there were paren-pairs in comment-start-skip,
|
|
2747 ;; position at the end of the first pair.
|
|
2748 (if (match-end 1)
|
|
2749 (goto-char (match-end 1))
|
|
2750 ;; If comment-start-skip matched a string with
|
|
2751 ;; internal whitespace (not final whitespace) then
|
|
2752 ;; the delimiter start at the end of that
|
|
2753 ;; whitespace. Otherwise, it starts at the
|
|
2754 ;; beginning of what was matched.
|
|
2755 (skip-syntax-backward " " (match-beginning 0))
|
|
2756 (skip-syntax-backward "^ " (match-beginning 0)))))
|
|
2757 (setq begpos (point))
|
|
2758 ;; Compute desired indent.
|
448
|
2759 ;; XEmacs change: Preserve indentation of comments starting in
|
|
2760 ;; column 0, as documented.
|
|
2761 (cond
|
|
2762 ((= (current-column) 0)
|
|
2763 (goto-char begpos))
|
|
2764 ((= (current-column)
|
|
2765 (setq indent (funcall comment-indent-function)))
|
|
2766 (goto-char begpos))
|
|
2767 (t
|
428
|
2768 ;; If that's different from current, change it.
|
|
2769 (skip-chars-backward " \t")
|
|
2770 (delete-region (point) begpos)
|
448
|
2771 (indent-to indent)))
|
428
|
2772 ;; An existing comment?
|
|
2773 (if cpos
|
|
2774 (progn (goto-char cpos)
|
|
2775 (set-marker cpos nil))
|
|
2776 ;; No, insert one.
|
|
2777 (insert starter)
|
|
2778 (save-excursion
|
|
2779 (insert ender)))))))
|
|
2780
|
|
2781 (defun set-comment-column (arg)
|
|
2782 "Set the comment column based on point.
|
|
2783 With no arg, set the comment column to the current column.
|
|
2784 With just minus as arg, kill any comment on this line.
|
|
2785 With any other arg, set comment column to indentation of the previous comment
|
|
2786 and then align or create a comment on this line at that column."
|
|
2787 (interactive "P")
|
|
2788 (if (eq arg '-)
|
|
2789 (kill-comment nil)
|
|
2790 (if arg
|
|
2791 (progn
|
|
2792 (save-excursion
|
|
2793 (beginning-of-line)
|
|
2794 (re-search-backward comment-start-skip)
|
|
2795 (beginning-of-line)
|
|
2796 (re-search-forward comment-start-skip)
|
|
2797 (goto-char (match-beginning 0))
|
|
2798 (setq comment-column (current-column))
|
|
2799 (lmessage 'command "Comment column set to %d" comment-column))
|
|
2800 (indent-for-comment))
|
|
2801 (setq comment-column (current-column))
|
|
2802 (lmessage 'command "Comment column set to %d" comment-column))))
|
|
2803
|
|
2804 (defun kill-comment (arg)
|
|
2805 "Kill the comment on this line, if any.
|
|
2806 With argument, kill comments on that many lines starting with this one."
|
|
2807 ;; this function loses in a lot of situations. it incorrectly recognizes
|
|
2808 ;; comment delimiters sometimes (ergo, inside a string), doesn't work
|
|
2809 ;; with multi-line comments, can kill extra whitespace if comment wasn't
|
|
2810 ;; through end-of-line, et cetera.
|
|
2811 (interactive "*P")
|
|
2812 (or comment-start-skip (error "No comment syntax defined"))
|
|
2813 (let ((count (prefix-numeric-value arg)) endc)
|
|
2814 (while (> count 0)
|
|
2815 (save-excursion
|
|
2816 (end-of-line)
|
|
2817 (setq endc (point))
|
|
2818 (beginning-of-line)
|
|
2819 (and (string< "" comment-end)
|
|
2820 (setq endc
|
|
2821 (progn
|
|
2822 (re-search-forward (regexp-quote comment-end) endc 'move)
|
|
2823 (skip-chars-forward " \t")
|
|
2824 (point))))
|
|
2825 (beginning-of-line)
|
|
2826 (if (re-search-forward comment-start-skip endc t)
|
|
2827 (progn
|
|
2828 (goto-char (match-beginning 0))
|
|
2829 (skip-chars-backward " \t")
|
|
2830 (kill-region (point) endc)
|
|
2831 ;; to catch comments a line beginnings
|
|
2832 (indent-according-to-mode))))
|
|
2833 (if arg (forward-line 1))
|
|
2834 (setq count (1- count)))))
|
|
2835
|
502
|
2836 ;; This variable: Synched up with 20.7.
|
|
2837 (defvar comment-padding 1
|
|
2838 "Number of spaces `comment-region' puts between comment chars and text.
|
|
2839
|
|
2840 Extra spacing between the comment characters and the comment text
|
|
2841 makes the comment easier to read. Default is 1. Nil means 0 and is
|
|
2842 more efficient.")
|
|
2843
|
|
2844 ;; This function: Synched up with 20.7.
|
444
|
2845 (defun comment-region (start end &optional arg)
|
428
|
2846 "Comment or uncomment each line in the region.
|
|
2847 With just C-u prefix arg, uncomment each line in region.
|
|
2848 Numeric prefix arg ARG means use ARG comment characters.
|
|
2849 If ARG is negative, delete that many comment characters instead.
|
|
2850 Comments are terminated on each line, even for syntax in which newline does
|
|
2851 not end the comment. Blank lines do not get comments."
|
|
2852 ;; if someone wants it to only put a comment-start at the beginning and
|
|
2853 ;; comment-end at the end then typing it, C-x C-x, closing it, C-x C-x
|
|
2854 ;; is easy enough. No option is made here for other than commenting
|
|
2855 ;; every line.
|
|
2856 (interactive "r\nP")
|
|
2857 (or comment-start (error "No comment syntax is defined"))
|
444
|
2858 (if (> start end) (let (mid) (setq mid start start end end mid)))
|
428
|
2859 (save-excursion
|
|
2860 (save-restriction
|
|
2861 (let ((cs comment-start) (ce comment-end)
|
502
|
2862 (cp (when comment-padding
|
|
2863 (make-string comment-padding ? )))
|
428
|
2864 numarg)
|
|
2865 (if (consp arg) (setq numarg t)
|
|
2866 (setq numarg (prefix-numeric-value arg))
|
|
2867 ;; For positive arg > 1, replicate the comment delims now,
|
|
2868 ;; then insert the replicated strings just once.
|
|
2869 (while (> numarg 1)
|
|
2870 (setq cs (concat cs comment-start)
|
|
2871 ce (concat ce comment-end))
|
|
2872 (setq numarg (1- numarg))))
|
444
|
2873 ;; Loop over all lines from START to END.
|
|
2874 (narrow-to-region start end)
|
|
2875 (goto-char start)
|
502
|
2876 ;; if user didn't specify how many comments to remove, be smart
|
|
2877 ;; and remove the minimal number that all lines have. that way,
|
|
2878 ;; comments in a region of Elisp code that gets commented out will
|
|
2879 ;; get put back correctly.
|
|
2880 (if (eq numarg t)
|
|
2881 (let ((min-comments 999999))
|
|
2882 (while (not (eobp))
|
|
2883 (let ((this-comments 0))
|
|
2884 (while (looking-at (regexp-quote cs))
|
|
2885 (incf this-comments)
|
|
2886 (forward-char (length cs)))
|
|
2887 (if (and (> this-comments 0) (< this-comments min-comments))
|
|
2888 (setq min-comments this-comments))
|
|
2889 (forward-line 1)))
|
|
2890 (if (< min-comments 999999)
|
|
2891 (setq numarg (- min-comments)))
|
|
2892 (goto-char start)))
|
|
2893 (if (or (eq numarg t) (< numarg 0))
|
|
2894 (while (not (eobp))
|
|
2895 (let (found-comment)
|
428
|
2896 ;; Delete comment start from beginning of line.
|
|
2897 (if (eq numarg t)
|
|
2898 (while (looking-at (regexp-quote cs))
|
502
|
2899 (setq found-comment t)
|
428
|
2900 (delete-char (length cs)))
|
|
2901 (let ((count numarg))
|
|
2902 (while (and (> 1 (setq count (1+ count)))
|
|
2903 (looking-at (regexp-quote cs)))
|
502
|
2904 (setq found-comment t)
|
428
|
2905 (delete-char (length cs)))))
|
502
|
2906 ;; Delete comment padding from beginning of line
|
|
2907 (when (and found-comment comment-padding
|
|
2908 (looking-at (regexp-quote cp)))
|
|
2909 (delete-char comment-padding))
|
428
|
2910 ;; Delete comment end from end of line.
|
|
2911 (if (string= "" ce)
|
|
2912 nil
|
|
2913 (if (eq numarg t)
|
|
2914 (progn
|
|
2915 (end-of-line)
|
|
2916 ;; This is questionable if comment-end ends in
|
|
2917 ;; whitespace. That is pretty brain-damaged,
|
|
2918 ;; though.
|
502
|
2919 (while (progn (skip-chars-backward " \t")
|
|
2920 (and (>= (- (point) (point-min))
|
|
2921 (length ce))
|
|
2922 (save-excursion
|
|
2923 (backward-char (length ce))
|
|
2924 (looking-at (regexp-quote ce)))))
|
|
2925 (delete-char (- (length ce)))))
|
428
|
2926 (let ((count numarg))
|
|
2927 (while (> 1 (setq count (1+ count)))
|
|
2928 (end-of-line)
|
|
2929 ;; This is questionable if comment-end ends in
|
|
2930 ;; whitespace. That is pretty brain-damaged though
|
|
2931 (skip-chars-backward " \t")
|
502
|
2932 (if (>= (- (point) (point-min)) (length ce))
|
|
2933 (save-excursion
|
|
2934 (backward-char (length ce))
|
|
2935 (if (looking-at (regexp-quote ce))
|
|
2936 (delete-char (length ce)))))))))
|
|
2937 (forward-line 1)))
|
|
2938
|
|
2939 (when comment-padding
|
|
2940 (setq cs (concat cs cp)))
|
|
2941 (while (not (eobp))
|
428
|
2942 ;; Insert at beginning and at end.
|
|
2943 (if (looking-at "[ \t]*$") ()
|
|
2944 (insert cs)
|
|
2945 (if (string= "" ce) ()
|
|
2946 (end-of-line)
|
|
2947 (insert ce)))
|
|
2948 (search-forward "\n" nil 'move)))))))
|
|
2949
|
|
2950 ;; XEmacs
|
|
2951 (defun prefix-region (prefix)
|
|
2952 "Add a prefix string to each line between mark and point."
|
|
2953 (interactive "sPrefix string: ")
|
|
2954 (if prefix
|
|
2955 (let ((count (count-lines (mark) (point))))
|
|
2956 (goto-char (min (mark) (point)))
|
|
2957 (while (> count 0)
|
|
2958 (setq count (1- count))
|
|
2959 (beginning-of-line 1)
|
|
2960 (insert prefix)
|
|
2961 (end-of-line 1)
|
|
2962 (forward-char 1)))))
|
|
2963
|
|
2964
|
446
|
2965 (defun backward-word (&optional count buffer)
|
|
2966 "Move point backward COUNT words (forward if COUNT is negative).
|
|
2967 Normally t is returned, but if an edge of the buffer is reached,
|
|
2968 point is left there and nil is returned.
|
|
2969
|
462
|
2970 COUNT defaults to 1, and BUFFER defaults to the current buffer.
|
|
2971
|
|
2972 The characters that are moved over may be added to the current selection
|
|
2973 \(i.e. active region) if the Shift key is held down, a motion key is used
|
|
2974 to invoke this command, and `shifted-motion-keys-select-region' is t; see
|
|
2975 the documentation for this variable for more details."
|
446
|
2976 (interactive "_p")
|
|
2977 (forward-word (- (or count 1)) buffer))
|
|
2978
|
|
2979 (defun mark-word (&optional count)
|
|
2980 "Mark the text from point until encountering the end of a word.
|
|
2981 With optional argument COUNT, mark COUNT words."
|
428
|
2982 (interactive "p")
|
446
|
2983 (mark-something 'mark-word 'forward-word count))
|
|
2984
|
|
2985 (defun kill-word (&optional count)
|
428
|
2986 "Kill characters forward until encountering the end of a word.
|
446
|
2987 With optional argument COUNT, do this that many times."
|
|
2988 (interactive "*p")
|
|
2989 (kill-region (point) (save-excursion (forward-word count) (point))))
|
|
2990
|
|
2991 (defun backward-kill-word (&optional count)
|
|
2992 "Kill characters backward until encountering the end of a word.
|
428
|
2993 With argument, do this that many times."
|
|
2994 (interactive "*p")
|
446
|
2995 (kill-word (- (or count 1))))
|
428
|
2996
|
|
2997 (defun current-word (&optional strict)
|
|
2998 "Return the word point is on (or a nearby word) as a string.
|
|
2999 If optional arg STRICT is non-nil, return nil unless point is within
|
|
3000 or adjacent to a word.
|
|
3001 If point is not between two word-constituent characters, but immediately
|
|
3002 follows one, move back first.
|
|
3003 Otherwise, if point precedes a word constituent, move forward first.
|
|
3004 Otherwise, move backwards until a word constituent is found and get that word;
|
|
3005 if you a newlines is reached first, move forward instead."
|
|
3006 (save-excursion
|
|
3007 (let ((oldpoint (point)) (start (point)) (end (point)))
|
|
3008 (skip-syntax-backward "w_") (setq start (point))
|
|
3009 (goto-char oldpoint)
|
|
3010 (skip-syntax-forward "w_") (setq end (point))
|
|
3011 (if (and (eq start oldpoint) (eq end oldpoint))
|
|
3012 ;; Point is neither within nor adjacent to a word.
|
|
3013 (and (not strict)
|
|
3014 (progn
|
|
3015 ;; Look for preceding word in same line.
|
|
3016 (skip-syntax-backward "^w_"
|
|
3017 (save-excursion
|
|
3018 (beginning-of-line) (point)))
|
|
3019 (if (bolp)
|
|
3020 ;; No preceding word in same line.
|
|
3021 ;; Look for following word in same line.
|
|
3022 (progn
|
|
3023 (skip-syntax-forward "^w_"
|
|
3024 (save-excursion
|
|
3025 (end-of-line) (point)))
|
|
3026 (setq start (point))
|
|
3027 (skip-syntax-forward "w_")
|
|
3028 (setq end (point)))
|
|
3029 (setq end (point))
|
|
3030 (skip-syntax-backward "w_")
|
|
3031 (setq start (point)))
|
|
3032 (buffer-substring start end)))
|
|
3033 (buffer-substring start end)))))
|
|
3034
|
|
3035 (defcustom fill-prefix nil
|
|
3036 "*String for filling to insert at front of new line, or nil for none.
|
|
3037 Setting this variable automatically makes it local to the current buffer."
|
|
3038 :type '(choice (const :tag "None" nil)
|
|
3039 string)
|
|
3040 :group 'fill)
|
|
3041 (make-variable-buffer-local 'fill-prefix)
|
|
3042
|
|
3043 (defcustom auto-fill-inhibit-regexp nil
|
|
3044 "*Regexp to match lines which should not be auto-filled."
|
|
3045 :type '(choice (const :tag "None" nil)
|
|
3046 regexp)
|
|
3047 :group 'fill)
|
|
3048
|
|
3049 (defvar comment-line-break-function 'indent-new-comment-line
|
|
3050 "*Mode-specific function which line breaks and continues a comment.
|
|
3051
|
|
3052 This function is only called during auto-filling of a comment section.
|
|
3053 The function should take a single optional argument which is a flag
|
|
3054 indicating whether soft newlines should be inserted.")
|
|
3055
|
|
3056 ;; This function is the auto-fill-function of a buffer
|
|
3057 ;; when Auto-Fill mode is enabled.
|
|
3058 ;; It returns t if it really did any work.
|
|
3059 ;; XEmacs: This function is totally different.
|
|
3060 (defun do-auto-fill ()
|
|
3061 (let (give-up)
|
|
3062 (or (and auto-fill-inhibit-regexp
|
|
3063 (save-excursion (beginning-of-line)
|
|
3064 (looking-at auto-fill-inhibit-regexp)))
|
|
3065 (while (and (not give-up) (> (current-column) fill-column))
|
|
3066 ;; Determine where to split the line.
|
|
3067 (let ((fill-prefix fill-prefix)
|
|
3068 (fill-point
|
|
3069 (let ((opoint (point))
|
|
3070 bounce
|
502
|
3071 (re-break-point ;; Kinsoku processing
|
|
3072 (if (featurep 'mule)
|
771
|
3073 (with-boundp 'word-across-newline
|
|
3074 (concat "[ \t\n]\\|" word-across-newline
|
|
3075 ".\\|." word-across-newline))
|
502
|
3076 "[ \t\n]"))
|
428
|
3077 (first t))
|
|
3078 (save-excursion
|
|
3079 (move-to-column (1+ fill-column))
|
|
3080 ;; Move back to a word boundary.
|
|
3081 (while (or first
|
|
3082 ;; If this is after period and a single space,
|
|
3083 ;; move back once more--we don't want to break
|
|
3084 ;; the line there and make it look like a
|
|
3085 ;; sentence end.
|
|
3086 (and (not (bobp))
|
|
3087 (not bounce)
|
|
3088 sentence-end-double-space
|
446
|
3089 (save-excursion (backward-char 1)
|
428
|
3090 (and (looking-at "\\. ")
|
|
3091 (not (looking-at "\\. "))))))
|
|
3092 (setq first nil)
|
502
|
3093 ;; XEmacs: change for Kinsoku processing
|
428
|
3094 (fill-move-backward-to-break-point re-break-point)
|
|
3095 ;; If we find nowhere on the line to break it,
|
|
3096 ;; break after one word. Set bounce to t
|
|
3097 ;; so we will not keep going in this while loop.
|
|
3098 (if (bolp)
|
|
3099 (progn
|
502
|
3100 ;; XEmacs: change for Kinsoku processing
|
428
|
3101 (fill-move-forward-to-break-point re-break-point
|
|
3102 opoint)
|
|
3103 (setq bounce t)))
|
|
3104 (skip-chars-backward " \t"))
|
|
3105 (if (and (featurep 'mule)
|
502
|
3106 (or bounce (bolp)))
|
|
3107 (declare-fboundp (kinsoku-process)))
|
428
|
3108 ;; Let fill-point be set to the place where we end up.
|
|
3109 (point)))))
|
|
3110
|
|
3111 ;; I'm not sure why Stig made this change but it breaks
|
|
3112 ;; auto filling in at least C mode so I'm taking it back
|
|
3113 ;; out. --cet
|
|
3114 ;; XEmacs - adaptive fill.
|
|
3115 ;;(maybe-adapt-fill-prefix
|
|
3116 ;; (or from (setq from (save-excursion (beginning-of-line)
|
|
3117 ;; (point))))
|
|
3118 ;; (or to (setq to (save-excursion (beginning-of-line 2)
|
|
3119 ;; (point))))
|
|
3120 ;; t)
|
|
3121
|
|
3122 ;; If that place is not the beginning of the line,
|
|
3123 ;; break the line there.
|
|
3124 (if (save-excursion
|
|
3125 (goto-char fill-point)
|
502
|
3126 ;; during kinsoku processing it is possible to move beyond
|
|
3127 (not (or (bolp) (eolp))))
|
428
|
3128 (let ((prev-column (current-column)))
|
|
3129 ;; If point is at the fill-point, do not `save-excursion'.
|
|
3130 ;; Otherwise, if a comment prefix or fill-prefix is inserted,
|
|
3131 ;; point will end up before it rather than after it.
|
|
3132 (if (save-excursion
|
|
3133 (skip-chars-backward " \t")
|
|
3134 (= (point) fill-point))
|
|
3135 ;; 1999-09-17 hniksic: turn off Kinsoku until
|
|
3136 ;; it's debugged.
|
444
|
3137 (funcall comment-line-break-function)
|
502
|
3138 ;; XEmacs: Kinsoku processing
|
428
|
3139 ; ;(indent-new-comment-line)
|
|
3140 ; (let ((spacep (memq (char-before (point)) '(?\ ?\t))))
|
|
3141 ; (funcall comment-line-break-function)
|
|
3142 ; ;; if user type space explicitly, leave SPC
|
|
3143 ; ;; even if there is no WAN.
|
|
3144 ; (if spacep
|
|
3145 ; (save-excursion
|
|
3146 ; (goto-char fill-point)
|
|
3147 ; ;; put SPC except that there is SPC
|
|
3148 ; ;; already or there is sentence end.
|
|
3149 ; (or (memq (char-after (point)) '(?\ ?\t))
|
|
3150 ; (fill-end-of-sentence-p)
|
|
3151 ; (insert ?\ )))))
|
|
3152 (save-excursion
|
|
3153 (goto-char fill-point)
|
|
3154 (funcall comment-line-break-function)))
|
|
3155 ;; If making the new line didn't reduce the hpos of
|
|
3156 ;; the end of the line, then give up now;
|
|
3157 ;; trying again will not help.
|
|
3158 (if (>= (current-column) prev-column)
|
|
3159 (setq give-up t)))
|
|
3160 ;; No place to break => stop trying.
|
|
3161 (setq give-up t)))))))
|
|
3162
|
|
3163 ;; Put FSF one in until I can one or the other working properly, then the
|
|
3164 ;; other one is history.
|
|
3165 ;(defun fsf:do-auto-fill ()
|
|
3166 ; (let (fc justify
|
|
3167 ; ;; bol
|
|
3168 ; give-up
|
|
3169 ; (fill-prefix fill-prefix))
|
|
3170 ; (if (or (not (setq justify (current-justification)))
|
|
3171 ; (null (setq fc (current-fill-column)))
|
|
3172 ; (and (eq justify 'left)
|
|
3173 ; (<= (current-column) fc))
|
|
3174 ; (save-excursion (beginning-of-line)
|
|
3175 ; ;; (setq bol (point))
|
|
3176 ; (and auto-fill-inhibit-regexp
|
|
3177 ; (looking-at auto-fill-inhibit-regexp))))
|
|
3178 ; nil ;; Auto-filling not required
|
|
3179 ; (if (memq justify '(full center right))
|
|
3180 ; (save-excursion (unjustify-current-line)))
|
|
3181
|
|
3182 ; ;; Choose a fill-prefix automatically.
|
|
3183 ; (if (and adaptive-fill-mode
|
|
3184 ; (or (null fill-prefix) (string= fill-prefix "")))
|
|
3185 ; (let ((prefix
|
|
3186 ; (fill-context-prefix
|
|
3187 ; (save-excursion (backward-paragraph 1) (point))
|
|
3188 ; (save-excursion (forward-paragraph 1) (point))
|
|
3189 ; ;; Don't accept a non-whitespace fill prefix
|
|
3190 ; ;; from the first line of a paragraph.
|
|
3191 ; "^[ \t]*$")))
|
|
3192 ; (and prefix (not (equal prefix ""))
|
|
3193 ; (setq fill-prefix prefix))))
|
|
3194
|
|
3195 ; (while (and (not give-up) (> (current-column) fc))
|
|
3196 ; ;; Determine where to split the line.
|
|
3197 ; (let ((fill-point
|
|
3198 ; (let ((opoint (point))
|
|
3199 ; bounce
|
|
3200 ; (first t))
|
|
3201 ; (save-excursion
|
|
3202 ; (move-to-column (1+ fc))
|
|
3203 ; ;; Move back to a word boundary.
|
|
3204 ; (while (or first
|
|
3205 ; ;; If this is after period and a single space,
|
|
3206 ; ;; move back once more--we don't want to break
|
|
3207 ; ;; the line there and make it look like a
|
|
3208 ; ;; sentence end.
|
|
3209 ; (and (not (bobp))
|
|
3210 ; (not bounce)
|
|
3211 ; sentence-end-double-space
|
446
|
3212 ; (save-excursion (backward-char 1)
|
428
|
3213 ; (and (looking-at "\\. ")
|
|
3214 ; (not (looking-at "\\. "))))))
|
|
3215 ; (setq first nil)
|
|
3216 ; (skip-chars-backward "^ \t\n")
|
|
3217 ; ;; If we find nowhere on the line to break it,
|
|
3218 ; ;; break after one word. Set bounce to t
|
|
3219 ; ;; so we will not keep going in this while loop.
|
|
3220 ; (if (bolp)
|
|
3221 ; (progn
|
|
3222 ; (re-search-forward "[ \t]" opoint t)
|
|
3223 ; (setq bounce t)))
|
|
3224 ; (skip-chars-backward " \t"))
|
|
3225 ; ;; Let fill-point be set to the place where we end up.
|
|
3226 ; (point)))))
|
|
3227 ; ;; If that place is not the beginning of the line,
|
|
3228 ; ;; break the line there.
|
|
3229 ; (if (save-excursion
|
|
3230 ; (goto-char fill-point)
|
|
3231 ; (not (bolp)))
|
|
3232 ; (let ((prev-column (current-column)))
|
|
3233 ; ;; If point is at the fill-point, do not `save-excursion'.
|
|
3234 ; ;; Otherwise, if a comment prefix or fill-prefix is inserted,
|
|
3235 ; ;; point will end up before it rather than after it.
|
|
3236 ; (if (save-excursion
|
|
3237 ; (skip-chars-backward " \t")
|
|
3238 ; (= (point) fill-point))
|
|
3239 ; (funcall comment-line-break-function t)
|
|
3240 ; (save-excursion
|
|
3241 ; (goto-char fill-point)
|
|
3242 ; (funcall comment-line-break-function t)))
|
|
3243 ; ;; Now do justification, if required
|
|
3244 ; (if (not (eq justify 'left))
|
|
3245 ; (save-excursion
|
|
3246 ; (end-of-line 0)
|
|
3247 ; (justify-current-line justify nil t)))
|
|
3248 ; ;; If making the new line didn't reduce the hpos of
|
|
3249 ; ;; the end of the line, then give up now;
|
|
3250 ; ;; trying again will not help.
|
|
3251 ; (if (>= (current-column) prev-column)
|
|
3252 ; (setq give-up t)))
|
|
3253 ; ;; No place to break => stop trying.
|
|
3254 ; (setq give-up t))))
|
|
3255 ; ;; Justify last line.
|
|
3256 ; (justify-current-line justify t t)
|
|
3257 ; t)))
|
|
3258
|
|
3259 (defvar normal-auto-fill-function 'do-auto-fill
|
|
3260 "The function to use for `auto-fill-function' if Auto Fill mode is turned on.
|
|
3261 Some major modes set this.")
|
|
3262
|
|
3263 (defun auto-fill-mode (&optional arg)
|
|
3264 "Toggle auto-fill mode.
|
|
3265 With arg, turn auto-fill mode on if and only if arg is positive.
|
|
3266 In Auto-Fill mode, inserting a space at a column beyond `current-fill-column'
|
|
3267 automatically breaks the line at a previous space.
|
|
3268
|
|
3269 The value of `normal-auto-fill-function' specifies the function to use
|
|
3270 for `auto-fill-function' when turning Auto Fill mode on."
|
|
3271 (interactive "P")
|
|
3272 (prog1 (setq auto-fill-function
|
|
3273 (if (if (null arg)
|
|
3274 (not auto-fill-function)
|
|
3275 (> (prefix-numeric-value arg) 0))
|
|
3276 normal-auto-fill-function
|
|
3277 nil))
|
|
3278 (redraw-modeline)))
|
|
3279
|
|
3280 ;; This holds a document string used to document auto-fill-mode.
|
|
3281 (defun auto-fill-function ()
|
|
3282 "Automatically break line at a previous space, in insertion of text."
|
|
3283 nil)
|
|
3284
|
|
3285 (defun turn-on-auto-fill ()
|
|
3286 "Unconditionally turn on Auto Fill mode."
|
444
|
3287 (interactive)
|
428
|
3288 (auto-fill-mode 1))
|
|
3289
|
|
3290 (defun set-fill-column (arg)
|
|
3291 "Set `fill-column' to specified argument.
|
|
3292 Just \\[universal-argument] as argument means to use the current column
|
|
3293 The variable `fill-column' has a separate value for each buffer."
|
|
3294 (interactive "_P") ; XEmacs
|
|
3295 (cond ((integerp arg)
|
|
3296 (setq fill-column arg))
|
|
3297 ((consp arg)
|
|
3298 (setq fill-column (current-column)))
|
|
3299 ;; Disallow missing argument; it's probably a typo for C-x C-f.
|
|
3300 (t
|
|
3301 (error "set-fill-column requires an explicit argument")))
|
|
3302 (lmessage 'command "fill-column set to %d" fill-column))
|
|
3303
|
|
3304 (defcustom comment-multi-line t ; XEmacs - this works well with adaptive fill
|
|
3305 "*Non-nil means \\[indent-new-comment-line] should continue same comment
|
|
3306 on new line, with no new terminator or starter.
|
|
3307 This is obsolete because you might as well use \\[newline-and-indent]."
|
|
3308 :type 'boolean
|
|
3309 :group 'fill-comments)
|
|
3310
|
|
3311 (defun indent-new-comment-line (&optional soft)
|
|
3312 "Break line at point and indent, continuing comment if within one.
|
|
3313 This indents the body of the continued comment
|
|
3314 under the previous comment line.
|
|
3315
|
|
3316 This command is intended for styles where you write a comment per line,
|
|
3317 starting a new comment (and terminating it if necessary) on each line.
|
|
3318 If you want to continue one comment across several lines, use \\[newline-and-indent].
|
|
3319
|
|
3320 If a fill column is specified, it overrides the use of the comment column
|
|
3321 or comment indentation.
|
|
3322
|
|
3323 The inserted newline is marked hard if `use-hard-newlines' is true,
|
|
3324 unless optional argument SOFT is non-nil."
|
|
3325 (interactive)
|
|
3326 (let (comcol comstart)
|
|
3327 (skip-chars-backward " \t")
|
|
3328 (if (featurep 'mule)
|
502
|
3329 (declare-fboundp (kinsoku-process)))
|
428
|
3330 (delete-region (point)
|
|
3331 (progn (skip-chars-forward " \t")
|
|
3332 (point)))
|
|
3333 (if soft (insert ?\n) (newline 1))
|
|
3334 (if fill-prefix
|
|
3335 (progn
|
|
3336 (indent-to-left-margin)
|
|
3337 (insert fill-prefix))
|
|
3338 ;; #### - Eric Eide reverts to v18 semantics for this function in
|
|
3339 ;; fa-extras, which I'm not gonna do. His changes are to (1) execute
|
|
3340 ;; the save-excursion below unconditionally, and (2) uncomment the check
|
|
3341 ;; for (not comment-multi-line) further below. --Stig
|
|
3342 ;;#### jhod: probably need to fix this for kinsoku processing
|
|
3343 (if (not comment-multi-line)
|
|
3344 (save-excursion
|
|
3345 (if (and comment-start-skip
|
|
3346 (let ((opoint (point)))
|
|
3347 (forward-line -1)
|
|
3348 (re-search-forward comment-start-skip opoint t)))
|
|
3349 ;; The old line is a comment.
|
|
3350 ;; Set WIN to the pos of the comment-start.
|
|
3351 ;; But if the comment is empty, look at preceding lines
|
|
3352 ;; to find one that has a nonempty comment.
|
|
3353
|
|
3354 ;; If comment-start-skip contains a \(...\) pair,
|
|
3355 ;; the real comment delimiter starts at the end of that pair.
|
|
3356 (let ((win (or (match-end 1) (match-beginning 0))))
|
|
3357 (while (and (eolp) (not (bobp))
|
|
3358 (let (opoint)
|
|
3359 (beginning-of-line)
|
|
3360 (setq opoint (point))
|
|
3361 (forward-line -1)
|
|
3362 (re-search-forward comment-start-skip opoint t)))
|
|
3363 (setq win (or (match-end 1) (match-beginning 0))))
|
|
3364 ;; Indent this line like what we found.
|
|
3365 (goto-char win)
|
|
3366 (setq comcol (current-column))
|
|
3367 (setq comstart
|
|
3368 (buffer-substring (point) (match-end 0)))))))
|
|
3369 (if (and comcol (not fill-prefix)) ; XEmacs - (ENE) from fa-extras.
|
|
3370 (let ((comment-column comcol)
|
|
3371 (comment-start comstart)
|
|
3372 (block-comment-start comstart)
|
|
3373 (comment-end comment-end))
|
|
3374 (and comment-end (not (equal comment-end ""))
|
|
3375 ; (if (not comment-multi-line)
|
|
3376 (progn
|
446
|
3377 (backward-char 1)
|
428
|
3378 (insert comment-end)
|
|
3379 (forward-char 1))
|
|
3380 ; (setq comment-column (+ comment-column (length comment-start))
|
|
3381 ; comment-start "")
|
|
3382 ; )
|
|
3383 )
|
|
3384 (if (not (eolp))
|
|
3385 (setq comment-end ""))
|
|
3386 (insert ?\n)
|
446
|
3387 (backward-char 1)
|
428
|
3388 (indent-for-comment)
|
|
3389 (save-excursion
|
|
3390 ;; Make sure we delete the newline inserted above.
|
|
3391 (end-of-line)
|
|
3392 (delete-char 1)))
|
|
3393 (indent-according-to-mode)))))
|
|
3394
|
|
3395
|
|
3396 (defun set-selective-display (arg)
|
|
3397 "Set `selective-display' to ARG; clear it if no arg.
|
|
3398 When the value of `selective-display' is a number > 0,
|
|
3399 lines whose indentation is >= that value are not displayed.
|
|
3400 The variable `selective-display' has a separate value for each buffer."
|
|
3401 (interactive "P")
|
|
3402 (if (eq selective-display t)
|
|
3403 (error "selective-display already in use for marked lines"))
|
|
3404 (let ((current-vpos
|
|
3405 (save-restriction
|
|
3406 (narrow-to-region (point-min) (point))
|
|
3407 (goto-char (window-start))
|
|
3408 (vertical-motion (window-height)))))
|
|
3409 (setq selective-display
|
|
3410 (and arg (prefix-numeric-value arg)))
|
|
3411 (recenter current-vpos))
|
|
3412 (set-window-start (selected-window) (window-start (selected-window)))
|
|
3413 ;; #### doesn't localize properly:
|
|
3414 (princ "selective-display set to " t)
|
|
3415 (prin1 selective-display t)
|
|
3416 (princ "." t))
|
|
3417
|
|
3418 ;; XEmacs
|
|
3419 (defun nuke-selective-display ()
|
|
3420 "Ensure that the buffer is not in selective-display mode.
|
|
3421 If `selective-display' is t, then restore the buffer text to its original
|
|
3422 state before disabling selective display."
|
|
3423 ;; by Stig@hackvan.com
|
|
3424 (interactive)
|
|
3425 (and (eq t selective-display)
|
|
3426 (save-excursion
|
|
3427 (save-restriction
|
|
3428 (widen)
|
|
3429 (goto-char (point-min))
|
|
3430 (let ((mod-p (buffer-modified-p))
|
|
3431 (buffer-read-only nil))
|
|
3432 (while (search-forward "\r" nil t)
|
|
3433 (delete-char -1)
|
|
3434 (insert "\n"))
|
|
3435 (set-buffer-modified-p mod-p)
|
|
3436 ))))
|
|
3437 (setq selective-display nil))
|
|
3438
|
|
3439 (add-hook 'change-major-mode-hook 'nuke-selective-display)
|
|
3440
|
444
|
3441 (defconst overwrite-mode-textual " Ovwrt"
|
428
|
3442 "The string displayed in the mode line when in overwrite mode.")
|
444
|
3443 (defconst overwrite-mode-binary " Bin Ovwrt"
|
428
|
3444 "The string displayed in the mode line when in binary overwrite mode.")
|
|
3445
|
|
3446 (defun overwrite-mode (arg)
|
|
3447 "Toggle overwrite mode.
|
444
|
3448 With arg, enable overwrite mode if arg is positive, else disable.
|
428
|
3449 In overwrite mode, printing characters typed in replace existing text
|
|
3450 on a one-for-one basis, rather than pushing it to the right. At the
|
|
3451 end of a line, such characters extend the line. Before a tab,
|
|
3452 such characters insert until the tab is filled in.
|
|
3453 \\[quoted-insert] still inserts characters in overwrite mode; this
|
|
3454 is supposed to make it easier to insert characters when necessary."
|
|
3455 (interactive "P")
|
|
3456 (setq overwrite-mode
|
|
3457 (if (if (null arg) (not overwrite-mode)
|
|
3458 (> (prefix-numeric-value arg) 0))
|
|
3459 'overwrite-mode-textual))
|
|
3460 (redraw-modeline))
|
|
3461
|
|
3462 (defun binary-overwrite-mode (arg)
|
|
3463 "Toggle binary overwrite mode.
|
444
|
3464 With arg, enable binary overwrite mode if arg is positive, else disable.
|
428
|
3465 In binary overwrite mode, printing characters typed in replace
|
|
3466 existing text. Newlines are not treated specially, so typing at the
|
|
3467 end of a line joins the line to the next, with the typed character
|
|
3468 between them. Typing before a tab character simply replaces the tab
|
|
3469 with the character typed.
|
|
3470 \\[quoted-insert] replaces the text at the cursor, just as ordinary
|
|
3471 typing characters do.
|
|
3472
|
|
3473 Note that binary overwrite mode is not its own minor mode; it is a
|
|
3474 specialization of overwrite-mode, entered by setting the
|
|
3475 `overwrite-mode' variable to `overwrite-mode-binary'."
|
|
3476 (interactive "P")
|
|
3477 (setq overwrite-mode
|
|
3478 (if (if (null arg)
|
|
3479 (not (eq overwrite-mode 'overwrite-mode-binary))
|
|
3480 (> (prefix-numeric-value arg) 0))
|
|
3481 'overwrite-mode-binary))
|
|
3482 (redraw-modeline))
|
|
3483
|
771
|
3484 (defcustom line-number-mode t
|
428
|
3485 "*Non-nil means display line number in modeline."
|
|
3486 :type 'boolean
|
|
3487 :group 'editing-basics)
|
|
3488
|
|
3489 (defun line-number-mode (arg)
|
|
3490 "Toggle Line Number mode.
|
444
|
3491 With arg, enable Line Number mode if arg is positive, else disable.
|
428
|
3492 When Line Number mode is enabled, the line number appears
|
|
3493 in the mode line."
|
|
3494 (interactive "P")
|
|
3495 (setq line-number-mode
|
|
3496 (if (null arg) (not line-number-mode)
|
|
3497 (> (prefix-numeric-value arg) 0)))
|
|
3498 (redraw-modeline))
|
|
3499
|
771
|
3500 (defcustom column-number-mode t
|
428
|
3501 "*Non-nil means display column number in mode line."
|
|
3502 :type 'boolean
|
|
3503 :group 'editing-basics)
|
|
3504
|
|
3505 (defun column-number-mode (arg)
|
|
3506 "Toggle Column Number mode.
|
444
|
3507 With arg, enable Column Number mode if arg is positive, else disable.
|
428
|
3508 When Column Number mode is enabled, the column number appears
|
|
3509 in the mode line."
|
|
3510 (interactive "P")
|
|
3511 (setq column-number-mode
|
|
3512 (if (null arg) (not column-number-mode)
|
|
3513 (> (prefix-numeric-value arg) 0)))
|
|
3514 (redraw-modeline))
|
|
3515
|
|
3516
|
|
3517 (defcustom blink-matching-paren t
|
|
3518 "*Non-nil means show matching open-paren when close-paren is inserted."
|
|
3519 :type 'boolean
|
|
3520 :group 'paren-blinking)
|
|
3521
|
|
3522 (defcustom blink-matching-paren-on-screen t
|
|
3523 "*Non-nil means show matching open-paren when it is on screen.
|
|
3524 nil means don't show it (but the open-paren can still be shown
|
|
3525 when it is off screen."
|
|
3526 :type 'boolean
|
|
3527 :group 'paren-blinking)
|
|
3528
|
|
3529 (defcustom blink-matching-paren-distance 12000
|
|
3530 "*If non-nil, is maximum distance to search for matching open-paren."
|
|
3531 :type '(choice integer (const nil))
|
|
3532 :group 'paren-blinking)
|
|
3533
|
|
3534 (defcustom blink-matching-delay 1
|
|
3535 "*The number of seconds that `blink-matching-open' will delay at a match."
|
|
3536 :type 'number
|
|
3537 :group 'paren-blinking)
|
|
3538
|
|
3539 (defcustom blink-matching-paren-dont-ignore-comments nil
|
|
3540 "*Non-nil means `blink-matching-paren' should not ignore comments."
|
|
3541 :type 'boolean
|
|
3542 :group 'paren-blinking)
|
|
3543
|
|
3544 (defun blink-matching-open ()
|
|
3545 "Move cursor momentarily to the beginning of the sexp before point."
|
|
3546 (interactive "_") ; XEmacs
|
|
3547 (and (> (point) (1+ (point-min)))
|
|
3548 blink-matching-paren
|
|
3549 ;; Verify an even number of quoting characters precede the close.
|
|
3550 (= 1 (logand 1 (- (point)
|
|
3551 (save-excursion
|
446
|
3552 (backward-char 1)
|
428
|
3553 (skip-syntax-backward "/\\")
|
|
3554 (point)))))
|
|
3555 (let* ((oldpos (point))
|
|
3556 (blinkpos)
|
|
3557 (mismatch))
|
|
3558 (save-excursion
|
|
3559 (save-restriction
|
|
3560 (if blink-matching-paren-distance
|
|
3561 (narrow-to-region (max (point-min)
|
|
3562 (- (point) blink-matching-paren-distance))
|
|
3563 oldpos))
|
|
3564 (condition-case ()
|
|
3565 (let ((parse-sexp-ignore-comments
|
|
3566 (and parse-sexp-ignore-comments
|
|
3567 (not blink-matching-paren-dont-ignore-comments))))
|
|
3568 (setq blinkpos (scan-sexps oldpos -1)))
|
|
3569 (error nil)))
|
|
3570 (and blinkpos
|
|
3571 (/= (char-syntax (char-after blinkpos))
|
|
3572 ?\$)
|
|
3573 (setq mismatch
|
|
3574 (or (null (matching-paren (char-after blinkpos)))
|
|
3575 (/= (char-after (1- oldpos))
|
|
3576 (matching-paren (char-after blinkpos))))))
|
|
3577 (if mismatch (setq blinkpos nil))
|
|
3578 (if blinkpos
|
|
3579 (progn
|
|
3580 (goto-char blinkpos)
|
|
3581 (if (pos-visible-in-window-p)
|
|
3582 (and blink-matching-paren-on-screen
|
|
3583 (progn
|
|
3584 (auto-show-make-point-visible)
|
|
3585 (sit-for blink-matching-delay)))
|
|
3586 (goto-char blinkpos)
|
|
3587 (lmessage 'command "Matches %s"
|
|
3588 ;; Show what precedes the open in its line, if anything.
|
|
3589 (if (save-excursion
|
|
3590 (skip-chars-backward " \t")
|
|
3591 (not (bolp)))
|
|
3592 (buffer-substring (progn (beginning-of-line) (point))
|
|
3593 (1+ blinkpos))
|
|
3594 ;; Show what follows the open in its line, if anything.
|
|
3595 (if (save-excursion
|
|
3596 (forward-char 1)
|
|
3597 (skip-chars-forward " \t")
|
|
3598 (not (eolp)))
|
|
3599 (buffer-substring blinkpos
|
|
3600 (progn (end-of-line) (point)))
|
|
3601 ;; Otherwise show the previous nonblank line,
|
|
3602 ;; if there is one.
|
|
3603 (if (save-excursion
|
|
3604 (skip-chars-backward "\n \t")
|
|
3605 (not (bobp)))
|
|
3606 (concat
|
|
3607 (buffer-substring (progn
|
|
3608 (skip-chars-backward "\n \t")
|
|
3609 (beginning-of-line)
|
|
3610 (point))
|
|
3611 (progn (end-of-line)
|
|
3612 (skip-chars-backward " \t")
|
|
3613 (point)))
|
|
3614 ;; Replace the newline and other whitespace with `...'.
|
|
3615 "..."
|
|
3616 (buffer-substring blinkpos (1+ blinkpos)))
|
|
3617 ;; There is nothing to show except the char itself.
|
|
3618 (buffer-substring blinkpos (1+ blinkpos))))))))
|
|
3619 (cond (mismatch
|
|
3620 (display-message 'no-log "Mismatched parentheses"))
|
|
3621 ((not blink-matching-paren-distance)
|
|
3622 (display-message 'no-log "Unmatched parenthesis"))))))))
|
|
3623
|
|
3624 ;Turned off because it makes dbx bomb out.
|
|
3625 (setq blink-paren-function 'blink-matching-open)
|
|
3626
|
|
3627
|
|
3628 ;; XEmacs: Some functions moved to cmdloop.el:
|
|
3629 ;; keyboard-quit
|
|
3630 ;; buffer-quit-function
|
|
3631 ;; keyboard-escape-quit
|
|
3632
|
|
3633 (defun assoc-ignore-case (key alist)
|
|
3634 "Like `assoc', but assumes KEY is a string and ignores case when comparing."
|
801
|
3635 (assoc* key alist :test #'equalp))
|
428
|
3636
|
|
3637
|
442
|
3638 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
3639 ;; mail composition code ;;
|
|
3640 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
3641
|
428
|
3642 (defcustom mail-user-agent 'sendmail-user-agent
|
|
3643 "*Your preference for a mail composition package.
|
|
3644 Various Emacs Lisp packages (e.g. reporter) require you to compose an
|
|
3645 outgoing email message. This variable lets you specify which
|
|
3646 mail-sending package you prefer.
|
|
3647
|
|
3648 Valid values include:
|
|
3649
|
|
3650 sendmail-user-agent -- use the default Emacs Mail package
|
|
3651 mh-e-user-agent -- use the Emacs interface to the MH mail system
|
|
3652 message-user-agent -- use the GNUS mail sending package
|
|
3653
|
|
3654 Additional valid symbols may be available; check with the author of
|
|
3655 your package for details."
|
|
3656 :type '(radio (function-item :tag "Default Emacs mail"
|
|
3657 :format "%t\n"
|
|
3658 sendmail-user-agent)
|
|
3659 (function-item :tag "Gnus mail sending package"
|
|
3660 :format "%t\n"
|
|
3661 message-user-agent)
|
|
3662 (function :tag "Other"))
|
|
3663 :group 'mail)
|
|
3664
|
|
3665 (defun define-mail-user-agent (symbol composefunc sendfunc
|
|
3666 &optional abortfunc hookvar)
|
|
3667 "Define a symbol to identify a mail-sending package for `mail-user-agent'.
|
|
3668
|
|
3669 SYMBOL can be any Lisp symbol. Its function definition and/or
|
|
3670 value as a variable do not matter for this usage; we use only certain
|
|
3671 properties on its property list, to encode the rest of the arguments.
|
|
3672
|
|
3673 COMPOSEFUNC is program callable function that composes an outgoing
|
|
3674 mail message buffer. This function should set up the basics of the
|
|
3675 buffer without requiring user interaction. It should populate the
|
|
3676 standard mail headers, leaving the `to:' and `subject:' headers blank
|
|
3677 by default.
|
|
3678
|
|
3679 COMPOSEFUNC should accept several optional arguments--the same
|
|
3680 arguments that `compose-mail' takes. See that function's documentation.
|
|
3681
|
|
3682 SENDFUNC is the command a user would run to send the message.
|
|
3683
|
|
3684 Optional ABORTFUNC is the command a user would run to abort the
|
|
3685 message. For mail packages that don't have a separate abort function,
|
|
3686 this can be `kill-buffer' (the equivalent of omitting this argument).
|
|
3687
|
|
3688 Optional HOOKVAR is a hook variable that gets run before the message
|
|
3689 is actually sent. Callers that use the `mail-user-agent' may
|
|
3690 install a hook function temporarily on this hook variable.
|
|
3691 If HOOKVAR is nil, `mail-send-hook' is used.
|
|
3692
|
|
3693 The properties used on SYMBOL are `composefunc', `sendfunc',
|
|
3694 `abortfunc', and `hookvar'."
|
|
3695 (put symbol 'composefunc composefunc)
|
|
3696 (put symbol 'sendfunc sendfunc)
|
|
3697 (put symbol 'abortfunc (or abortfunc 'kill-buffer))
|
|
3698 (put symbol 'hookvar (or hookvar 'mail-send-hook)))
|
|
3699
|
|
3700 (define-mail-user-agent 'sendmail-user-agent
|
|
3701 'sendmail-user-agent-compose 'mail-send-and-exit)
|
|
3702
|
|
3703 (define-mail-user-agent 'message-user-agent
|
|
3704 'message-mail 'message-send-and-exit
|
|
3705 'message-kill-buffer 'message-send-hook)
|
|
3706
|
|
3707 (defun sendmail-user-agent-compose (&optional to subject other-headers continue
|
|
3708 switch-function yank-action
|
|
3709 send-actions)
|
|
3710 (if switch-function
|
|
3711 (let ((special-display-buffer-names nil)
|
|
3712 (special-display-regexps nil)
|
|
3713 (same-window-buffer-names nil)
|
|
3714 (same-window-regexps nil))
|
|
3715 (funcall switch-function "*mail*")))
|
|
3716 (let ((cc (cdr (assoc-ignore-case "cc" other-headers)))
|
|
3717 (in-reply-to (cdr (assoc-ignore-case "in-reply-to" other-headers))))
|
776
|
3718 (or (declare-fboundp
|
|
3719 (mail continue to subject in-reply-to cc yank-action send-actions))
|
428
|
3720 continue
|
|
3721 (error "Message aborted"))
|
|
3722 (save-excursion
|
|
3723 (goto-char (point-min))
|
776
|
3724 (search-forward (declare-boundp mail-header-separator))
|
428
|
3725 (beginning-of-line)
|
|
3726 (while other-headers
|
|
3727 (if (not (member (car (car other-headers)) '("in-reply-to" "cc")))
|
|
3728 (insert (car (car other-headers)) ": "
|
|
3729 (cdr (car other-headers)) "\n"))
|
|
3730 (setq other-headers (cdr other-headers)))
|
|
3731 t)))
|
|
3732
|
|
3733 (define-mail-user-agent 'mh-e-user-agent
|
|
3734 'mh-user-agent-compose 'mh-send-letter 'mh-fully-kill-draft
|
|
3735 'mh-before-send-letter-hook)
|
|
3736
|
|
3737 (defun compose-mail (&optional to subject other-headers continue
|
|
3738 switch-function yank-action send-actions)
|
|
3739 "Start composing a mail message to send.
|
|
3740 This uses the user's chosen mail composition package
|
|
3741 as selected with the variable `mail-user-agent'.
|
|
3742 The optional arguments TO and SUBJECT specify recipients
|
|
3743 and the initial Subject field, respectively.
|
|
3744
|
|
3745 OTHER-HEADERS is an alist specifying additional
|
|
3746 header fields. Elements look like (HEADER . VALUE) where both
|
|
3747 HEADER and VALUE are strings.
|
|
3748
|
|
3749 CONTINUE, if non-nil, says to continue editing a message already
|
|
3750 being composed.
|
|
3751
|
|
3752 SWITCH-FUNCTION, if non-nil, is a function to use to
|
|
3753 switch to and display the buffer used for mail composition.
|
|
3754
|
|
3755 YANK-ACTION, if non-nil, is an action to perform, if and when necessary,
|
|
3756 to insert the raw text of the message being replied to.
|
|
3757 It has the form (FUNCTION . ARGS). The user agent will apply
|
|
3758 FUNCTION to ARGS, to insert the raw text of the original message.
|
|
3759 \(The user agent will also run `mail-citation-hook', *after* the
|
|
3760 original text has been inserted in this way.)
|
|
3761
|
|
3762 SEND-ACTIONS is a list of actions to call when the message is sent.
|
|
3763 Each action has the form (FUNCTION . ARGS)."
|
|
3764 (interactive
|
|
3765 (list nil nil nil current-prefix-arg))
|
|
3766 (let ((function (get mail-user-agent 'composefunc)))
|
|
3767 (funcall function to subject other-headers continue
|
|
3768 switch-function yank-action send-actions)))
|
|
3769
|
|
3770 (defun compose-mail-other-window (&optional to subject other-headers continue
|
|
3771 yank-action send-actions)
|
|
3772 "Like \\[compose-mail], but edit the outgoing message in another window."
|
|
3773 (interactive
|
|
3774 (list nil nil nil current-prefix-arg))
|
|
3775 (compose-mail to subject other-headers continue
|
|
3776 'switch-to-buffer-other-window yank-action send-actions))
|
|
3777
|
|
3778
|
|
3779 (defun compose-mail-other-frame (&optional to subject other-headers continue
|
|
3780 yank-action send-actions)
|
|
3781 "Like \\[compose-mail], but edit the outgoing message in another frame."
|
|
3782 (interactive
|
|
3783 (list nil nil nil current-prefix-arg))
|
|
3784 (compose-mail to subject other-headers continue
|
|
3785 'switch-to-buffer-other-frame yank-action send-actions))
|
|
3786
|
|
3787
|
442
|
3788 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
3789 ;; set variable ;;
|
|
3790 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
3791
|
428
|
3792 (defun set-variable (var val)
|
|
3793 "Set VARIABLE to VALUE. VALUE is a Lisp object.
|
|
3794 When using this interactively, supply a Lisp expression for VALUE.
|
|
3795 If you want VALUE to be a string, you must surround it with doublequotes.
|
|
3796 If VARIABLE is a specifier, VALUE is added to it as an instantiator in
|
|
3797 the 'global locale with nil tag set (see `set-specifier').
|
|
3798
|
|
3799 If VARIABLE has a `variable-interactive' property, that is used as if
|
|
3800 it were the arg to `interactive' (which see) to interactively read the value."
|
|
3801 (interactive
|
|
3802 (let* ((var (read-variable "Set variable: "))
|
|
3803 ;; #### - yucky code replication here. This should use something
|
|
3804 ;; from help.el or hyper-apropos.el
|
|
3805 (myhelp
|
|
3806 #'(lambda ()
|
|
3807 (with-output-to-temp-buffer "*Help*"
|
|
3808 (prin1 var)
|
|
3809 (princ "\nDocumentation:\n")
|
|
3810 (princ (substring (documentation-property var 'variable-documentation)
|
|
3811 1))
|
|
3812 (if (boundp var)
|
|
3813 (let ((print-length 20))
|
|
3814 (princ "\n\nCurrent value: ")
|
|
3815 (prin1 (symbol-value var))))
|
|
3816 (save-excursion
|
|
3817 (set-buffer standard-output)
|
|
3818 (help-mode))
|
442
|
3819 nil)))
|
|
3820 (minibuffer-help-form
|
|
3821 '(funcall myhelp)))
|
428
|
3822 (list var
|
|
3823 (let ((prop (get var 'variable-interactive)))
|
|
3824 (if prop
|
|
3825 ;; Use VAR's `variable-interactive' property
|
|
3826 ;; as an interactive spec for prompting.
|
|
3827 (call-interactively (list 'lambda '(arg)
|
|
3828 (list 'interactive prop)
|
|
3829 'arg))
|
|
3830 (eval-minibuffer (format "Set %s to value: " var)))))))
|
|
3831 (if (and (boundp var) (specifierp (symbol-value var)))
|
|
3832 (set-specifier (symbol-value var) val)
|
|
3833 (set var val)))
|
442
|
3834
|
428
|
3835
|
442
|
3836 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
3837 ;; case changing code ;;
|
|
3838 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
428
|
3839
|
|
3840 ;; A bunch of stuff was moved elsewhere:
|
|
3841 ;; completion-list-mode-map
|
|
3842 ;; completion-reference-buffer
|
|
3843 ;; completion-base-size
|
|
3844 ;; delete-completion-window
|
|
3845 ;; previous-completion
|
|
3846 ;; next-completion
|
|
3847 ;; choose-completion
|
|
3848 ;; choose-completion-delete-max-match
|
|
3849 ;; choose-completion-string
|
|
3850 ;; completion-list-mode
|
|
3851 ;; completion-fixup-function
|
|
3852 ;; completion-setup-function
|
|
3853 ;; switch-to-completions
|
|
3854 ;; event stuffs
|
|
3855 ;; keypad stuffs
|
|
3856
|
|
3857 ;; The rest of this file is not in Lisp in FSF
|
|
3858 (defun capitalize-region-or-word (arg)
|
|
3859 "Capitalize the selected region or the following word (or ARG words)."
|
|
3860 (interactive "p")
|
|
3861 (if (region-active-p)
|
|
3862 (capitalize-region (region-beginning) (region-end))
|
|
3863 (capitalize-word arg)))
|
|
3864
|
|
3865 (defun upcase-region-or-word (arg)
|
|
3866 "Upcase the selected region or the following word (or ARG words)."
|
|
3867 (interactive "p")
|
|
3868 (if (region-active-p)
|
|
3869 (upcase-region (region-beginning) (region-end))
|
|
3870 (upcase-word arg)))
|
|
3871
|
|
3872 (defun downcase-region-or-word (arg)
|
|
3873 "Downcase the selected region or the following word (or ARG words)."
|
|
3874 (interactive "p")
|
|
3875 (if (region-active-p)
|
|
3876 (downcase-region (region-beginning) (region-end))
|
|
3877 (downcase-word arg)))
|
|
3878
|
442
|
3879 ;; #### not localized
|
|
3880 (defvar uncapitalized-title-words
|
|
3881 '("the" "a" "an" "in" "of" "for" "to" "and" "but" "at" "on" "as" "by"))
|
|
3882
|
|
3883 (defvar uncapitalized-title-word-regexp
|
|
3884 (concat "[ \t]*\\(" (mapconcat #'identity uncapitalized-title-words "\\|")
|
|
3885 "\\)\\>"))
|
|
3886
|
|
3887 (defun capitalize-string-as-title (string)
|
|
3888 "Capitalize the words in the string, except for small words (as in titles).
|
|
3889 The words not capitalized are specified in `uncapitalized-title-words'."
|
|
3890 (let ((buffer (get-buffer-create " *capitalize-string-as-title*")))
|
|
3891 (unwind-protect
|
|
3892 (progn
|
|
3893 (insert-string string buffer)
|
|
3894 (capitalize-region-as-title 1 (point-max buffer) buffer)
|
|
3895 (buffer-string buffer))
|
|
3896 (kill-buffer buffer))))
|
|
3897
|
|
3898 (defun capitalize-region-as-title (b e &optional buffer)
|
|
3899 "Capitalize the words in the region, except for small words (as in titles).
|
|
3900 The words not capitalized are specified in `uncapitalized-title-words'."
|
|
3901 (interactive "r")
|
|
3902 (save-excursion
|
|
3903 (and buffer
|
|
3904 (set-buffer buffer))
|
|
3905 (save-restriction
|
|
3906 (narrow-to-region b e)
|
|
3907 (goto-char (point-min))
|
|
3908 (let ((first t))
|
|
3909 (while (< (point) (point-max))
|
|
3910 (if (or first
|
|
3911 (not (looking-at uncapitalized-title-word-regexp)))
|
|
3912 (capitalize-word 1)
|
|
3913 (forward-word 1))
|
|
3914 (setq first nil))))))
|
|
3915
|
|
3916
|
|
3917 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
3918 ;; zmacs active region code ;;
|
|
3919 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
3920
|
428
|
3921 ;; Most of the zmacs code is now in elisp. The only thing left in C
|
|
3922 ;; are the variables zmacs-regions, zmacs-region-active-p and
|
|
3923 ;; zmacs-region-stays plus the function zmacs_update_region which
|
|
3924 ;; simply calls the lisp level zmacs-update-region. It must remain
|
|
3925 ;; for convenience, since it is called by core C code.
|
|
3926
|
442
|
3927 ;; XEmacs
|
|
3928 (defun activate-region ()
|
|
3929 "Activate the region, if `zmacs-regions' is true.
|
|
3930 Setting `zmacs-regions' to true causes LISPM-style active regions to be used.
|
|
3931 This function has no effect if `zmacs-regions' is false."
|
|
3932 (interactive)
|
|
3933 (and zmacs-regions (zmacs-activate-region)))
|
|
3934
|
|
3935 ;; XEmacs
|
|
3936 (defsubst region-exists-p ()
|
|
3937 "Return t if the region exists.
|
|
3938 If active regions are in use (i.e. `zmacs-regions' is true), this means that
|
|
3939 the region is active. Otherwise, this means that the user has pushed
|
|
3940 a mark in this buffer at some point in the past.
|
|
3941 The functions `region-beginning' and `region-end' can be used to find the
|
502
|
3942 limits of the region.
|
|
3943
|
|
3944 You should use this, *NOT* `region-active-p', in a menu item
|
|
3945 specification that you want grayed out when the region is not active:
|
|
3946
|
|
3947 [ ... ... :active (region-exists-p)]
|
|
3948
|
|
3949 This correctly caters to the user's setting of `zmacs-regions'."
|
442
|
3950 (not (null (mark))))
|
|
3951
|
|
3952 ;; XEmacs
|
|
3953 (defun region-active-p ()
|
|
3954 "Return non-nil if the region is active.
|
|
3955 If `zmacs-regions' is true, this is equivalent to `region-exists-p'.
|
502
|
3956 Otherwise, this function always returns false.
|
|
3957
|
|
3958 You should generally *NOT* use this in a menu item specification that you
|
|
3959 want grayed out when the region is not active. Instead, use this:
|
|
3960
|
|
3961 [ ... ... :active (region-exists-p)]
|
|
3962
|
|
3963 Which correctly caters to the user's setting of `zmacs-regions'."
|
442
|
3964 (and zmacs-regions zmacs-region-extent))
|
|
3965
|
428
|
3966 (defvar zmacs-activate-region-hook nil
|
|
3967 "Function or functions called when the region becomes active;
|
|
3968 see the variable `zmacs-regions'.")
|
|
3969
|
|
3970 (defvar zmacs-deactivate-region-hook nil
|
|
3971 "Function or functions called when the region becomes inactive;
|
|
3972 see the variable `zmacs-regions'.")
|
|
3973
|
|
3974 (defvar zmacs-update-region-hook nil
|
|
3975 "Function or functions called when the active region changes.
|
|
3976 This is called after each command that sets `zmacs-region-stays' to t.
|
|
3977 See the variable `zmacs-regions'.")
|
|
3978
|
487
|
3979 (add-hook 'zmacs-deactivate-region-hook 'disown-selection)
|
|
3980 (add-hook 'zmacs-activate-region-hook 'activate-region-as-selection)
|
|
3981 (add-hook 'zmacs-update-region-hook 'activate-region-as-selection)
|
|
3982
|
428
|
3983 (defvar zmacs-region-extent nil
|
|
3984 "The extent of the zmacs region; don't use this.")
|
|
3985
|
|
3986 (defvar zmacs-region-rectangular-p nil
|
|
3987 "Whether the zmacs region is a rectangle; don't use this.")
|
|
3988
|
|
3989 (defun zmacs-make-extent-for-region (region)
|
|
3990 ;; Given a region, this makes an extent in the buffer which holds that
|
|
3991 ;; region, for highlighting purposes. If the region isn't associated
|
|
3992 ;; with a buffer, this does nothing.
|
|
3993 (let ((buffer nil)
|
|
3994 (valid (and (extentp zmacs-region-extent)
|
|
3995 (extent-object zmacs-region-extent)
|
|
3996 (buffer-live-p (extent-object zmacs-region-extent))))
|
|
3997 start end)
|
|
3998 (cond ((consp region)
|
|
3999 (setq start (min (car region) (cdr region))
|
|
4000 end (max (car region) (cdr region))
|
|
4001 valid (and valid
|
|
4002 (eq (marker-buffer (car region))
|
|
4003 (extent-object zmacs-region-extent)))
|
|
4004 buffer (marker-buffer (car region))))
|
|
4005 (t
|
|
4006 (signal 'error (list "Invalid region" region))))
|
|
4007
|
|
4008 (if valid
|
|
4009 nil
|
|
4010 ;; The condition case is in case any of the extents are dead or
|
|
4011 ;; otherwise incapacitated.
|
|
4012 (condition-case ()
|
|
4013 (if (listp zmacs-region-extent)
|
|
4014 (mapc 'delete-extent zmacs-region-extent)
|
|
4015 (delete-extent zmacs-region-extent))
|
|
4016 (error nil)))
|
|
4017
|
|
4018 (if valid
|
|
4019 (set-extent-endpoints zmacs-region-extent start end)
|
|
4020 (setq zmacs-region-extent (make-extent start end buffer))
|
|
4021
|
|
4022 ;; Make the extent be closed on the right, which means that if
|
|
4023 ;; characters are inserted exactly at the end of the extent, the
|
|
4024 ;; extent will grow to cover them. This is important for shell
|
|
4025 ;; buffers - suppose one makes a region, and one end is at point-max.
|
|
4026 ;; If the shell produces output, that marker will remain at point-max
|
|
4027 ;; (its position will increase). So it's important that the extent
|
|
4028 ;; exhibit the same behavior, lest the region covered by the extent
|
|
4029 ;; (the visual indication), and the region between point and mark
|
|
4030 ;; (the actual region value) become different!
|
|
4031 (set-extent-property zmacs-region-extent 'end-open nil)
|
|
4032
|
|
4033 ;; use same priority as mouse-highlighting so that conflicts between
|
|
4034 ;; the region extent and a mouse-highlighted extent are resolved by
|
|
4035 ;; the usual size-and-endpoint-comparison method.
|
|
4036 (set-extent-priority zmacs-region-extent mouse-highlight-priority)
|
|
4037 (set-extent-face zmacs-region-extent 'zmacs-region)
|
|
4038
|
|
4039 ;; #### It might be better to actually break
|
|
4040 ;; default-mouse-track-next-move-rect out of mouse.el so that we
|
|
4041 ;; can use its logic here.
|
|
4042 (cond
|
|
4043 (zmacs-region-rectangular-p
|
|
4044 (setq zmacs-region-extent (list zmacs-region-extent))
|
|
4045 (default-mouse-track-next-move-rect start end zmacs-region-extent)
|
|
4046 ))
|
|
4047
|
|
4048 zmacs-region-extent)))
|
|
4049
|
|
4050 (defun zmacs-region-buffer ()
|
|
4051 "Return the buffer containing the zmacs region, or nil."
|
|
4052 ;; #### this is horrible and kludgy! This stuff needs to be rethought.
|
|
4053 (and zmacs-regions zmacs-region-active-p
|
|
4054 (or (marker-buffer (mark-marker t))
|
|
4055 (and (extent-live-p zmacs-region-extent)
|
|
4056 (buffer-live-p (extent-object zmacs-region-extent))
|
|
4057 (extent-object zmacs-region-extent)))))
|
|
4058
|
|
4059 (defun zmacs-activate-region ()
|
|
4060 "Make the region between `point' and `mark' be active (highlighted),
|
|
4061 if `zmacs-regions' is true. Only a very small number of commands
|
|
4062 should ever do this. Calling this function will call the hook
|
|
4063 `zmacs-activate-region-hook', if the region was previously inactive.
|
|
4064 Calling this function ensures that the region stays active after the
|
|
4065 current command terminates, even if `zmacs-region-stays' is not set.
|
|
4066 Returns t if the region was activated (i.e. if `zmacs-regions' if t)."
|
|
4067 (if (not zmacs-regions)
|
|
4068 nil
|
|
4069 (setq zmacs-region-active-p t
|
|
4070 zmacs-region-stays t
|
|
4071 zmacs-region-rectangular-p (and (boundp 'mouse-track-rectangle-p)
|
|
4072 mouse-track-rectangle-p))
|
|
4073 (if (marker-buffer (mark-marker t))
|
|
4074 (zmacs-make-extent-for-region (cons (point-marker t) (mark-marker t))))
|
|
4075 (run-hooks 'zmacs-activate-region-hook)
|
|
4076 t))
|
|
4077
|
|
4078 (defun zmacs-deactivate-region ()
|
|
4079 "Make the region between `point' and `mark' no longer be active,
|
|
4080 if `zmacs-regions' is true. You shouldn't need to call this; the
|
|
4081 command loop calls it when appropriate. Calling this function will
|
|
4082 call the hook `zmacs-deactivate-region-hook', if the region was
|
|
4083 previously active. Returns t if the region had been active, nil
|
|
4084 otherwise."
|
|
4085 (if (not zmacs-region-active-p)
|
|
4086 nil
|
|
4087 (setq zmacs-region-active-p nil
|
|
4088 zmacs-region-stays nil
|
|
4089 zmacs-region-rectangular-p nil)
|
|
4090 (if zmacs-region-extent
|
|
4091 (let ((inhibit-quit t))
|
|
4092 (if (listp zmacs-region-extent)
|
|
4093 (mapc 'delete-extent zmacs-region-extent)
|
|
4094 (delete-extent zmacs-region-extent))
|
|
4095 (setq zmacs-region-extent nil)))
|
|
4096 (run-hooks 'zmacs-deactivate-region-hook)
|
|
4097 t))
|
|
4098
|
|
4099 (defun zmacs-update-region ()
|
|
4100 "Update the highlighted region between `point' and `mark'.
|
|
4101 You shouldn't need to call this; the command loop calls it
|
|
4102 when appropriate. Calling this function will call the hook
|
|
4103 `zmacs-update-region-hook', if the region is active."
|
|
4104 (when zmacs-region-active-p
|
|
4105 (when (marker-buffer (mark-marker t))
|
|
4106 (zmacs-make-extent-for-region (cons (point-marker t)
|
|
4107 (mark-marker t))))
|
|
4108 (run-hooks 'zmacs-update-region-hook)))
|
|
4109
|
442
|
4110
|
|
4111 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
4112 ;; message logging code ;;
|
|
4113 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
428
|
4114
|
|
4115 ;;; #### Should this be moved to a separate file, for clarity?
|
|
4116 ;;; -hniksic
|
|
4117
|
|
4118 ;;; The `message-stack' is an alist of labels with messages; the first
|
|
4119 ;;; message in this list is always in the echo area. A call to
|
|
4120 ;;; `display-message' inserts a label/message pair at the head of the
|
|
4121 ;;; list, and removes any other pairs with that label. Calling
|
|
4122 ;;; `clear-message' causes any pair with matching label to be removed,
|
|
4123 ;;; and this may cause the displayed message to change or vanish. If
|
|
4124 ;;; the label arg is nil, the entire message stack is cleared.
|
|
4125 ;;;
|
|
4126 ;;; Message/error filtering will be a little tricker to implement than
|
|
4127 ;;; logging, since messages can be built up incrementally
|
|
4128 ;;; using clear-message followed by repeated calls to append-message
|
|
4129 ;;; (this happens with error messages). For messages which aren't
|
|
4130 ;;; created this way, filtering could be implemented at display-message
|
|
4131 ;;; very easily.
|
|
4132 ;;;
|
|
4133 ;;; Bits of the logging code are borrowed from log-messages.el by
|
|
4134 ;;; Robert Potter (rpotter@grip.cis.upenn.edu).
|
|
4135
|
|
4136 ;; need this to terminate the currently-displayed message
|
|
4137 ;; ("Loading simple ...")
|
|
4138 (when (and
|
|
4139 (not (fboundp 'display-message))
|
|
4140 (not (featurep 'debug)))
|
|
4141 (send-string-to-terminal "\n"))
|
|
4142
|
|
4143 (defvar message-stack nil
|
|
4144 "An alist of label/string pairs representing active echo-area messages.
|
|
4145 The first element in the list is currently displayed in the echo area.
|
|
4146 Do not modify this directly--use the `message' or
|
|
4147 `display-message'/`clear-message' functions.")
|
|
4148
|
|
4149 (defvar remove-message-hook 'log-message
|
|
4150 "A function or list of functions to be called when a message is removed
|
|
4151 from the echo area at the bottom of the frame. The label of the removed
|
|
4152 message is passed as the first argument, and the text of the message
|
|
4153 as the second argument.")
|
|
4154
|
|
4155 (defcustom log-message-max-size 50000
|
|
4156 "Maximum size of the \" *Message-Log*\" buffer. See `log-message'."
|
|
4157 :type 'integer
|
|
4158 :group 'log-message)
|
|
4159 (make-compatible-variable 'message-log-max 'log-message-max-size)
|
|
4160
|
|
4161 ;; We used to reject quite a lot of stuff here, but it was a bad idea,
|
|
4162 ;; for two reasons:
|
|
4163 ;;
|
|
4164 ;; a) In most circumstances, you *want* to see the message in the log.
|
|
4165 ;; The explicitly non-loggable messages should be marked as such by
|
|
4166 ;; the issuer. Gratuitous non-displaying of random regexps made
|
|
4167 ;; debugging harder, too (because various reasonable debugging
|
|
4168 ;; messages would get eaten).
|
|
4169 ;;
|
|
4170 ;; b) It slowed things down. Yes, visibly.
|
|
4171 ;;
|
|
4172 ;; So, I left only a few of the really useless ones on this kill-list.
|
|
4173 ;;
|
|
4174 ;; --hniksic
|
|
4175 (defcustom log-message-ignore-regexps
|
|
4176 '(;; Note: adding entries to this list slows down messaging
|
440
|
4177 ;; significantly. Wherever possible, use message labels.
|
428
|
4178
|
|
4179 ;; Often-seen messages
|
|
4180 "\\`\\'" ; empty message
|
|
4181 "\\`\\(Beginning\\|End\\) of buffer\\'"
|
|
4182 ;;"^Quit$"
|
|
4183 ;; completions
|
|
4184 ;; Many packages print this -- impossible to categorize
|
|
4185 ;;"^Making completion list"
|
|
4186 ;; Gnus
|
|
4187 ;; "^No news is no news$"
|
|
4188 ;; "^No more\\( unread\\)? newsgroups$"
|
|
4189 ;; "^Opening [^ ]+ server\\.\\.\\."
|
|
4190 ;; "^[^:]+: Reading incoming mail"
|
|
4191 ;; "^Getting mail from "
|
|
4192 ;; "^\\(Generating Summary\\|Sorting threads\\|Making sparse threads\\|Scoring\\|Checking new news\\|Expiring articles\\|Sending\\)\\.\\.\\."
|
|
4193 ;; "^\\(Fetching headers for\\|Retrieving newsgroup\\|Reading active file\\)"
|
|
4194 ;; "^No more\\( unread\\)? articles"
|
|
4195 ;; "^Deleting article "
|
|
4196 ;; W3
|
|
4197 ;; "^Parsed [0-9]+ of [0-9]+ ([0-9]+%)"
|
|
4198 )
|
|
4199 "List of regular expressions matching messages which shouldn't be logged.
|
|
4200 See `log-message'.
|
|
4201
|
|
4202 Ideally, packages which generate messages which might need to be ignored
|
|
4203 should label them with 'progress, 'prompt, or 'no-log, so they can be
|
|
4204 filtered by the log-message-ignore-labels."
|
|
4205 :type '(repeat regexp)
|
|
4206 :group 'log-message)
|
|
4207
|
|
4208 (defcustom log-message-ignore-labels
|
|
4209 '(help-echo command progress prompt no-log garbage-collecting auto-saving)
|
|
4210 "List of symbols indicating labels of messages which shouldn't be logged.
|
|
4211 See `display-message' for some common labels. See also `log-message'."
|
|
4212 :type '(repeat (symbol :tag "Label"))
|
|
4213 :group 'log-message)
|
|
4214
|
|
4215 ;;Subsumed by view-lossage
|
|
4216 ;; Not really, I'm adding it back by popular demand. -slb
|
|
4217 (defun show-message-log ()
|
|
4218 "Show the \" *Message-Log*\" buffer, which contains old messages and errors."
|
|
4219 (interactive)
|
793
|
4220 (view-lossage t))
|
428
|
4221
|
|
4222 (defvar log-message-filter-function 'log-message-filter
|
|
4223 "Value must be a function of two arguments: a symbol (label) and
|
|
4224 a string (message). It should return non-nil to indicate a message
|
|
4225 should be logged. Possible values include 'log-message-filter and
|
|
4226 'log-message-filter-errors-only.")
|
|
4227
|
|
4228 (defun log-message-filter (label message)
|
|
4229 "Default value of `log-message-filter-function'.
|
|
4230 Messages whose text matches one of the `log-message-ignore-regexps'
|
|
4231 or whose label appears in `log-message-ignore-labels' are not saved."
|
|
4232 (let ((r log-message-ignore-regexps)
|
|
4233 (ok (not (memq label log-message-ignore-labels))))
|
|
4234 (save-match-data
|
|
4235 (while (and r ok)
|
|
4236 (when (string-match (car r) message)
|
|
4237 (setq ok nil))
|
|
4238 (setq r (cdr r))))
|
|
4239 ok))
|
|
4240
|
|
4241 (defun log-message-filter-errors-only (label message)
|
|
4242 "For use as the `log-message-filter-function'. Only logs error messages."
|
|
4243 (eq label 'error))
|
|
4244
|
|
4245 (defun log-message (label message)
|
|
4246 "Stuff a copy of the message into the \" *Message-Log*\" buffer,
|
|
4247 if it satisfies the `log-message-filter-function'.
|
|
4248
|
|
4249 For use on `remove-message-hook'."
|
|
4250 (when (and (not noninteractive)
|
|
4251 (funcall log-message-filter-function label message))
|
|
4252 ;; Use save-excursion rather than save-current-buffer because we
|
|
4253 ;; change the value of point.
|
|
4254 (save-excursion
|
|
4255 (set-buffer (get-buffer-create " *Message-Log*"))
|
|
4256 (goto-char (point-max))
|
|
4257 ;(insert (concat (upcase (symbol-name label)) ": " message "\n"))
|
|
4258 (let (extent)
|
|
4259 ;; Mark multiline message with an extent, which `view-lossage'
|
|
4260 ;; will recognize.
|
793
|
4261 (save-match-data
|
|
4262 (when (string-match "\n" message)
|
|
4263 (setq extent (make-extent (point) (point)))
|
|
4264 (set-extent-properties extent '(end-open nil message-multiline t)))
|
|
4265 )
|
428
|
4266 (insert message "\n")
|
|
4267 (when extent
|
|
4268 (set-extent-property extent 'end-open t)))
|
|
4269 (when (> (point-max) (max log-message-max-size (point-min)))
|
|
4270 ;; Trim log to ~90% of max size.
|
|
4271 (goto-char (max (- (point-max)
|
|
4272 (truncate (* 0.9 log-message-max-size)))
|
|
4273 (point-min)))
|
|
4274 (forward-line 1)
|
|
4275 (delete-region (point-min) (point))))))
|
|
4276
|
|
4277 (defun message-displayed-p (&optional return-string frame)
|
|
4278 "Return a non-nil value if a message is presently displayed in the\n\
|
|
4279 minibuffer's echo area. If optional argument RETURN-STRING is non-nil,\n\
|
|
4280 return a string containing the message, otherwise just return t."
|
|
4281 ;; by definition, a message is displayed if the echo area buffer is
|
|
4282 ;; non-empty (see also echo_area_active()). It had better also
|
|
4283 ;; be the case that message-stack is nil exactly when the echo area
|
|
4284 ;; is non-empty.
|
|
4285 (let ((buffer (get-buffer " *Echo Area*")))
|
|
4286 (and (< (point-min buffer) (point-max buffer))
|
|
4287 (if return-string
|
|
4288 (buffer-substring nil nil buffer)
|
|
4289 t))))
|
|
4290
|
|
4291 ;;; Returns the string which remains in the echo area, or nil if none.
|
|
4292 ;;; If label is nil, the whole message stack is cleared.
|
|
4293 (defun clear-message (&optional label frame stdout-p no-restore)
|
|
4294 "Remove any message with the given LABEL from the message-stack,
|
|
4295 erasing it from the echo area if it's currently displayed there.
|
|
4296 If a message remains at the head of the message-stack and NO-RESTORE
|
|
4297 is nil, it will be displayed. The string which remains in the echo
|
|
4298 area will be returned, or nil if the message-stack is now empty.
|
|
4299 If LABEL is nil, the entire message-stack is cleared.
|
|
4300
|
|
4301 Unless you need the return value or you need to specify a label,
|
|
4302 you should just use (message nil)."
|
|
4303 (or frame (setq frame (selected-frame)))
|
|
4304 (let ((clear-stream (and message-stack (eq 'stream (frame-type frame)))))
|
|
4305 (remove-message label frame)
|
502
|
4306 (let ((inhibit-read-only t))
|
428
|
4307 (erase-buffer " *Echo Area*"))
|
|
4308 (if clear-stream
|
|
4309 (send-string-to-terminal ?\n stdout-p))
|
|
4310 (if no-restore
|
|
4311 nil ; just preparing to put another msg up
|
|
4312 (if message-stack
|
|
4313 (let ((oldmsg (cdr (car message-stack))))
|
|
4314 (raw-append-message oldmsg frame stdout-p)
|
|
4315 oldmsg)
|
|
4316 ;; #### Should we (redisplay-echo-area) here? Messes some
|
|
4317 ;; things up.
|
|
4318 nil))))
|
|
4319
|
|
4320 (defun remove-message (&optional label frame)
|
|
4321 ;; If label is nil, we want to remove all matching messages.
|
|
4322 ;; Must reverse the stack first to log them in the right order.
|
|
4323 (let ((log nil))
|
|
4324 (while (and message-stack
|
|
4325 (or (null label) ; null label means clear whole stack
|
|
4326 (eq label (car (car message-stack)))))
|
|
4327 (push (car message-stack) log)
|
|
4328 (setq message-stack (cdr message-stack)))
|
|
4329 (let ((s message-stack))
|
|
4330 (while (cdr s)
|
|
4331 (let ((msg (car (cdr s))))
|
|
4332 (if (eq label (car msg))
|
|
4333 (progn
|
|
4334 (push msg log)
|
|
4335 (setcdr s (cdr (cdr s))))
|
|
4336 (setq s (cdr s))))))
|
|
4337 ;; (possibly) log each removed message
|
|
4338 (while log
|
793
|
4339 (with-trapping-errors
|
|
4340 :operation 'remove-message-hook
|
|
4341 :class 'message-log
|
|
4342 :error-form (progn
|
|
4343 (setq remove-message-hook nil)
|
|
4344 (let ((inhibit-read-only t))
|
|
4345 (erase-buffer " *Echo Area*")))
|
|
4346 :resignal t
|
|
4347 (run-hook-with-args 'remove-message-hook
|
|
4348 (car (car log)) (cdr (car log))))
|
428
|
4349 (setq log (cdr log)))))
|
|
4350
|
|
4351 (defun append-message (label message &optional frame stdout-p)
|
|
4352 (or frame (setq frame (selected-frame)))
|
|
4353 ;; Add a new entry to the message-stack, or modify an existing one
|
|
4354 (let ((top (car message-stack)))
|
|
4355 (if (eq label (car top))
|
|
4356 (setcdr top (concat (cdr top) message))
|
|
4357 (push (cons label message) message-stack)))
|
|
4358 (raw-append-message message frame stdout-p))
|
|
4359
|
|
4360 ;; Really append the message to the echo area. no fiddling with
|
|
4361 ;; message-stack.
|
|
4362 (defun raw-append-message (message &optional frame stdout-p)
|
|
4363 (unless (equal message "")
|
502
|
4364 (let ((inhibit-read-only t))
|
428
|
4365 (insert-string message " *Echo Area*")
|
|
4366 ;; Conditionalizing on the device type in this way is not that clean,
|
|
4367 ;; but neither is having a device method, as I originally implemented
|
|
4368 ;; it: all non-stream devices behave in the same way. Perhaps
|
|
4369 ;; the cleanest way is to make the concept of a "redisplayable"
|
|
4370 ;; device, which stream devices are not. Look into this more if
|
|
4371 ;; we ever create another non-redisplayable device type (e.g.
|
|
4372 ;; processes? printers?).
|
|
4373
|
|
4374 ;; Don't redisplay the echo area if we are executing a macro.
|
|
4375 (if (not executing-kbd-macro)
|
|
4376 (if (eq 'stream (frame-type frame))
|
|
4377 (send-string-to-terminal message stdout-p (frame-device frame))
|
|
4378 (redisplay-echo-area))))))
|
|
4379
|
|
4380 (defun display-message (label message &optional frame stdout-p)
|
|
4381 "Print a one-line message at the bottom of the frame. First argument
|
|
4382 LABEL is an identifier for this message. MESSAGE is the string to display.
|
|
4383 Use `clear-message' to remove a labelled message.
|
|
4384
|
|
4385 Here are some standard labels (those marked with `*' are not logged
|
|
4386 by default--see the `log-message-ignore-labels' variable):
|
|
4387 message default label used by the `message' function
|
|
4388 error default label used for reporting errors
|
|
4389 * progress progress indicators like \"Converting... 45%\"
|
|
4390 * prompt prompt-like messages like \"I-search: foo\"
|
|
4391 * command helper command messages like \"Mark set\"
|
|
4392 * no-log messages that should never be logged"
|
|
4393 (clear-message label frame stdout-p t)
|
|
4394 (append-message label message frame stdout-p))
|
|
4395
|
|
4396 (defun current-message (&optional frame)
|
|
4397 "Return the current message in the echo area, or nil.
|
|
4398 The FRAME argument is currently unused."
|
|
4399 (cdr (car message-stack)))
|
|
4400
|
|
4401 ;;; may eventually be frame-dependent
|
|
4402 (defun current-message-label (&optional frame)
|
|
4403 (car (car message-stack)))
|
|
4404
|
|
4405 (defun message (fmt &rest args)
|
|
4406 "Print a one-line message at the bottom of the frame.
|
|
4407 The arguments are the same as to `format'.
|
|
4408
|
|
4409 If the only argument is nil, clear any existing message; let the
|
|
4410 minibuffer contents show."
|
|
4411 ;; questionable junk in the C code
|
|
4412 ;; (if (framep default-minibuffer-frame)
|
|
4413 ;; (make-frame-visible default-minibuffer-frame))
|
|
4414 (if (and (null fmt) (null args))
|
|
4415 (prog1 nil
|
|
4416 (clear-message nil))
|
|
4417 (let ((str (apply 'format fmt args)))
|
|
4418 (display-message 'message str)
|
|
4419 str)))
|
|
4420
|
|
4421 (defun lmessage (label fmt &rest args)
|
|
4422 "Print a one-line message at the bottom of the frame.
|
|
4423 First argument LABEL is an identifier for this message. The rest of the
|
|
4424 arguments are the same as to `format'.
|
|
4425
|
|
4426 See `display-message' for a list of standard labels."
|
|
4427 (if (and (null fmt) (null args))
|
|
4428 (prog1 nil
|
|
4429 (clear-message label nil))
|
|
4430 (let ((str (apply 'format fmt args)))
|
|
4431 (display-message label str)
|
|
4432 str)))
|
|
4433
|
442
|
4434
|
|
4435 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
4436 ;; warning code ;;
|
|
4437 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
428
|
4438
|
|
4439 (defcustom log-warning-minimum-level 'info
|
|
4440 "Minimum level of warnings that should be logged.
|
|
4441 The warnings in levels below this are completely ignored, as if they never
|
|
4442 happened.
|
|
4443
|
|
4444 The recognized warning levels, in decreasing order of priority, are
|
793
|
4445 'emergency, 'critical, 'error, 'warning, 'alert, 'notice, 'info, and
|
428
|
4446 'debug.
|
|
4447
|
|
4448 See also `display-warning-minimum-level'.
|
|
4449
|
|
4450 You can also control which warnings are displayed on a class-by-class
|
|
4451 basis. See `display-warning-suppressed-classes' and
|
793
|
4452 `log-warning-suppressed-classes'.
|
|
4453
|
|
4454 For a description of the meaning of the levels, see `display-warning.'"
|
|
4455 :type '(choice (const emergency) (const critical)
|
|
4456 (const error) (const warning) (const alert) (const notice)
|
428
|
4457 (const info) (const debug))
|
|
4458 :group 'warnings)
|
|
4459
|
793
|
4460 (defcustom display-warning-minimum-level 'warning
|
|
4461 "Minimum level of warnings that cause the warnings buffer to be displayed.
|
|
4462 Warnings at this level or higher will force the *Warnings* buffer, in which
|
|
4463 the warnings are logged, to be displayed. The warnings in levels below
|
|
4464 this, but at least as high as `log-warning-suppressed-classes', will be
|
|
4465 shown in the minibuffer.
|
428
|
4466
|
|
4467 The recognized warning levels, in decreasing order of priority, are
|
793
|
4468 'emergency, 'critical, 'error, 'warning, 'alert, 'notice, 'info, and
|
428
|
4469 'debug.
|
|
4470
|
|
4471 See also `log-warning-minimum-level'.
|
|
4472
|
|
4473 You can also control which warnings are displayed on a class-by-class
|
|
4474 basis. See `display-warning-suppressed-classes' and
|
793
|
4475 `log-warning-suppressed-classes'.
|
|
4476
|
|
4477 For a description of the meaning of the levels, see `display-warning.'"
|
|
4478 :type '(choice (const emergency) (const critical)
|
|
4479 (const error) (const warning) (const alert) (const notice)
|
428
|
4480 (const info) (const debug))
|
|
4481 :group 'warnings)
|
|
4482
|
|
4483 (defvar log-warning-suppressed-classes nil
|
|
4484 "List of classes of warnings that shouldn't be logged or displayed.
|
|
4485 If any of the CLASS symbols associated with a warning is the same as
|
|
4486 any of the symbols listed here, the warning will be completely ignored,
|
|
4487 as it they never happened.
|
|
4488
|
|
4489 NOTE: In most circumstances, you should *not* set this variable.
|
|
4490 Set `display-warning-suppressed-classes' instead. That way the suppressed
|
|
4491 warnings are not displayed but are still unobtrusively logged.
|
|
4492
|
|
4493 See also `log-warning-minimum-level' and `display-warning-minimum-level'.")
|
|
4494
|
|
4495 (defcustom display-warning-suppressed-classes nil
|
|
4496 "List of classes of warnings that shouldn't be displayed.
|
|
4497 If any of the CLASS symbols associated with a warning is the same as
|
|
4498 any of the symbols listed here, the warning will not be displayed.
|
|
4499 The warning will still logged in the *Warnings* buffer (unless also
|
|
4500 contained in `log-warning-suppressed-classes'), but the buffer will
|
|
4501 not be automatically popped up.
|
|
4502
|
|
4503 See also `log-warning-minimum-level' and `display-warning-minimum-level'."
|
|
4504 :type '(repeat symbol)
|
|
4505 :group 'warnings)
|
|
4506
|
|
4507 (defvar warning-count 0
|
|
4508 "Count of the number of warning messages displayed so far.")
|
|
4509
|
|
4510 (defconst warning-level-alist '((emergency . 8)
|
793
|
4511 (critical . 7)
|
|
4512 (error . 6)
|
|
4513 (warning . 5)
|
|
4514 (alert . 4)
|
428
|
4515 (notice . 3)
|
|
4516 (info . 2)
|
|
4517 (debug . 1)))
|
|
4518
|
|
4519 (defun warning-level-p (level)
|
|
4520 "Non-nil if LEVEL specifies a warning level."
|
|
4521 (and (symbolp level) (assq level warning-level-alist)))
|
|
4522
|
793
|
4523 (defun warning-level-< (level1 level2)
|
|
4524 "Non-nil if warning level LEVEL1 is lower than LEVEL2."
|
|
4525 (check-argument-type 'warning-level-p level1)
|
|
4526 (check-argument-type 'warning-level-p level2)
|
|
4527 (< (cdr (assq level1 warning-level-alist))
|
|
4528 (cdr (assq level2 warning-level-alist))))
|
|
4529
|
428
|
4530 ;; If you're interested in rewriting this function, be aware that it
|
|
4531 ;; could be called at arbitrary points in a Lisp program (when a
|
|
4532 ;; built-in function wants to issue a warning, it will call out to
|
|
4533 ;; this function the next time some Lisp code is evaluated). Therefore,
|
|
4534 ;; this function *must* not permanently modify any global variables
|
|
4535 ;; (e.g. the current buffer) except those that specifically apply
|
|
4536 ;; to the warning system.
|
|
4537
|
|
4538 (defvar before-init-deferred-warnings nil)
|
|
4539
|
|
4540 (defun after-init-display-warnings ()
|
|
4541 "Display warnings deferred till after the init file is run.
|
|
4542 Warnings that occur before then are deferred so that warning
|
|
4543 suppression in the .emacs file will be honored."
|
|
4544 (while before-init-deferred-warnings
|
|
4545 (apply 'display-warning (car before-init-deferred-warnings))
|
|
4546 (setq before-init-deferred-warnings
|
|
4547 (cdr before-init-deferred-warnings))))
|
|
4548
|
|
4549 (add-hook 'after-init-hook 'after-init-display-warnings)
|
|
4550
|
|
4551 (defun display-warning (class message &optional level)
|
|
4552 "Display a warning message.
|
793
|
4553
|
|
4554 \[This is the most basic entry point for displaying a warning. In practice,
|
|
4555 `lwarn' or `warn' are probably more convenient for most usages.]
|
|
4556
|
|
4557 CLASS should be a symbol describing what sort of warning this is, such as
|
|
4558 `resource' or `key-mapping' -- this refers, more or less, to the module in
|
|
4559 which the warning is generated and serves to group warnings together with
|
|
4560 similar semantics. A list of such symbols is also accepted.
|
|
4561
|
|
4562 Optional argument LEVEL can be used to specify a priority for the warning,
|
|
4563 other than default priority `warning'. The currently defined levels are,
|
|
4564 from highest to lowest:
|
|
4565
|
|
4566 Level Meaning
|
|
4567 -----------------------------------------------------------------------------
|
|
4568 emergency A fatal or near-fatal error. XEmacs is likely to crash.
|
|
4569
|
|
4570 critical A serious, nonrecoverable problem has occurred -- e.g., the
|
|
4571 loss of a major subsystem, such as the crash of the X server
|
|
4572 when XEmacs is connected to the server.
|
|
4573
|
|
4574 error A warning about a problematic condition that should be fixed,
|
|
4575 and XEmacs cannot work around it -- it causes a failure of an
|
|
4576 operation. (In most circumstances, consider just signalling
|
|
4577 an error). However, there is no permanent damage and the
|
|
4578 situation is ultimately recoverable.
|
|
4579
|
|
4580 warning A warning about a problematic condition that should be fixed,
|
|
4581 but XEmacs can work around it.
|
|
4582
|
|
4583 \[By default, warnings above here, as well as being logged, cause the
|
|
4584 *Warnings* buffer to be forcibly displayed, so that the warning (and
|
|
4585 previous warnings, since often a whole series of warnings are issued at
|
|
4586 once) can be examined in detail. Also, the annoying presence of the
|
|
4587 *Warnings* buffer will encourage people to go out and fix the
|
|
4588 problem. Warnings below here are displayed in the minibuffer as well as
|
|
4589 logged in the *Warnings* buffer. but the *Warnings* buffer will not be
|
|
4590 forcibly shown, as these represent conditions the user is not expected to
|
|
4591 fix.]
|
|
4592
|
|
4593 alert A warning about a problematic condition that can't easily be
|
|
4594 fixed (often having to do with the external environment), and
|
|
4595 causes a failure. We don't force the *Warnings* buffer to be
|
|
4596 displayed because the purpose of doing that is to force the
|
|
4597 user to fix the problem so that the buffer no longer appears.
|
|
4598 When the problem is outside the user's control, forcing the
|
|
4599 buffer is pointless and annoying.
|
|
4600
|
|
4601 notice A warning about a problematic condition that can't easily be
|
|
4602 fixed (often having to do with the external environment),
|
|
4603 but XEmacs can work around it.
|
|
4604
|
|
4605 info Random info about something new or unexpected that was noticed;
|
|
4606 does not generally indicate a problem.
|
|
4607
|
|
4608 \[By default, warnings below here are ignored entirely. All warnings above
|
|
4609 here are logged in the *Warnings* buffer.]
|
|
4610
|
|
4611 debug A debugging notice; normally, not seen at all.
|
|
4612
|
|
4613 NOTE: `specifier-instance' outputs warnings at level `debug' when errors occur
|
|
4614 in the process of trying to instantiate a particular instantiator. If you
|
|
4615 want to see these, change `log-warning-minimum-level'.
|
|
4616
|
|
4617 There are two sets of variables. One controls the lower level (see the
|
|
4618 above diagram) -- i.e. ignored entirely. One controls the upper level --
|
|
4619 whether the *Warnings* buffer is forcibly displayed. In particular:
|
|
4620
|
|
4621 `display-warning-minimum-level' sets the upper level (see above), and
|
|
4622 `log-warning-minimum-level' the lower level.
|
|
4623
|
|
4624 Individual classes can be suppressed. `log-warning-suppressed-classes'
|
|
4625 specifies a list of classes where warnings on those classes will be treated
|
|
4626 as if their level is below `log-warning-minimum-level' (i.e. they will be
|
|
4627 ignored completely), regardless of their actual level. Similarly,
|
|
4628 `display-warning-suppressed-classes' specifies a list of classes where
|
|
4629 warnings on those classes will be treated as if their level is below
|
|
4630 `display-warning-minimum-level', but above `log-warning-minimum-level' so
|
|
4631 long as they're not listed in that variable as well."
|
428
|
4632 (or level (setq level 'warning))
|
|
4633 (or (listp class) (setq class (list class)))
|
|
4634 (check-argument-type 'warning-level-p level)
|
|
4635 (if (and (not (featurep 'infodock))
|
|
4636 (not init-file-loaded))
|
|
4637 (push (list class message level) before-init-deferred-warnings)
|
|
4638 (catch 'ignored
|
|
4639 (let ((display-p t)
|
|
4640 (level-num (cdr (assq level warning-level-alist))))
|
|
4641 (if (< level-num (cdr (assq log-warning-minimum-level
|
|
4642 warning-level-alist)))
|
|
4643 (throw 'ignored nil))
|
|
4644 (if (intersection class log-warning-suppressed-classes)
|
|
4645 (throw 'ignored nil))
|
|
4646
|
|
4647 (if (< level-num (cdr (assq display-warning-minimum-level
|
|
4648 warning-level-alist)))
|
|
4649 (setq display-p nil))
|
|
4650 (if (and display-p
|
|
4651 (intersection class display-warning-suppressed-classes))
|
|
4652 (setq display-p nil))
|
|
4653 (let ((buffer (get-buffer-create "*Warnings*")))
|
|
4654 (when display-p
|
|
4655 ;; The C code looks at display-warning-tick to determine
|
|
4656 ;; when it should call `display-warning-buffer'. Change it
|
|
4657 ;; to get the C code's attention.
|
|
4658 (incf display-warning-tick))
|
|
4659 (with-current-buffer buffer
|
|
4660 (goto-char (point-max))
|
|
4661 (incf warning-count)
|
793
|
4662 (let ((start (point)))
|
|
4663 (princ (format "(%d) (%s/%s) "
|
|
4664 warning-count
|
|
4665 (mapconcat 'symbol-name class ",")
|
|
4666 level)
|
|
4667 buffer)
|
|
4668 (princ message buffer)
|
|
4669 (terpri buffer)
|
|
4670 (terpri buffer)
|
|
4671 (let ((ex (make-extent start (point))))
|
|
4672 (set-extent-properties ex
|
|
4673 `(warning t warning-count ,warning-count
|
|
4674 warning-class ,class
|
|
4675 warning-level ,level)))))
|
|
4676 (message "%s: %s" (capitalize (symbol-name level)) message))))))
|
428
|
4677
|
|
4678 (defun warn (&rest args)
|
793
|
4679 "Display a formatted warning message at default class and level.
|
428
|
4680 The message is constructed by passing all args to `format'. The message
|
|
4681 is placed in the *Warnings* buffer, which will be popped up at the next
|
793
|
4682 redisplay. The class of the warning is `general'; the level is `warning'.
|
|
4683
|
|
4684 See `display-warning' for more info."
|
|
4685 (display-warning 'default (apply 'format args)))
|
428
|
4686
|
|
4687 (defun lwarn (class level &rest args)
|
793
|
4688 "Display a formatted warning message at specified class and level.
|
|
4689 The message is constructed by passing all args to `format'. The message
|
|
4690 is placed in the *Warnings* buffer, which will be popped up at the next
|
|
4691 redisplay.
|
|
4692
|
|
4693 See `display-warning' for more info."
|
428
|
4694 (display-warning class (apply 'format args)
|
|
4695 (or level 'warning)))
|
|
4696
|
|
4697 (defvar warning-marker nil)
|
|
4698
|
|
4699 ;; When this function is called by the C code, all non-local exits are
|
|
4700 ;; trapped and C-g is inhibited; therefore, it would be a very, very
|
|
4701 ;; bad idea for this function to get into an infinite loop.
|
|
4702
|
|
4703 (defun display-warning-buffer ()
|
|
4704 "Make the buffer that contains the warnings be visible.
|
|
4705 The C code calls this periodically, right before redisplay."
|
|
4706 (let ((buffer (get-buffer-create "*Warnings*")))
|
|
4707 (when (or (not warning-marker)
|
|
4708 (not (eq (marker-buffer warning-marker) buffer)))
|
|
4709 (setq warning-marker (make-marker))
|
|
4710 (set-marker warning-marker 1 buffer))
|
|
4711 (if temp-buffer-show-function
|
442
|
4712 (progn
|
|
4713 (funcall temp-buffer-show-function buffer)
|
|
4714 (mapc #'(lambda (win) (set-window-start win warning-marker))
|
|
4715 (windows-of-buffer buffer nil t)))
|
428
|
4716 (set-window-start (display-buffer buffer) warning-marker))
|
|
4717 (set-marker warning-marker (point-max buffer) buffer)))
|
|
4718
|
442
|
4719
|
|
4720 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
4721 ;; misc junk ;;
|
|
4722 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
4723
|
428
|
4724 (defun emacs-name ()
|
|
4725 "Return the printable name of this instance of Emacs."
|
|
4726 (cond ((featurep 'infodock) "InfoDock")
|
|
4727 ((featurep 'xemacs) "XEmacs")
|
|
4728 (t "Emacs")))
|
|
4729
|
793
|
4730 (defun debug-print-1 (&rest args)
|
|
4731 "Send a debugging-type string to standard output.
|
|
4732 If the first argument is a string, it is considered to be a format
|
|
4733 specifier if there are sufficient numbers of other args, and the string is
|
|
4734 formatted using (apply #'format args). Otherwise, each argument is printed
|
|
4735 individually in a numbered list."
|
|
4736 (let ((standard-output 'external-debugging-output)
|
|
4737 (fmt (condition-case nil
|
|
4738 (and (stringp (first args))
|
|
4739 (apply #'format args))
|
|
4740 (error nil))))
|
|
4741 (if fmt
|
|
4742 (progn
|
|
4743 (prin1 (apply #'format args))
|
|
4744 (terpri))
|
|
4745 (princ "--> ")
|
|
4746 (let ((i 1))
|
|
4747 (dolist (sgra args)
|
|
4748 (if (> i 1) (princ " "))
|
|
4749 (princ (format "%d. " i))
|
|
4750 (prin1 sgra)
|
|
4751 (incf i))
|
|
4752 (terpri)))))
|
|
4753
|
|
4754 (defun debug-print (&rest args)
|
442
|
4755 "Send a string to the debugging output.
|
793
|
4756 If the first argument is a string, it is considered to be a format
|
|
4757 specifier if there are sufficient numbers of other args, and the string is
|
|
4758 formatted using (apply #'format args). Otherwise, each argument is printed
|
|
4759 individually in a numbered list."
|
|
4760 (let ((standard-output 'external-debugging-output))
|
|
4761 (apply #'debug-print-1 args)))
|
|
4762
|
|
4763 (defun debug-backtrace ()
|
|
4764 "Send a backtrace to the debugging output."
|
|
4765 (let ((standard-output 'external-debugging-output))
|
|
4766 (backtrace nil t)
|
|
4767 (terpri)))
|
444
|
4768
|
428
|
4769 ;;; simple.el ends here
|