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