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