annotate lisp/prim/simple.el @ 195:a2f645c6b9f8 r20-3b24

Import from CVS: tag r20-3b24
author cvs
date Mon, 13 Aug 2007 09:59:05 +0200
parents f53b5ca2e663
children 169c0442b401
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; simple.el --- basic editing commands for XEmacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Copyright (C) 1985, 1986, 1987, 1993-1995 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; Copyright (C) 1995 Tinker Systems and INS Engineering Corp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; You should have received a copy of the GNU General Public License
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
19 ;; along with XEmacs; see the file COPYING. If not, write to the Free
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
20 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
21 ;; 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
23 ;;; Synched up with: FSF 19.34 [But not very closely].
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;; A grab-bag of basic XEmacs commands not specifically related to some
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;; major mode or to file-handling.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
30 ;; Changes for zmacs-style active-regions:
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
31 ;;
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
32 ;; beginning-of-buffer, end-of-buffer, count-lines-region,
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
33 ;; count-lines-buffer, what-line, what-cursor-position, set-goal-column,
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
34 ;; set-fill-column, prefix-arg-internal, and line-move (which is used by
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
35 ;; next-line and previous-line) set zmacs-region-stays to t, so that they
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
36 ;; don't affect the current region-hilighting state.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
37 ;;
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
38 ;; mark-whole-buffer, mark-word, exchange-point-and-mark, and
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
39 ;; set-mark-command (without an argument) call zmacs-activate-region.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
40 ;;
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
41 ;; mark takes an optional arg like the new Fmark_marker() does. When
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
42 ;; the region is not active, mark returns nil unless the optional arg is true.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
43 ;;
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
44 ;; push-mark, pop-mark, exchange-point-and-mark, and set-marker, and
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
45 ;; set-mark-command use (mark t) so that they can access the mark whether
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
46 ;; the region is active or not.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
47 ;;
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
48 ;; shell-command, shell-command-on-region, yank, and yank-pop (which all
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
49 ;; push a mark) have been altered to call exchange-point-and-mark with an
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
50 ;; argument, meaning "don't activate the region". These commands only use
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
51 ;; exchange-point-and-mark to position the newly-pushed mark correctly, so
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
52 ;; this isn't a user-visible change. These functions have also been altered
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
53 ;; to use (mark t) for the same reason.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
55 ;; 97/3/14 Jareth Hein (jhod@po.iijnet.or.jp) added kinsoku processing (support
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
56 ;; for filling of Asian text) into the fill code. This was ripped bleeding from
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
57 ;; Mule-2.3, and could probably use some feature additions (like additional wrap
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
58 ;; styles, etc)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
59
159
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
60 ;; 97/06/11 Steve Baur (steve@altair.xemacs.org) Convert use of
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
61 ;; (preceding|following)-char to char-(after|before).
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
62
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
65 (defgroup editing-basics nil
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 159
diff changeset
66 "Most basic editing variables."
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
67 :group 'editing)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
68
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
69 (defgroup killing nil
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 159
diff changeset
70 "Killing and yanking commands."
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
71 :group 'editing)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
72
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 159
diff changeset
73 (defgroup fill-comments nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 159
diff changeset
74 "Indenting and filling of comments."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 159
diff changeset
75 :prefix "comment-"
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 159
diff changeset
76 :group 'fill)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 159
diff changeset
77
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
78 (defgroup paren-matching nil
126
1370575f1259 Import from CVS: tag xemacs-20-1p1
cvs
parents: 124
diff changeset
79 "Highlight (un)matching of parens and expressions."
1370575f1259 Import from CVS: tag xemacs-20-1p1
cvs
parents: 124
diff changeset
80 :prefix "paren-"
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
81 :group 'matching)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
82
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
83
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (defun newline (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 "Insert a newline, and move to left margin of the new line if it's blank.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 The newline is marked with the text-property `hard'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 With arg, insert that many newlines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 In Auto Fill mode, if no numeric arg, break the preceding line if it's long."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (interactive "*P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (barf-if-buffer-read-only nil (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 ;; Inserting a newline at the end of a line produces better redisplay in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 ;; try_window_id than inserting at the beginning of a line, and the textual
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 ;; result is the same. So, if we're at beginning of line, pretend to be at
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 ;; the end of the previous line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (let ((flag (and (not (bobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (bolp)
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
97 ;; Make sure the newline before point isn't intangible.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
98 (not (get-char-property (1- (point)) 'intangible))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
99 ;; Make sure the newline before point isn't read-only.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
100 (not (get-char-property (1- (point)) 'read-only))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
101 ;; Make sure the newline before point isn't invisible.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
102 (not (get-char-property (1- (point)) 'invisible))
104
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 100
diff changeset
103 ;; This should probably also test for the previous char
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 100
diff changeset
104 ;; being the *last* character too.
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 100
diff changeset
105 (not (get-char-property (1- (point)) 'end-open))
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
106 ;; Make sure the newline before point has the same
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
107 ;; properties as the char before it (if any).
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (< (or (previous-extent-change (point)) -2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (- (point) 2))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (was-page-start (and (bolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (looking-at page-delimiter)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (beforepos (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (if flag (backward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 ;; Call self-insert so that auto-fill, abbrev expansion etc. happens.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 ;; Set last-command-char to tell self-insert what to insert.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (let ((last-command-char ?\n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 ;; Don't auto-fill if we have a numeric argument.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 ;; Also not if flag is true (it would fill wrong line);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 ;; there is no need to since we're at BOL.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (auto-fill-function (if (or arg flag) nil auto-fill-function)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (self-insert-command (prefix-numeric-value arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 ;; If we get an error in self-insert-command, put point at right place.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (if flag (forward-char 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 ;; If we did *not* get an error, cancel that forward-char.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (if flag (backward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 ;; Mark the newline(s) `hard'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (if use-hard-newlines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (let* ((from (- (point) (if arg (prefix-numeric-value arg) 1)))
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
130 (sticky (get-text-property from 'end-open))) ; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (put-text-property from (point) 'hard 't)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 ;; If end-open is not "t", add 'hard to end-open list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (if (and (listp sticky) (not (memq 'hard sticky)))
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
134 (put-text-property from (point) 'end-open ; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (cons 'hard sticky)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 ;; If the newline leaves the previous line blank,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 ;; and we have a left margin, delete that from the blank line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (or flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (goto-char beforepos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (and (looking-at "[ \t]$")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (> (current-left-margin) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (delete-region (point) (progn (end-of-line) (point))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (if flag (forward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 ;; Indent the line after the newline, except in one case:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 ;; when we added the newline at the beginning of a line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 ;; which starts a page.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (or was-page-start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (move-to-left-margin nil t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (defun open-line (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 "Insert a newline and leave point before it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 If there is a fill prefix and/or a left-margin, insert them on the new line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 if the line would have been blank.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 With arg N, insert N newlines."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (interactive "*p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (let* ((do-fill-prefix (and fill-prefix (bolp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (do-left-margin (and (bolp) (> (current-left-margin) 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (loc (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (newline arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (goto-char loc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (while (> arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (cond ((bolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (if do-left-margin (indent-to (current-left-margin)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (if do-fill-prefix (insert fill-prefix))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (setq arg (1- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (goto-char loc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (end-of-line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (defun split-line ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 "Split current line, moving portion beyond point vertically down."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (interactive "*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (let ((col (current-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (pos (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (newline 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (indent-to col 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (goto-char pos)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (defun quoted-insert (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 "Read next input character and insert it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 This is useful for inserting control characters.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 You may also type up to 3 octal digits, to insert a character with that code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 In overwrite mode, this function inserts the character anyway, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 does not handle octal digits specially. This means that if you use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 overwrite as your normal editing mode, you can use this function to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 insert characters when necessary.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 In binary overwrite mode, this function does overwrite, and octal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 digits are interpreted as a character code. This is supposed to make
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 this function useful in editing binary files."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (interactive "*p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (let ((char (if (or (not overwrite-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (eq overwrite-mode 'overwrite-mode-binary))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (read-quoted-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (read-char))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (if (> arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (if (eq overwrite-mode 'overwrite-mode-binary)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (delete-char arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (while (> arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (insert char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (setq arg (1- arg)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (defun delete-indentation (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 "Join this line to previous and fix up whitespace at join.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 If there is a fill prefix, delete it from the beginning of this line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 With argument, join this line to following line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (interactive "*P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (if arg (forward-line 1))
159
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
215 (if (eq (char-before (point)) ?\n)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (delete-region (point) (1- (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 ;; If the second line started with the fill prefix,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 ;; delete the prefix.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (if (and fill-prefix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (<= (+ (point) (length fill-prefix)) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (string= fill-prefix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (buffer-substring (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (+ (point) (length fill-prefix)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (delete-region (point) (+ (point) (length fill-prefix))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (fixup-whitespace))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (defun fixup-whitespace ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 "Fixup white space between objects around point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 Leave one space or none, according to the context."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (interactive "*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (delete-horizontal-space)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (if (or (looking-at "^\\|\\s)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (save-excursion (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (looking-at "$\\|\\s(\\|\\s'")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (insert ?\ ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (defun delete-horizontal-space ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 "Delete all spaces and tabs around point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (interactive "*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (skip-chars-backward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (delete-region (point) (progn (skip-chars-forward " \t") (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (defun just-one-space ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 "Delete all spaces and tabs around point, leaving one space."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (interactive "*")
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
249 (if abbrev-mode ; XEmacs
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
250 (expand-abbrev))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (skip-chars-backward " \t")
159
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
252 (if (eq (char-after (point)) ? ) ; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (insert ? ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (delete-region (point) (progn (skip-chars-forward " \t") (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (defun delete-blank-lines ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 "On blank line, delete all surrounding blank lines, leaving just one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 On isolated blank line, delete that one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 On nonblank line, delete any immediately following blank lines."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (interactive "*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (let (thisblank singleblank)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (setq thisblank (looking-at "[ \t]*$"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 ;; Set singleblank if there is just one blank line here.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (setq singleblank
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (and thisblank
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (not (looking-at "[ \t]*\n[ \t]*$"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (or (bobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (progn (forward-line -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (not (looking-at "[ \t]*$")))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 ;; Delete preceding blank lines, and this one too if it's the only one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (if thisblank
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (if singleblank (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (delete-region (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (if (re-search-backward "[^ \t\n]" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (progn (forward-line 1) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (point-min)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 ;; Delete following blank lines, unless the current line is blank
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 ;; and there are no following blank lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 (if (not (and thisblank singleblank))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (delete-region (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (if (re-search-forward "[^ \t\n]" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (progn (beginning-of-line) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (point-max)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 ;; Handle the special case where point is followed by newline and eob.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 ;; Delete the line, leaving point at eob.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (if (looking-at "^[ \t]*\n\\'")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (delete-region (point) (point-max)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (defun back-to-indentation ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 "Move point to the first non-whitespace character on this line."
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
299 ;; XEmacs change
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 (interactive "_")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (beginning-of-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 (skip-chars-forward " \t"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (defun newline-and-indent ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 "Insert a newline, then indent according to major mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 Indentation is done using the value of `indent-line-function'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 In programming language modes, this is the same as TAB.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 In some text modes, where TAB inserts a tab, this command indents to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 column specified by the function `current-left-margin'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 (interactive "*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (delete-region (point) (progn (skip-chars-backward " \t") (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (newline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (indent-according-to-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (defun reindent-then-newline-and-indent ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 "Reindent current line, insert newline, then indent the new line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 Indentation of both lines is done according to the current major mode,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 which means calling the current value of `indent-line-function'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 In programming language modes, this is the same as TAB.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 In some text modes, where TAB inserts a tab, this indents to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 column specified by the function `current-left-margin'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 (interactive "*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 (delete-region (point) (progn (skip-chars-backward " \t") (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 (indent-according-to-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 (newline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 (indent-according-to-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 ;; Internal subroutine of delete-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 (defun kill-forward-chars (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 (if (listp arg) (setq arg (car arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (if (eq arg '-) (setq arg -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 (kill-region (point) (+ (point) arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 ;; Internal subroutine of backward-delete-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 (defun kill-backward-chars (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (if (listp arg) (setq arg (car arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (if (eq arg '-) (setq arg -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 (kill-region (point) (- (point) arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 (defun backward-delete-char-untabify (arg &optional killp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 "Delete characters backward, changing tabs into spaces.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 Delete ARG chars, and kill (save in kill ring) if KILLP is non-nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 Interactively, ARG is the prefix arg (default 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 and KILLP is t if a prefix arg was specified."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 (interactive "*p\nP")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 (let ((count arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 (while (and (> count 0) (not (bobp)))
159
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
350 (if (eq (char-before (point)) ?\t) ; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 (let ((col (current-column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 (setq col (- col (current-column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 (insert-char ?\ col)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 (delete-char 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 (setq count (1- count)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 (delete-backward-char arg killp)
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
359 ;; XEmacs: In overwrite mode, back over columns while clearing them out,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 ;; unless at end of line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 (and overwrite-mode (not (eolp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 (save-excursion (insert-char ?\ arg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363
159
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
364 (defcustom delete-key-deletes-forward nil
169
15872534500d Import from CVS: tag r20-3b11
cvs
parents: 167
diff changeset
365 "*If non-nil, the DEL key will erase one character forwards.
153
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
366 If nil, the DEL key will erase one character backwards."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
367 :type 'boolean
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
368 :group 'editing-basics)
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
369
159
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
370 (defun backward-or-forward-delete-char (arg)
153
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
371 "Delete either one character backwards or one character forwards.
159
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
372 Controlled by the state of `delete-key-deletes-forward' and whether the
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
373 BackSpace keysym even exists on your keyboard. If you don't have a
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
374 BackSpace keysym, the delete key should always delete one character
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
375 backwards."
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
376 (interactive "*p")
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
377 (if (and delete-key-deletes-forward
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
378 (or (eq 'tty (device-type))
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
379 (x-keysym-on-keyboard-p "BackSpace")))
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
380 (delete-char arg)
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
381 (delete-backward-char arg)))
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
382
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
383 (defun backward-or-forward-kill-word (arg)
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
384 "Delete either one word backwards or one word forwards.
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
385 Controlled by the state of `delete-key-deletes-forward' and whether the
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
386 BackSpace keysym even exists on your keyboard. If you don't have a
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
387 BackSpace keysym, the delete key should always delete one character
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
388 backwards."
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
389 (interactive "*p")
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
390 (if (and delete-key-deletes-forward
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
391 (or (eq 'tty (device-type))
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
392 (x-keysym-on-keyboard-p "BackSpace")))
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
393 (kill-word arg)
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
394 (backward-kill-word arg)))
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
395
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
396 (defun backward-or-forward-kill-sentence (arg)
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
397 "Delete either one sentence backwards or one sentence forwards.
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
398 Controlled by the state of `delete-key-deletes-forward' and whether the
153
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
399 BackSpace keysym even exists on your keyboard. If you don't have a
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
400 BackSpace keysym, the delete key should always delete one character
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
401 backwards."
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
402 (interactive "*P")
159
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
403 (if (and delete-key-deletes-forward
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
404 (or (eq 'tty (device-type))
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
405 (x-keysym-on-keyboard-p "BackSpace")))
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
406 (kill-sentence arg)
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
407 (backward-kill-sentence (prefix-numeric-value arg))))
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
408
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
409 (defun backward-or-forward-kill-sexp (arg)
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
410 "Delete either one sexpr backwards or one sexpr forwards.
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
411 Controlled by the state of `delete-key-deletes-forward' and whether the
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
412 BackSpace keysym even exists on your keyboard. If you don't have a
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
413 BackSpace keysym, the delete key should always delete one character
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
414 backwards."
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
415 (interactive "*p")
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
416 (if (and delete-key-deletes-forward
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
417 (or (eq 'tty (device-type))
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
418 (x-keysym-on-keyboard-p "BackSpace")))
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
419 (kill-sexp arg)
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
420 (backward-kill-sexp arg)))
153
25f70ba0133c Import from CVS: tag r20-3b3
cvs
parents: 149
diff changeset
421
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 (defun zap-to-char (arg char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 "Kill up to and including ARG'th occurrence of CHAR.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 Goes backward if ARG is negative; error if CHAR not found."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 (interactive "*p\ncZap to char: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 (kill-region (point) (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 (search-forward (char-to-string char) nil nil arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 ; (goto-char (if (> arg 0) (1- (point)) (1+ (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 (defun beginning-of-buffer (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 "Move point to the beginning of the buffer; leave mark at previous position.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 With arg N, put point N/10 of the way from the beginning.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 If the buffer is narrowed, this command uses the beginning and size
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 of the accessible part of the buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 Don't use this command in Lisp programs!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 \(goto-char (point-min)) is faster and avoids clobbering the mark."
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
440 ;; XEmacs change
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 (interactive "_P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 (push-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 (let ((size (- (point-max) (point-min))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 (goto-char (if arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 (+ (point-min)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 (if (> size 10000)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 ;; Avoid overflow for large buffer sizes!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 (* (prefix-numeric-value arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 (/ size 10))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 (/ (+ 10 (* size (prefix-numeric-value arg))) 10)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 (point-min))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 (if arg (forward-line 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 (defun end-of-buffer (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 "Move point to the end of the buffer; leave mark at previous position.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 With arg N, put point N/10 of the way from the end.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 If the buffer is narrowed, this command uses the beginning and size
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 of the accessible part of the buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 Don't use this command in Lisp programs!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 \(goto-char (point-max)) is faster and avoids clobbering the mark."
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
463 ;; XEmacs change
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 (interactive "_P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 (push-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 ;; XEmacs changes here.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 (let ((scroll-to-end (not (pos-visible-in-window-p (point-max))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 (size (- (point-max) (point-min))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 (goto-char (if arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 (- (point-max)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 (if (> size 10000)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 ;; Avoid overflow for large buffer sizes!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 (* (prefix-numeric-value arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 (/ size 10))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 (/ (* size (prefix-numeric-value arg)) 10)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 (cond (arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 ;; If we went to a place in the middle of the buffer,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 ;; adjust it to the beginning of a line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 (forward-line 1))
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
481 ;; XEmacs change
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 (scroll-to-end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 ;; If the end of the buffer is not already on the screen,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 ;; then scroll specially to put it near, but not at, the bottom.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 (recenter -3)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
487 ;; XEmacs (not in FSF)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 (defun mark-beginning-of-buffer (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 "Push a mark at the beginning of the buffer; leave point where it is.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 With arg N, push mark N/10 of the way from the true beginning."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 (push-mark (if arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 (if (> (buffer-size) 10000)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 ;; Avoid overflow for large buffer sizes!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 (* (prefix-numeric-value arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 (/ (buffer-size) 10))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 (/ (+ 10 (* (buffer-size) (prefix-numeric-value arg))) 10))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 (define-function 'mark-bob 'mark-beginning-of-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
503 ;; XEmacs (not in FSF)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 (defun mark-end-of-buffer (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 "Push a mark at the end of the buffer; leave point where it is.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 With arg N, push mark N/10 of the way from the true end."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 (push-mark (if arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 (- (1+ (buffer-size))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 (if (> (buffer-size) 10000)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 ;; Avoid overflow for large buffer sizes!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 (* (prefix-numeric-value arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 (/ (buffer-size) 10))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 (/ (* (buffer-size) (prefix-numeric-value arg)) 10)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 (define-function 'mark-eob 'mark-end-of-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 (defun mark-whole-buffer ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 "Put point at beginning and mark at end of buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 You probably should not use this function in Lisp programs;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 it is usually a mistake for a Lisp function to use any subroutine
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 that uses or sets the mark."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 (push-mark (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 (push-mark (point-max) nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 (goto-char (point-min)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
530 ;; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 (defun eval-current-buffer (&optional printflag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 "Evaluate the current buffer as Lisp code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 Programs can pass argument PRINTFLAG which controls printing of output:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 nil means discard it; anything else is stream for print."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 (eval-buffer (current-buffer) printflag))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
538 ;; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 (defun count-words-buffer (b)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 (interactive "b")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 (let ((buf (or b (current-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 (set-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 (message "Buffer has %d words"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 (count-words-region (point-min) (point-max))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
547 ;; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 (defun count-words-region (start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 (interactive "r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 (let ((n 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 (while (< (point) end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 (if (forward-word 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 (setq n (1+ n))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 (message "Region has %d words" n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 n)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 (defun count-lines-region (start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 "Print number of lines and characters in the region."
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
561 ;; XEmacs change
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 (interactive "_r")
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
563 (message "Region has %d lines, %d characters"
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
564 (count-lines start end) (- end start)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
566 ;; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 (defun count-lines-buffer (b)
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 104
diff changeset
568 "Print number of lines and characters in the specified buffer."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 (interactive "_b")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 (let ((buf (or b (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 cnt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 (set-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 (setq cnt (count-lines (point-min) (point-max)))
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
575 (message "Buffer has %d lines, %d characters"
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 cnt (- (point-max) (point-min)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 cnt)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 (defun what-line ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 "Print the current buffer line number and narrowed line number of point."
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
581 ;; XEmacs change
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 (interactive "_")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 (let ((opoint (point)) start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 (setq start (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 (goto-char opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 (if (/= start 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 (message "line %d (narrowed line %d)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 (1+ (count-lines 1 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 (1+ (count-lines start (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 (message "Line %d" (1+ (count-lines 1 (point)))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 (defun count-lines (start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 "Return number of lines between START and END.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 This is usually the number of newlines between them,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 but can be one more if START is not equal to END
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 and the greater of them is not at the start of a line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 (narrow-to-region start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 (if (eq selective-display t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 (save-match-data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 (let ((done 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 (while (re-search-forward "[\n\C-m]" nil t 40)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 (setq done (+ 40 done)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 (while (re-search-forward "[\n\C-m]" nil t 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 (setq done (+ 1 done)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 (if (and (/= start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 (not (bolp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 (1+ done)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 done)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 (- (buffer-size) (forward-line (buffer-size)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 (defun what-cursor-position ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 "Print info on cursor position (on screen and within buffer)."
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
624 ;; XEmacs change
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 (interactive "_")
159
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
626 (let* ((char (char-after (point))) ; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 (beg (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 (end (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 (pos (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 (total (buffer-size))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 (percent (if (> total 50000)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 ;; Avoid overflow from multiplying by 100!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 (/ (+ (/ total 200) (1- pos)) (max (/ total 100) 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 (/ (+ (/ total 2) (* 100 (1- pos))) (max total 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 (hscroll (if (= (window-hscroll) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 ""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 (format " Hscroll=%d" (window-hscroll))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 (col (current-column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 (if (= pos end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 (if (or (/= beg 1) (/= end (1+ total)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 (message "point=%d of %d(%d%%) <%d - %d> column %d %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 pos total percent beg end col hscroll)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 (message "point=%d of %d(%d%%) column %d %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 pos total percent col hscroll))
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
645 ;; XEmacs: don't use single-key-description
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 (if (or (/= beg 1) (/= end (1+ total)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 (message "Char: %s (0%o, %d, 0x%x) point=%d of %d(%d%%) <%d - %d> column %d %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 (text-char-description char) char char char pos total
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 percent beg end col hscroll)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 (message "Char: %s (0%o, %d, 0x%x) point=%d of %d(%d%%) column %d %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 (text-char-description char) char char char pos total
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 percent col hscroll)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 (defun fundamental-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 "Major mode not specialized for anything in particular.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 Other major modes are defined by comparison with this one."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 (kill-all-local-variables))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
660 ;; XEmacs the following are declared elsewhere
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
661 ;(defvar read-expression-map (cons 'keymap minibuffer-local-map)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
662 ; "Minibuffer keymap used for reading Lisp expressions.")
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
663 ;(define-key read-expression-map "\M-\t" 'lisp-complete-symbol)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
664
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
665 ;(put 'eval-expression 'disabled t)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
666
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
667 ;(defvar read-expression-history nil)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 ;; We define this, rather than making `eval' interactive,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 ;; for the sake of completion of names like eval-region, eval-current-buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 (defun eval-expression (expression)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 "Evaluate EXPRESSION and print value in minibuffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 Value is also consed on to front of the variable `values'."
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
674 ;(interactive "xEval: ")
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
675 (interactive
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
676 (list (read-from-minibuffer "Eval: "
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
677 nil read-expression-map t
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
678 'read-expression-history)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 (setq values (cons (eval expression) values))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 (prin1 (car values) t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
682 ;; XEmacs -- extra parameter (variant, but equivalent logic)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 (defun edit-and-eval-command (prompt command &optional history)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 "Prompting with PROMPT, let user edit COMMAND and eval result.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 COMMAND is a Lisp expression. Let user edit that expression in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 the minibuffer, then read and evaluate the result."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 (let ((command (read-expression prompt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 ;; first try to format the thing readably;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 ;; and if that fails, print it normally.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 (let ((print-readably t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 (prin1-to-string command))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 (error (prin1-to-string command)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 (or history '(command-history . 1)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 (or history (setq history 'command-history))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 (if (consp history)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 (setq history (car history)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 (if (eq history t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 ;; If command was added to the history as a string,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 ;; get rid of that. We want only evallable expressions there.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 (if (stringp (car (symbol-value history)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 (set history (cdr (symbol-value history))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 ;; If command to be redone does not match front of history,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 ;; add it to the history.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 (or (equal command (car (symbol-value history)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 (set history (cons command (symbol-value history)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 (eval command)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 (defun repeat-complex-command (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 "Edit and re-evaluate last complex command, or ARGth from last.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 A complex command is one which used the minibuffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 The command is placed in the minibuffer as a Lisp form for editing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 The result is executed, repeating the command as changed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 If the command has been changed or is not the most recent previous command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 it is added to the front of the command history.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 You can use the minibuffer history commands \\<minibuffer-local-map>\\[next-history-element] and \\[previous-history-element]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 to get different commands to edit and resubmit."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 (interactive "p")
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
721 ;; XEmacs: It looks like our version is better -sb
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 (let ((print-level nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 (edit-and-eval-command "Redo: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 (or (nth (1- arg) command-history)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 (error ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 (cons 'command-history arg))))
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
727
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
728 ;; XEmacs: Functions moved to minibuf.el
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
729 ;; previous-matching-history-element
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
730 ;; next-matching-history-element
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
731 ;; next-history-element
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
732 ;; previous-history-element
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
733 ;; next-complete-history-element
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
734 ;; previous-complete-history-element
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 (defun goto-line (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 "Goto line ARG, counting from line 1 at beginning of buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 (interactive "NGoto line: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 (setq arg (prefix-numeric-value arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 (goto-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 (if (eq selective-display t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 (re-search-forward "[\n\C-m]" nil 'end (1- arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 (forward-line (1- arg)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 ;Put this on C-x u, so we can force that rather than C-_ into startup msg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 (define-function 'advertised-undo 'undo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 (defun undo (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 "Undo some previous changes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 Repeat this command to undo more changes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 A numeric argument serves as a repeat count."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 (interactive "*p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 ;; If we don't get all the way through, make last-command indicate that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 ;; for the following command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 (setq this-command t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 (let ((modified (buffer-modified-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 (recent-save (recent-auto-save-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 (or (eq (selected-window) (minibuffer-window))
193
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
761 (display-message 'command "Undo!"))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 (or (and (eq last-command 'undo)
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
763 (eq (current-buffer) last-undo-buffer)) ; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 (progn (undo-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 (undo-more 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 (undo-more (or arg 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 ;; Don't specify a position in the undo record for the undo command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 ;; Instead, undoing this should move point to where the change is.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 (let ((tail buffer-undo-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 done)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 (while (and tail (not done) (not (null (car tail))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 (if (integerp (car tail))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 (setq done t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 (setq buffer-undo-list (delq (car tail) buffer-undo-list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 (setq tail (cdr tail))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 (and modified (not (buffer-modified-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 (delete-auto-save-file-if-necessary recent-save)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 ;; If we do get all the way through, make this-command indicate that.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 (setq this-command 'undo))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 (defvar pending-undo-list nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 "Within a run of consecutive undo commands, list remaining to be undone.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
785 (defvar last-undo-buffer nil) ; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 (defun undo-start ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 "Set `pending-undo-list' to the front of the undo list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 The next call to `undo-more' will undo the most recently made change."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 (if (eq buffer-undo-list t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 (error "No undo information in this buffer"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 (setq pending-undo-list buffer-undo-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 (defun undo-more (count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 "Undo back N undo-boundaries beyond what was already undone recently.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 Call `undo-start' to get ready to undo recent changes,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 then call `undo-more' one or more times to undo them."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 (or pending-undo-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 (error "No further undo information"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 (setq pending-undo-list (primitive-undo count pending-undo-list)
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
801 last-undo-buffer (current-buffer))) ; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
803 ;; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 (defun call-with-transparent-undo (fn &rest args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 "Apply FN to ARGS, and then undo all changes made by FN to the current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806 buffer. The undo records are processed even if FN returns non-locally.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 There is no trace of the changes made by FN in the buffer's undo history.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 You can use this in a write-file-hooks function with continue-save-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 to make the contents of a disk file differ from its in-memory buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 (let ((buffer-undo-list nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 ;; Kludge to prevent undo list truncation:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 (undo-high-threshold -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 (undo-threshold -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 (obuffer (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 (apply fn args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 ;; Go to the buffer we will restore and make it writable:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 (set-buffer obuffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 (let ((buffer-read-only nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 ;; Perform all undos, with further undo logging disabled:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 (let ((tail buffer-undo-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 (setq buffer-undo-list t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 (while tail
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 (setq tail (primitive-undo (length tail) tail))))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
830 ;; XEmacs: The following are in other files
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
831 ;; shell-command-history
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
832 ;; shell-command-switch
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
833 ;; shell-command
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
834 ;; shell-command-sentinel
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
835
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 (defconst universal-argument-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 (let ((map (make-sparse-keymap)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 (set-keymap-default-binding map 'universal-argument-other-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 ;FSFmacs (define-key map [switch-frame] nil)
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
841 (define-key map [(t)] 'universal-argument-other-key)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
842 (define-key map [(meta t)] 'universal-argument-other-key)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 (define-key map [(control u)] 'universal-argument-more)
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
844 (define-key map [?-] 'universal-argument-minus)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
845 (define-key map [?0] 'digit-argument)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
846 (define-key map [?1] 'digit-argument)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
847 (define-key map [?2] 'digit-argument)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
848 (define-key map [?3] 'digit-argument)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
849 (define-key map [?4] 'digit-argument)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
850 (define-key map [?5] 'digit-argument)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
851 (define-key map [?6] 'digit-argument)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
852 (define-key map [?7] 'digit-argument)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
853 (define-key map [?8] 'digit-argument)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
854 (define-key map [?9] 'digit-argument)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 "Keymap used while processing \\[universal-argument].")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 (defvar universal-argument-num-events nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 "Number of argument-specifying events read by `universal-argument'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860 `universal-argument-other-key' uses this to discard those events
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861 from (this-command-keys), and reread only the final command.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 (defun universal-argument ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 "Begin a numeric argument for the following command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865 Digits or minus sign following \\[universal-argument] make up the numeric argument.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 \\[universal-argument] following the digits or minus sign ends the argument.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867 \\[universal-argument] without digits or minus sign provides 4 as argument.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 Repeating \\[universal-argument] without digits or minus sign
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869 multiplies the argument by 4 each time."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 (setq prefix-arg (list 4))
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
872 (setq zmacs-region-stays t) ; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 (setq universal-argument-num-events (length (this-command-keys)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874 (setq overriding-terminal-local-map universal-argument-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 ;; A subsequent C-u means to multiply the factor by 4 if we've typed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 ;; nothing but C-u's; otherwise it means to terminate the prefix arg.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 (defun universal-argument-more (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880 (if (consp arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 (setq prefix-arg (list (* 4 (car arg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 (setq prefix-arg arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883 (setq overriding-terminal-local-map nil))
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
884 (setq zmacs-region-stays t) ; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885 (setq universal-argument-num-events (length (this-command-keys))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 (defun negative-argument (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 "Begin a negative numeric argument for the next command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889 \\[universal-argument] following digits or minus sign ends the argument."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891 (cond ((integerp arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 (setq prefix-arg (- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893 ((eq arg '-)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 (setq prefix-arg nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896 (setq prefix-arg '-)))
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
897 (setq zmacs-region-stays t) ; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898 (setq universal-argument-num-events (length (this-command-keys)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899 (setq overriding-terminal-local-map universal-argument-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
901 ;; XEmacs: This function not synched with FSF
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902 (defun digit-argument (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903 "Part of the numeric argument for the next command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904 \\[universal-argument] following digits or minus sign ends the argument."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 (let* ((event last-command-event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907 (key (and (key-press-event-p event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908 (event-key event)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909 (digit (and key (characterp key) (>= key ?0) (<= key ?9)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
910 (- key ?0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911 (if (null digit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912 (universal-argument-other-key arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913 (cond ((integerp arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914 (setq prefix-arg (+ (* arg 10)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 (if (< arg 0) (- digit) digit))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
916 ((eq arg '-)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917 ;; Treat -0 as just -, so that -01 will work.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918 (setq prefix-arg (if (zerop digit) '- (- digit))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
920 (setq prefix-arg digit)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921 (setq zmacs-region-stays t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
922 (setq universal-argument-num-events (length (this-command-keys)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
923 (setq overriding-terminal-local-map universal-argument-map))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925 ;; For backward compatibility, minus with no modifiers is an ordinary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926 ;; command if digits have already been entered.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
927 (defun universal-argument-minus (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
928 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
929 (if (integerp arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
930 (universal-argument-other-key arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
931 (negative-argument arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
932
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
933 ;; Anything else terminates the argument and is left in the queue to be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
934 ;; executed as a command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
935 (defun universal-argument-other-key (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
936 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
937 (setq prefix-arg arg)
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
938 (setq zmacs-region-stays t) ; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
939 (let* ((key (this-command-keys))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
940 ;; FSF calls silly function `listify-key-sequence' here.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
941 (keylist (append key nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
942 (setq unread-command-events
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
943 (append (nthcdr universal-argument-num-events keylist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
944 unread-command-events)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
945 (reset-this-command-lengths)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
946 (setq overriding-terminal-local-map nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
947
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
948
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
949 ;; XEmacs -- shouldn't these functions keep the zmacs region active?
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
950 (defun forward-to-indentation (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
951 "Move forward ARG lines and position at first nonblank character."
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
952 (interactive "_p")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
953 (forward-line arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
954 (skip-chars-forward " \t"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
955
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
956 (defun backward-to-indentation (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
957 "Move backward ARG lines and position at first nonblank character."
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
958 (interactive "_p")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
959 (forward-line (- arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
960 (skip-chars-forward " \t"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
961
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
962 (defcustom kill-whole-line nil
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
963 "*If non-nil, `kill-line' with no arg at beg of line kills the whole line."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
964 :type 'boolean
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
965 :group 'killing)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
966
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
967 (defun kill-line (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
968 "Kill the rest of the current line; if no nonblanks there, kill thru newline.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
969 With prefix argument, kill that many lines from point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
970 Negative arguments kill lines backward.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
971
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
972 When calling from a program, nil means \"no arg\",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
973 a number counts as a prefix arg.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
974
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
975 If `kill-whole-line' is non-nil, then kill the whole line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
976 when given no argument at the beginning of a line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
977 (interactive "*P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
978 (kill-region (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
979 ;; Don't shift point before doing the delete; that way,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
980 ;; undo will record the right position of point.
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
981 ;; FSF
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
982 ; ;; It is better to move point to the other end of the kill
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
983 ; ;; before killing. That way, in a read-only buffer, point
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
984 ; ;; moves across the text that is copied to the kill ring.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
985 ; ;; The choice has no effect on undo now that undo records
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
986 ; ;; the value of point from before the command was run.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
987 ; (progn
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
988 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
989 (if arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
990 (forward-line (prefix-numeric-value arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
991 (if (eobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
992 (signal 'end-of-buffer nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
993 (if (or (looking-at "[ \t]*$") (and kill-whole-line (bolp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
994 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
995 (end-of-line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
996 (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
997
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
998 ;; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
999 (defun backward-kill-line nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1000 "Kill back to the beginning of the line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1001 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1002 (let ((point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1003 (beginning-of-line nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1004 (kill-region (point) point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1005
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1006
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1007 ;;;; Window system cut and paste hooks.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1008 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1009 ;;; I think that kill-hooks is a better name and more general mechanism
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1010 ;;; than interprogram-cut-function (from FSFmacs). I don't like the behavior
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1011 ;;; of interprogram-paste-function: ^Y should always come from the kill ring,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1012 ;;; not the X selection. But if that were provided, it should be called (and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1013 ;;; behave as) yank-hooks instead. -- jwz
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1014
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1015 ;(defvar interprogram-cut-function nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1016 ; "Function to call to make a killed region available to other programs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1017 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1018 ;Most window systems provide some sort of facility for cutting and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1019 ;pasting text between the windows of different programs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1020 ;This variable holds a function that XEmacs calls whenever text
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1021 ;is put in the kill ring, to make the new kill available to other
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1022 ;programs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1023 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1024 ;The function takes one or two arguments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1025 ;The first argument, TEXT, is a string containing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1026 ;the text which should be made available.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1027 ;The second, PUSH, if non-nil means this is a \"new\" kill;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1028 ;nil means appending to an \"old\" kill.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1029 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1030 ;(defvar interprogram-paste-function nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1031 ; "Function to call to get text cut from other programs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1032 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1033 ;Most window systems provide some sort of facility for cutting and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1034 ;pasting text between the windows of different programs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1035 ;This variable holds a function that Emacs calls to obtain
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1036 ;text that other programs have provided for pasting.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1037 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1038 ;The function should be called with no arguments. If the function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1039 ;returns nil, then no other program has provided such text, and the top
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1040 ;of the Emacs kill ring should be used. If the function returns a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1041 ;string, that string should be put in the kill ring as the latest kill.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1042 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1043 ;Note that the function should return a string only if a program other
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1044 ;than Emacs has provided a string for pasting; if Emacs provided the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1045 ;most recent string, the function should return nil. If it is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1046 ;difficult to tell whether Emacs or some other program provided the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1047 ;current string, it is probably good enough to return nil if the string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1048 ;is equal (according to `string=') to the last text Emacs provided.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1049
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
1050 (defcustom kill-hooks nil
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
1051 "*Functions run when something is added to the XEmacs kill ring.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1052 These functions are called with one argument, the string most recently
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1053 cut or copied. You can use this to, for example, make the most recent
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
1054 kill become the X Clipboard selection."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
1055 :type 'hook
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
1056 :group 'killing)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1057
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1058
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1059 ;;;; The kill ring data structure.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1060
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1061 (defvar kill-ring nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1062 "List of killed text sequences.
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1063 Since the kill ring is supposed to interact nicely with cut-and-paste
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1064 facilities offered by window systems, use of this variable should
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1065 interact nicely with `interprogram-cut-function' and
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1066 `interprogram-paste-function'. The functions `kill-new',
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1067 `kill-append', and `current-kill' are supposed to implement this
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1068 interaction; you may want to use them instead of manipulating the kill
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1069 ring directly.")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1070
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
1071 (defcustom kill-ring-max 30
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
1072 "*Maximum length of kill ring before oldest elements are thrown away."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
1073 :type 'integer
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
1074 :group 'killing)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1075
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1076 (defvar kill-ring-yank-pointer nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1077 "The tail of the kill ring whose car is the last thing yanked.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1078
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1079 (defun kill-new (string &optional replace)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1080 "Make STRING the latest kill in the kill ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1081 Set the kill-ring-yank pointer to point to it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1082 Run `kill-hooks'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1083 Optional second argument REPLACE non-nil means that STRING will replace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1084 the front of the kill ring, rather than being added to the list."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1085 ; (and (fboundp 'menu-bar-update-yank-menu)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1086 ; (menu-bar-update-yank-menu string (and replace (car kill-ring))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1087 (if replace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1088 (setcar kill-ring string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1089 (setq kill-ring (cons string kill-ring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1090 (if (> (length kill-ring) kill-ring-max)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1091 (setcdr (nthcdr (1- kill-ring-max) kill-ring) nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1092 (setq kill-ring-yank-pointer kill-ring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1093 ; (if interprogram-cut-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1094 ; (funcall interprogram-cut-function string (not replace)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1095 (run-hook-with-args 'kill-hooks string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1096
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1097 (defun kill-append (string before-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1098 "Append STRING to the end of the latest kill in the kill ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1099 If BEFORE-P is non-nil, prepend STRING to the kill.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1100 Run `kill-hooks'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1101 (kill-new (if before-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1102 (concat string (car kill-ring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1103 (concat (car kill-ring) string)) t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1104
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1105 (defun current-kill (n &optional do-not-move)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1106 "Rotate the yanking point by N places, and then return that kill.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1107 If optional arg DO-NOT-MOVE is non-nil, then don't actually move the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1108 yanking point\; just return the Nth kill forward."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1109 (or kill-ring (error "Kill ring is empty"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1110 (let* ((tem (nthcdr (mod (- n (length kill-ring-yank-pointer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1111 (length kill-ring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1112 kill-ring)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1113 (or do-not-move
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1114 (setq kill-ring-yank-pointer tem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1115 (car tem)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1116
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1117
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1118
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1119 ;;;; Commands for manipulating the kill ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1120
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1121 ;;FSFmacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1122 ;(defvar kill-read-only-ok nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1123 ; "*Non-nil means don't signal an error for killing read-only text.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1124
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1125 ;(put 'text-read-only 'error-conditions
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1126 ; '(text-read-only buffer-read-only error))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1127 ;(put 'text-read-only 'error-message "Text is read-only")
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1128
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1129 (defun kill-region (beg end &optional verbose) ; verbose is XEmacs addition
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1130 "Kill between point and mark.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1131 The text is deleted but saved in the kill ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1132 The command \\[yank] can retrieve it from there.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1133 \(If you want to kill and then yank immediately, use \\[copy-region-as-kill].)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1134
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1135 This is the primitive for programs to kill text (as opposed to deleting it).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1136 Supply two arguments, character numbers indicating the stretch of text
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1137 to be killed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1138 Any command that calls this function is a \"kill command\".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1139 If the previous command was also a kill command,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1140 the text killed this time appends to the text killed last time
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1141 to make one entry in the kill ring."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1142 (interactive "*r\np")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1143 ; (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1144 ; (let ((region-hack (and zmacs-regions (eq last-command 'yank))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1145 ; ;; This lets "^Y^W" work. I think this is dumb, but zwei did it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1146 ; (if region-hack (zmacs-activate-region))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1147 ; (prog1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1148 ; (list (point) (mark) current-prefix-arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1149 ; (if region-hack (zmacs-deactivate-region)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1150 ;; beg and end can be markers but the rest of this function is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1151 ;; written as if they are only integers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1152 (if (markerp beg) (setq beg (marker-position beg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1153 (if (markerp end) (setq end (marker-position end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1154 (or (and beg end) (if zmacs-regions ;; rewritten for I18N3 snarfing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1155 (error "The region is not active now")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1156 (error "The mark is not set now")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1157 (if verbose (if buffer-read-only
193
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
1158 (display-message
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
1159 'command
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
1160 (format "Copying %d characters"
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
1161 (- (max beg end) (min beg end))))
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
1162 (display-message
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
1163 'command
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
1164 (format "Killing %d characters"
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
1165 (- (max beg end) (min beg end))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1166 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1167
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1168 ;; I don't like this large change in behavior -- jwz
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1169 ;; Read-Only text means it shouldn't be deleted, so I'm restoring
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1170 ;; this code, but only for text-properties and not full extents. -sb
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1171 ;; If the buffer is read-only, we should beep, in case the person
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1172 ;; just isn't aware of this. However, there's no harm in putting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1173 ;; the region's text in the kill ring, anyway.
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1174 ((or (and buffer-read-only (not inhibit-read-only))
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 163
diff changeset
1175 (text-property-not-all (min beg end) (max beg end) 'read-only nil))
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1176 ;; This is redundant.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1177 ;; (if verbose (message "Copying %d characters"
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1178 ;; (- (max beg end) (min beg end))))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1179 (copy-region-as-kill beg end)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1180 ;; ;; This should always barf, and give us the correct error.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1181 ;; (if kill-read-only-ok
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1182 ;; (message "Read only text copied to kill ring")
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1183 (setq this-command 'kill-region)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1184 (barf-if-buffer-read-only)
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 78
diff changeset
1185 (signal 'buffer-read-only (list (current-buffer))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1186
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1187 ;; In certain cases, we can arrange for the undo list and the kill
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1188 ;; ring to share the same string object. This code does that.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1189 ((not (or (eq buffer-undo-list t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1190 (eq last-command 'kill-region)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1191 ;; Use = since positions may be numbers or markers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1192 (= beg end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1193 ;; Don't let the undo list be truncated before we can even access it.
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1194 ;; FSF calls this `undo-strong-limit'
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1195 (let ((undo-high-threshold (+ (- end beg) 100))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1196 ;(old-list buffer-undo-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1197 tail)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1198 (delete-region beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1199 ;; Search back in buffer-undo-list for this string,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1200 ;; in case a change hook made property changes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1201 (setq tail buffer-undo-list)
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 163
diff changeset
1202 (while (and tail
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 163
diff changeset
1203 (not (stringp (car-safe (car-safe tail))))) ; XEmacs
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 163
diff changeset
1204 (pop tail))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1205 ;; Take the same string recorded for undo
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1206 ;; and put it in the kill-ring.
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 163
diff changeset
1207 (and tail
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 163
diff changeset
1208 (kill-new (car (car tail))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1209
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1210 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1211 ;; if undo is not kept, grab the string then delete it (which won't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1212 ;; add another string to the undo list).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1213 (copy-region-as-kill beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1214 (delete-region beg end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1215 (setq this-command 'kill-region))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1216
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1217 ;; copy-region-as-kill no longer sets this-command, because it's confusing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1218 ;; to get two copies of the text when the user accidentally types M-w and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1219 ;; then corrects it with the intended C-w.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1220 (defun copy-region-as-kill (beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1221 "Save the region as if killed, but don't kill it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1222 Run `kill-hooks'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1223 (interactive "r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1224 (if (eq last-command 'kill-region)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1225 (kill-append (buffer-substring beg end) (< end beg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1226 (kill-new (buffer-substring beg end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1227 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1228
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1229 (defun kill-ring-save (beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1230 "Save the region as if killed, but don't kill it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1231 This command is similar to `copy-region-as-kill', except that it gives
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1232 visual feedback indicating the extent of the region being copied."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1233 (interactive "r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1234 (copy-region-as-kill beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1235 ;; copy before delay, for xclipboard's benefit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1236 (if (interactive-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1237 (let ((other-end (if (= (point) beg) end beg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1238 (opoint (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1239 ;; Inhibit quitting so we can make a quit here
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1240 ;; look like a C-g typed as a command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1241 (inhibit-quit t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1242 (if (pos-visible-in-window-p other-end (selected-window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1243 (progn
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1244 ;; FSF (I'm not sure what this does -sb)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1245 ; ;; Swap point and mark.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1246 ; (set-marker (mark-marker) (point) (current-buffer))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1247 (goto-char other-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1248 (sit-for 1)
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1249 ; ;; Swap back.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1250 ; (set-marker (mark-marker) other-end (current-buffer))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1251 (goto-char opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1252 ;; If user quit, deactivate the mark
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1253 ;; as C-g would as a command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1254 (and quit-flag (mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1255 (zmacs-deactivate-region)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1256 ;; too noisy. -- jwz
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1257 ; (let* ((killed-text (current-kill 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1258 ; (message-len (min (length killed-text) 40)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1259 ; (if (= (point) beg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1260 ; ;; Don't say "killed"; that is misleading.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1261 ; (message "Saved text until \"%s\""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1262 ; (substring killed-text (- message-len)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1263 ; (message "Saved text from \"%s\""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1264 ; (substring killed-text 0 message-len))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1265 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1266
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1267 (defun append-next-kill ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1268 "Cause following command, if it kills, to append to previous kill."
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1269 ;; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1270 (interactive "_")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1271 (if (interactive-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1272 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1273 (setq this-command 'kill-region)
193
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
1274 (display-message 'command
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
1275 "If the next command is a kill, it will append"))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1276 (setq last-command 'kill-region)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1277
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1278 (defun yank-pop (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1279 "Replace just-yanked stretch of killed text with a different stretch.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1280 This command is allowed only immediately after a `yank' or a `yank-pop'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1281 At such a time, the region contains a stretch of reinserted
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1282 previously-killed text. `yank-pop' deletes that text and inserts in its
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1283 place a different stretch of killed text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1284
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1285 With no argument, the previous kill is inserted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1286 With argument N, insert the Nth previous kill.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1287 If N is negative, this is a more recent kill.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1288
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1289 The sequence of kills wraps around, so that after the oldest one
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1290 comes the newest one."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1291 (interactive "*p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1292 (if (not (eq last-command 'yank))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1293 (error "Previous command was not a yank"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1294 (setq this-command 'yank)
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1295 (let ((inhibit-read-only t)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1296 (before (< (point) (mark t))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1297 (delete-region (point) (mark t))
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1298 ;;(set-marker (mark-marker) (point) (current-buffer))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1299 (set-mark (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1300 (insert (current-kill arg))
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1301 (if before
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1302 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1303 ;; It is cleaner to avoid activation, even though the command
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1304 ;; loop would deactivate the mark because we inserted text.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1305 (goto-char (prog1 (mark t)
124
9b50b4588a93 Import from CVS: tag r20-1b15
cvs
parents: 120
diff changeset
1306 (set-marker (mark-marker t) (point) (current-buffer))))))
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1307 nil)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1308
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1309
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1310 (defun yank (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1311 "Reinsert the last stretch of killed text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1312 More precisely, reinsert the stretch of killed text most recently
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1313 killed OR yanked. Put point at end, and set mark at beginning.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1314 With just C-u as argument, same but put point at beginning (and mark at end).
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1315 With argument N, reinsert the Nth most recently killed stretch of killed
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1316 text.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1317 See also the command \\[yank-pop]."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1318 (interactive "*P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1319 ;; If we don't get all the way through, make last-command indicate that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1320 ;; for the following command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1321 (setq this-command t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1322 (push-mark (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1323 (insert (current-kill (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1324 ((listp arg) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1325 ((eq arg '-) -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1326 (t (1- arg)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1327 (if (consp arg)
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1328 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1329 ;; It is cleaner to avoid activation, even though the command
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1330 ;; loop would deactivate the mark because we inserted text.
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
1331 ;; (But doesn't work in XEmacs)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
1332 ;(goto-char (prog1 (mark t)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
1333 ;(set-marker (mark-marker) (point) (current-buffer)))))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
1334 (exchange-point-and-mark t))
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1335 ;; If we do get all the way thru, make this-command indicate that.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1336 (setq this-command 'yank)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1337 nil)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1338
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1339 (defun rotate-yank-pointer (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1340 "Rotate the yanking point in the kill ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1341 With argument, rotate that many kills forward (or backward, if negative)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1342 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1343 (current-kill arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1344
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1345
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1346 (defun insert-buffer (buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1347 "Insert after point the contents of BUFFER.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1348 Puts mark after the inserted text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1349 BUFFER may be a buffer or a buffer name."
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1350 (interactive
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1351 (list
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1352 (progn
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1353 (barf-if-buffer-read-only)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1354 (read-buffer "Insert buffer: "
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1355 ;; XEmacs: we have different args
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1356 (other-buffer (current-buffer) nil t)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1357 t))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1358 (or (bufferp buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1359 (setq buffer (get-buffer buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1360 (let (start end newmark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1361 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1362 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1363 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1364 (setq start (point-min) end (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1365 (insert-buffer-substring buffer start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1366 (setq newmark (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1367 (push-mark newmark))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1368 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1369
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1370 (defun append-to-buffer (buffer start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1371 "Append to specified buffer the text of the region.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1372 It is inserted into that buffer before its point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1373
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1374 When calling from a program, give three arguments:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1375 BUFFER (or buffer name), START and END.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1376 START and END specify the portion of the current buffer to be copied."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1377 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1378 ;; XEmacs: we have different args to other-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1379 (list (read-buffer "Append to buffer: " (other-buffer (current-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1380 nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1381 (region-beginning) (region-end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1382 (let ((oldbuf (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1383 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1384 (set-buffer (get-buffer-create buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1385 (insert-buffer-substring oldbuf start end))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1386
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1387 (defun prepend-to-buffer (buffer start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1388 "Prepend to specified buffer the text of the region.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1389 It is inserted into that buffer after its point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1390
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1391 When calling from a program, give three arguments:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1392 BUFFER (or buffer name), START and END.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1393 START and END specify the portion of the current buffer to be copied."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1394 (interactive "BPrepend to buffer: \nr")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1395 (let ((oldbuf (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1396 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1397 (set-buffer (get-buffer-create buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1398 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1399 (insert-buffer-substring oldbuf start end)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1400
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1401 (defun copy-to-buffer (buffer start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1402 "Copy to specified buffer the text of the region.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1403 It is inserted into that buffer, replacing existing text there.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1404
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1405 When calling from a program, give three arguments:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1406 BUFFER (or buffer name), START and END.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1407 START and END specify the portion of the current buffer to be copied."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1408 (interactive "BCopy to buffer: \nr")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1409 (let ((oldbuf (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1410 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1411 (set-buffer (get-buffer-create buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1412 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1413 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1414 (insert-buffer-substring oldbuf start end)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1415
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1416 ;FSFmacs
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1417 ;(put 'mark-inactive 'error-conditions '(mark-inactive error))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1418 ;(put 'mark-inactive 'error-message "The mark is not active now")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1419
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1420 (defun mark (&optional force buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1421 "Return this buffer's mark value as integer, or nil if no mark.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1422
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1423 If `zmacs-regions' is true, then this returns nil unless the region is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1424 currently in the active (highlighted) state. With an argument of t, this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1425 returns the mark (if there is one) regardless of the active-region state.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1426 You should *generally* not use the mark unless the region is active, if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1427 the user has expressed a preference for the active-region model.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1428
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1429 If you are using this in an editing command, you are most likely making
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1430 a mistake; see the documentation of `set-mark'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1431 (setq buffer (decode-buffer buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1432 ;FSFmacs version:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1433 ; (if (or force (not transient-mark-mode) mark-active mark-even-if-inactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1434 ; (marker-position (mark-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1435 ; (signal 'mark-inactive nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1436 (let ((m (mark-marker force buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1437 (and m (marker-position m))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1438
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1439 ;;;#### FSFmacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1440 ;;; Many places set mark-active directly, and several of them failed to also
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1441 ;;; run deactivate-mark-hook. This shorthand should simplify.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1442 ;(defsubst deactivate-mark ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1443 ; "Deactivate the mark by setting `mark-active' to nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1444 ;\(That makes a difference only in Transient Mark mode.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1445 ;Also runs the hook `deactivate-mark-hook'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1446 ; (if transient-mark-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1447 ; (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1448 ; (setq mark-active nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1449 ; (run-hooks 'deactivate-mark-hook))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1450
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1451 (defun set-mark (pos &optional buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1452 "Set this buffer's mark to POS. Don't use this function!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1453 That is to say, don't use this function unless you want
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1454 the user to see that the mark has moved, and you want the previous
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1455 mark position to be lost.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1456
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1457 Normally, when a new mark is set, the old one should go on the stack.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1458 This is why most applications should use push-mark, not set-mark.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1459
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1460 Novice Emacs Lisp programmers often try to use the mark for the wrong
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1461 purposes. The mark saves a location for the user's convenience.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1462 Most editing commands should not alter the mark.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1463 To remember a location for internal use in the Lisp program,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1464 store it in a Lisp variable. Example:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1465
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1466 (let ((beg (point))) (forward-line 1) (delete-region beg (point)))."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1467
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1468 (setq buffer (decode-buffer buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1469 (set-marker (mark-marker t buffer) pos buffer))
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1470 ;; FSF
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1471 ; (if pos
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1472 ; (progn
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1473 ; (setq mark-active t)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1474 ; (run-hooks 'activate-mark-hook)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1475 ; (set-marker (mark-marker) pos (current-buffer)))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1476 ; ;; Normally we never clear mark-active except in Transient Mark mode.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1477 ; ;; But when we actually clear out the mark value too,
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1478 ; ;; we must clear mark-active in any mode.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1479 ; (setq mark-active nil)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1480 ; (run-hooks 'deactivate-mark-hook)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1481 ; (set-marker (mark-marker) nil)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1482
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1483 (defvar mark-ring nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1484 "The list of former marks of the current buffer, most recent first.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1485 (make-variable-buffer-local 'mark-ring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1486 (put 'mark-ring 'permanent-local t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1487
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
1488 (defcustom mark-ring-max 16
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
1489 "*Maximum size of mark ring. Start discarding off end if gets this big."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
1490 :type 'integer
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
1491 :group 'killing)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1492
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1493 (defvar global-mark-ring nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1494 "The list of saved global marks, most recent first.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1495
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
1496 (defcustom global-mark-ring-max 16
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1497 "*Maximum size of global mark ring. \
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
1498 Start discarding off end if gets this big."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
1499 :type 'integer
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
1500 :group 'killing)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1501
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1502 (defun set-mark-command (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1503 "Set mark at where point is, or jump to mark.
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1504 With no prefix argument, set mark, push old mark position on local mark
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1505 ring, and push mark on global mark ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1506 With argument, jump to mark, and pop a new position for mark off the ring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1507 \(does not affect global mark ring\).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1508
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1509 Novice Emacs Lisp programmers often try to use the mark for the wrong
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1510 purposes. See the documentation of `set-mark' for more information."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1511 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1512 (if (null arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1513 (push-mark nil nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1514 (if (null (mark t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1515 (error "No mark set in this buffer")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1516 (goto-char (mark t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1517 (pop-mark))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1518
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1519 ;; XEmacs: Extra parameter
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1520 (defun push-mark (&optional location nomsg activate-region buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1521 "Set mark at LOCATION (point, by default) and push old mark on mark ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1522 If the last global mark pushed was not in the current buffer,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1523 also push LOCATION on the global mark ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1524 Display `Mark set' unless the optional second arg NOMSG is non-nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1525 Activate mark if optional third arg ACTIVATE-REGION non-nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1526
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1527 Novice Emacs Lisp programmers often try to use the mark for the wrong
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1528 purposes. See the documentation of `set-mark' for more information."
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1529 (setq buffer (decode-buffer buffer)) ; XEmacs
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1530 (if (null (mark t buffer)) ; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1531 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1532 ;; The save-excursion / set-buffer is necessary because mark-ring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1533 ;; is a buffer local variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1534 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1535 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1536 (setq mark-ring (cons (copy-marker (mark-marker t buffer)) mark-ring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1537 (if (> (length mark-ring) mark-ring-max)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1538 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1539 (move-marker (car (nthcdr mark-ring-max mark-ring)) nil buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1540 (setcdr (nthcdr (1- mark-ring-max) mark-ring) nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1541 (set-mark (or location (point buffer)) buffer)
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1542 ; (set-marker (mark-marker) (or location (point)) (current-buffer)) ; FSF
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1543 ;; Now push the mark on the global mark ring.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1544 (if (or (null global-mark-ring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1545 (not (eq (marker-buffer (car global-mark-ring)) buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1546 ;; The last global mark pushed wasn't in this same buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1547 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1548 (setq global-mark-ring (cons (copy-marker (mark-marker t buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1549 global-mark-ring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1550 (if (> (length global-mark-ring) global-mark-ring-max)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1551 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1552 (move-marker (car (nthcdr global-mark-ring-max global-mark-ring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1553 nil buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1554 (setcdr (nthcdr (1- global-mark-ring-max) global-mark-ring) nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1555 (or nomsg executing-kbd-macro (> (minibuffer-depth) 0)
193
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
1556 (display-message 'command "Mark set"))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1557 (if activate-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1558 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1559 (setq zmacs-region-stays t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1560 (zmacs-activate-region)))
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1561 ; (if (or activate (not transient-mark-mode)) ; FSF
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1562 ; (set-mark (mark t))) ; FSF
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1563 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1564
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1565 (defun pop-mark ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1566 "Pop off mark ring into the buffer's actual mark.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1567 Does not set point. Does nothing if mark ring is empty."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1568 (if mark-ring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1569 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1570 (setq mark-ring (nconc mark-ring (list (copy-marker (mark-marker t)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1571 (set-mark (car mark-ring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1572 (move-marker (car mark-ring) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1573 (if (null (mark t)) (ding))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1574 (setq mark-ring (cdr mark-ring)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1575
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1576 (define-function 'exchange-dot-and-mark 'exchange-point-and-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1577 (defun exchange-point-and-mark (&optional dont-activate-region)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1578 "Put the mark where point is now, and point where the mark is now.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1579 The mark is activated unless DONT-ACTIVATE-REGION is non-nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1580 (interactive nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1581 (let ((omark (mark t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1582 (if (null omark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1583 (error "No mark set in this buffer"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1584 (set-mark (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1585 (goto-char omark)
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1586 (or dont-activate-region (zmacs-activate-region)) ; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1587 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1588
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1589 ;; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1590 (defun mark-something (mark-fn movement-fn arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1591 "internal function used by mark-sexp, mark-word, etc."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1592 (let (newmark (pushp t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1593 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1594 (if (and (eq last-command mark-fn) (mark))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1595 ;; Extend the previous state in the same direction:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1596 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1597 (if (< (mark) (point)) (setq arg (- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1598 (goto-char (mark))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1599 (setq pushp nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1600 (funcall movement-fn arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1601 (setq newmark (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1602 (if pushp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1603 (push-mark newmark nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1604 ;; Do not mess with the mark stack, but merely adjust the previous state:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1605 (set-mark newmark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1606 (activate-region))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1607
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1608 ;(defun transient-mark-mode (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1609 ; "Toggle Transient Mark mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1610 ;With arg, turn Transient Mark mode on if arg is positive, off otherwise.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1611 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1612 ;In Transient Mark mode, when the mark is active, the region is highlighted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1613 ;Changing the buffer \"deactivates\" the mark.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1614 ;So do certain other operations that set the mark
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1615 ;but whose main purpose is something else--for example,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1616 ;incremental search, \\[beginning-of-buffer], and \\[end-of-buffer]."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1617 ; (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1618 ; (setq transient-mark-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1619 ; (if (null arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1620 ; (not transient-mark-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1621 ; (> (prefix-numeric-value arg) 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1622
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1623 (defun pop-global-mark ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1624 "Pop off global mark ring and jump to the top location."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1625 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1626 ;; Pop entries which refer to non-existent buffers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1627 (while (and global-mark-ring (not (marker-buffer (car global-mark-ring))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1628 (setq global-mark-ring (cdr global-mark-ring)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1629 (or global-mark-ring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1630 (error "No global mark set"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1631 (let* ((marker (car global-mark-ring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1632 (buffer (marker-buffer marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1633 (position (marker-position marker)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1634 (setq global-mark-ring (nconc (cdr global-mark-ring)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1635 (list (car global-mark-ring))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1636 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1637 (or (and (>= position (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1638 (<= position (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1639 (widen))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1640 (goto-char position)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1641 (switch-to-buffer buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1642
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1643
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
1644 ;;; After 8 years of waiting ... -sb
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
1645 (defcustom next-line-add-newlines nil ; XEmacs
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
1646 "*If non-nil, `next-line' inserts newline to avoid `end of buffer' error."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
1647 :type 'boolean
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
1648 :group 'editing-basics)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1649
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1650 (defun next-line (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1651 "Move cursor vertically down ARG lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1652 If there is no character in the target line exactly under the current column,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1653 the cursor is positioned after the character in that line which spans this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1654 column, or at the end of the line if it is not long enough.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1655
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1656 If there is no line in the buffer after this one, behavior depends on the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1657 value of `next-line-add-newlines'. If non-nil, it inserts a newline character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1658 to create a line, and moves the cursor to that line. Otherwise it moves the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1659 cursor to the end of the buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1660
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1661 The command \\[set-goal-column] can be used to create
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1662 a semipermanent goal column to which this command always moves.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1663 Then it does not try to move vertically. This goal column is stored
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1664 in `goal-column', which is nil when there is none.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1665
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1666 If you are thinking of using this in a Lisp program, consider
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1667 using `forward-line' instead. It is usually easier to use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1668 and more reliable (no dependence on goal column, etc.)."
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1669 (interactive "_p") ; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1670 (if (and next-line-add-newlines (= arg 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1671 (let ((opoint (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1672 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1673 (if (eobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1674 (newline 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1675 (goto-char opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1676 (line-move arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1677 (if (interactive-p)
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 80
diff changeset
1678 ;; XEmacs: Not sure what to do about this. It's inconsistent. -sb
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1679 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1680 (line-move arg)
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 80
diff changeset
1681 ((beginning-of-buffer end-of-buffer)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 80
diff changeset
1682 (when signal-error-on-buffer-boundary
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 80
diff changeset
1683 (ding nil 'buffer-bound))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1684 (line-move arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1685 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1686
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1687 (defun previous-line (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1688 "Move cursor vertically up ARG lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1689 If there is no character in the target line exactly over the current column,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1690 the cursor is positioned after the character in that line which spans this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1691 column, or at the end of the line if it is not long enough.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1692
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1693 The command \\[set-goal-column] can be used to create
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1694 a semipermanent goal column to which this command always moves.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1695 Then it does not try to move vertically.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1696
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1697 If you are thinking of using this in a Lisp program, consider using
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1698 `forward-line' with a negative argument instead. It is usually easier
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1699 to use and more reliable (no dependence on goal column, etc.)."
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1700 (interactive "_p") ; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1701 (if (interactive-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1702 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1703 (line-move (- arg))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 80
diff changeset
1704 ((beginning-of-buffer end-of-buffer)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 80
diff changeset
1705 (when signal-error-on-buffer-boundary ; XEmacs
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents: 80
diff changeset
1706 (ding nil 'buffer-bound))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1707 (line-move (- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1708 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1709
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
1710 (defcustom track-eol nil
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1711 "*Non-nil means vertical motion starting at end of line keeps to ends of lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1712 This means moving to the end of each line moved onto.
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
1713 The beginning of a blank line does not count as the end of a line."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
1714 :type 'boolean
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
1715 :group 'editing-basics)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
1716
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
1717 (defcustom goal-column nil
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
1718 "*Semipermanent goal column for vertical motion, as set by \\[set-goal-column], or nil."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
1719 :type '(choice integer (const nil))
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
1720 :group 'editing-basics)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1721 (make-variable-buffer-local 'goal-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1722
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1723 (defvar temporary-goal-column 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1724 "Current goal column for vertical motion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1725 It is the column where point was
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1726 at the start of current run of vertical motion commands.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1727 When the `track-eol' feature is doing its job, the value is 9999.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1728
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1729 ;XEmacs: not yet ported, so avoid compiler warnings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1730 (eval-when-compile
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1731 (defvar inhibit-point-motion-hooks))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1732
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
1733 (defcustom line-move-ignore-invisible nil
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1734 "*Non-nil means \\[next-line] and \\[previous-line] ignore invisible lines.
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
1735 Use with care, as it slows down movement significantly. Outline mode sets this."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
1736 :type 'boolean
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
1737 :group 'editing-basics)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1738
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1739 ;; This is the guts of next-line and previous-line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1740 ;; Arg says how many lines to move.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1741 (defun line-move (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1742 ;; Don't run any point-motion hooks, and disregard intangibility,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1743 ;; for intermediate positions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1744 (let ((inhibit-point-motion-hooks t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1745 (opoint (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1746 new)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1747 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1748 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1749 (if (not (or (eq last-command 'next-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1750 (eq last-command 'previous-line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1751 (setq temporary-goal-column
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1752 (if (and track-eol (eolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1753 ;; Don't count beg of empty line as end of line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1754 ;; unless we just did explicit end-of-line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1755 (or (not (bolp)) (eq last-command 'end-of-line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1756 9999
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1757 (current-column))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1758 (if (and (not (integerp selective-display))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1759 (not line-move-ignore-invisible))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1760 ;; Use just newline characters.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1761 (or (if (> arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1762 (progn (if (> arg 1) (forward-line (1- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1763 ;; This way of moving forward ARG lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1764 ;; verifies that we have a newline after the last one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1765 ;; It doesn't get confused by intangible text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1766 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1767 (zerop (forward-line 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1768 (and (zerop (forward-line arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1769 (bolp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1770 (signal (if (< arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1771 'beginning-of-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1772 'end-of-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1773 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1774 ;; Move by arg lines, but ignore invisible ones.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1775 (while (> arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1776 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1777 (and (zerop (vertical-motion 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1778 (signal 'end-of-buffer nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1779 ;; If the following character is currently invisible,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1780 ;; skip all characters with that same `invisible' property value.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1781 (while (and (not (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1782 (let ((prop
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1783 (get-char-property (point) 'invisible)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1784 (if (eq buffer-invisibility-spec t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1785 prop
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1786 (or (memq prop buffer-invisibility-spec)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1787 (assq prop buffer-invisibility-spec)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1788 (if (get-text-property (point) 'invisible)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1789 (goto-char (next-single-property-change (point) 'invisible))
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1790 (goto-char (next-extent-change (point))))) ; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1791 (setq arg (1- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1792 (while (< arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1793 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1794 (and (zerop (vertical-motion -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1795 (signal 'beginning-of-buffer nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1796 (while (and (not (bobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1797 (let ((prop
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1798 (get-char-property (1- (point)) 'invisible)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1799 (if (eq buffer-invisibility-spec t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1800 prop
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1801 (or (memq prop buffer-invisibility-spec)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1802 (assq prop buffer-invisibility-spec)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1803 (if (get-text-property (1- (point)) 'invisible)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1804 (goto-char (previous-single-property-change (point) 'invisible))
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1805 (goto-char (previous-extent-change (point))))) ; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1806 (setq arg (1+ arg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1807 (move-to-column (or goal-column temporary-goal-column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1808 ;; Remember where we moved to, go back home,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1809 ;; then do the motion over again
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1810 ;; in just one step, with intangibility and point-motion hooks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1811 ;; enabled this time.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1812 (setq new (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1813 (goto-char opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1814 (setq inhibit-point-motion-hooks nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1815 (goto-char new)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1816 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1817
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1818 ;;; Many people have said they rarely use this feature, and often type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1819 ;;; it by accident. Maybe it shouldn't even be on a key.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1820 (put 'set-goal-column 'disabled t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1821
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1822 (defun set-goal-column (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1823 "Set the current horizontal position as a goal for \\[next-line] and \\[previous-line].
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1824 Those commands will move to this position in the line moved to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1825 rather than trying to keep the same horizontal position.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1826 With a non-nil argument, clears out the goal column
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1827 so that \\[next-line] and \\[previous-line] resume vertical motion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1828 The goal column is stored in the variable `goal-column'."
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1829 (interactive "_P") ; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1830 (if arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1831 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1832 (setq goal-column nil)
193
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
1833 (display-message 'command "No goal column"))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1834 (setq goal-column (current-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1835 (message (substitute-command-keys
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1836 "Goal column %d (use \\[set-goal-column] with an arg to unset it)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1837 goal-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1838 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1839
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1840 ;; deleted FSFmacs terminal randomness hscroll-point-visible stuff.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1841 ;; hscroll-step
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1842 ;; hscroll-point-visible
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1843 ;; hscroll-window-column
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1844 ;; right-arrow
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1845 ;; left-arrow
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1846
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1847 (defun scroll-other-window-down (lines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1848 "Scroll the \"other window\" down.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1849 For more details, see the documentation for `scroll-other-window'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1850 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1851 (scroll-other-window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1852 ;; Just invert the argument's meaning.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1853 ;; We can do that without knowing which window it will be.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1854 (if (eq lines '-) nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1855 (if (null lines) '-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1856 (- (prefix-numeric-value lines))))))
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1857 ;(define-key esc-map [?\C-\S-v] 'scroll-other-window-down)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1858
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1859 (defun beginning-of-buffer-other-window (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1860 "Move point to the beginning of the buffer in the other window.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1861 Leave mark at previous position.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1862 With arg N, put point N/10 of the way from the true beginning."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1863 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1864 (let ((orig-window (selected-window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1865 (window (other-window-for-scrolling)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1866 ;; We use unwind-protect rather than save-window-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1867 ;; because the latter would preserve the things we want to change.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1868 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1869 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1870 (select-window window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1871 ;; Set point and mark in that window's buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1872 (beginning-of-buffer arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1873 ;; Set point accordingly.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1874 (recenter '(t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1875 (select-window orig-window))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1876
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1877 (defun end-of-buffer-other-window (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1878 "Move point to the end of the buffer in the other window.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1879 Leave mark at previous position.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1880 With arg N, put point N/10 of the way from the true end."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1881 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1882 ;; See beginning-of-buffer-other-window for comments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1883 (let ((orig-window (selected-window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1884 (window (other-window-for-scrolling)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1885 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1886 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1887 (select-window window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1888 (end-of-buffer arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1889 (recenter '(t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1890 (select-window orig-window))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1891
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1892 (defun transpose-chars (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1893 "Interchange characters around point, moving forward one character.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1894 With prefix arg ARG, effect is to take character before point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1895 and drag it forward past ARG other characters (backward if ARG negative).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1896 If no argument and at end of line, the previous two chars are exchanged."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1897 (interactive "*P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1898 (and (null arg) (eolp) (forward-char -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1899 (transpose-subr 'forward-char (prefix-numeric-value arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1900
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 142
diff changeset
1901 ;;; A very old implementation of transpose-chars from the old days ...
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 142
diff changeset
1902 (defun transpose-preceding-chars (arg)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 142
diff changeset
1903 "Interchange characters before point.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 142
diff changeset
1904 With prefix arg ARG, effect is to take character before point
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 142
diff changeset
1905 and drag it forward past ARG other characters (backward if ARG negative).
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 142
diff changeset
1906 If no argument and not at start of line, the previous two chars are exchanged."
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 142
diff changeset
1907 (interactive "*P")
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 142
diff changeset
1908 (and (null arg) (not (bolp)) (forward-char -1))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 142
diff changeset
1909 (transpose-subr 'forward-char (prefix-numeric-value arg)))
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 142
diff changeset
1910
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 142
diff changeset
1911
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1912 (defun transpose-words (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1913 "Interchange words around point, leaving point at end of them.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1914 With prefix arg ARG, effect is to take word before or around point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1915 and drag it forward past ARG other words (backward if ARG negative).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1916 If ARG is zero, the words around or after point and around or after mark
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1917 are interchanged."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1918 (interactive "*p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1919 (transpose-subr 'forward-word arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1920
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1921 (defun transpose-sexps (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1922 "Like \\[transpose-words] but applies to sexps.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1923 Does not work on a sexp that point is in the middle of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1924 if it is a list or string."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1925 (interactive "*p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1926 (transpose-subr 'forward-sexp arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1927
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1928 (defun transpose-lines (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1929 "Exchange current line and previous line, leaving point after both.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1930 With argument ARG, takes previous line and moves it past ARG lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1931 With argument 0, interchanges line point is in with line mark is in."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1932 (interactive "*p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1933 (transpose-subr #'(lambda (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1934 (if (= arg 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1935 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1936 ;; Move forward over a line,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1937 ;; but create a newline if none exists yet.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1938 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1939 (if (eobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1940 (newline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1941 (forward-char 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1942 (forward-line arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1943 arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1944
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1945 (eval-when-compile
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1946 ;; avoid byte-compiler warnings...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1947 (defvar start1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1948 (defvar start2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1949 (defvar end1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1950 (defvar end2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1951
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1952 ; start[12] and end[12] used in transpose-subr-1 below
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1953 (defun transpose-subr (mover arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1954 (let (start1 end1 start2 end2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1955 (if (= arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1956 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1957 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1958 (funcall mover 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1959 (setq end2 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1960 (funcall mover -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1961 (setq start2 (point))
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1962 (goto-char (mark t)) ; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1963 (funcall mover 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1964 (setq end1 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1965 (funcall mover -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1966 (setq start1 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1967 (transpose-subr-1))
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
1968 (exchange-point-and-mark t))) ; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1969 (while (> arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1970 (funcall mover -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1971 (setq start1 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1972 (funcall mover 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1973 (setq end1 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1974 (funcall mover 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1975 (setq end2 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1976 (funcall mover -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1977 (setq start2 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1978 (transpose-subr-1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1979 (goto-char end2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1980 (setq arg (1- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1981 (while (< arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1982 (funcall mover -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1983 (setq start2 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1984 (funcall mover -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1985 (setq start1 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1986 (funcall mover 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1987 (setq end1 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1988 (funcall mover 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1989 (setq end2 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1990 (transpose-subr-1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1991 (setq arg (1+ arg)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1992
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1993 ; start[12] and end[12] used free
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1994 (defun transpose-subr-1 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1995 (if (> (min end1 end2) (max start1 start2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1996 (error "Don't have two things to transpose"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1997 (let ((word1 (buffer-substring start1 end1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1998 (word2 (buffer-substring start2 end2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1999 (delete-region start2 end2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2000 (goto-char start2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2001 (insert word1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2002 (goto-char (if (< start1 start2) start1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2003 (+ start1 (- (length word1) (length word2)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2004 (delete-char (length word1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2005 (insert word2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2006
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 159
diff changeset
2007 (defcustom comment-column 32
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2008 "*Column to indent right-margin comments to.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2009 Setting this variable automatically makes it local to the current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2010 Each mode establishes a different default value for this variable; you
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 159
diff changeset
2011 can set the value for a particular mode using that mode's hook."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 159
diff changeset
2012 :type 'integer
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 159
diff changeset
2013 :group 'fill-comments)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2014 (make-variable-buffer-local 'comment-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2015
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 159
diff changeset
2016 (defcustom comment-start nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 159
diff changeset
2017 "*String to insert to start a new comment, or nil if no comment syntax."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 159
diff changeset
2018 :type '(choice (const :tag "None" nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 159
diff changeset
2019 string)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 159
diff changeset
2020 :group 'fill-comments)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 159
diff changeset
2021
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 159
diff changeset
2022 (defcustom comment-start-skip nil
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2023 "*Regexp to match the start of a comment plus everything up to its body.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2024 If there are any \\(...\\) pairs, the comment delimiter text is held to begin
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 159
diff changeset
2025 at the place matched by the close of the first pair."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 159
diff changeset
2026 :type '(choice (const :tag "None" nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 159
diff changeset
2027 regexp)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 159
diff changeset
2028 :group 'fill-comments)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 159
diff changeset
2029
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 159
diff changeset
2030 (defcustom comment-end ""
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2031 "*String to insert to end a new comment.
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 159
diff changeset
2032 Should be an empty string if comments are terminated by end-of-line."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 159
diff changeset
2033 :type 'string
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 159
diff changeset
2034 :group 'fill-comments)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2035
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2036 (defconst comment-indent-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2037 "Obsolete variable for function to compute desired indentation for a comment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2038 Use `comment-indent-function' instead.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2039 This function is called with no args with point at the beginning of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2040 the comment's starting delimiter.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2041
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2042 (defconst comment-indent-function
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2043 ;; XEmacs - add at least one space after the end of the text on the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2044 ;; current line...
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
2045 (lambda ()
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
2046 (save-excursion
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
2047 (beginning-of-line)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
2048 (let ((eol (save-excursion (end-of-line) (point))))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
2049 (and comment-start-skip
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
2050 (re-search-forward comment-start-skip eol t)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
2051 (setq eol (match-beginning 0)))
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
2052 (goto-char eol)
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
2053 (skip-chars-backward " \t")
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 72
diff changeset
2054 (max comment-column (1+ (current-column))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2055 "Function to compute desired indentation for a comment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2056 This function is called with no args with point at the beginning of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2057 the comment's starting delimiter.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2058
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 159
diff changeset
2059 (defcustom block-comment-start nil
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2060 "*String to insert to start a new comment on a line by itself.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2061 If nil, use `comment-start' instead.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2062 Note that the regular expression `comment-start-skip' should skip this string
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 159
diff changeset
2063 as well as the `comment-start' string."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 159
diff changeset
2064 :type '(choice (const :tag "Use `comment-start'" nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 159
diff changeset
2065 string)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 159
diff changeset
2066 :group 'fill-comments)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 159
diff changeset
2067
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 159
diff changeset
2068 (defcustom block-comment-end nil
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2069 "*String to insert to end a new comment on a line by itself.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2070 Should be an empty string if comments are terminated by end-of-line.
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 159
diff changeset
2071 If nil, use `comment-end' instead."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 159
diff changeset
2072 :type '(choice (const :tag "Use `comment-end'" nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 159
diff changeset
2073 string)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 159
diff changeset
2074 :group 'fill-comments)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2075
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2076 (defun indent-for-comment ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2077 "Indent this line's comment to comment column, or insert an empty comment."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2078 (interactive "*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2079 (let* ((empty (save-excursion (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2080 (looking-at "[ \t]*$")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2081 (starter (or (and empty block-comment-start) comment-start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2082 (ender (or (and empty block-comment-end) comment-end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2083 (if (null starter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2084 (error "No comment syntax defined")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2085 (let* ((eolpos (save-excursion (end-of-line) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2086 cpos indent begpos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2087 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2088 (if (re-search-forward comment-start-skip eolpos 'move)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2089 (progn (setq cpos (point-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2090 ;; Find the start of the comment delimiter.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2091 ;; If there were paren-pairs in comment-start-skip,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2092 ;; position at the end of the first pair.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2093 (if (match-end 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2094 (goto-char (match-end 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2095 ;; If comment-start-skip matched a string with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2096 ;; internal whitespace (not final whitespace) then
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2097 ;; the delimiter start at the end of that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2098 ;; whitespace. Otherwise, it starts at the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2099 ;; beginning of what was matched.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2100 (skip-syntax-backward " " (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2101 (skip-syntax-backward "^ " (match-beginning 0)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2102 (setq begpos (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2103 ;; Compute desired indent.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2104 (if (= (current-column)
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2105 (setq indent (funcall comment-indent-function)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2106 (goto-char begpos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2107 ;; If that's different from current, change it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2108 (skip-chars-backward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2109 (delete-region (point) begpos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2110 (indent-to indent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2111 ;; An existing comment?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2112 (if cpos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2113 (progn (goto-char cpos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2114 (set-marker cpos nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2115 ;; No, insert one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2116 (insert starter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2117 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2118 (insert ender)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2119
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2120 (defun set-comment-column (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2121 "Set the comment column based on point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2122 With no arg, set the comment column to the current column.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2123 With just minus as arg, kill any comment on this line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2124 With any other arg, set comment column to indentation of the previous comment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2125 and then align or create a comment on this line at that column."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2126 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2127 (if (eq arg '-)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2128 (kill-comment nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2129 (if arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2130 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2131 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2132 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2133 (re-search-backward comment-start-skip)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2134 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2135 (re-search-forward comment-start-skip)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2136 (goto-char (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2137 (setq comment-column (current-column))
193
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
2138 (display-message
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
2139 'command
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
2140 (format "Comment column set to %d" comment-column)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2141 (indent-for-comment))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2142 (setq comment-column (current-column))
193
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
2143 (display-message
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
2144 'command
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
2145 (format "Comment column set to %d" comment-column)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2146
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2147 (defun kill-comment (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2148 "Kill the comment on this line, if any.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2149 With argument, kill comments on that many lines starting with this one."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2150 ;; this function loses in a lot of situations. it incorrectly recognises
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2151 ;; comment delimiters sometimes (ergo, inside a string), doesn't work
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2152 ;; with multi-line comments, can kill extra whitespace if comment wasn't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2153 ;; through end-of-line, et cetera.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2154 (interactive "*P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2155 (or comment-start-skip (error "No comment syntax defined"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2156 (let ((count (prefix-numeric-value arg)) endc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2157 (while (> count 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2158 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2159 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2160 (setq endc (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2161 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2162 (and (string< "" comment-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2163 (setq endc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2164 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2165 (re-search-forward (regexp-quote comment-end) endc 'move)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2166 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2167 (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2168 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2169 (if (re-search-forward comment-start-skip endc t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2170 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2171 (goto-char (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2172 (skip-chars-backward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2173 (kill-region (point) endc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2174 ;; to catch comments a line beginnings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2175 (indent-according-to-mode))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2176 (if arg (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2177 (setq count (1- count)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2178
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2179 (defun comment-region (beg end &optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2180 "Comment or uncomment each line in the region.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2181 With just C-u prefix arg, uncomment each line in region.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2182 Numeric prefix arg ARG means use ARG comment characters.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2183 If ARG is negative, delete that many comment characters instead.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2184 Comments are terminated on each line, even for syntax in which newline does
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2185 not end the comment. Blank lines do not get comments."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2186 ;; if someone wants it to only put a comment-start at the beginning and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2187 ;; comment-end at the end then typing it, C-x C-x, closing it, C-x C-x
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2188 ;; is easy enough. No option is made here for other than commenting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2189 ;; every line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2190 (interactive "r\nP")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2191 (or comment-start (error "No comment syntax is defined"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2192 (if (> beg end) (let (mid) (setq mid beg beg end end mid)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2193 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2194 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2195 (let ((cs comment-start) (ce comment-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2196 numarg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2197 (if (consp arg) (setq numarg t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2198 (setq numarg (prefix-numeric-value arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2199 ;; For positive arg > 1, replicate the comment delims now,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2200 ;; then insert the replicated strings just once.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2201 (while (> numarg 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2202 (setq cs (concat cs comment-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2203 ce (concat ce comment-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2204 (setq numarg (1- numarg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2205 ;; Loop over all lines from BEG to END.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2206 (narrow-to-region beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2207 (goto-char beg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2208 (while (not (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2209 (if (or (eq numarg t) (< numarg 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2210 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2211 ;; Delete comment start from beginning of line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2212 (if (eq numarg t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2213 (while (looking-at (regexp-quote cs))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2214 (delete-char (length cs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2215 (let ((count numarg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2216 (while (and (> 1 (setq count (1+ count)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2217 (looking-at (regexp-quote cs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2218 (delete-char (length cs)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2219 ;; Delete comment end from end of line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2220 (if (string= "" ce)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2221 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2222 (if (eq numarg t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2223 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2224 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2225 ;; This is questionable if comment-end ends in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2226 ;; whitespace. That is pretty brain-damaged,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2227 ;; though.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2228 (skip-chars-backward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2229 (if (and (>= (- (point) (point-min)) (length ce))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2230 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2231 (backward-char (length ce))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2232 (looking-at (regexp-quote ce))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2233 (delete-char (- (length ce)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2234 (let ((count numarg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2235 (while (> 1 (setq count (1+ count)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2236 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2237 ;; This is questionable if comment-end ends in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2238 ;; whitespace. That is pretty brain-damaged though
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2239 (skip-chars-backward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2240 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2241 (backward-char (length ce))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2242 (if (looking-at (regexp-quote ce))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2243 (delete-char (length ce))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2244 (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2245 ;; Insert at beginning and at end.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2246 (if (looking-at "[ \t]*$") ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2247 (insert cs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2248 (if (string= "" ce) ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2249 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2250 (insert ce)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2251 (search-forward "\n" nil 'move)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2252
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2253 ;; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2254 (defun prefix-region (prefix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2255 "Add a prefix string to each line between mark and point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2256 (interactive "sPrefix string: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2257 (if prefix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2258 (let ((count (count-lines (mark) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2259 (goto-char (min (mark) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2260 (while (> count 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2261 (setq count (1- count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2262 (beginning-of-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2263 (insert prefix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2264 (end-of-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2265 (forward-char 1)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2266
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2267
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2268 ;; XEmacs - extra parameter
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2269 (defun backward-word (arg &optional buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2270 "Move backward until encountering the end of a word.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2271 With argument, do this that many times.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2272 In programs, it is faster to call `forward-word' with negative arg."
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2273 (interactive "_p") ; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2274 (forward-word (- arg) buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2275
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2276 (defun mark-word (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2277 "Set mark arg words away from point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2278 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2279 (mark-something 'mark-word 'forward-word arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2280
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2281 ;; XEmacs modified
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2282 (defun kill-word (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2283 "Kill characters forward until encountering the end of a word.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2284 With argument, do this that many times."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2285 (interactive "*p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2286 (kill-region (point) (save-excursion (forward-word arg) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2287
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2288 (defun backward-kill-word (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2289 "Kill characters backward until encountering the end of a word.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2290 With argument, do this that many times."
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2291 (interactive "*p") ; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2292 (kill-word (- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2293
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2294 (defun current-word (&optional strict)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2295 "Return the word point is on (or a nearby word) as a string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2296 If optional arg STRICT is non-nil, return nil unless point is within
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2297 or adjacent to a word.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2298 If point is not between two word-constituent characters, but immediately
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2299 follows one, move back first.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2300 Otherwise, if point precedes a word constituent, move forward first.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2301 Otherwise, move backwards until a word constituent is found and get that word;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2302 if you a newlines is reached first, move forward instead."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2303 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2304 (let ((oldpoint (point)) (start (point)) (end (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2305 (skip-syntax-backward "w_") (setq start (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2306 (goto-char oldpoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2307 (skip-syntax-forward "w_") (setq end (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2308 (if (and (eq start oldpoint) (eq end oldpoint))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2309 ;; Point is neither within nor adjacent to a word.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2310 (and (not strict)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2311 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2312 ;; Look for preceding word in same line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2313 (skip-syntax-backward "^w_"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2314 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2315 (beginning-of-line) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2316 (if (bolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2317 ;; No preceding word in same line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2318 ;; Look for following word in same line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2319 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2320 (skip-syntax-forward "^w_"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2321 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2322 (end-of-line) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2323 (setq start (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2324 (skip-syntax-forward "w_")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2325 (setq end (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2326 (setq end (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2327 (skip-syntax-backward "w_")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2328 (setq start (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2329 (buffer-substring start end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2330 (buffer-substring start end)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2331
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 159
diff changeset
2332 (defcustom fill-prefix nil
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2333 "*String for filling to insert at front of new line, or nil for none.
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 159
diff changeset
2334 Setting this variable automatically makes it local to the current buffer."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 159
diff changeset
2335 :type '(choice (const :tag "None" nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 159
diff changeset
2336 string)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 159
diff changeset
2337 :group 'fill)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2338 (make-variable-buffer-local 'fill-prefix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2339
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 159
diff changeset
2340 (defcustom auto-fill-inhibit-regexp nil
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 159
diff changeset
2341 "*Regexp to match lines which should not be auto-filled."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 159
diff changeset
2342 :type '(choice (const :tag "None" nil)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 159
diff changeset
2343 regexp)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 159
diff changeset
2344 :group 'fill)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2345
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
2346 (defvar comment-line-break-function 'indent-new-comment-line
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
2347 "*Mode-specific function which line breaks and continues a comment.
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
2348
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
2349 This function is only called during auto-filling of a comment section.
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
2350 The function should take a single optional argument which is a flag
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
2351 indicating whether soft newlines should be inserted.")
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
2352
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2353 ;; This function is the auto-fill-function of a buffer
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2354 ;; when Auto-Fill mode is enabled.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2355 ;; It returns t if it really did any work.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2356 ;; XEmacs: This function is totally different.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2357 (defun do-auto-fill ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2358 (let (give-up)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2359 (or (and auto-fill-inhibit-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2360 (save-excursion (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2361 (looking-at auto-fill-inhibit-regexp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2362 (while (and (not give-up) (> (current-column) fill-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2363 ;; Determine where to split the line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2364 (let ((fill-prefix fill-prefix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2365 (fill-point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2366 (let ((opoint (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2367 bounce
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
2368 ;; 97/3/14 jhod: Kinsoku
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
2369 (re-break-point (if (featurep 'mule)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
2370 (concat "[ \t\n]\\|" word-across-newline)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
2371 "[ \t\n]"))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
2372 ;; end patch
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2373 (first t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2374 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2375 (move-to-column (1+ fill-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2376 ;; Move back to a word boundary.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2377 (while (or first
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2378 ;; If this is after period and a single space,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2379 ;; move back once more--we don't want to break
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2380 ;; the line there and make it look like a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2381 ;; sentence end.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2382 (and (not (bobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2383 (not bounce)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2384 sentence-end-double-space
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2385 (save-excursion (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2386 (and (looking-at "\\. ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2387 (not (looking-at "\\. "))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2388 (setq first nil)
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
2389 ;; 97/3/14 jhod: Kinsoku
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
2390 ; (skip-chars-backward "^ \t\n"))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
2391 (fill-move-backward-to-break-point re-break-point)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
2392 ;; end patch
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2393 ;; If we find nowhere on the line to break it,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2394 ;; break after one word. Set bounce to t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2395 ;; so we will not keep going in this while loop.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2396 (if (bolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2397 (progn
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
2398 ;; 97/3/14 jhod: Kinsoku
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
2399 ; (re-search-forward "[ \t]" opoint t)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
2400 (fill-move-forward-to-break-point re-break-point
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
2401 opoint)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
2402 ;; end patch
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2403 (setq bounce t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2404 (skip-chars-backward " \t"))
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
2405 (if (and (featurep 'mule)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
2406 (or bounce (bolp))) (kinsoku-process)) ;; 97/3/14 jhod: Kinsoku
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2407 ;; Let fill-point be set to the place where we end up.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2408 (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2409
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2410 ;; I'm not sure why Stig made this change but it breaks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2411 ;; auto filling in at least C mode so I'm taking it back
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2412 ;; out. --cet
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2413 ;; XEmacs - adaptive fill.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2414 ;;(maybe-adapt-fill-prefix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2415 ;; (or from (setq from (save-excursion (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2416 ;; (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2417 ;; (or to (setq to (save-excursion (beginning-of-line 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2418 ;; (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2419 ;; t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2420
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2421 ;; If that place is not the beginning of the line,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2422 ;; break the line there.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2423 (if (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2424 (goto-char fill-point)
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
2425 (not (or (bolp) (eolp)))) ; 97/3/14 jhod: during kinsoku processing it is possible to move beyond
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2426 (let ((prev-column (current-column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2427 ;; If point is at the fill-point, do not `save-excursion'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2428 ;; Otherwise, if a comment prefix or fill-prefix is inserted,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2429 ;; point will end up before it rather than after it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2430 (if (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2431 (skip-chars-backward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2432 (= (point) fill-point))
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
2433 ;; 97/3/14 jhod: Kinsoku processing
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
2434 ;(indent-new-comment-line)
159
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
2435 (let ((spacep (memq (char-before (point)) '(?\ ?\t))))
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
2436 (funcall comment-line-break-function)
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
2437 ;; if user type space explicitly, leave SPC
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
2438 ;; even if there is no WAN.
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
2439 (if spacep
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
2440 (save-excursion
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
2441 (goto-char fill-point)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
2442 ;; put SPC except that there is SPC
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
2443 ;; already or there is sentence end.
159
3bb7ccffb0c0 Import from CVS: tag r20-3b6
cvs
parents: 155
diff changeset
2444 (or (memq (char-after (point)) '(?\ ?\t))
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
2445 (fill-end-of-sentence-p)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
2446 (insert ?\ )))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2447 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2448 (goto-char fill-point)
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
2449 (funcall comment-line-break-function)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2450 ;; If making the new line didn't reduce the hpos of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2451 ;; the end of the line, then give up now;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2452 ;; trying again will not help.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2453 (if (>= (current-column) prev-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2454 (setq give-up t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2455 ;; No place to break => stop trying.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2456 (setq give-up t)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2457
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2458 ;; Put FSF one in until I can one or the other working properly, then the
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2459 ;; other one is history.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2460 (defun fsf:do-auto-fill ()
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2461 (let (fc justify
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2462 ;; bol
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2463 give-up
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2464 (fill-prefix fill-prefix))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2465 (if (or (not (setq justify (current-justification)))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2466 (null (setq fc (current-fill-column)))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2467 (and (eq justify 'left)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2468 (<= (current-column) fc))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2469 (save-excursion (beginning-of-line)
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2470 ;; (setq bol (point))
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2471 (and auto-fill-inhibit-regexp
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2472 (looking-at auto-fill-inhibit-regexp))))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2473 nil ;; Auto-filling not required
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2474 (if (memq justify '(full center right))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2475 (save-excursion (unjustify-current-line)))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2476
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2477 ;; Choose a fill-prefix automatically.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2478 (if (and adaptive-fill-mode
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2479 (or (null fill-prefix) (string= fill-prefix "")))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2480 (let ((prefix
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2481 (fill-context-prefix
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2482 (save-excursion (backward-paragraph 1) (point))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2483 (save-excursion (forward-paragraph 1) (point))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2484 ;; Don't accept a non-whitespace fill prefix
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2485 ;; from the first line of a paragraph.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2486 "^[ \t]*$")))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2487 (and prefix (not (equal prefix ""))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2488 (setq fill-prefix prefix))))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2489
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2490 (while (and (not give-up) (> (current-column) fc))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2491 ;; Determine where to split the line.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2492 (let ((fill-point
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2493 (let ((opoint (point))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2494 bounce
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2495 (first t))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2496 (save-excursion
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2497 (move-to-column (1+ fc))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2498 ;; Move back to a word boundary.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2499 (while (or first
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2500 ;; If this is after period and a single space,
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2501 ;; move back once more--we don't want to break
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2502 ;; the line there and make it look like a
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2503 ;; sentence end.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2504 (and (not (bobp))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2505 (not bounce)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2506 sentence-end-double-space
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2507 (save-excursion (forward-char -1)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2508 (and (looking-at "\\. ")
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2509 (not (looking-at "\\. "))))))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2510 (setq first nil)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2511 (skip-chars-backward "^ \t\n")
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2512 ;; If we find nowhere on the line to break it,
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2513 ;; break after one word. Set bounce to t
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2514 ;; so we will not keep going in this while loop.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2515 (if (bolp)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2516 (progn
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2517 (re-search-forward "[ \t]" opoint t)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2518 (setq bounce t)))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2519 (skip-chars-backward " \t"))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2520 ;; Let fill-point be set to the place where we end up.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2521 (point)))))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2522 ;; If that place is not the beginning of the line,
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2523 ;; break the line there.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2524 (if (save-excursion
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2525 (goto-char fill-point)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2526 (not (bolp)))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2527 (let ((prev-column (current-column)))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2528 ;; If point is at the fill-point, do not `save-excursion'.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2529 ;; Otherwise, if a comment prefix or fill-prefix is inserted,
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2530 ;; point will end up before it rather than after it.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2531 (if (save-excursion
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2532 (skip-chars-backward " \t")
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2533 (= (point) fill-point))
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
2534 (funcall comment-line-break-function t)
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2535 (save-excursion
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2536 (goto-char fill-point)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 173
diff changeset
2537 (funcall comment-line-break-function t)))
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2538 ;; Now do justification, if required
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2539 (if (not (eq justify 'left))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2540 (save-excursion
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2541 (end-of-line 0)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2542 (justify-current-line justify nil t)))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2543 ;; If making the new line didn't reduce the hpos of
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2544 ;; the end of the line, then give up now;
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2545 ;; trying again will not help.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2546 (if (>= (current-column) prev-column)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2547 (setq give-up t)))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2548 ;; No place to break => stop trying.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2549 (setq give-up t))))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2550 ;; Justify last line.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2551 (justify-current-line justify t t)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2552 t)))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2553
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2554 (defvar normal-auto-fill-function 'do-auto-fill
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2555 "The function to use for `auto-fill-function' if Auto Fill mode is turned on.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2556 Some major modes set this.")
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2557
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2558 (defun auto-fill-mode (&optional arg)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2559 "Toggle auto-fill mode.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2560 With arg, turn auto-fill mode on if and only if arg is positive.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2561 In Auto-Fill mode, inserting a space at a column beyond `current-fill-column'
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2562 automatically breaks the line at a previous space.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2563
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2564 The value of `normal-auto-fill-function' specifies the function to use
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2565 for `auto-fill-function' when turning Auto Fill mode on."
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2566 (interactive "P")
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2567 (prog1 (setq auto-fill-function
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2568 (if (if (null arg)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2569 (not auto-fill-function)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2570 (> (prefix-numeric-value arg) 0))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2571 normal-auto-fill-function
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2572 nil))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2573 (redraw-modeline)))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2574
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2575 ;; This holds a document string used to document auto-fill-mode.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2576 (defun auto-fill-function ()
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2577 "Automatically break line at a previous space, in insertion of text."
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2578 nil)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2579
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2580 (defun turn-on-auto-fill ()
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2581 "Unconditionally turn on Auto Fill mode."
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2582 (auto-fill-mode 1))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2583
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2584 (defun set-fill-column (arg)
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
2585 "Set `fill-column' to specified argument.
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
2586 Just \\[universal-argument] as argument means to use the current column
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2587 The variable `fill-column' has a separate value for each buffer."
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2588 (interactive "_P") ; XEmacs
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2589 (cond ((integerp arg)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2590 (setq fill-column arg))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2591 ((consp arg)
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2592 (setq fill-column (current-column)))
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2593 ;; Disallow missing argument; it's probably a typo for C-x C-f.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2594 (t
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2595 (error "set-fill-column requires an explicit argument")))
193
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
2596 (display-message 'command "fill-column set to %d" fill-column))
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2597
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 159
diff changeset
2598 (defcustom comment-multi-line t ; XEmacs - this works well with adaptive fill
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2599 "*Non-nil means \\[indent-new-comment-line] should continue same comment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2600 on new line, with no new terminator or starter.
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 159
diff changeset
2601 This is obsolete because you might as well use \\[newline-and-indent]."
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 159
diff changeset
2602 :type 'boolean
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 159
diff changeset
2603 :group 'fill-comments)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2604
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2605 (defun indent-new-comment-line (&optional soft)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2606 "Break line at point and indent, continuing comment if within one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2607 This indents the body of the continued comment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2608 under the previous comment line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2609
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2610 This command is intended for styles where you write a comment per line,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2611 starting a new comment (and terminating it if necessary) on each line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2612 If you want to continue one comment across several lines, use \\[newline-and-indent].
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2613
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2614 If a fill column is specified, it overrides the use of the comment column
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2615 or comment indentation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2616
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2617 The inserted newline is marked hard if `use-hard-newlines' is true,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2618 unless optional argument SOFT is non-nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2619 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2620 (let (comcol comstart)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2621 (skip-chars-backward " \t")
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
2622 ;; 97/3/14 jhod: Kinsoku processing
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
2623 (if (featurep 'mule)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
2624 (kinsoku-process))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2625 (delete-region (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2626 (progn (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2627 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2628 (if soft (insert ?\n) (newline 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2629 (if fill-prefix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2630 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2631 (indent-to-left-margin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2632 (insert fill-prefix))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2633 ;; #### - Eric Eide reverts to v18 semantics for this function in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2634 ;; fa-extras, which I'm not gonna do. His changes are to (1) execute
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2635 ;; the save-excursion below unconditionally, and (2) uncomment the check
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2636 ;; for (not comment-multi-line) further below. --Stig
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
2637 ;;### jhod: probably need to fix this for kinsoku processing
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2638 (if (not comment-multi-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2639 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2640 (if (and comment-start-skip
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2641 (let ((opoint (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2642 (forward-line -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2643 (re-search-forward comment-start-skip opoint t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2644 ;; The old line is a comment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2645 ;; Set WIN to the pos of the comment-start.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2646 ;; But if the comment is empty, look at preceding lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2647 ;; to find one that has a nonempty comment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2648
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2649 ;; If comment-start-skip contains a \(...\) pair,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2650 ;; the real comment delimiter starts at the end of that pair.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2651 (let ((win (or (match-end 1) (match-beginning 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2652 (while (and (eolp) (not (bobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2653 (let (opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2654 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2655 (setq opoint (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2656 (forward-line -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2657 (re-search-forward comment-start-skip opoint t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2658 (setq win (or (match-end 1) (match-beginning 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2659 ;; Indent this line like what we found.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2660 (goto-char win)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2661 (setq comcol (current-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2662 (setq comstart
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2663 (buffer-substring (point) (match-end 0)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2664 (if (and comcol (not fill-prefix)) ; XEmacs - (ENE) from fa-extras.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2665 (let ((comment-column comcol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2666 (comment-start comstart)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2667 (comment-end comment-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2668 (and comment-end (not (equal comment-end ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2669 ; (if (not comment-multi-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2670 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2671 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2672 (insert comment-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2673 (forward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2674 ; (setq comment-column (+ comment-column (length comment-start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2675 ; comment-start "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2676 ; )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2677 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2678 (if (not (eolp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2679 (setq comment-end ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2680 (insert ?\n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2681 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2682 (indent-for-comment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2683 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2684 ;; Make sure we delete the newline inserted above.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2685 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2686 (delete-char 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2687 (indent-according-to-mode)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2688
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2689
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2690 (defun set-selective-display (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2691 "Set `selective-display' to ARG; clear it if no arg.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2692 When the value of `selective-display' is a number > 0,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2693 lines whose indentation is >= that value are not displayed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2694 The variable `selective-display' has a separate value for each buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2695 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2696 (if (eq selective-display t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2697 (error "selective-display already in use for marked lines"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2698 (let ((current-vpos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2699 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2700 (narrow-to-region (point-min) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2701 (goto-char (window-start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2702 (vertical-motion (window-height)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2703 (setq selective-display
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2704 (and arg (prefix-numeric-value arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2705 (recenter current-vpos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2706 (set-window-start (selected-window) (window-start (selected-window)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2707 ;; #### doesn't localize properly:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2708 (princ "selective-display set to " t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2709 (prin1 selective-display t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2710 (princ "." t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2711
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2712 ;; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2713 (defun nuke-selective-display ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2714 "Ensure that the buffer is not in selective-display mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2715 If `selective-display' is t, then restore the buffer text to it's original
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2716 state before disabling selective display."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2717 ;; by Stig@hackvan.com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2718 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2719 (and (eq t selective-display)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2720 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2721 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2722 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2723 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2724 (let ((mod-p (buffer-modified-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2725 (buffer-read-only nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2726 (while (search-forward "\r" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2727 (delete-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2728 (insert "\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2729 (set-buffer-modified-p mod-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2730 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2731 (setq selective-display nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2732
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2733 (add-hook 'change-major-mode-hook 'nuke-selective-display)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2734
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2735 (defconst overwrite-mode-textual (purecopy " Ovwrt")
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2736 "The string displayed in the mode line when in overwrite mode.")
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2737 (defconst overwrite-mode-binary (purecopy " Bin Ovwrt")
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2738 "The string displayed in the mode line when in binary overwrite mode.")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2739
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2740 (defun overwrite-mode (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2741 "Toggle overwrite mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2742 With arg, turn overwrite mode on iff arg is positive.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2743 In overwrite mode, printing characters typed in replace existing text
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2744 on a one-for-one basis, rather than pushing it to the right. At the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2745 end of a line, such characters extend the line. Before a tab,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2746 such characters insert until the tab is filled in.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2747 \\[quoted-insert] still inserts characters in overwrite mode; this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2748 is supposed to make it easier to insert characters when necessary."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2749 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2750 (setq overwrite-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2751 (if (if (null arg) (not overwrite-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2752 (> (prefix-numeric-value arg) 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2753 'overwrite-mode-textual))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2754 (redraw-modeline))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2755
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2756 (defun binary-overwrite-mode (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2757 "Toggle binary overwrite mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2758 With arg, turn binary overwrite mode on iff arg is positive.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2759 In binary overwrite mode, printing characters typed in replace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2760 existing text. Newlines are not treated specially, so typing at the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2761 end of a line joins the line to the next, with the typed character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2762 between them. Typing before a tab character simply replaces the tab
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2763 with the character typed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2764 \\[quoted-insert] replaces the text at the cursor, just as ordinary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2765 typing characters do.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2766
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2767 Note that binary overwrite mode is not its own minor mode; it is a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2768 specialization of overwrite-mode, entered by setting the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2769 `overwrite-mode' variable to `overwrite-mode-binary'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2770 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2771 (setq overwrite-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2772 (if (if (null arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2773 (not (eq overwrite-mode 'overwrite-mode-binary))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2774 (> (prefix-numeric-value arg) 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2775 'overwrite-mode-binary))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2776 (redraw-modeline))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2777
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
2778 (defcustom line-number-mode nil
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
2779 "*Non-nil means display line number in modeline."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
2780 :type 'boolean
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
2781 :group 'editing-basics)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2782
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2783 (defun line-number-mode (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2784 "Toggle Line Number mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2785 With arg, turn Line Number mode on iff arg is positive.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2786 When Line Number mode is enabled, the line number appears
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2787 in the mode line."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2788 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2789 (setq line-number-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2790 (if (null arg) (not line-number-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2791 (> (prefix-numeric-value arg) 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2792 (redraw-modeline))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2793
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
2794 (defcustom column-number-mode nil
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
2795 "*Non-nil means display column number in mode line."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
2796 :type 'boolean
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
2797 :group 'editing-basics)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2798
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2799 (defun column-number-mode (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2800 "Toggle Column Number mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2801 With arg, turn Column Number mode on iff arg is positive.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2802 When Column Number mode is enabled, the column number appears
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2803 in the mode line."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2804 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2805 (setq column-number-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2806 (if (null arg) (not column-number-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2807 (> (prefix-numeric-value arg) 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2808 (redraw-modeline))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2809
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2810
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
2811 (defcustom blink-matching-paren t
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
2812 "*Non-nil means show matching open-paren when close-paren is inserted."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
2813 :type 'boolean
126
1370575f1259 Import from CVS: tag xemacs-20-1p1
cvs
parents: 124
diff changeset
2814 :group 'paren-blinking)
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
2815
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
2816 (defcustom blink-matching-paren-on-screen t
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2817 "*Non-nil means show matching open-paren when it is on screen.
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2818 nil means don't show it (but the open-paren can still be shown
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
2819 when it is off screen."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
2820 :type 'boolean
126
1370575f1259 Import from CVS: tag xemacs-20-1p1
cvs
parents: 124
diff changeset
2821 :group 'paren-blinking)
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
2822
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
2823 (defcustom blink-matching-paren-distance 12000
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
2824 "*If non-nil, is maximum distance to search for matching open-paren."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
2825 :type '(choice integer (const nil))
126
1370575f1259 Import from CVS: tag xemacs-20-1p1
cvs
parents: 124
diff changeset
2826 :group 'paren-blinking)
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
2827
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
2828 (defcustom blink-matching-delay 1
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
2829 "*The number of seconds that `blink-matching-open' will delay at a match."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
2830 :type 'number
126
1370575f1259 Import from CVS: tag xemacs-20-1p1
cvs
parents: 124
diff changeset
2831 :group 'paren-blinking)
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
2832
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
2833 (defcustom blink-matching-paren-dont-ignore-comments nil
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
2834 "*Non-nil means `blink-matching-paren' should not ignore comments."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 110
diff changeset
2835 :type 'boolean
126
1370575f1259 Import from CVS: tag xemacs-20-1p1
cvs
parents: 124
diff changeset
2836 :group 'paren-blinking)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2837
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2838 (defun blink-matching-open ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2839 "Move cursor momentarily to the beginning of the sexp before point."
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2840 (interactive "_") ; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2841 (and (> (point) (1+ (point-min)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2842 blink-matching-paren
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2843 ;; Verify an even number of quoting characters precede the close.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2844 (= 1 (logand 1 (- (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2845 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2846 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2847 (skip-syntax-backward "/\\")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2848 (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2849 (let* ((oldpos (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2850 (parse-sexp-ignore-comments t) ; to avoid C++ lossage
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2851 (blinkpos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2852 (mismatch))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2853 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2854 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2855 (if blink-matching-paren-distance
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2856 (narrow-to-region (max (point-min)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2857 (- (point) blink-matching-paren-distance))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2858 oldpos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2859 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2860 (let ((parse-sexp-ignore-comments
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2861 (and parse-sexp-ignore-comments
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2862 (not blink-matching-paren-dont-ignore-comments))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2863 (setq blinkpos (scan-sexps oldpos -1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2864 (error nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2865 (and blinkpos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2866 (/= (char-syntax (char-after blinkpos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2867 ?\$)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2868 (setq mismatch
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2869 (or (null (matching-paren (char-after blinkpos)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2870 (/= (char-after (1- oldpos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2871 (matching-paren (char-after blinkpos))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2872 (if mismatch (setq blinkpos nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2873 (if blinkpos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2874 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2875 (goto-char blinkpos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2876 (if (pos-visible-in-window-p)
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2877 (and blink-matching-paren-on-screen
78
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 74
diff changeset
2878 (progn
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 74
diff changeset
2879 (auto-show-make-point-visible)
c7528f8e288d Import from CVS: tag r20-0b34
cvs
parents: 74
diff changeset
2880 (sit-for blink-matching-delay)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2881 (goto-char blinkpos)
193
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
2882 (display-message
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
2883 'command
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
2884 (format
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
2885 "Matches %s"
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
2886 ;; Show what precedes the open in its line, if anything.
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
2887 (if (save-excursion
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
2888 (skip-chars-backward " \t")
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
2889 (not (bolp)))
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
2890 (buffer-substring (progn (beginning-of-line) (point))
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
2891 (1+ blinkpos))
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
2892 ;; Show what follows the open in its line, if anything.
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
2893 (if (save-excursion
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
2894 (forward-char 1)
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
2895 (skip-chars-forward " \t")
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
2896 (not (eolp)))
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
2897 (buffer-substring blinkpos
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
2898 (progn (end-of-line) (point)))
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
2899 ;; Otherwise show the previous nonblank line,
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
2900 ;; if there is one.
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
2901 (if (save-excursion
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
2902 (skip-chars-backward "\n \t")
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
2903 (not (bobp)))
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
2904 (concat
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
2905 (buffer-substring (progn
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
2906 (skip-chars-backward "\n \t")
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
2907 (beginning-of-line)
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
2908 (point))
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
2909 (progn (end-of-line)
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
2910 (skip-chars-backward " \t")
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
2911 (point)))
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
2912 ;; Replace the newline and other whitespace with `...'.
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
2913 "..."
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
2914 (buffer-substring blinkpos (1+ blinkpos)))
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
2915 ;; There is nothing to show except the char itself.
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
2916 (buffer-substring blinkpos (1+ blinkpos)))))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2917 (cond (mismatch
193
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
2918 (display-message 'no-log "Mismatched parentheses"))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2919 ((not blink-matching-paren-distance)
193
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
2920 (display-message 'no-log "Unmatched parenthesis"))))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2921
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2922 ;Turned off because it makes dbx bomb out.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2923 (setq blink-paren-function 'blink-matching-open)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2924
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2925 (eval-when-compile (defvar myhelp)) ; suppress compiler warning
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2926
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2927 ;; XEmacs: Some functions moved to cmdloop.el:
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2928 ;; keyboard-quit
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2929 ;; buffer-quit-function
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2930 ;; keyboard-escape-quit
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
2931
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2932 (defun assoc-ignore-case (key alist)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2933 "Like `assoc', but assumes KEY is a string and ignores case when comparing."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2934 (let (element)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2935 (while (and alist (not element))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2936 (if (equal key (downcase (car (car alist))))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2937 (setq element (car alist)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2938 (setq alist (cdr alist)))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2939 element))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
2940
195
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2941
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2942 (defcustom mail-user-agent 'sendmail-user-agent
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2943 "*Your preference for a mail composition package.
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2944 Various Emacs Lisp packages (e.g. reporter) require you to compose an
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2945 outgoing email message. This variable lets you specify which
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2946 mail-sending package you prefer.
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2947
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2948 Valid values include:
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2949
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2950 sendmail-user-agent -- use the default Emacs Mail package
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2951 mh-e-user-agent -- use the Emacs interface to the MH mail system
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2952 message-user-agent -- use the GNUS mail sending package
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2953
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2954 Additional valid symbols may be available; check with the author of
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2955 your package for details."
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2956 :type '(radio (function-item :tag "Default Emacs mail"
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2957 :format "%t\n"
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2958 sendmail-user-agent)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2959 (function-item :tag "Gnus mail sending package"
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2960 :format "%t\n"
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2961 message-user-agent)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2962 (function :tag "Other"))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2963 :group 'mail)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2964
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2965 (defun define-mail-user-agent (symbol composefunc sendfunc
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2966 &optional abortfunc hookvar)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2967 "Define a symbol to identify a mail-sending package for `mail-user-agent'.
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2968
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2969 SYMBOL can be any Lisp symbol. Its function definition and/or
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2970 value as a variable do not matter for this usage; we use only certain
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2971 properties on its property list, to encode the rest of the arguments.
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2972
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2973 COMPOSEFUNC is program callable function that composes an outgoing
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2974 mail message buffer. This function should set up the basics of the
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2975 buffer without requiring user interaction. It should populate the
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2976 standard mail headers, leaving the `to:' and `subject:' headers blank
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2977 by default.
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2978
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2979 COMPOSEFUNC should accept several optional arguments--the same
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2980 arguments that `compose-mail' takes. See that function's documentation.
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2981
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2982 SENDFUNC is the command a user would run to send the message.
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2983
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2984 Optional ABORTFUNC is the command a user would run to abort the
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2985 message. For mail packages that don't have a separate abort function,
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2986 this can be `kill-buffer' (the equivalent of omitting this argument).
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2987
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2988 Optional HOOKVAR is a hook variable that gets run before the message
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2989 is actually sent. Callers that use the `mail-user-agent' may
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2990 install a hook function temporarily on this hook variable.
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2991 If HOOKVAR is nil, `mail-send-hook' is used.
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2992
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2993 The properties used on SYMBOL are `composefunc', `sendfunc',
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2994 `abortfunc', and `hookvar'."
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2995 (put symbol 'composefunc composefunc)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2996 (put symbol 'sendfunc sendfunc)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2997 (put symbol 'abortfunc (or abortfunc 'kill-buffer))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2998 (put symbol 'hookvar (or hookvar 'mail-send-hook)))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
2999
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3000 (define-mail-user-agent 'sendmail-user-agent
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3001 'sendmail-user-agent-compose 'mail-send-and-exit)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3002
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3003 (define-mail-user-agent 'message-user-agent
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3004 'message-mail 'message-send-and-exit
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3005 'message-kill-buffer 'message-send-hook)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3006
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3007 (defun sendmail-user-agent-compose (&optional to subject other-headers continue
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3008 switch-function yank-action
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3009 send-actions)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3010 (if switch-function
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3011 (let ((special-display-buffer-names nil)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3012 (special-display-regexps nil)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3013 (same-window-buffer-names nil)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3014 (same-window-regexps nil))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3015 (funcall switch-function "*mail*")))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3016 (let ((cc (cdr (assoc-ignore-case "cc" other-headers)))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3017 (in-reply-to (cdr (assoc-ignore-case "in-reply-to" other-headers))))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3018 (or (mail continue to subject in-reply-to cc yank-action send-actions)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3019 continue
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3020 (error "Message aborted"))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3021 (save-excursion
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3022 (goto-char (point-min))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3023 (search-forward mail-header-separator)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3024 (beginning-of-line)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3025 (while other-headers
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3026 (if (not (member (car (car other-headers)) '("in-reply-to" "cc")))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3027 (insert (car (car other-headers)) ": "
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3028 (cdr (car other-headers)) "\n"))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3029 (setq other-headers (cdr other-headers)))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3030 t)))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3031
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3032 (define-mail-user-agent 'mh-e-user-agent
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3033 'mh-smail-batch 'mh-send-letter 'mh-fully-kill-draft
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3034 'mh-before-send-letter-hook)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3035
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3036 (defun compose-mail (&optional to subject other-headers continue
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3037 switch-function yank-action send-actions)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3038 "Start composing a mail message to send.
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3039 This uses the user's chosen mail composition package
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3040 as selected with the variable `mail-user-agent'.
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3041 The optional arguments TO and SUBJECT specify recipients
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3042 and the initial Subject field, respectively.
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3043
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3044 OTHER-HEADERS is an alist specifying additional
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3045 header fields. Elements look like (HEADER . VALUE) where both
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3046 HEADER and VALUE are strings.
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3047
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3048 CONTINUE, if non-nil, says to continue editing a message already
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3049 being composed.
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3050
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3051 SWITCH-FUNCTION, if non-nil, is a function to use to
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3052 switch to and display the buffer used for mail composition.
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3053
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3054 YANK-ACTION, if non-nil, is an action to perform, if and when necessary,
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3055 to insert the raw text of the message being replied to.
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3056 It has the form (FUNCTION . ARGS). The user agent will apply
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3057 FUNCTION to ARGS, to insert the raw text of the original message.
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3058 \(The user agent will also run `mail-citation-hook', *after* the
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3059 original text has been inserted in this way.)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3060
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3061 SEND-ACTIONS is a list of actions to call when the message is sent.
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3062 Each action has the form (FUNCTION . ARGS)."
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3063 (interactive
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3064 (list nil nil nil current-prefix-arg))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3065 (let ((function (get mail-user-agent 'composefunc)))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3066 (funcall function to subject other-headers continue
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3067 switch-function yank-action send-actions)))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3068
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3069 (defun compose-mail-other-window (&optional to subject other-headers continue
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3070 yank-action send-actions)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3071 "Like \\[compose-mail], but edit the outgoing message in another window."
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3072 (interactive
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3073 (list nil nil nil current-prefix-arg))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3074 (compose-mail to subject other-headers continue
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3075 'switch-to-buffer-other-window yank-action send-actions))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3076
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3077
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3078 (defun compose-mail-other-frame (&optional to subject other-headers continue
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3079 yank-action send-actions)
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3080 "Like \\[compose-mail], but edit the outgoing message in another frame."
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3081 (interactive
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3082 (list nil nil nil current-prefix-arg))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3083 (compose-mail to subject other-headers continue
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3084 'switch-to-buffer-other-frame yank-action send-actions))
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3085
a2f645c6b9f8 Import from CVS: tag r20-3b24
cvs
parents: 193
diff changeset
3086
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3087 (defun set-variable (var val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3088 "Set VARIABLE to VALUE. VALUE is a Lisp object.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3089 When using this interactively, supply a Lisp expression for VALUE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3090 If you want VALUE to be a string, you must surround it with doublequotes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3091
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3092 If VARIABLE has a `variable-interactive' property, that is used as if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3093 it were the arg to `interactive' (which see) to interactively read the value."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3094 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3095 (let* ((var (read-variable "Set variable: "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3096 ;; #### - yucky code replication here. This should use something
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3097 ;; from help.el or hyper-apropos.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3098 (minibuffer-help-form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3099 '(funcall myhelp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3100 (myhelp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3101 #'(lambda ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3102 (with-output-to-temp-buffer "*Help*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3103 (prin1 var)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3104 (princ "\nDocumentation:\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3105 (princ (substring (documentation-property var 'variable-documentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3106 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3107 (if (boundp var)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3108 (let ((print-length 20))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3109 (princ "\n\nCurrent value: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3110 (prin1 (symbol-value var))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3111 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3112 (set-buffer standard-output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3113 (help-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3114 nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3115 (list var
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3116 (let ((prop (get var 'variable-interactive)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3117 (if prop
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3118 ;; Use VAR's `variable-interactive' property
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3119 ;; as an interactive spec for prompting.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3120 (call-interactively (list 'lambda '(arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3121 (list 'interactive prop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3122 'arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3123 (eval-minibuffer (format "Set %s to value: " var)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3124 (set var val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3125
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
3126 ;; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3127 (defun activate-region ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3128 "Activate the region, if `zmacs-regions' is true.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3129 Setting `zmacs-regions' to true causes LISPM-style active regions to be used.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3130 This function has no effect if `zmacs-regions' is false."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3131 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3132 (and zmacs-regions (zmacs-activate-region)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3133
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
3134 ;; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3135 (defsubst region-exists-p ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3136 "Non-nil iff the region exists.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3137 If active regions are in use (i.e. `zmacs-regions' is true), this means that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3138 the region is active. Otherwise, this means that the user has pushed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3139 a mark in this buffer at some point in the past.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3140 The functions `region-beginning' and `region-end' can be used to find the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3141 limits of the region."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3142 (not (null (mark))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3143
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
3144 ;; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3145 (defun region-active-p ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3146 "Non-nil iff the region is active.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3147 If `zmacs-regions' is true, this is equivalent to `region-exists-p'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3148 Otherwise, this function always returns false."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3149 (and zmacs-regions zmacs-region-extent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3150
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
3151 ;; A bunch of stuff was moved elsewhere:
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
3152 ;; completion-list-mode-map
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
3153 ;; completion-reference-buffer
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
3154 ;; completion-base-size
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
3155 ;; delete-completion-window
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
3156 ;; previous-completion
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
3157 ;; next-completion
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
3158 ;; choose-completion
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
3159 ;; choose-completion-delete-max-match
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
3160 ;; choose-completion-string
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
3161 ;; completion-list-mode
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
3162 ;; completion-fixup-function
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
3163 ;; completion-setup-function
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
3164 ;; switch-to-completions
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
3165 ;; event stuffs
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
3166 ;; keypad stuffs
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
3167
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
3168 ;; The rest of this file is not in Lisp in FSF
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3169 (defun capitalize-region-or-word (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3170 "Capitalize the selected region or the following word (or ARG words)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3171 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3172 (if (region-active-p) (capitalize-region (region-beginning) (region-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3173 (capitalize-word arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3174
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3175 (defun upcase-region-or-word (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3176 "Upcase the selected region or the following word (or ARG words)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3177 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3178 (if (region-active-p) (upcase-region (region-beginning) (region-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3179 (upcase-word arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3180
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3181 (defun downcase-region-or-word (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3182 "Downcase the selected region or the following word (or ARG words)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3183 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3184 (if (region-active-p) (downcase-region (region-beginning) (region-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3185 (downcase-word arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3186
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3187 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3188 ;;; Most of the zmacs code is now in elisp. The only thing left in C
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3189 ;;; are the variables zmacs-regions, zmacs-region-active-p and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3190 ;;; zmacs-region-stays plus the function zmacs_update_region which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3191 ;;; calls the lisp level zmacs-update-region. It must remain since it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3192 ;;; must be called by core C code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3193 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3194
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3195 (defvar zmacs-activate-region-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3196 "Function or functions called when the region becomes active;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3197 see the variable `zmacs-regions'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3198
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3199 (defvar zmacs-deactivate-region-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3200 "Function or functions called when the region becomes inactive;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3201 see the variable `zmacs-regions'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3202
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3203 (defvar zmacs-update-region-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3204 "Function or functions called when the active region changes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3205 This is called after each command that sets `zmacs-region-stays' to t.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3206 See the variable `zmacs-regions'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3207
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3208 (defvar zmacs-region-extent nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3209 "The extent of the zmacs region; don't use this.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3210
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3211 (defvar zmacs-region-rectangular-p nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3212 "Whether the zmacs region is a rectangle; don't use this.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3213
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3214 (defun zmacs-make-extent-for-region (region)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3215 ;; Given a region, this makes an extent in the buffer which holds that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3216 ;; region, for highlighting purposes. If the region isn't associated
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3217 ;; with a buffer, this does nothing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3218 (let ((buffer nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3219 (valid (and (extentp zmacs-region-extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3220 (extent-object zmacs-region-extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3221 (buffer-live-p (extent-object zmacs-region-extent))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3222 start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3223 (cond ((consp region)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3224 (setq start (min (car region) (cdr region))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3225 end (max (car region) (cdr region))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3226 valid (and valid
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3227 (eq (marker-buffer (car region))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3228 (extent-object zmacs-region-extent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3229 buffer (marker-buffer (car region))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3230 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3231 (signal 'error (list "invalid region" region))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3232
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3233 (if valid
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3234 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3235 ;; The condition case is in case any of the extents are dead or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3236 ;; otherwise incapacitated.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3237 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3238 (if (listp zmacs-region-extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3239 (mapcar 'delete-extent zmacs-region-extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3240 (delete-extent zmacs-region-extent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3241 (error nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3242
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3243 (if valid
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3244 (set-extent-endpoints zmacs-region-extent start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3245 (setq zmacs-region-extent (make-extent start end buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3246
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3247 ;; Make the extent be closed on the right, which means that if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3248 ;; characters are inserted exactly at the end of the extent, the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3249 ;; extent will grow to cover them. This is important for shell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3250 ;; buffers - suppose one makes a region, and one end is at point-max.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3251 ;; If the shell produces output, that marker will remain at point-max
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3252 ;; (its position will increase). So it's important that the extent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3253 ;; exhibit the same behavior, lest the region covered by the extent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3254 ;; (the visual indication), and the region between point and mark
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3255 ;; (the actual region value) become different!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3256 (set-extent-property zmacs-region-extent 'end-open nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3257
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3258 ;; use same priority as mouse-highlighting so that conflicts between
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3259 ;; the region extent and a mouse-highlighted extent are resolved by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3260 ;; the usual size-and-endpoint-comparison method.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3261 (set-extent-priority zmacs-region-extent mouse-highlight-priority)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3262 (set-extent-face zmacs-region-extent 'zmacs-region)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3263
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3264 ;; #### It might be better to actually break
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3265 ;; default-mouse-track-next-move-rect out of mouse.el so that we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3266 ;; can use its logic here.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3267 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3268 (zmacs-region-rectangular-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3269 (setq zmacs-region-extent (list zmacs-region-extent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3270 (default-mouse-track-next-move-rect start end zmacs-region-extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3271 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3272
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3273 zmacs-region-extent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3274
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3275 (defun zmacs-region-buffer ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3276 "Return the buffer containing the zmacs region, or nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3277 ;; #### this is horrible and kludgy! This stuff needs to be rethought.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3278 (and zmacs-regions zmacs-region-active-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3279 (or (marker-buffer (mark-marker t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3280 (and (extent-live-p zmacs-region-extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3281 (buffer-live-p (extent-object zmacs-region-extent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3282 (extent-object zmacs-region-extent)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3283
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3284 (defun zmacs-activate-region ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3285 "Make the region between `point' and `mark' be active (highlighted),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3286 if `zmacs-regions' is true. Only a very small number of commands
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3287 should ever do this. Calling this function will call the hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3288 `zmacs-activate-region-hook', if the region was previously inactive.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3289 Calling this function ensures that the region stays active after the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3290 current command terminates, even if `zmacs-region-stays' is not set.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3291 Returns t if the region was activated (i.e. if `zmacs-regions' if t)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3292 (if (not zmacs-regions)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3293 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3294 (setq zmacs-region-active-p t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3295 zmacs-region-stays t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3296 zmacs-region-rectangular-p (and (boundp 'mouse-track-rectangle-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3297 mouse-track-rectangle-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3298 (if (marker-buffer (mark-marker t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3299 (zmacs-make-extent-for-region (cons (point-marker t) (mark-marker t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3300 (run-hooks 'zmacs-activate-region-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3301 t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3302
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3303 (defun zmacs-deactivate-region ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3304 "Make the region between `point' and `mark' no longer be active,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3305 if `zmacs-regions' is true. You shouldn't need to call this; the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3306 command loop calls it when appropriate. Calling this function will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3307 call the hook `zmacs-deactivate-region-hook', if the region was
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3308 previously active. Returns t if the region had been active, nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3309 otherwise."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3310 (if (not zmacs-region-active-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3311 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3312 (setq zmacs-region-active-p nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3313 zmacs-region-stays nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3314 zmacs-region-rectangular-p nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3315 (if zmacs-region-extent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3316 (let ((inhibit-quit t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3317 (if (listp zmacs-region-extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3318 (mapcar 'delete-extent zmacs-region-extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3319 (delete-extent zmacs-region-extent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3320 (setq zmacs-region-extent nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3321 (run-hooks 'zmacs-deactivate-region-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3322 t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3323
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3324 (defun zmacs-update-region ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3325 "Update the highlighted region between `point' and `mark'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3326 You shouldn't need to call this; the command loop calls it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3327 when appropriate. Calling this function will call the hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3328 `zmacs-update-region-hook', if the region is active."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3329 (if zmacs-region-active-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3330 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3331 (if (marker-buffer (mark-marker t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3332 (zmacs-make-extent-for-region (cons (point-marker t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3333 (mark-marker t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3334 (run-hooks 'zmacs-update-region-hook))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3335
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3336 ;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3337 ;;;;;; echo area stuff
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3338 ;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3339
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3340 ;;; The `message-stack' is an alist of labels with messages; the first
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3341 ;;; message in this list is always in the echo area. A call to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3342 ;;; `display-message' inserts a label/message pair at the head of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3343 ;;; list, and removes any other pairs with that label. Calling
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3344 ;;; `clear-message' causes any pair with matching label to be removed,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3345 ;;; and this may cause the displayed message to change or vanish. If
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3346 ;;; the label arg is nil, the entire message stack is cleared.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3347 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3348 ;;; Message/error filtering will be a little tricker to implement than
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3349 ;;; logging, since messages can be built up incrementally
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3350 ;;; using clear-message followed by repeated calls to append-message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3351 ;;; (this happens with error messages). For messages which aren't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3352 ;;; created this way, filtering could be implemented at display-message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3353 ;;; very easily.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3354 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3355 ;;; Bits of the logging code are borrowed from log-messages.el by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3356 ;;; Robert Potter (rpotter@grip.cis.upenn.edu).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3357
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3358 ;; need this to terminate the currently-displayed message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3359 ;; ("Loading simple ...")
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
3360 (when (and
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
3361 (not (fboundp 'display-message))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
3362 (not (featurep 'debug)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
3363 (send-string-to-terminal "\n"))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3364
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3365 (defvar message-stack nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3366 "An alist of label/string pairs representing active echo-area messages.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3367 The first element in the list is currently displayed in the echo area.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3368 Do not modify this directly--use the `message' or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3369 `display-message'/`clear-message' functions.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3370
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3371 (defvar remove-message-hook 'log-message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3372 "A function or list of functions to be called when a message is removed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3373 from the echo area at the bottom of the frame. The label of the removed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3374 message is passed as the first argument, and the text of the message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3375 as the second argument.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3376
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3377 (defvar log-message-max-size 50000
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3378 "Maximum size of the \" *Message-Log*\" buffer. See `log-message'.")
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
3379 (make-compatible-variable 'message-log-max 'log-message-max-size)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3380
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
3381 ;; We used to reject quite a lot of stuff here, but it was a bad idea,
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
3382 ;; for two reasons:
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
3383 ;;
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
3384 ;; a) In most circumstances, you *want* to see the message in the log.
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
3385 ;; The explicitly non-loggable messages should be marked as such by
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
3386 ;; the issuer. Gratuitous non-displaying of random regexps made
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
3387 ;; debugging harder, too (because various reasonable debugging
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
3388 ;; messages would get eaten).
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
3389 ;;
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
3390 ;; b) It slowed things down. Yes, visibly.
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
3391 ;;
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
3392 ;; So, I left only a few of the really useless ones on this kill-list.
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
3393 ;;
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
3394 ;; --hniksic
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3395 (defvar log-message-ignore-regexps
193
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
3396 '(;; Note: adding entries to this list slows down messaging
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
3397 ;; significantly. Wherever possible, use message lables.
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
3398
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
3399 ;; Often-seen messages
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
3400 "\\`\\'" ; empty message
193
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
3401 "\\`\\(Beginning\\|End\\) of buffer\\'"
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
3402 ;;"^Quit$"
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
3403 ;; completions
193
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
3404 ;; Many packages print this -- impossible to categorize
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 169
diff changeset
3405 ;;"^Making completion list"
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
3406 ;; Gnus
193
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
3407 ;; "^No news is no news$"
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
3408 ;; "^No more\\( unread\\)? newsgroups$"
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
3409 ;; "^Opening [^ ]+ server\\.\\.\\."
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
3410 ;; "^[^:]+: Reading incoming mail"
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
3411 ;; "^Getting mail from "
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
3412 ;; "^\\(Generating Summary\\|Sorting threads\\|Making sparse threads\\|Scoring\\|Checking new news\\|Expiring articles\\|Sending\\)\\.\\.\\."
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
3413 ;; "^\\(Fetching headers for\\|Retrieving newsgroup\\|Reading active file\\)"
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
3414 ;; "^No more\\( unread\\)? articles"
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
3415 ;; "^Deleting article "
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
3416 ;; W3
193
f53b5ca2e663 Import from CVS: tag r20-3b23
cvs
parents: 189
diff changeset
3417 ;; "^Parsed [0-9]+ of [0-9]+ ([0-9]+%)"
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3418 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3419 "List of regular expressions matching messages which shouldn't be logged.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3420 See `log-message'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3421
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3422 Ideally, packages which generate messages which might need to be ignored
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3423 should label them with 'progress, 'prompt, or 'no-log, so they can be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3424 filtered by the log-message-ignore-labels.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3425
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3426 (defvar log-message-ignore-labels
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3427 '(help-echo command progress prompt no-log garbage-collecting auto-saving)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3428 "List of symbols indicating labels of messages which shouldn't be logged.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3429 See `display-message' for some common labels. See also `log-message'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3430
169
15872534500d Import from CVS: tag r20-3b11
cvs
parents: 167
diff changeset
3431 ;;Subsumed by view-lossage
15872534500d Import from CVS: tag r20-3b11
cvs
parents: 167
diff changeset
3432 ;; Not really, I'm adding it back by popular demand. -slb
15872534500d Import from CVS: tag r20-3b11
cvs
parents: 167
diff changeset
3433 (defun show-message-log ()
15872534500d Import from CVS: tag r20-3b11
cvs
parents: 167
diff changeset
3434 "Show the \" *Message-Log*\" buffer, which contains old messages and errors."
15872534500d Import from CVS: tag r20-3b11
cvs
parents: 167
diff changeset
3435 (interactive)
15872534500d Import from CVS: tag r20-3b11
cvs
parents: 167
diff changeset
3436 (pop-to-buffer " *Message-Log*"))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3437
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3438 (defvar log-message-filter-function 'log-message-filter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3439 "Value must be a function of two arguments: a symbol (label) and
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 104
diff changeset
3440 a string (message). It should return non-nil to indicate a message
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3441 should be logged. Possible values include 'log-message-filter and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3442 'log-message-filter-errors-only.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3443
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3444 (defun log-message-filter (label message)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3445 "Default value of log-message-filter-function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3446 Mesages whose text matches one of the log-message-ignore-regexps
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3447 or whose label appears in log-message-ignore-labels are not saved."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3448 (let ((r log-message-ignore-regexps)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3449 (ok (not (memq label log-message-ignore-labels))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3450 (while (and r ok)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3451 (if (save-match-data (string-match (car r) message))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3452 (setq ok nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3453 (setq r (cdr r)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3454 ok))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3455
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3456 (defun log-message-filter-errors-only (label message)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3457 "For use as the log-message-filter-function. Only logs error messages."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3458 (eq label 'error))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3459
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3460 (defun log-message (label message)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3461 "Stuff a copy of the message into the \" *Message-Log*\" buffer,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3462 if it satisfies the log-message-filter-function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3463
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3464 For use on remove-message-hook."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3465 (if (and (not noninteractive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3466 (funcall log-message-filter-function label message))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3467 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3468 (set-buffer (get-buffer-create " *Message-Log*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3469 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3470 ;; (insert (concat (upcase (symbol-name label)) ": " message "\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3471 (insert message "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3472 (if (> (point-max) (max log-message-max-size (point-min)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3473 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3474 ;; trim log to ~90% of max size
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3475 (goto-char (max (- (point-max)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3476 (truncate (* 0.9 log-message-max-size)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3477 (point-min)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3478 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3479 (delete-region (point-min) (point)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3480
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3481 (defun message-displayed-p (&optional return-string frame)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3482 "Return a non-nil value if a message is presently displayed in the\n\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3483 minibuffer's echo area. If optional argument RETURN-STRING is non-nil,\n\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3484 return a string containing the message, otherwise just return t."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3485 ;; by definition, a message is displayed if the echo area buffer is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3486 ;; non-empty (see also echo_area_active()). It had better also
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3487 ;; be the case that message-stack is nil exactly when the echo area
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3488 ;; is non-empty.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3489 (let ((buffer (get-buffer " *Echo Area*")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3490 (and (< (point-min buffer) (point-max buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3491 (if return-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3492 (buffer-substring nil nil buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3493 t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3494
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3495 ;;; Returns the string which remains in the echo area, or nil if none.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3496 ;;; If label is nil, the whole message stack is cleared.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3497 (defun clear-message (&optional label frame stdout-p no-restore)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3498 "Remove any message with the given LABEL from the message-stack,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3499 erasing it from the echo area if it's currently displayed there.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3500 If a message remains at the head of the message-stack and NO-RESTORE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3501 is nil, it will be displayed. The string which remains in the echo
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3502 area will be returned, or nil if the message-stack is now empty.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3503 If LABEL is nil, the entire message-stack is cleared.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3504
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
3505 Unless you need the return value or you need to specify a label,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3506 you should just use (message nil)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3507 (or frame (setq frame (selected-frame)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3508 (let ((clear-stream (and message-stack (eq 'stream (frame-type frame)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3509 (remove-message label frame)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3510 (let ((buffer (get-buffer " *Echo Area*"))
169
15872534500d Import from CVS: tag r20-3b11
cvs
parents: 167
diff changeset
3511 (inhibit-read-only t)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3512 (zmacs-region-stays zmacs-region-stays)) ; preserve from change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3513 (erase-buffer buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3514 (if clear-stream
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3515 (send-string-to-terminal ?\n stdout-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3516 (if no-restore
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3517 nil ; just preparing to put another msg up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3518 (if message-stack
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3519 (let ((oldmsg (cdr (car message-stack))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3520 (raw-append-message oldmsg frame stdout-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3521 oldmsg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3522 ;; ### should we (redisplay-echo-area) here? messes some things up.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3523 nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3524
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3525 (defun remove-message (&optional label frame)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3526 ;; If label is nil, we want to remove all matching messages.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3527 ;; Must reverse the stack first to log them in the right order.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3528 (let ((log nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3529 (while (and message-stack
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3530 (or (null label) ; null label means clear whole stack
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3531 (eq label (car (car message-stack)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3532 (setq log (cons (car message-stack) log))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3533 (setq message-stack (cdr message-stack)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3534 (let ((s message-stack))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3535 (while (cdr s)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3536 (let ((msg (car (cdr s))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3537 (if (eq label (car msg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3538 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3539 (setq log (cons msg log))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3540 (setcdr s (cdr (cdr s))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3541 (setq s (cdr s))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3542 ;; (possibly) log each removed message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3543 (while log
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3544 (condition-case e
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3545 (run-hook-with-args 'remove-message-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3546 (car (car log)) (cdr (car log)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3547 (error (setq remove-message-hook nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3548 (message "remove-message-hook error: %s" e)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3549 (sit-for 2)
169
15872534500d Import from CVS: tag r20-3b11
cvs
parents: 167
diff changeset
3550 (let ((inhibit-read-only t))
15872534500d Import from CVS: tag r20-3b11
cvs
parents: 167
diff changeset
3551 (erase-buffer (get-buffer " *Echo Area*")))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3552 (signal (car e) (cdr e))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3553 (setq log (cdr log)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3554
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3555 (defun append-message (label message &optional frame stdout-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3556 (or frame (setq frame (selected-frame)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3557 ;; add a new entry to the message-stack, or modify an existing one
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3558 (let ((top (car message-stack)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3559 (if (eq label (car top))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3560 (setcdr top (concat (cdr top) message))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3561 (setq message-stack (cons (cons label message) message-stack))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3562 (raw-append-message message frame stdout-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3563
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3564 ;; really append the message to the echo area. no fiddling with message-stack.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3565 (defun raw-append-message (message &optional frame stdout-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3566 (if (eq message "") nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3567 (let ((buffer (get-buffer " *Echo Area*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3568 (zmacs-region-stays zmacs-region-stays)) ; preserve from change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3569 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3570 (set-buffer buffer)
169
15872534500d Import from CVS: tag r20-3b11
cvs
parents: 167
diff changeset
3571 (let ((inhibit-read-only t))
15872534500d Import from CVS: tag r20-3b11
cvs
parents: 167
diff changeset
3572 (insert message)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3573 ;; Conditionalizing on the device type in this way is not that clean,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3574 ;; but neither is having a device method, as I originally implemented
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3575 ;; it: all non-stream devices behave in the same way. Perhaps
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3576 ;; the cleanest way is to make the concept of a "redisplayable"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3577 ;; device, which stream devices are not. Look into this more if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3578 ;; we ever create another non-redisplayable device type (e.g.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3579 ;; processes? printers?).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3580
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3581 ;; Don't redisplay the echo area if we are executing a macro.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3582 (if (not executing-kbd-macro)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3583 (if (eq 'stream (frame-type frame))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3584 (send-string-to-terminal message stdout-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3585 (redisplay-echo-area))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3586
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3587 (defun display-message (label message &optional frame stdout-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3588 "Print a one-line message at the bottom of the frame. First argument
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3589 LABEL is an identifier for this message. MESSAGE is the string to display.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3590 Use `clear-message' to remove a labelled message.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3591
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3592 Here are some standard labels (those marked with `*' are not logged
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3593 by default--see the `log-message-ignore-labels' variable):
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3594 message default label used by the `message' function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3595 error default label used for reporting errors
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3596 * progress progress indicators like \"Converting... 45%\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3597 * prompt prompt-like messages like \"I-search: foo\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3598 * no-log messages that should never be logged"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3599 (clear-message label frame stdout-p t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3600 (append-message label message frame stdout-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3601
189
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
3602 (defun current-message (&optional frame)
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
3603 "Returns the current message in the echo area, or nil.
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
3604 The FRAME argument is currently unused."
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
3605 (cdr (car message-stack)))
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
3606
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3607 ;;; may eventually be frame-dependent
189
489f57a838ef Import from CVS: tag r20-3b21
cvs
parents: 183
diff changeset
3608 (defun current-message-label (&optional frame)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3609 (if message-stack
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3610 (car (car message-stack))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3611 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3612
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3613 (defun message (fmt &rest args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3614 "Print a one-line message at the bottom of the frame.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3615 The arguments are the same as to `format'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3616
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3617 If the only argument is nil, clear any existing message; let the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3618 minibuffer contents show."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3619 ;; questionable junk in the C code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3620 ;; (if (framep default-minibuffer-frame)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3621 ;; (make-frame-visible default-minibuffer-frame))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3622 (if (and (null fmt) (null args))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3623 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3624 (clear-message nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3625 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3626 (let ((str (apply 'format fmt args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3627 (display-message 'message str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3628 str)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3629
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3630 ;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3631 ;;;;;; warning stuff
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3632 ;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3633
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3634 (defvar log-warning-minimum-level 'info
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3635 "Minimum level of warnings that should be logged.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3636 The warnings in levels below this are completely ignored, as if they never
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3637 happened.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3638
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3639 The recognized warning levels, in decreasing order of priority, are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3640 'emergency, 'alert, 'critical, 'error, 'warning, 'notice, 'info, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3641 'debug.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3642
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3643 See also `display-warning-minimum-level'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3644
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3645 You can also control which warnings are displayed on a class-by-class
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3646 basis. See `display-warning-suppressed-classes' and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3647 `log-warning-suppressed-classes'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3648
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3649 (defvar display-warning-minimum-level 'info
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3650 "Minimum level of warnings that should be displayed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3651 The warnings in levels below this are completely ignored, as if they never
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3652 happened.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3653
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3654 The recognized warning levels, in decreasing order of priority, are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3655 'emergency, 'alert, 'critical, 'error, 'warning, 'notice, 'info, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3656 'debug.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3657
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3658 See also `log-warning-minimum-level'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3659
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3660 You can also control which warnings are displayed on a class-by-class
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3661 basis. See `display-warning-suppressed-classes' and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3662 `log-warning-suppressed-classes'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3663
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3664 (defvar log-warning-suppressed-classes nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3665 "List of classes of warnings that shouldn't be logged or displayed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3666 If any of the CLASS symbols associated with a warning is the same as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3667 any of the symbols listed here, the warning will be completely ignored,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3668 as it they never happened.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3669
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3670 NOTE: In most circumstances, you should *not* set this variable.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3671 Set `display-warning-suppressed-classes' instead. That way the suppressed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3672 warnings are not displayed but are still unobtrusively logged.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3673
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3674 See also `log-warning-minimum-level' and `display-warning-minimum-level'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3675
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3676 (defvar display-warning-suppressed-classes nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3677 "List of classes of warnings that shouldn't be displayed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3678 If any of the CLASS symbols associated with a warning is the same as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3679 any of the symbols listed here, the warning will not be displayed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3680 The warning will still logged in the *Warnings* buffer (unless also
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3681 contained in `log-warning-suppressed-classes'), but the buffer will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3682 not be automatically popped up.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3683
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3684 See also `log-warning-minimum-level' and `display-warning-minimum-level'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3685
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3686 (defvar warning-count 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3687 "Count of the number of warning messages displayed so far.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3688
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3689 (defconst warning-level-alist '((emergency . 8)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3690 (alert . 7)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3691 (critical . 6)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3692 (error . 5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3693 (warning . 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3694 (notice . 3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3695 (info . 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3696 (debug . 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3697
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3698 (defun warning-level-p (level)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3699 "Non-nil if LEVEL specifies a warning level."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3700 (and (symbolp level) (assq level warning-level-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3701
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3702 ;; If you're interested in rewriting this function, be aware that it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3703 ;; could be called at arbitrary points in a Lisp program (when a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3704 ;; built-in function wants to issue a warning, it will call out to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3705 ;; this function the next time some Lisp code is evaluated). Therefore,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3706 ;; this function *must* not permanently modify any global variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3707 ;; (e.g. the current buffer) except those that specifically apply
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3708 ;; to the warning system.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3709
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3710 (defvar before-init-deferred-warnings nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3711
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3712 (defun after-init-display-warnings ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3713 "Display warnings deferred till after the init file is run.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3714 Warnings that occur before then are deferred so that warning
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3715 suppression in the .emacs file will be honored."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3716 (while before-init-deferred-warnings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3717 (apply 'display-warning (car before-init-deferred-warnings))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3718 (setq before-init-deferred-warnings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3719 (cdr before-init-deferred-warnings))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3720
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
3721 #-infodock (add-hook 'after-init-hook 'after-init-display-warnings)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3722
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3723 (defun display-warning (class message &optional level)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3724 "Display a warning message.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3725 CLASS should be a symbol describing what sort of warning this is, such
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3726 as `resource' or `key-mapping'. A list of such symbols is also
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3727 accepted. (Individual classes can be suppressed; see
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3728 `display-warning-suppressed-classes'.) Optional argument LEVEL can
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3729 be used to specify a priority for the warning, other than default priority
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3730 `warning'. (See `display-warning-minimum-level'). The message is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3731 inserted into the *Warnings* buffer, which is made visible at appropriate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3732 times."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3733 (or level (setq level 'warning))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3734 (or (listp class) (setq class (list class)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3735 (check-argument-type 'warning-level-p level)
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
3736 (if (and (not (featurep 'infodock))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
3737 (not init-file-loaded))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3738 (setq before-init-deferred-warnings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3739 (cons (list class message level) before-init-deferred-warnings))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3740 (catch 'ignored
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3741 (let ((display-p t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3742 (level-num (cdr (assq level warning-level-alist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3743 (if (< level-num (cdr (assq log-warning-minimum-level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3744 warning-level-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3745 (throw 'ignored nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3746 (if (intersection class log-warning-suppressed-classes)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3747 (throw 'ignored nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3748
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3749 (if (< level-num (cdr (assq display-warning-minimum-level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3750 warning-level-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3751 (setq display-p nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3752 (if (and display-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3753 (intersection class display-warning-suppressed-classes))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3754 (setq display-p nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3755 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3756 (let ((buffer (get-buffer-create "*Warnings*")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3757 (if display-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3758 ;; The C code looks at display-warning-tick to determine
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3759 ;; when it should call `display-warning-buffer'. Change it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3760 ;; to get the C code's attention.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3761 (setq display-warning-tick (1+ display-warning-tick)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3762 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3763 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3764 (setq warning-count (1+ warning-count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3765 (princ (format "(%d) (%s/%s) "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3766 warning-count
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3767 (mapconcat 'symbol-name class ",")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3768 level) buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3769 (princ message buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3770 (terpri buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3771 (terpri buffer)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3772
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3773 (defun warn (&rest args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3774 "Display a warning message.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3775 The message is constructed by passing all args to `format'. The message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3776 is placed in the *Warnings* buffer, which will be popped up at the next
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3777 redisplay. The class of the warning is `warning'. See also
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3778 `display-warning'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3779 (display-warning 'warning (apply 'format args)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3780
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3781 (defvar warning-marker nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3782
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3783 ;; When this function is called by the C code, all non-local exits are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3784 ;; trapped and C-g is inhibited; therefore, it would be a very, very
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3785 ;; bad idea for this function to get into an infinite loop.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3786
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3787 (defun display-warning-buffer ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3788 "Make the buffer that contains the warnings be visible.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3789 The C code calls this periodically, right before redisplay."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3790 (let ((buffer (get-buffer-create "*Warnings*")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3791 (if (or (not warning-marker) (not (eq (marker-buffer warning-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3792 buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3793 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3794 (setq warning-marker (make-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3795 (set-marker warning-marker 1 buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3796 (set-window-start (display-buffer buffer) warning-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3797 (set-marker warning-marker (point-max buffer) buffer)))
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
3798
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
3799 (defun emacs-name ()
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
3800 "Return the printable name of this instance of GNU Emacs."
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
3801 (cond ((featurep 'infodock) "InfoDock")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
3802 ((featurep 'xemacs) "XEmacs")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
3803 (t "Emacs")))
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
3804
72
b9518feda344 Import from CVS: tag r20-0b31
cvs
parents: 70
diff changeset
3805 ;;; simple.el ends here