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