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