annotate lisp/simple.el @ 404:2f8bb876ab1d r21-2-32

Import from CVS: tag r21-2-32
author cvs
date Mon, 13 Aug 2007 11:16:07 +0200
parents 74fd4e045ea6
children b8cc9ab3f761
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1 ;;; simple.el --- basic editing commands for XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3 ;; Copyright (C) 1985-7, 1993-5, 1997 Free Software Foundation, Inc.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4 ;; Copyright (C) 1995 Tinker Systems and INS Engineering Corp.
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
5 ;; Copyright (C) 2000 Ben Wing.
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
6
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
7 ;; Maintainer: XEmacs Development Team
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
8 ;; Keywords: lisp, extensions, internal, dumped
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
9
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
10 ;; This file is part of XEmacs.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
11
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
12 ;; XEmacs is free software; you can redistribute it and/or modify it
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
13 ;; under the terms of the GNU General Public License as published by
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
14 ;; the Free Software Foundation; either version 2, or (at your option)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
15 ;; any later version.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
16
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
17 ;; XEmacs is distributed in the hope that it will be useful, but
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
20 ;; General Public License for more details.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
21
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
23 ;; along with XEmacs; see the file COPYING. If not, write to the Free
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
24 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
25 ;; 02111-1307, USA.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
26
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
27 ;;; Synched up with: FSF 19.34 [But not very closely].
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
28
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
29 ;;; Commentary:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
30
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
31 ;; This file is dumped with XEmacs.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
32
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
33 ;; A grab-bag of basic XEmacs commands not specifically related to some
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
34 ;; major mode or to file-handling.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
35
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
36 ;; Changes for zmacs-style active-regions:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
37 ;;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
38 ;; beginning-of-buffer, end-of-buffer, count-lines-region,
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
39 ;; count-lines-buffer, what-line, what-cursor-position, set-goal-column,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
40 ;; set-fill-column, prefix-arg-internal, and line-move (which is used by
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
41 ;; next-line and previous-line) set zmacs-region-stays to t, so that they
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
42 ;; don't affect the current region-hilighting state.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
43 ;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
44 ;; mark-whole-buffer, mark-word, exchange-point-and-mark, and
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
45 ;; set-mark-command (without an argument) call zmacs-activate-region.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
46 ;;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
47 ;; mark takes an optional arg like the new Fmark_marker() does. When
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
48 ;; the region is not active, mark returns nil unless the optional arg is true.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
49 ;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
50 ;; push-mark, pop-mark, exchange-point-and-mark, and set-marker, and
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
51 ;; set-mark-command use (mark t) so that they can access the mark whether
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
52 ;; the region is active or not.
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
53 ;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
54 ;; shell-command, shell-command-on-region, yank, and yank-pop (which all
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
55 ;; push a mark) have been altered to call exchange-point-and-mark with an
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
56 ;; argument, meaning "don't activate the region". These commands only use
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
57 ;; exchange-point-and-mark to position the newly-pushed mark correctly, so
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
58 ;; this isn't a user-visible change. These functions have also been altered
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
59 ;; to use (mark t) for the same reason.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
60
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
61 ;; 97/3/14 Jareth Hein (jhod@po.iijnet.or.jp) added kinsoku processing (support
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
62 ;; for filling of Asian text) into the fill code. This was ripped bleeding from
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
63 ;; Mule-2.3, and could probably use some feature additions (like additional wrap
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
64 ;; styles, etc)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
65
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
66 ;; 97/06/11 Steve Baur (steve@xemacs.org) Convert use of
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
67 ;; (preceding|following)-char to char-(after|before).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
68
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
69 ;;; Code:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
70
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
71 (defgroup editing-basics nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
72 "Most basic editing variables."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
73 :group 'editing)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
74
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
75 (defgroup killing nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
76 "Killing and yanking commands."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
77 :group 'editing)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
78
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
79 (defgroup fill-comments nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
80 "Indenting and filling of comments."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
81 :prefix "comment-"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
82 :group 'fill)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
83
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
84 (defgroup paren-matching nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
85 "Highlight (un)matching of parens and expressions."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
86 :prefix "paren-"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
87 :group 'matching)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
88
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
89 (defgroup log-message nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
90 "Messages logging and display customizations."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
91 :group 'minibuffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
92
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
93 (defgroup warnings nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
94 "Warnings customizations."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
95 :group 'minibuffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
96
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
97
375
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
98 (defcustom search-caps-disable-folding t
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
99 "*If non-nil, upper case chars disable case fold searching.
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
100 This does not apply to \"yanked\" strings."
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
101 :type 'boolean
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
102 :group 'editing-basics)
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
103
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
104 ;; This is stolen (and slightly modified) from FSF emacs's
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
105 ;; `isearch-no-upper-case-p'.
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
106 (defun no-upper-case-p (string &optional regexp-flag)
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
107 "Return t if there are no upper case chars in STRING.
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
108 If REGEXP-FLAG is non-nil, disregard letters preceded by `\\' (but not `\\\\')
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
109 since they have special meaning in a regexp."
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
110 (let ((case-fold-search nil))
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
111 (not (string-match (if regexp-flag
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
112 "\\(^\\|\\\\\\\\\\|[^\\]\\)[A-Z]"
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
113 "[A-Z]")
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
114 string))
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
115 ))
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
116
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
117 (defmacro with-search-caps-disable-folding (string regexp-flag &rest body) "\
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
118 Eval BODY with `case-fold-search' let to nil if `search-caps-disable-folding'
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
119 is non-nil, and if STRING (either a string or a regular expression according
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
120 to REGEXP-FLAG) contains uppercase letters."
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
121 `(let ((case-fold-search
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
122 (if (and case-fold-search search-caps-disable-folding)
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
123 (no-upper-case-p ,string ,regexp-flag)
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
124 case-fold-search)))
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
125 ,@body))
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
126 (put 'with-search-caps-disable-folding 'lisp-indent-function 2)
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
127 (put 'with-search-caps-disable-folding 'edebug-form-spec
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
128 '(sexp sexp &rest form))
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
129
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
130 (defmacro with-interactive-search-caps-disable-folding (string regexp-flag
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
131 &rest body)
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
132 "Same as `with-search-caps-disable-folding', but only in the case of a
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
133 function called interactively."
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
134 `(let ((case-fold-search
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
135 (if (and (interactive-p)
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
136 case-fold-search search-caps-disable-folding)
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
137 (no-upper-case-p ,string ,regexp-flag)
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
138 case-fold-search)))
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
139 ,@body))
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
140 (put 'with-interactive-search-caps-disable-folding 'lisp-indent-function 2)
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
141 (put 'with-interactive-search-caps-disable-folding 'edebug-form-spec
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
142 '(sexp sexp &rest form))
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
143
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
144 (defun newline (&optional arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
145 "Insert a newline, and move to left margin of the new line if it's blank.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
146 The newline is marked with the text-property `hard'.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
147 With arg, insert that many newlines.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
148 In Auto Fill mode, if no numeric arg, break the preceding line if it's long."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
149 (interactive "*P")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
150 (barf-if-buffer-read-only nil (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
151 ;; Inserting a newline at the end of a line produces better redisplay in
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
152 ;; try_window_id than inserting at the beginning of a line, and the textual
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
153 ;; result is the same. So, if we're at beginning of line, pretend to be at
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
154 ;; the end of the previous line.
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
155 ;; #### Does this have any relevance in XEmacs?
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
156 (let ((flag (and (not (bobp))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
157 (bolp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
158 ;; Make sure the newline before point isn't intangible.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
159 (not (get-char-property (1- (point)) 'intangible))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
160 ;; Make sure the newline before point isn't read-only.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
161 (not (get-char-property (1- (point)) 'read-only))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
162 ;; Make sure the newline before point isn't invisible.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
163 (not (get-char-property (1- (point)) 'invisible))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
164 ;; This should probably also test for the previous char
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
165 ;; being the *last* character too.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
166 (not (get-char-property (1- (point)) 'end-open))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
167 ;; Make sure the newline before point has the same
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
168 ;; properties as the char before it (if any).
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
169 (< (or (previous-extent-change (point)) -2)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
170 (- (point) 2))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
171 (was-page-start (and (bolp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
172 (looking-at page-delimiter)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
173 (beforepos (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
174 (if flag (backward-char 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
175 ;; Call self-insert so that auto-fill, abbrev expansion etc. happens.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
176 ;; Set last-command-char to tell self-insert what to insert.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
177 (let ((last-command-char ?\n)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
178 ;; Don't auto-fill if we have a numeric argument.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
179 ;; Also not if flag is true (it would fill wrong line);
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
180 ;; there is no need to since we're at BOL.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
181 (auto-fill-function (if (or arg flag) nil auto-fill-function)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
182 (unwind-protect
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
183 (self-insert-command (prefix-numeric-value arg))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
184 ;; If we get an error in self-insert-command, put point at right place.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
185 (if flag (forward-char 1))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
186 ;; If we did *not* get an error, cancel that forward-char.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
187 (if flag (backward-char 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
188 ;; Mark the newline(s) `hard'.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
189 (if use-hard-newlines
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
190 (let* ((from (- (point) (if arg (prefix-numeric-value arg) 1)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
191 (sticky (get-text-property from 'end-open))) ; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
192 (put-text-property from (point) 'hard 't)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
193 ;; If end-open is not "t", add 'hard to end-open list
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
194 (if (and (listp sticky) (not (memq 'hard sticky)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
195 (put-text-property from (point) 'end-open ; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
196 (cons 'hard sticky)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
197 ;; If the newline leaves the previous line blank,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
198 ;; and we have a left margin, delete that from the blank line.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
199 (or flag
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
200 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
201 (goto-char beforepos)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
202 (beginning-of-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
203 (and (looking-at "[ \t]$")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
204 (> (current-left-margin) 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
205 (delete-region (point) (progn (end-of-line) (point))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
206 (if flag (forward-char 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
207 ;; Indent the line after the newline, except in one case:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
208 ;; when we added the newline at the beginning of a line
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
209 ;; which starts a page.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
210 (or was-page-start
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
211 (move-to-left-margin nil t)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
212 nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
213
215
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 209
diff changeset
214 (defun set-hard-newline-properties (from to)
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 209
diff changeset
215 (let ((sticky (get-text-property from 'rear-nonsticky)))
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 209
diff changeset
216 (put-text-property from to 'hard 't)
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 209
diff changeset
217 ;; If rear-nonsticky is not "t", add 'hard to rear-nonsticky list
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 209
diff changeset
218 (if (and (listp sticky) (not (memq 'hard sticky)))
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 209
diff changeset
219 (put-text-property from (point) 'rear-nonsticky
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 209
diff changeset
220 (cons 'hard sticky)))))
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 209
diff changeset
221
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
222 (defun open-line (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
223 "Insert a newline and leave point before it.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
224 If there is a fill prefix and/or a left-margin, insert them on the new line
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
225 if the line would have been blank.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
226 With arg N, insert N newlines."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
227 (interactive "*p")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
228 (let* ((do-fill-prefix (and fill-prefix (bolp)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
229 (do-left-margin (and (bolp) (> (current-left-margin) 0)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
230 (loc (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
231 (newline arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
232 (goto-char loc)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
233 (while (> arg 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
234 (cond ((bolp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
235 (if do-left-margin (indent-to (current-left-margin)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
236 (if do-fill-prefix (insert fill-prefix))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
237 (forward-line 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
238 (setq arg (1- arg)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
239 (goto-char loc)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
240 (end-of-line)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
241
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
242 (defun split-line ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
243 "Split current line, moving portion beyond point vertically down."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
244 (interactive "*")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
245 (skip-chars-forward " \t")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
246 (let ((col (current-column))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
247 (pos (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
248 (newline 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
249 (indent-to col 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
250 (goto-char pos)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
251
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
252 (defun quoted-insert (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
253 "Read next input character and insert it.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
254 This is useful for inserting control characters.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
255 You may also type up to 3 octal digits, to insert a character with that code.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
256
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
257 In overwrite mode, this function inserts the character anyway, and
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
258 does not handle octal digits specially. This means that if you use
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
259 overwrite as your normal editing mode, you can use this function to
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
260 insert characters when necessary.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
261
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
262 In binary overwrite mode, this function does overwrite, and octal
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
263 digits are interpreted as a character code. This is supposed to make
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
264 this function useful in editing binary files."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
265 (interactive "*p")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
266 (let ((char (if (or (not overwrite-mode)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
267 (eq overwrite-mode 'overwrite-mode-binary))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
268 (read-quoted-char)
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
269 ;; read-char obeys C-g, so we should protect. FSF
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
270 ;; doesn't have the protection here, but it's a bug in
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
271 ;; FSF.
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
272 (let ((inhibit-quit t))
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
273 (read-char)))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
274 (if (> arg 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
275 (if (eq overwrite-mode 'overwrite-mode-binary)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
276 (delete-char arg)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
277 (while (> arg 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
278 (insert char)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
279 (setq arg (1- arg)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
280
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
281 (defun delete-indentation (&optional arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
282 "Join this line to previous and fix up whitespace at join.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
283 If there is a fill prefix, delete it from the beginning of this line.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
284 With argument, join this line to following line."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
285 (interactive "*P")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
286 (beginning-of-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
287 (if arg (forward-line 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
288 (if (eq (char-before (point)) ?\n)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
289 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
290 (delete-region (point) (1- (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
291 ;; If the second line started with the fill prefix,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
292 ;; delete the prefix.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
293 (if (and fill-prefix
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
294 (<= (+ (point) (length fill-prefix)) (point-max))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
295 (string= fill-prefix
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
296 (buffer-substring (point)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
297 (+ (point) (length fill-prefix)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
298 (delete-region (point) (+ (point) (length fill-prefix))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
299 (fixup-whitespace))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
300
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
301 (defun fixup-whitespace ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
302 "Fixup white space between objects around point.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
303 Leave one space or none, according to the context."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
304 (interactive "*")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
305 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
306 (delete-horizontal-space)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
307 (if (or (looking-at "^\\|\\s)")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
308 (save-excursion (forward-char -1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
309 (looking-at "$\\|\\s(\\|\\s'")))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
310 nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
311 (insert ?\ ))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
312
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
313 (defun delete-horizontal-space ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
314 "Delete all spaces and tabs around point."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
315 (interactive "*")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
316 (skip-chars-backward " \t")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
317 (delete-region (point) (progn (skip-chars-forward " \t") (point))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
318
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
319 (defun just-one-space ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
320 "Delete all spaces and tabs around point, leaving one space."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
321 (interactive "*")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
322 (if abbrev-mode ; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
323 (expand-abbrev))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
324 (skip-chars-backward " \t")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
325 (if (eq (char-after (point)) ? ) ; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
326 (forward-char 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
327 (insert ? ))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
328 (delete-region (point) (progn (skip-chars-forward " \t") (point))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
329
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
330 (defun delete-blank-lines ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
331 "On blank line, delete all surrounding blank lines, leaving just one.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
332 On isolated blank line, delete that one.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
333 On nonblank line, delete any immediately following blank lines."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
334 (interactive "*")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
335 (let (thisblank singleblank)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
336 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
337 (beginning-of-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
338 (setq thisblank (looking-at "[ \t]*$"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
339 ;; Set singleblank if there is just one blank line here.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
340 (setq singleblank
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
341 (and thisblank
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
342 (not (looking-at "[ \t]*\n[ \t]*$"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
343 (or (bobp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
344 (progn (forward-line -1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
345 (not (looking-at "[ \t]*$")))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
346 ;; Delete preceding blank lines, and this one too if it's the only one.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
347 (if thisblank
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
348 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
349 (beginning-of-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
350 (if singleblank (forward-line 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
351 (delete-region (point)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
352 (if (re-search-backward "[^ \t\n]" nil t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
353 (progn (forward-line 1) (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
354 (point-min)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
355 ;; Delete following blank lines, unless the current line is blank
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
356 ;; and there are no following blank lines.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
357 (if (not (and thisblank singleblank))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
358 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
359 (end-of-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
360 (forward-line 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
361 (delete-region (point)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
362 (if (re-search-forward "[^ \t\n]" nil t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
363 (progn (beginning-of-line) (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
364 (point-max)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
365 ;; Handle the special case where point is followed by newline and eob.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
366 ;; Delete the line, leaving point at eob.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
367 (if (looking-at "^[ \t]*\n\\'")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
368 (delete-region (point) (point-max)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
369
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
370 (defun back-to-indentation ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
371 "Move point to the first non-whitespace character on this line."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
372 ;; XEmacs change
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
373 (interactive "_")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
374 (beginning-of-line 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
375 (skip-chars-forward " \t"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
376
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
377 (defun newline-and-indent ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
378 "Insert a newline, then indent according to major mode.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
379 Indentation is done using the value of `indent-line-function'.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
380 In programming language modes, this is the same as TAB.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
381 In some text modes, where TAB inserts a tab, this command indents to the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
382 column specified by the function `current-left-margin'."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
383 (interactive "*")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
384 (delete-region (point) (progn (skip-chars-backward " \t") (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
385 (newline)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
386 (indent-according-to-mode))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
387
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
388 (defun reindent-then-newline-and-indent ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
389 "Reindent current line, insert newline, then indent the new line.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
390 Indentation of both lines is done according to the current major mode,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
391 which means calling the current value of `indent-line-function'.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
392 In programming language modes, this is the same as TAB.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
393 In some text modes, where TAB inserts a tab, this indents to the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
394 column specified by the function `current-left-margin'."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
395 (interactive "*")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
396 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
397 (delete-region (point) (progn (skip-chars-backward " \t") (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
398 (indent-according-to-mode))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
399 (newline)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
400 (indent-according-to-mode))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
401
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
402 ;; Internal subroutine of delete-char
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
403 (defun kill-forward-chars (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
404 (if (listp arg) (setq arg (car arg)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
405 (if (eq arg '-) (setq arg -1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
406 (kill-region (point) (+ (point) arg)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
407
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
408 ;; Internal subroutine of backward-delete-char
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
409 (defun kill-backward-chars (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
410 (if (listp arg) (setq arg (car arg)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
411 (if (eq arg '-) (setq arg -1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
412 (kill-region (point) (- (point) arg)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
413
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
414 (defun backward-delete-char-untabify (arg &optional killp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
415 "Delete characters backward, changing tabs into spaces.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
416 Delete ARG chars, and kill (save in kill ring) if KILLP is non-nil.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
417 Interactively, ARG is the prefix arg (default 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
418 and KILLP is t if a prefix arg was specified."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
419 (interactive "*p\nP")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
420 (let ((count arg))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
421 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
422 (while (and (> count 0) (not (bobp)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
423 (if (eq (char-before (point)) ?\t) ; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
424 (let ((col (current-column)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
425 (forward-char -1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
426 (setq col (- col (current-column)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
427 (insert-char ?\ col)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
428 (delete-char 1)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
429 (forward-char -1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
430 (setq count (1- count)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
431 (delete-backward-char arg killp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
432 ;; XEmacs: In overwrite mode, back over columns while clearing them out,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
433 ;; unless at end of line.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
434 (and overwrite-mode (not (eolp))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
435 (save-excursion (insert-char ?\ arg))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
436
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
437 (defcustom delete-key-deletes-forward t
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
438 "*If non-nil, the DEL key will erase one character forwards.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
439 If nil, the DEL key will erase one character backwards."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
440 :type 'boolean
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
441 :group 'editing-basics)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
442
239
41f2f0e326e9 Import from CVS: tag r20-5b18
cvs
parents: 235
diff changeset
443 (defcustom backward-delete-function 'backward-delete-char
41f2f0e326e9 Import from CVS: tag r20-5b18
cvs
parents: 235
diff changeset
444 "*Function called to delete backwards on a delete keypress.
41f2f0e326e9 Import from CVS: tag r20-5b18
cvs
parents: 235
diff changeset
445 If `delete-key-deletes-forward' is nil, `backward-or-forward-delete-char'
41f2f0e326e9 Import from CVS: tag r20-5b18
cvs
parents: 235
diff changeset
446 calls this function to erase one character backwards. Default value
41f2f0e326e9 Import from CVS: tag r20-5b18
cvs
parents: 235
diff changeset
447 is 'backward-delete-char, with 'backward-delete-char-untabify being a
41f2f0e326e9 Import from CVS: tag r20-5b18
cvs
parents: 235
diff changeset
448 popular alternate setting."
41f2f0e326e9 Import from CVS: tag r20-5b18
cvs
parents: 235
diff changeset
449 :type 'function
41f2f0e326e9 Import from CVS: tag r20-5b18
cvs
parents: 235
diff changeset
450 :group 'editing-basics)
41f2f0e326e9 Import from CVS: tag r20-5b18
cvs
parents: 235
diff changeset
451
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
452 ;; Trash me, baby.
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
453 (defsubst delete-forward-p ()
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
454 (and delete-key-deletes-forward
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
455 (or (not (eq (device-type) 'x))
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
456 (x-keysym-on-keyboard-sans-modifiers-p 'backspace))))
253
157b30c96d03 Import from CVS: tag r20-5b25
cvs
parents: 243
diff changeset
457
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
458 (defun backward-or-forward-delete-char (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
459 "Delete either one character backwards or one character forwards.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
460 Controlled by the state of `delete-key-deletes-forward' and whether the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
461 BackSpace keysym even exists on your keyboard. If you don't have a
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
462 BackSpace keysym, the delete key should always delete one character
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
463 backwards."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
464 (interactive "*p")
253
157b30c96d03 Import from CVS: tag r20-5b25
cvs
parents: 243
diff changeset
465 (if (delete-forward-p)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
466 (delete-char arg)
239
41f2f0e326e9 Import from CVS: tag r20-5b18
cvs
parents: 235
diff changeset
467 (funcall backward-delete-function arg)))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
468
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
469 (defun backward-or-forward-kill-word (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
470 "Delete either one word backwards or one word forwards.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
471 Controlled by the state of `delete-key-deletes-forward' and whether the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
472 BackSpace keysym even exists on your keyboard. If you don't have a
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
473 BackSpace keysym, the delete key should always delete one character
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
474 backwards."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
475 (interactive "*p")
253
157b30c96d03 Import from CVS: tag r20-5b25
cvs
parents: 243
diff changeset
476 (if (delete-forward-p)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
477 (kill-word arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
478 (backward-kill-word arg)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
479
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
480 (defun backward-or-forward-kill-sentence (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
481 "Delete either one sentence backwards or one sentence forwards.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
482 Controlled by the state of `delete-key-deletes-forward' and whether the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
483 BackSpace keysym even exists on your keyboard. If you don't have a
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
484 BackSpace keysym, the delete key should always delete one character
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
485 backwards."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
486 (interactive "*P")
253
157b30c96d03 Import from CVS: tag r20-5b25
cvs
parents: 243
diff changeset
487 (if (delete-forward-p)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
488 (kill-sentence arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
489 (backward-kill-sentence (prefix-numeric-value arg))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
490
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
491 (defun backward-or-forward-kill-sexp (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
492 "Delete either one sexpr backwards or one sexpr forwards.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
493 Controlled by the state of `delete-key-deletes-forward' and whether the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
494 BackSpace keysym even exists on your keyboard. If you don't have a
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
495 BackSpace keysym, the delete key should always delete one character
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
496 backwards."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
497 (interactive "*p")
253
157b30c96d03 Import from CVS: tag r20-5b25
cvs
parents: 243
diff changeset
498 (if (delete-forward-p)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
499 (kill-sexp arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
500 (backward-kill-sexp arg)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
501
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
502 (defun zap-to-char (arg char)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
503 "Kill up to and including ARG'th occurrence of CHAR.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
504 Goes backward if ARG is negative; error if CHAR not found."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
505 (interactive "*p\ncZap to char: ")
375
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
506 (kill-region (point) (with-interactive-search-caps-disable-folding
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
507 (char-to-string char) nil
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
508 (search-forward (char-to-string char) nil nil arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
509 (point))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
510
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
511 (defun zap-up-to-char (arg char)
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
512 "Kill up to ARG'th occurrence of CHAR.
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
513 Goes backward if ARG is negative; error if CHAR not found."
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
514 (interactive "*p\ncZap up to char: ")
375
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
515 (kill-region (point) (with-interactive-search-caps-disable-folding
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
516 (char-to-string char) nil
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
517 (search-forward (char-to-string char) nil nil arg)
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
518 (goto-char (if (> arg 0) (1- (point)) (1+ (point))))
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
519 (point))))
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
520
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
521 (defun beginning-of-buffer (&optional arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
522 "Move point to the beginning of the buffer; leave mark at previous position.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
523 With arg N, put point N/10 of the way from the beginning.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
524
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
525 If the buffer is narrowed, this command uses the beginning and size
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
526 of the accessible part of the buffer.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
527
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
528 Don't use this command in Lisp programs!
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
529 \(goto-char (point-min)) is faster and avoids clobbering the mark."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
530 ;; XEmacs change
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
531 (interactive "_P")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
532 (push-mark)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
533 (let ((size (- (point-max) (point-min))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
534 (goto-char (if arg
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
535 (+ (point-min)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
536 (if (> size 10000)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
537 ;; Avoid overflow for large buffer sizes!
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
538 (* (prefix-numeric-value arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
539 (/ size 10))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
540 (/ (+ 10 (* size (prefix-numeric-value arg))) 10)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
541 (point-min))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
542 (if arg (forward-line 1)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
543
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
544 (defun end-of-buffer (&optional arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
545 "Move point to the end of the buffer; leave mark at previous position.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
546 With arg N, put point N/10 of the way from the end.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
547
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
548 If the buffer is narrowed, this command uses the beginning and size
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
549 of the accessible part of the buffer.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
550
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
551 Don't use this command in Lisp programs!
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
552 \(goto-char (point-max)) is faster and avoids clobbering the mark."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
553 ;; XEmacs change
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
554 (interactive "_P")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
555 (push-mark)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
556 ;; XEmacs changes here.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
557 (let ((scroll-to-end (not (pos-visible-in-window-p (point-max))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
558 (size (- (point-max) (point-min))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
559 (goto-char (if arg
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
560 (- (point-max)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
561 (if (> size 10000)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
562 ;; Avoid overflow for large buffer sizes!
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
563 (* (prefix-numeric-value arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
564 (/ size 10))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
565 (/ (* size (prefix-numeric-value arg)) 10)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
566 (point-max)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
567 (cond (arg
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
568 ;; If we went to a place in the middle of the buffer,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
569 ;; adjust it to the beginning of a line.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
570 (forward-line 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
571 ;; XEmacs change
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
572 (scroll-to-end
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
573 ;; If the end of the buffer is not already on the screen,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
574 ;; then scroll specially to put it near, but not at, the bottom.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
575 (recenter -3)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
576
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
577 ;; XEmacs (not in FSF)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
578 (defun mark-beginning-of-buffer (&optional arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
579 "Push a mark at the beginning of the buffer; leave point where it is.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
580 With arg N, push mark N/10 of the way from the true beginning."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
581 (interactive "P")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
582 (push-mark (if arg
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
583 (if (> (buffer-size) 10000)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
584 ;; Avoid overflow for large buffer sizes!
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
585 (* (prefix-numeric-value arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
586 (/ (buffer-size) 10))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
587 (/ (+ 10 (* (buffer-size) (prefix-numeric-value arg))) 10))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
588 (point-min))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
589 nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
590 t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
591 (define-function 'mark-bob 'mark-beginning-of-buffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
592
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
593 ;; XEmacs (not in FSF)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
594 (defun mark-end-of-buffer (&optional arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
595 "Push a mark at the end of the buffer; leave point where it is.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
596 With arg N, push mark N/10 of the way from the true end."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
597 (interactive "P")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
598 (push-mark (if arg
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
599 (- (1+ (buffer-size))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
600 (if (> (buffer-size) 10000)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
601 ;; Avoid overflow for large buffer sizes!
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
602 (* (prefix-numeric-value arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
603 (/ (buffer-size) 10))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
604 (/ (* (buffer-size) (prefix-numeric-value arg)) 10)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
605 (point-max))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
606 nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
607 t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
608 (define-function 'mark-eob 'mark-end-of-buffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
609
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
610 (defun mark-whole-buffer ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
611 "Put point at beginning and mark at end of buffer.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
612 You probably should not use this function in Lisp programs;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
613 it is usually a mistake for a Lisp function to use any subroutine
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
614 that uses or sets the mark."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
615 (interactive)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
616 (push-mark (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
617 (push-mark (point-max) nil t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
618 (goto-char (point-min)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
619
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
620 ;; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
621 (defun eval-current-buffer (&optional printflag)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
622 "Evaluate the current buffer as Lisp code.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
623 Programs can pass argument PRINTFLAG which controls printing of output:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
624 nil means discard it; anything else is stream for print."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
625 (interactive)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
626 (eval-buffer (current-buffer) printflag))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
627
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
628 ;; XEmacs
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
629 (defun count-words-buffer (&optional buffer)
253
157b30c96d03 Import from CVS: tag r20-5b25
cvs
parents: 243
diff changeset
630 "Print the number of words in BUFFER.
157b30c96d03 Import from CVS: tag r20-5b25
cvs
parents: 243
diff changeset
631 If called noninteractively, the value is returned rather than printed.
157b30c96d03 Import from CVS: tag r20-5b25
cvs
parents: 243
diff changeset
632 BUFFER defaults to the current buffer."
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
633 (interactive)
253
157b30c96d03 Import from CVS: tag r20-5b25
cvs
parents: 243
diff changeset
634 (let ((words (count-words-region (point-min) (point-max) buffer)))
157b30c96d03 Import from CVS: tag r20-5b25
cvs
parents: 243
diff changeset
635 (when (interactive-p)
157b30c96d03 Import from CVS: tag r20-5b25
cvs
parents: 243
diff changeset
636 (message "Buffer has %d words" words))
157b30c96d03 Import from CVS: tag r20-5b25
cvs
parents: 243
diff changeset
637 words))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
638
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
639 ;; XEmacs
253
157b30c96d03 Import from CVS: tag r20-5b25
cvs
parents: 243
diff changeset
640 (defun count-words-region (start end &optional buffer)
157b30c96d03 Import from CVS: tag r20-5b25
cvs
parents: 243
diff changeset
641 "Print the number of words in region between START and END in BUFFER.
157b30c96d03 Import from CVS: tag r20-5b25
cvs
parents: 243
diff changeset
642 If called noninteractively, the value is returned rather than printed.
157b30c96d03 Import from CVS: tag r20-5b25
cvs
parents: 243
diff changeset
643 BUFFER defaults to the current buffer."
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
644 (interactive "_r")
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
645 (save-excursion
253
157b30c96d03 Import from CVS: tag r20-5b25
cvs
parents: 243
diff changeset
646 (set-buffer (or buffer (current-buffer)))
157b30c96d03 Import from CVS: tag r20-5b25
cvs
parents: 243
diff changeset
647 (let ((words 0))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
648 (goto-char start)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
649 (while (< (point) end)
253
157b30c96d03 Import from CVS: tag r20-5b25
cvs
parents: 243
diff changeset
650 (when (forward-word 1)
157b30c96d03 Import from CVS: tag r20-5b25
cvs
parents: 243
diff changeset
651 (incf words)))
282
c42ec1d1cded Import from CVS: tag r21-0b39
cvs
parents: 280
diff changeset
652 (when (interactive-p)
253
157b30c96d03 Import from CVS: tag r20-5b25
cvs
parents: 243
diff changeset
653 (message "Region has %d words" words))
157b30c96d03 Import from CVS: tag r20-5b25
cvs
parents: 243
diff changeset
654 words)))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
655
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
656 (defun count-lines-region (start end)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
657 "Print number of lines and characters in the region."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
658 ;; XEmacs change
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
659 (interactive "_r")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
660 (message "Region has %d lines, %d characters"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
661 (count-lines start end) (- end start)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
662
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
663 ;; XEmacs
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
664 (defun count-lines-buffer (&optional buffer)
253
157b30c96d03 Import from CVS: tag r20-5b25
cvs
parents: 243
diff changeset
665 "Print number of lines and characters in BUFFER."
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
666 (interactive)
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
667 (with-current-buffer (or buffer (current-buffer))
253
157b30c96d03 Import from CVS: tag r20-5b25
cvs
parents: 243
diff changeset
668 (let ((cnt (count-lines (point-min) (point-max))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
669 (message "Buffer has %d lines, %d characters"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
670 cnt (- (point-max) (point-min)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
671 cnt)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
672
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
673 ;;; Modified by Bob Weiner, 8/24/95, to print narrowed line number also.
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
674 ;;; Expanded by Bob Weiner, BeOpen, on 02/12/1997
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
675 (defun what-line ()
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
676 "Print the following variants of the line number of point:
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
677 Region line - displayed line within the active region
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
678 Collapsed line - includes only selectively displayed lines;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
679 Buffer line - physical line in the buffer;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
680 Narrowed line - line number from the start of the buffer narrowing."
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
681 ;; XEmacs change
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
682 (interactive "_")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
683 (let ((opoint (point)) start)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
684 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
685 (save-restriction
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
686 (if (region-active-p)
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
687 (goto-char (region-beginning))
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
688 (goto-char (point-min)))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
689 (widen)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
690 (beginning-of-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
691 (setq start (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
692 (goto-char opoint)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
693 (beginning-of-line)
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
694 (let* ((buffer-line (1+ (count-lines 1 (point))))
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
695 (narrowed-p (or (/= start 1)
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
696 (/= (point-max) (1+ (buffer-size)))))
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
697 (narrowed-line (if narrowed-p (1+ (count-lines start (point)))))
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
698 (selective-line (if selective-display
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
699 (1+ (count-lines start (point) t))))
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
700 (region-line (if (region-active-p)
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
701 (1+ (count-lines start (point) selective-display)))))
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
702 (cond (region-line
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
703 (message "Region line %d; Buffer line %d"
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
704 region-line buffer-line))
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
705 ((and narrowed-p selective-line (/= selective-line narrowed-line))
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
706 ;; buffer narrowed and some lines selectively displayed
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
707 (message "Collapsed line %d; Buffer line %d; Narrowed line %d"
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
708 selective-line buffer-line narrowed-line))
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
709 (narrowed-p
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
710 ;; buffer narrowed
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
711 (message "Buffer line %d; Narrowed line %d"
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
712 buffer-line narrowed-line))
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
713 ((and selective-line (/= selective-line buffer-line))
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
714 ;; some lines selectively displayed
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
715 (message "Collapsed line %d; Buffer line %d"
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
716 selective-line buffer-line))
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
717 (t
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
718 ;; give a basic line count
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
719 (message "Line %d" buffer-line)))))))
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
720 (setq zmacs-region-stays t))
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
721
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
722 ;;; Bob Weiner, Altrasoft, 02/12/1998
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
723 ;;; Added the 3rd arg in `count-lines' to conditionalize the counting of
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
724 ;;; collapsed lines.
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
725 (defun count-lines (start end &optional ignore-invisible-lines-flag)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
726 "Return number of lines between START and END.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
727 This is usually the number of newlines between them,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
728 but can be one more if START is not equal to END
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
729 and the greater of them is not at the start of a line.
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
730
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
731 With optional IGNORE-INVISIBLE-LINES-FLAG non-nil, lines collapsed with
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
732 selective-display are excluded from the line count."
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
733 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
734 (save-restriction
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
735 (narrow-to-region start end)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
736 (goto-char (point-min))
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
737 (if (and (not ignore-invisible-lines-flag) (eq selective-display t))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
738 (save-match-data
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
739 (let ((done 0))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
740 (while (re-search-forward "[\n\C-m]" nil t 40)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
741 (setq done (+ 40 done)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
742 (while (re-search-forward "[\n\C-m]" nil t 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
743 (setq done (+ 1 done)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
744 (goto-char (point-max))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
745 (if (and (/= start end)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
746 (not (bolp)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
747 (1+ done)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
748 done)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
749 (- (buffer-size) (forward-line (buffer-size)))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
750
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
751 (defun what-cursor-position ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
752 "Print info on cursor position (on screen and within buffer)."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
753 ;; XEmacs change
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
754 (interactive "_")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
755 (let* ((char (char-after (point))) ; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
756 (beg (point-min))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
757 (end (point-max))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
758 (pos (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
759 (total (buffer-size))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
760 (percent (if (> total 50000)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
761 ;; Avoid overflow from multiplying by 100!
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
762 (/ (+ (/ total 200) (1- pos)) (max (/ total 100) 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
763 (/ (+ (/ total 2) (* 100 (1- pos))) (max total 1))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
764 (hscroll (if (= (window-hscroll) 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
765 ""
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
766 (format " Hscroll=%d" (window-hscroll))))
294
4b85ae5eabfb Import from CVS: tag r21-0b45
cvs
parents: 288
diff changeset
767 (col (+ (current-column) (if column-number-start-at-one 1 0))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
768 (if (= pos end)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
769 (if (or (/= beg 1) (/= end (1+ total)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
770 (message "point=%d of %d(%d%%) <%d - %d> column %d %s"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
771 pos total percent beg end col hscroll)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
772 (message "point=%d of %d(%d%%) column %d %s"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
773 pos total percent col hscroll))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
774 ;; XEmacs: don't use single-key-description
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
775 (if (or (/= beg 1) (/= end (1+ total)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
776 (message "Char: %s (0%o, %d, 0x%x) point=%d of %d(%d%%) <%d - %d> column %d %s"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
777 (text-char-description char) char char char pos total
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
778 percent beg end col hscroll)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
779 (message "Char: %s (0%o, %d, 0x%x) point=%d of %d(%d%%) column %d %s"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
780 (text-char-description char) char char char pos total
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
781 percent col hscroll)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
782
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
783 (defun fundamental-mode ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
784 "Major mode not specialized for anything in particular.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
785 Other major modes are defined by comparison with this one."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
786 (interactive)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
787 (kill-all-local-variables))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
788
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
789 ;; XEmacs the following are declared elsewhere
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
790 ;(defvar read-expression-map (cons 'keymap minibuffer-local-map)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
791 ; "Minibuffer keymap used for reading Lisp expressions.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
792 ;(define-key read-expression-map "\M-\t" 'lisp-complete-symbol)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
793
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
794 ;(put 'eval-expression 'disabled t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
795
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
796 ;(defvar read-expression-history nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
797
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
798 ;; We define this, rather than making `eval' interactive,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
799 ;; for the sake of completion of names like eval-region, eval-current-buffer.
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
800 (defun eval-expression (expression &optional eval-expression-insert-value)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
801 "Evaluate EXPRESSION and print value in minibuffer.
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
802 Value is also consed on to front of the variable `values'.
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
803 With prefix argument, insert the result to the current buffer."
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
804 ;(interactive "xEval: ")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
805 (interactive
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
806 (list (read-from-minibuffer "Eval: "
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
807 nil read-expression-map t
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
808 'read-expression-history)
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
809 current-prefix-arg))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
810 (setq values (cons (eval expression) values))
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
811 (prin1 (car values)
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 282
diff changeset
812 (if eval-expression-insert-value (current-buffer) t)))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
813
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
814 ;; XEmacs -- extra parameter (variant, but equivalent logic)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
815 (defun edit-and-eval-command (prompt command &optional history)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
816 "Prompting with PROMPT, let user edit COMMAND and eval result.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
817 COMMAND is a Lisp expression. Let user edit that expression in
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
818 the minibuffer, then read and evaluate the result."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
819 (let ((command (read-expression prompt
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
820 ;; first try to format the thing readably;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
821 ;; and if that fails, print it normally.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
822 (condition-case ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
823 (let ((print-readably t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
824 (prin1-to-string command))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
825 (error (prin1-to-string command)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
826 (or history '(command-history . 1)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
827 (or history (setq history 'command-history))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
828 (if (consp history)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
829 (setq history (car history)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
830 (if (eq history t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
831 nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
832 ;; If command was added to the history as a string,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
833 ;; get rid of that. We want only evallable expressions there.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
834 (if (stringp (car (symbol-value history)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
835 (set history (cdr (symbol-value history))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
836
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
837 ;; If command to be redone does not match front of history,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
838 ;; add it to the history.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
839 (or (equal command (car (symbol-value history)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
840 (set history (cons command (symbol-value history)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
841 (eval command)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
842
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
843 (defun repeat-complex-command (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
844 "Edit and re-evaluate last complex command, or ARGth from last.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
845 A complex command is one which used the minibuffer.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
846 The command is placed in the minibuffer as a Lisp form for editing.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
847 The result is executed, repeating the command as changed.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
848 If the command has been changed or is not the most recent previous command
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
849 it is added to the front of the command history.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
850 You can use the minibuffer history commands \\<minibuffer-local-map>\\[next-history-element] and \\[previous-history-element]
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
851 to get different commands to edit and resubmit."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
852 (interactive "p")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
853 ;; XEmacs: It looks like our version is better -sb
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
854 (let ((print-level nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
855 (edit-and-eval-command "Redo: "
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
856 (or (nth (1- arg) command-history)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
857 (error ""))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
858 (cons 'command-history arg))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
859
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
860 ;; XEmacs: Functions moved to minibuf.el
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
861 ;; previous-matching-history-element
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
862 ;; next-matching-history-element
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
863 ;; next-history-element
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
864 ;; previous-history-element
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
865 ;; next-complete-history-element
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
866 ;; previous-complete-history-element
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
867
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
868 (defun goto-line (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
869 "Goto line ARG, counting from line 1 at beginning of buffer."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
870 (interactive "NGoto line: ")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
871 (setq arg (prefix-numeric-value arg))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
872 (save-restriction
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
873 (widen)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
874 (goto-char 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
875 (if (eq selective-display t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
876 (re-search-forward "[\n\C-m]" nil 'end (1- arg))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
877 (forward-line (1- arg)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
878
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
879 ;Put this on C-x u, so we can force that rather than C-_ into startup msg
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
880 (define-function 'advertised-undo 'undo)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
881
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
882 (defun undo (&optional arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
883 "Undo some previous changes.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
884 Repeat this command to undo more changes.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
885 A numeric argument serves as a repeat count."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
886 (interactive "*p")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
887 ;; If we don't get all the way through, make last-command indicate that
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
888 ;; for the following command.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
889 (setq this-command t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
890 (let ((modified (buffer-modified-p))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
891 (recent-save (recent-auto-save-p)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
892 (or (eq (selected-window) (minibuffer-window))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
893 (display-message 'command "Undo!"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
894 (or (and (eq last-command 'undo)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
895 (eq (current-buffer) last-undo-buffer)) ; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
896 (progn (undo-start)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
897 (undo-more 1)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
898 (undo-more (or arg 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
899 ;; Don't specify a position in the undo record for the undo command.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
900 ;; Instead, undoing this should move point to where the change is.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
901 (let ((tail buffer-undo-list)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
902 done)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
903 (while (and tail (not done) (not (null (car tail))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
904 (if (integerp (car tail))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
905 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
906 (setq done t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
907 (setq buffer-undo-list (delq (car tail) buffer-undo-list))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
908 (setq tail (cdr tail))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
909 (and modified (not (buffer-modified-p))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
910 (delete-auto-save-file-if-necessary recent-save)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
911 ;; If we do get all the way through, make this-command indicate that.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
912 (setq this-command 'undo))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
913
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
914 (defvar pending-undo-list nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
915 "Within a run of consecutive undo commands, list remaining to be undone.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
916
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
917 (defvar last-undo-buffer nil) ; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
918
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
919 (defun undo-start ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
920 "Set `pending-undo-list' to the front of the undo list.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
921 The next call to `undo-more' will undo the most recently made change."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
922 (if (eq buffer-undo-list t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
923 (error "No undo information in this buffer"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
924 (setq pending-undo-list buffer-undo-list))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
925
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
926 (defun undo-more (count)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
927 "Undo back N undo-boundaries beyond what was already undone recently.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
928 Call `undo-start' to get ready to undo recent changes,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
929 then call `undo-more' one or more times to undo them."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
930 (or pending-undo-list
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
931 (error "No further undo information"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
932 (setq pending-undo-list (primitive-undo count pending-undo-list)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
933 last-undo-buffer (current-buffer))) ; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
934
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
935 ;; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
936 (defun call-with-transparent-undo (fn &rest args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
937 "Apply FN to ARGS, and then undo all changes made by FN to the current
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
938 buffer. The undo records are processed even if FN returns non-locally.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
939 There is no trace of the changes made by FN in the buffer's undo history.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
940
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
941 You can use this in a write-file-hooks function with continue-save-buffer
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
942 to make the contents of a disk file differ from its in-memory buffer."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
943 (let ((buffer-undo-list nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
944 ;; Kludge to prevent undo list truncation:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
945 (undo-high-threshold -1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
946 (undo-threshold -1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
947 (obuffer (current-buffer)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
948 (unwind-protect
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
949 (apply fn args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
950 ;; Go to the buffer we will restore and make it writable:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
951 (set-buffer obuffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
952 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
953 (let ((buffer-read-only nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
954 (save-restriction
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
955 (widen)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
956 ;; Perform all undos, with further undo logging disabled:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
957 (let ((tail buffer-undo-list))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
958 (setq buffer-undo-list t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
959 (while tail
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
960 (setq tail (primitive-undo (length tail) tail))))))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
961
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
962 ;; XEmacs: The following are in other files
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
963 ;; shell-command-history
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
964 ;; shell-command-switch
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
965 ;; shell-command
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
966 ;; shell-command-sentinel
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
967
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
968
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
969 (defconst universal-argument-map
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
970 (let ((map (make-sparse-keymap)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
971 (set-keymap-default-binding map 'universal-argument-other-key)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
972 ;FSFmacs (define-key map [switch-frame] nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
973 (define-key map [(t)] 'universal-argument-other-key)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
974 (define-key map [(meta t)] 'universal-argument-other-key)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
975 (define-key map [(control u)] 'universal-argument-more)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
976 (define-key map [?-] 'universal-argument-minus)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
977 (define-key map [?0] 'digit-argument)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
978 (define-key map [?1] 'digit-argument)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
979 (define-key map [?2] 'digit-argument)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
980 (define-key map [?3] 'digit-argument)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
981 (define-key map [?4] 'digit-argument)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
982 (define-key map [?5] 'digit-argument)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
983 (define-key map [?6] 'digit-argument)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
984 (define-key map [?7] 'digit-argument)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
985 (define-key map [?8] 'digit-argument)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
986 (define-key map [?9] 'digit-argument)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
987 map)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
988 "Keymap used while processing \\[universal-argument].")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
989
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
990 (defvar universal-argument-num-events nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
991 "Number of argument-specifying events read by `universal-argument'.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
992 `universal-argument-other-key' uses this to discard those events
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
993 from (this-command-keys), and reread only the final command.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
994
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
995 (defun universal-argument ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
996 "Begin a numeric argument for the following command.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
997 Digits or minus sign following \\[universal-argument] make up the numeric argument.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
998 \\[universal-argument] following the digits or minus sign ends the argument.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
999 \\[universal-argument] without digits or minus sign provides 4 as argument.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1000 Repeating \\[universal-argument] without digits or minus sign
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1001 multiplies the argument by 4 each time."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1002 (interactive)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1003 (setq prefix-arg (list 4))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1004 (setq zmacs-region-stays t) ; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1005 (setq universal-argument-num-events (length (this-command-keys)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1006 (setq overriding-terminal-local-map universal-argument-map))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1007
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1008 ;; A subsequent C-u means to multiply the factor by 4 if we've typed
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1009 ;; nothing but C-u's; otherwise it means to terminate the prefix arg.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1010 (defun universal-argument-more (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1011 (interactive "_P") ; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1012 (if (consp arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1013 (setq prefix-arg (list (* 4 (car arg))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1014 (setq prefix-arg arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1015 (setq overriding-terminal-local-map nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1016 (setq universal-argument-num-events (length (this-command-keys))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1017
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1018 (defun negative-argument (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1019 "Begin a negative numeric argument for the next command.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1020 \\[universal-argument] following digits or minus sign ends the argument."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1021 (interactive "_P") ; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1022 (cond ((integerp arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1023 (setq prefix-arg (- arg)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1024 ((eq arg '-)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1025 (setq prefix-arg nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1026 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1027 (setq prefix-arg '-)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1028 (setq universal-argument-num-events (length (this-command-keys)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1029 (setq overriding-terminal-local-map universal-argument-map))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1030
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1031 ;; XEmacs: This function not synched with FSF
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1032 (defun digit-argument (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1033 "Part of the numeric argument for the next command.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1034 \\[universal-argument] following digits or minus sign ends the argument."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1035 (interactive "_P") ; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1036 (let* ((event last-command-event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1037 (key (and (key-press-event-p event)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1038 (event-key event)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1039 (digit (and key (characterp key) (>= key ?0) (<= key ?9)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1040 (- key ?0))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1041 (if (null digit)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1042 (universal-argument-other-key arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1043 (cond ((integerp arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1044 (setq prefix-arg (+ (* arg 10)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1045 (if (< arg 0) (- digit) digit))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1046 ((eq arg '-)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1047 ;; Treat -0 as just -, so that -01 will work.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1048 (setq prefix-arg (if (zerop digit) '- (- digit))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1049 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1050 (setq prefix-arg digit)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1051 (setq universal-argument-num-events (length (this-command-keys)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1052 (setq overriding-terminal-local-map universal-argument-map))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1053
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1054 ;; For backward compatibility, minus with no modifiers is an ordinary
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1055 ;; command if digits have already been entered.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1056 (defun universal-argument-minus (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1057 (interactive "_P") ; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1058 (if (integerp arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1059 (universal-argument-other-key arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1060 (negative-argument arg)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1061
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1062 ;; Anything else terminates the argument and is left in the queue to be
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1063 ;; executed as a command.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1064 (defun universal-argument-other-key (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1065 (interactive "_P") ; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1066 (setq prefix-arg arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1067 (let* ((key (this-command-keys))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1068 ;; FSF calls silly function `listify-key-sequence' here.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1069 (keylist (append key nil)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1070 (setq unread-command-events
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1071 (append (nthcdr universal-argument-num-events keylist)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1072 unread-command-events)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1073 (reset-this-command-lengths)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1074 (setq overriding-terminal-local-map nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1075
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1076
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1077 ;; XEmacs -- keep zmacs-region active.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1078 (defun forward-to-indentation (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1079 "Move forward ARG lines and position at first nonblank character."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1080 (interactive "_p")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1081 (forward-line arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1082 (skip-chars-forward " \t"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1083
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1084 (defun backward-to-indentation (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1085 "Move backward ARG lines and position at first nonblank character."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1086 (interactive "_p")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1087 (forward-line (- arg))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1088 (skip-chars-forward " \t"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1089
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1090 (defcustom kill-whole-line nil
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1091 "*Control when and whether `kill-line' removes entire lines.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1092 Note: This only applies when `kill-line' is called interactively;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1093 otherwise, it behaves \"historically\".
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1094
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1095 If `always', `kill-line' with no arg always kills the whole line,
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1096 wherever point is in the line. (If you want to just kill to the end
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1097 of the line, use \\[historical-kill-line].)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1098
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1099 If not `always' but non-nil, `kill-line' with no arg kills the whole
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1100 line if point is at the beginning, and otherwise behaves historically.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1101
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1102 If nil, `kill-line' behaves historically."
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1103 :type '(radio (const :tag "Kill to end of line" nil)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1104 (const :tag "Kill whole line" always)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1105 (const
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1106 :tag "Kill whole line at beginning, otherwise end of line" t))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1107 :group 'killing)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1108
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1109 (defun historical-kill-line (&optional arg)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1110 "Same as `kill-line' but ignores value of `kill-whole-line'."
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1111 (interactive "*P")
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1112 (let ((kill-whole-line nil))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1113 (if (interactive-p)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1114 (call-interactively 'kill-line)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1115 (kill-line arg))))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1116
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1117 (defun kill-line (&optional arg)
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1118 "Kill the rest of the current line, or the entire line.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1119 If no nonblanks there, kill thru newline.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1120 If called interactively, may kill the entire line; see `kill-whole-line'.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1121 when given no argument at the beginning of a line.
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1122 With prefix argument, kill that many lines from point.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1123 Negative arguments kill lines backward.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1124
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1125 When calling from a program, nil means \"no arg\",
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1126 a number counts as a prefix arg."
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1127 (interactive "*P")
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1128 (kill-region (if (and (interactive-p)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1129 (not arg)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1130 (eq kill-whole-line 'always))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1131 (save-excursion
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1132 (beginning-of-line)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1133 (point))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1134 (point))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1135 ;; Don't shift point before doing the delete; that way,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1136 ;; undo will record the right position of point.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1137 ;; FSF
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1138 ; ;; It is better to move point to the other end of the kill
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1139 ; ;; before killing. That way, in a read-only buffer, point
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1140 ; ;; moves across the text that is copied to the kill ring.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1141 ; ;; The choice has no effect on undo now that undo records
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1142 ; ;; the value of point from before the command was run.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1143 ; (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1144 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1145 (if arg
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1146 (forward-line (prefix-numeric-value arg))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1147 (if (eobp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1148 (signal 'end-of-buffer nil))
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1149 (if (or (looking-at "[ \t]*$")
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1150 (and (interactive-p)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1151 (or (eq kill-whole-line 'always)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1152 (and kill-whole-line (bolp)))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1153 (forward-line 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1154 (end-of-line)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1155 (point))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1156
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1157 ;; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1158 (defun backward-kill-line nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1159 "Kill back to the beginning of the line."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1160 (interactive)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1161 (let ((point (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1162 (beginning-of-line nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1163 (kill-region (point) point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1164
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1165
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1166 ;;;; Window system cut and paste hooks.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1167 ;;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1168 ;;; I think that kill-hooks is a better name and more general mechanism
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1169 ;;; than interprogram-cut-function (from FSFmacs). I don't like the behavior
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1170 ;;; of interprogram-paste-function: ^Y should always come from the kill ring,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1171 ;;; not the X selection. But if that were provided, it should be called (and
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1172 ;;; behave as) yank-hooks instead. -- jwz
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1173
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1174 ;; [... code snipped ...]
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1175
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1176 (defcustom kill-hooks nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1177 "*Functions run when something is added to the XEmacs kill ring.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1178 These functions are called with one argument, the string most recently
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
1179 cut or copied. You can use this to, for example, make the most recent
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1180 kill become the X Clipboard selection."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1181 :type 'hook
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1182 :group 'killing)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1183
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1184 ;;; `kill-hooks' seems not sufficient because
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1185 ;;; `interprogram-cut-function' requires more variable about to rotate
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1186 ;;; the cut buffers. I'm afraid to change interface of `kill-hooks',
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1187 ;;; so I add it. (1997-11-03 by MORIOKA Tomohiko)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1188
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1189 (defcustom interprogram-cut-function 'own-clipboard
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1190 "Function to call to make a killed region available to other programs.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1191
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1192 Most window systems provide some sort of facility for cutting and
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1193 pasting text between the windows of different programs.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1194 This variable holds a function that Emacs calls whenever text
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1195 is put in the kill ring, to make the new kill available to other
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1196 programs.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1197
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1198 The function takes one or two arguments.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1199 The first argument, TEXT, is a string containing
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1200 the text which should be made available.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1201 The second, PUSH, if non-nil means this is a \"new\" kill;
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1202 nil means appending to an \"old\" kill."
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1203 :type '(radio (function-item :tag "Send to Clipboard"
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1204 :format "%t\n"
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1205 own-clipboard)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1206 (const :tag "None" nil)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1207 (function :tag "Other"))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1208 :group 'killing)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1209
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1210 (defcustom interprogram-paste-function 'get-clipboard
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1211 "Function to call to get text cut from other programs.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1212
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1213 Most window systems provide some sort of facility for cutting and
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1214 pasting text between the windows of different programs.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1215 This variable holds a function that Emacs calls to obtain
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1216 text that other programs have provided for pasting.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1217
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1218 The function should be called with no arguments. If the function
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1219 returns nil, then no other program has provided such text, and the top
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1220 of the Emacs kill ring should be used. If the function returns a
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1221 string, that string should be put in the kill ring as the latest kill.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1222
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1223 Note that the function should return a string only if a program other
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1224 than Emacs has provided a string for pasting; if Emacs provided the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1225 most recent string, the function should return nil. If it is
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1226 difficult to tell whether Emacs or some other program provided the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1227 current string, it is probably good enough to return nil if the string
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1228 is equal (according to `string=') to the last text Emacs provided."
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1229 :type '(radio (function-item :tag "Get from Clipboard"
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1230 :format "%t\n"
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1231 get-clipboard)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1232 (const :tag "None" nil)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1233 (function :tag "Other"))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1234 :group 'killing)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1235
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1236
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1237 ;;;; The kill ring data structure.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1238
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1239 (defvar kill-ring nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1240 "List of killed text sequences.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1241 Since the kill ring is supposed to interact nicely with cut-and-paste
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1242 facilities offered by window systems, use of this variable should
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1243 interact nicely with `interprogram-cut-function' and
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1244 `interprogram-paste-function'. The functions `kill-new',
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1245 `kill-append', and `current-kill' are supposed to implement this
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1246 interaction; you may want to use them instead of manipulating the kill
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1247 ring directly.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1248
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1249 (defcustom kill-ring-max 30
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1250 "*Maximum length of kill ring before oldest elements are thrown away."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1251 :type 'integer
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1252 :group 'killing)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1253
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1254 (defvar kill-ring-yank-pointer nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1255 "The tail of the kill ring whose car is the last thing yanked.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1256
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1257 (defun kill-new (string &optional replace)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1258 "Make STRING the latest kill in the kill ring.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1259 Set the kill-ring-yank pointer to point to it.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1260 Run `kill-hooks'.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1261 Optional second argument REPLACE non-nil means that STRING will replace
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1262 the front of the kill ring, rather than being added to the list."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1263 ; (and (fboundp 'menu-bar-update-yank-menu)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1264 ; (menu-bar-update-yank-menu string (and replace (car kill-ring))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1265 (if replace
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1266 (setcar kill-ring string)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1267 (setq kill-ring (cons string kill-ring))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1268 (if (> (length kill-ring) kill-ring-max)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1269 (setcdr (nthcdr (1- kill-ring-max) kill-ring) nil)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1270 (setq kill-ring-yank-pointer kill-ring)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1271 (if interprogram-cut-function
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1272 (funcall interprogram-cut-function string (not replace)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1273 (run-hook-with-args 'kill-hooks string))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1274
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1275 (defun kill-append (string before-p)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1276 "Append STRING to the end of the latest kill in the kill ring.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1277 If BEFORE-P is non-nil, prepend STRING to the kill.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1278 Run `kill-hooks'."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1279 (kill-new (if before-p
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1280 (concat string (car kill-ring))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1281 (concat (car kill-ring) string)) t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1282
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1283 (defun current-kill (n &optional do-not-move)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1284 "Rotate the yanking point by N places, and then return that kill.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1285 If N is zero, `interprogram-paste-function' is set, and calling it
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1286 returns a string, then that string is added to the front of the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1287 kill ring and returned as the latest kill.
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
1288 If optional arg DO-NOT-MOVE is non-nil, then don't actually move the
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1289 yanking point\; just return the Nth kill forward."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1290 (let ((interprogram-paste (and (= n 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1291 interprogram-paste-function
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1292 (funcall interprogram-paste-function))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1293 (if interprogram-paste
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1294 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1295 ;; Disable the interprogram cut function when we add the new
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1296 ;; text to the kill ring, so Emacs doesn't try to own the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1297 ;; selection, with identical text.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1298 (let ((interprogram-cut-function nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1299 (kill-new interprogram-paste))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1300 interprogram-paste)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1301 (or kill-ring (error "Kill ring is empty"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1302 (let* ((tem (nthcdr (mod (- n (length kill-ring-yank-pointer))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1303 (length kill-ring))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1304 kill-ring)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1305 (or do-not-move
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1306 (setq kill-ring-yank-pointer tem))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1307 (car tem)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1308
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1309
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1310
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1311 ;;;; Commands for manipulating the kill ring.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1312
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1313 ;; In FSF killing read-only text just pastes it into kill-ring. Which
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1314 ;; is a very bad idea -- see Jamie's comment below.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1315
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1316 ;(defvar kill-read-only-ok nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1317 ; "*Non-nil means don't signal an error for killing read-only text.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1318
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1319 (defun kill-region (beg end &optional verbose) ; verbose is XEmacs addition
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1320 "Kill between point and mark.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1321 The text is deleted but saved in the kill ring.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1322 The command \\[yank] can retrieve it from there.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1323 \(If you want to kill and then yank immediately, use \\[copy-region-as-kill].)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1324
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1325 This is the primitive for programs to kill text (as opposed to deleting it).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1326 Supply two arguments, character numbers indicating the stretch of text
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1327 to be killed.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1328 Any command that calls this function is a \"kill command\".
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1329 If the previous command was also a kill command,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1330 the text killed this time appends to the text killed last time
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1331 to make one entry in the kill ring."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1332 (interactive "*r\np")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1333 ; (interactive
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1334 ; (let ((region-hack (and zmacs-regions (eq last-command 'yank))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1335 ; ;; This lets "^Y^W" work. I think this is dumb, but zwei did it.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1336 ; (if region-hack (zmacs-activate-region))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1337 ; (prog1
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1338 ; (list (point) (mark) current-prefix-arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1339 ; (if region-hack (zmacs-deactivate-region)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1340 ;; beg and end can be markers but the rest of this function is
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1341 ;; written as if they are only integers
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1342 (if (markerp beg) (setq beg (marker-position beg)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1343 (if (markerp end) (setq end (marker-position end)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1344 (or (and beg end) (if zmacs-regions ;; rewritten for I18N3 snarfing
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1345 (error "The region is not active now")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1346 (error "The mark is not set now")))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1347 (if verbose (if buffer-read-only
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
1348 (lmessage 'command "Copying %d characters"
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
1349 (- (max beg end) (min beg end)))
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
1350 (lmessage 'command "Killing %d characters"
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
1351 (- (max beg end) (min beg end)))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1352 (cond
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1353
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1354 ;; I don't like this large change in behavior -- jwz
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1355 ;; Read-Only text means it shouldn't be deleted, so I'm restoring
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1356 ;; this code, but only for text-properties and not full extents. -sb
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1357 ;; If the buffer is read-only, we should beep, in case the person
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1358 ;; just isn't aware of this. However, there's no harm in putting
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1359 ;; the region's text in the kill ring, anyway.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1360 ((or (and buffer-read-only (not inhibit-read-only))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1361 (text-property-not-all (min beg end) (max beg end) 'read-only nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1362 ;; This is redundant.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1363 ;; (if verbose (message "Copying %d characters"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1364 ;; (- (max beg end) (min beg end))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1365 (copy-region-as-kill beg end)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1366 ;; ;; This should always barf, and give us the correct error.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1367 ;; (if kill-read-only-ok
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1368 ;; (message "Read only text copied to kill ring")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1369 (setq this-command 'kill-region)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1370 (barf-if-buffer-read-only)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1371 (signal 'buffer-read-only (list (current-buffer))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1372
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1373 ;; In certain cases, we can arrange for the undo list and the kill
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1374 ;; ring to share the same string object. This code does that.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1375 ((not (or (eq buffer-undo-list t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1376 (eq last-command 'kill-region)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1377 ;; Use = since positions may be numbers or markers.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1378 (= beg end)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1379 ;; Don't let the undo list be truncated before we can even access it.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1380 ;; FSF calls this `undo-strong-limit'
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1381 (let ((undo-high-threshold (+ (- end beg) 100))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1382 ;(old-list buffer-undo-list)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1383 tail)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1384 (delete-region beg end)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1385 ;; Search back in buffer-undo-list for this string,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1386 ;; in case a change hook made property changes.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1387 (setq tail buffer-undo-list)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1388 (while (and tail
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1389 (not (stringp (car-safe (car-safe tail))))) ; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1390 (pop tail))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1391 ;; Take the same string recorded for undo
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1392 ;; and put it in the kill-ring.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1393 (and tail
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1394 (kill-new (car (car tail))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1395
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1396 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1397 ;; if undo is not kept, grab the string then delete it (which won't
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1398 ;; add another string to the undo list).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1399 (copy-region-as-kill beg end)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1400 (delete-region beg end)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1401 (setq this-command 'kill-region))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1402
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1403 ;; copy-region-as-kill no longer sets this-command, because it's confusing
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1404 ;; to get two copies of the text when the user accidentally types M-w and
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1405 ;; then corrects it with the intended C-w.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1406 (defun copy-region-as-kill (beg end)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1407 "Save the region as if killed, but don't kill it.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1408 Run `kill-hooks'."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1409 (interactive "r")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1410 (if (eq last-command 'kill-region)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1411 (kill-append (buffer-substring beg end) (< end beg))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1412 (kill-new (buffer-substring beg end)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1413 nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1414
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1415 (defun kill-ring-save (beg end)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1416 "Save the region as if killed, but don't kill it.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1417 This command is similar to `copy-region-as-kill', except that it gives
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1418 visual feedback indicating the extent of the region being copied."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1419 (interactive "r")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1420 (copy-region-as-kill beg end)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1421 ;; copy before delay, for xclipboard's benefit
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1422 (if (interactive-p)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1423 (let ((other-end (if (= (point) beg) end beg))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1424 (opoint (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1425 ;; Inhibit quitting so we can make a quit here
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1426 ;; look like a C-g typed as a command.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1427 (inhibit-quit t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1428 (if (pos-visible-in-window-p other-end (selected-window))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1429 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1430 ;; FSF (I'm not sure what this does -sb)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1431 ; ;; Swap point and mark.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1432 ; (set-marker (mark-marker) (point) (current-buffer))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1433 (goto-char other-end)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1434 (sit-for 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1435 ; ;; Swap back.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1436 ; (set-marker (mark-marker) other-end (current-buffer))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1437 (goto-char opoint)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1438 ;; If user quit, deactivate the mark
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1439 ;; as C-g would as a command.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1440 (and quit-flag (mark)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1441 (zmacs-deactivate-region)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1442 ;; too noisy. -- jwz
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1443 ; (let* ((killed-text (current-kill 0))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1444 ; (message-len (min (length killed-text) 40)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1445 ; (if (= (point) beg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1446 ; ;; Don't say "killed"; that is misleading.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1447 ; (message "Saved text until \"%s\""
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1448 ; (substring killed-text (- message-len)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1449 ; (message "Saved text from \"%s\""
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1450 ; (substring killed-text 0 message-len))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1451 ))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1452
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1453 (defun append-next-kill ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1454 "Cause following command, if it kills, to append to previous kill."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1455 ;; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1456 (interactive "_")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1457 (if (interactive-p)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1458 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1459 (setq this-command 'kill-region)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1460 (display-message 'command
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
1461 "If the next command is a kill, it will append"))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1462 (setq last-command 'kill-region)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1463
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1464 (defun yank-pop (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1465 "Replace just-yanked stretch of killed text with a different stretch.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1466 This command is allowed only immediately after a `yank' or a `yank-pop'.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1467 At such a time, the region contains a stretch of reinserted
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1468 previously-killed text. `yank-pop' deletes that text and inserts in its
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1469 place a different stretch of killed text.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1470
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1471 With no argument, the previous kill is inserted.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1472 With argument N, insert the Nth previous kill.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1473 If N is negative, this is a more recent kill.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1474
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1475 The sequence of kills wraps around, so that after the oldest one
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1476 comes the newest one."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1477 (interactive "*p")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1478 (if (not (eq last-command 'yank))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1479 (error "Previous command was not a yank"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1480 (setq this-command 'yank)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1481 (let ((inhibit-read-only t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1482 (before (< (point) (mark t))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1483 (delete-region (point) (mark t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1484 ;;(set-marker (mark-marker) (point) (current-buffer))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1485 (set-mark (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1486 (insert (current-kill arg))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1487 (if before
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1488 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1489 ;; It is cleaner to avoid activation, even though the command
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1490 ;; loop would deactivate the mark because we inserted text.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1491 (goto-char (prog1 (mark t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1492 (set-marker (mark-marker t) (point) (current-buffer))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1493 nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1494
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1495
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1496 (defun yank (&optional arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1497 "Reinsert the last stretch of killed text.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1498 More precisely, reinsert the stretch of killed text most recently
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1499 killed OR yanked. Put point at end, and set mark at beginning.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1500 With just C-u as argument, same but put point at beginning (and mark at end).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1501 With argument N, reinsert the Nth most recently killed stretch of killed
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1502 text.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1503 See also the command \\[yank-pop]."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1504 (interactive "*P")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1505 ;; If we don't get all the way through, make last-command indicate that
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1506 ;; for the following command.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1507 (setq this-command t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1508 (push-mark (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1509 (insert (current-kill (cond
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1510 ((listp arg) 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1511 ((eq arg '-) -1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1512 (t (1- arg)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1513 (if (consp arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1514 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1515 ;; It is cleaner to avoid activation, even though the command
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1516 ;; loop would deactivate the mark because we inserted text.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1517 ;; (But it's an unnecessary kludge in XEmacs.)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1518 ;(goto-char (prog1 (mark t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1519 ;(set-marker (mark-marker) (point) (current-buffer)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1520 (exchange-point-and-mark t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1521 ;; If we do get all the way thru, make this-command indicate that.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1522 (setq this-command 'yank)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1523 nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1524
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1525 (defun rotate-yank-pointer (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1526 "Rotate the yanking point in the kill ring.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1527 With argument, rotate that many kills forward (or backward, if negative)."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1528 (interactive "p")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1529 (current-kill arg))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1530
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1531
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1532 (defun insert-buffer (buffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1533 "Insert after point the contents of BUFFER.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1534 Puts mark after the inserted text.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1535 BUFFER may be a buffer or a buffer name."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1536 (interactive
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1537 (list
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1538 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1539 (barf-if-buffer-read-only)
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
1540 (read-buffer "Insert buffer: "
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1541 ;; XEmacs: we have different args
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1542 (other-buffer (current-buffer) nil t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1543 t))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1544 (or (bufferp buffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1545 (setq buffer (get-buffer buffer)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1546 (let (start end newmark)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1547 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1548 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1549 (set-buffer buffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1550 (setq start (point-min) end (point-max)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1551 (insert-buffer-substring buffer start end)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1552 (setq newmark (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1553 (push-mark newmark))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1554 nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1555
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1556 (defun append-to-buffer (buffer start end)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1557 "Append to specified buffer the text of the region.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1558 It is inserted into that buffer before its point.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1559
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1560 When calling from a program, give three arguments:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1561 BUFFER (or buffer name), START and END.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1562 START and END specify the portion of the current buffer to be copied."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1563 (interactive
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1564 ;; XEmacs: we have different args to other-buffer
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1565 (list (read-buffer "Append to buffer: " (other-buffer (current-buffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1566 nil t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1567 (region-beginning) (region-end)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1568 (let ((oldbuf (current-buffer)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1569 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1570 (set-buffer (get-buffer-create buffer))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1571 (insert-buffer-substring oldbuf start end))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1572
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1573 (defun prepend-to-buffer (buffer start end)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1574 "Prepend to specified buffer the text of the region.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1575 It is inserted into that buffer after its point.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1576
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1577 When calling from a program, give three arguments:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1578 BUFFER (or buffer name), START and END.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1579 START and END specify the portion of the current buffer to be copied."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1580 (interactive "BPrepend to buffer: \nr")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1581 (let ((oldbuf (current-buffer)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1582 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1583 (set-buffer (get-buffer-create buffer))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1584 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1585 (insert-buffer-substring oldbuf start end)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1586
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1587 (defun copy-to-buffer (buffer start end)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1588 "Copy to specified buffer the text of the region.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1589 It is inserted into that buffer, replacing existing text there.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1590
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1591 When calling from a program, give three arguments:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1592 BUFFER (or buffer name), START and END.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1593 START and END specify the portion of the current buffer to be copied."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1594 (interactive "BCopy to buffer: \nr")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1595 (let ((oldbuf (current-buffer)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1596 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1597 (set-buffer (get-buffer-create buffer))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1598 (erase-buffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1599 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1600 (insert-buffer-substring oldbuf start end)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1601
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1602 ;FSFmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1603 ;(put 'mark-inactive 'error-conditions '(mark-inactive error))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1604 ;(put 'mark-inactive 'error-message "The mark is not active now")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1605
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1606 (defun mark (&optional force buffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1607 "Return this buffer's mark value as integer, or nil if no mark.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1608
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1609 If `zmacs-regions' is true, then this returns nil unless the region is
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1610 currently in the active (highlighted) state. With an argument of t, this
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1611 returns the mark (if there is one) regardless of the active-region state.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1612 You should *generally* not use the mark unless the region is active, if
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1613 the user has expressed a preference for the active-region model.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1614
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1615 If you are using this in an editing command, you are most likely making
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1616 a mistake; see the documentation of `set-mark'."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1617 (setq buffer (decode-buffer buffer))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1618 ;FSFmacs version:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1619 ; (if (or force (not transient-mark-mode) mark-active mark-even-if-inactive)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1620 ; (marker-position (mark-marker))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1621 ; (signal 'mark-inactive nil)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1622 (let ((m (mark-marker force buffer)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1623 (and m (marker-position m))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1624
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1625 ;;;#### FSFmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1626 ;;; Many places set mark-active directly, and several of them failed to also
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1627 ;;; run deactivate-mark-hook. This shorthand should simplify.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1628 ;(defsubst deactivate-mark ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1629 ; "Deactivate the mark by setting `mark-active' to nil.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1630 ;\(That makes a difference only in Transient Mark mode.)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1631 ;Also runs the hook `deactivate-mark-hook'."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1632 ; (if transient-mark-mode
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1633 ; (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1634 ; (setq mark-active nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1635 ; (run-hooks 'deactivate-mark-hook))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1636
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1637 (defun set-mark (pos &optional buffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1638 "Set this buffer's mark to POS. Don't use this function!
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1639 That is to say, don't use this function unless you want
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1640 the user to see that the mark has moved, and you want the previous
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1641 mark position to be lost.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1642
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1643 Normally, when a new mark is set, the old one should go on the stack.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1644 This is why most applications should use push-mark, not set-mark.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1645
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1646 Novice Emacs Lisp programmers often try to use the mark for the wrong
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1647 purposes. The mark saves a location for the user's convenience.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1648 Most editing commands should not alter the mark.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1649 To remember a location for internal use in the Lisp program,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1650 store it in a Lisp variable. Example:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1651
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1652 (let ((beg (point))) (forward-line 1) (delete-region beg (point)))."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1653
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1654 (setq buffer (decode-buffer buffer))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1655 (set-marker (mark-marker t buffer) pos buffer))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1656 ;; FSF
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1657 ; (if pos
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1658 ; (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1659 ; (setq mark-active t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1660 ; (run-hooks 'activate-mark-hook)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1661 ; (set-marker (mark-marker) pos (current-buffer)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1662 ; ;; Normally we never clear mark-active except in Transient Mark mode.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1663 ; ;; But when we actually clear out the mark value too,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1664 ; ;; we must clear mark-active in any mode.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1665 ; (setq mark-active nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1666 ; (run-hooks 'deactivate-mark-hook)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1667 ; (set-marker (mark-marker) nil)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1668
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1669 (defvar mark-ring nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1670 "The list of former marks of the current buffer, most recent first.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1671 (make-variable-buffer-local 'mark-ring)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1672 (put 'mark-ring 'permanent-local t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1673
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1674 (defcustom mark-ring-max 16
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1675 "*Maximum size of mark ring. Start discarding off end if gets this big."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1676 :type 'integer
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1677 :group 'killing)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1678
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1679 (defvar global-mark-ring nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1680 "The list of saved global marks, most recent first.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1681
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1682 (defcustom global-mark-ring-max 16
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1683 "*Maximum size of global mark ring. \
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1684 Start discarding off end if gets this big."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1685 :type 'integer
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1686 :group 'killing)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1687
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1688 (defun set-mark-command (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1689 "Set mark at where point is, or jump to mark.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1690 With no prefix argument, set mark, push old mark position on local mark
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1691 ring, and push mark on global mark ring.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1692 With argument, jump to mark, and pop a new position for mark off the ring
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1693 \(does not affect global mark ring\).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1694
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1695 Novice Emacs Lisp programmers often try to use the mark for the wrong
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1696 purposes. See the documentation of `set-mark' for more information."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1697 (interactive "P")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1698 (if (null arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1699 (push-mark nil nil t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1700 (if (null (mark t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1701 (error "No mark set in this buffer")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1702 (goto-char (mark t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1703 (pop-mark))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1704
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1705 ;; XEmacs: Extra parameter
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1706 (defun push-mark (&optional location nomsg activate-region buffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1707 "Set mark at LOCATION (point, by default) and push old mark on mark ring.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1708 If the last global mark pushed was not in the current buffer,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1709 also push LOCATION on the global mark ring.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1710 Display `Mark set' unless the optional second arg NOMSG is non-nil.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1711 Activate mark if optional third arg ACTIVATE-REGION non-nil.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1712
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1713 Novice Emacs Lisp programmers often try to use the mark for the wrong
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1714 purposes. See the documentation of `set-mark' for more information."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1715 (setq buffer (decode-buffer buffer)) ; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1716 (if (null (mark t buffer)) ; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1717 nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1718 ;; The save-excursion / set-buffer is necessary because mark-ring
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1719 ;; is a buffer local variable
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1720 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1721 (set-buffer buffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1722 (setq mark-ring (cons (copy-marker (mark-marker t buffer)) mark-ring))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1723 (if (> (length mark-ring) mark-ring-max)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1724 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1725 (move-marker (car (nthcdr mark-ring-max mark-ring)) nil buffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1726 (setcdr (nthcdr (1- mark-ring-max) mark-ring) nil)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1727 (set-mark (or location (point buffer)) buffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1728 ; (set-marker (mark-marker) (or location (point)) (current-buffer)) ; FSF
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1729 ;; Now push the mark on the global mark ring.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1730 (if (or (null global-mark-ring)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1731 (not (eq (marker-buffer (car global-mark-ring)) buffer)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1732 ;; The last global mark pushed wasn't in this same buffer.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1733 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1734 (setq global-mark-ring (cons (copy-marker (mark-marker t buffer))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1735 global-mark-ring))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1736 (if (> (length global-mark-ring) global-mark-ring-max)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1737 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1738 (move-marker (car (nthcdr global-mark-ring-max global-mark-ring))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1739 nil buffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1740 (setcdr (nthcdr (1- global-mark-ring-max) global-mark-ring) nil)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1741 (or nomsg executing-kbd-macro (> (minibuffer-depth) 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1742 (display-message 'command "Mark set"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1743 (if activate-region
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1744 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1745 (setq zmacs-region-stays t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1746 (zmacs-activate-region)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1747 ; (if (or activate (not transient-mark-mode)) ; FSF
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1748 ; (set-mark (mark t))) ; FSF
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1749 nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1750
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1751 (defun pop-mark ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1752 "Pop off mark ring into the buffer's actual mark.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1753 Does not set point. Does nothing if mark ring is empty."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1754 (if mark-ring
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1755 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1756 (setq mark-ring (nconc mark-ring (list (copy-marker (mark-marker t)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1757 (set-mark (car mark-ring))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1758 (move-marker (car mark-ring) nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1759 (if (null (mark t)) (ding))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1760 (setq mark-ring (cdr mark-ring)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1761
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1762 (define-function 'exchange-dot-and-mark 'exchange-point-and-mark)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1763 (defun exchange-point-and-mark (&optional dont-activate-region)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1764 "Put the mark where point is now, and point where the mark is now.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1765 The mark is activated unless DONT-ACTIVATE-REGION is non-nil."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1766 (interactive nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1767 (let ((omark (mark t)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1768 (if (null omark)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1769 (error "No mark set in this buffer"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1770 (set-mark (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1771 (goto-char omark)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1772 (or dont-activate-region (zmacs-activate-region)) ; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1773 nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1774
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1775 ;; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1776 (defun mark-something (mark-fn movement-fn arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1777 "internal function used by mark-sexp, mark-word, etc."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1778 (let (newmark (pushp t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1779 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1780 (if (and (eq last-command mark-fn) (mark))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1781 ;; Extend the previous state in the same direction:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1782 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1783 (if (< (mark) (point)) (setq arg (- arg)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1784 (goto-char (mark))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1785 (setq pushp nil)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1786 (funcall movement-fn arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1787 (setq newmark (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1788 (if pushp
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1789 (push-mark newmark nil t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1790 ;; Do not mess with the mark stack, but merely adjust the previous state:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1791 (set-mark newmark)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1792 (activate-region))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1793
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1794 ;(defun transient-mark-mode (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1795 ; "Toggle Transient Mark mode.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1796 ;With arg, turn Transient Mark mode on if arg is positive, off otherwise.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1797 ;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1798 ;In Transient Mark mode, when the mark is active, the region is highlighted.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1799 ;Changing the buffer \"deactivates\" the mark.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1800 ;So do certain other operations that set the mark
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1801 ;but whose main purpose is something else--for example,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1802 ;incremental search, \\[beginning-of-buffer], and \\[end-of-buffer]."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1803 ; (interactive "P")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1804 ; (setq transient-mark-mode
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1805 ; (if (null arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1806 ; (not transient-mark-mode)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1807 ; (> (prefix-numeric-value arg) 0))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1808
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1809 (defun pop-global-mark ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1810 "Pop off global mark ring and jump to the top location."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1811 (interactive)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1812 ;; Pop entries which refer to non-existent buffers.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1813 (while (and global-mark-ring (not (marker-buffer (car global-mark-ring))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1814 (setq global-mark-ring (cdr global-mark-ring)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1815 (or global-mark-ring
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1816 (error "No global mark set"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1817 (let* ((marker (car global-mark-ring))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1818 (buffer (marker-buffer marker))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1819 (position (marker-position marker)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1820 (setq global-mark-ring (nconc (cdr global-mark-ring)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1821 (list (car global-mark-ring))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1822 (set-buffer buffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1823 (or (and (>= position (point-min))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1824 (<= position (point-max)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1825 (widen))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1826 (goto-char position)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1827 (switch-to-buffer buffer)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1828
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1829
265
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1830 (defcustom signal-error-on-buffer-boundary t
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1831 "*Non-nil value causes XEmacs to beep or signal an error when certain interactive commands would move point past (point-min) or (point-max).
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1832 The commands that honor this variable are
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1833
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1834 forward-char-command
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1835 backward-char-command
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1836 next-line
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1837 previous-line
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1838 scroll-up-command
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1839 scroll-down-command"
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1840 :type 'boolean
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1841 :group 'editing-basics)
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1842
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1843 ;;; After 8 years of waiting ... -sb
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1844 (defcustom next-line-add-newlines nil ; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1845 "*If non-nil, `next-line' inserts newline when the point is at end of buffer.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1846 This behavior used to be the default, and is still default in FSF Emacs.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1847 We think it is an unnecessary and unwanted side-effect."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1848 :type 'boolean
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1849 :group 'editing-basics)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1850
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1851 (defcustom shifted-motion-keys-select-region t
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1852 "*If non-nil, shifted motion keys select text, like in MS Windows.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1853 See also `unshifted-motion-keys-deselect-region'."
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1854 :type 'boolean
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1855 :group 'editing-basics)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1856
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1857 (defcustom unshifted-motion-keys-deselect-region t
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1858 "*If non-nil, unshifted motion keys deselect a shifted-motion region.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1859 This only occurs after a region has been selected using shifted motion keys
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1860 (not when using the traditional set-mark-then-move method), and has no effect
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1861 if `shifted-motion-keys-select-region' is nil."
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1862 :type 'boolean
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1863 :group 'editing-basics)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1864
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1865 (defun handle-pre-motion-command-current-command-is-motion ()
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1866 (and (key-press-event-p last-input-event)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1867 (memq (event-key last-input-event)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1868 '(left right up down home end prior next
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1869 kp-left kp-right kp-up kp-down
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1870 kp-home kp-end kp-prior kp-next))))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1871
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1872 (defun handle-pre-motion-command ()
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1873 (if
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1874 (and
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1875 (handle-pre-motion-command-current-command-is-motion)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1876 zmacs-regions
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1877 shifted-motion-keys-select-region
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1878 (not (region-active-p))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1879 (memq 'shift (event-modifiers last-input-event)))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1880 (push-mark nil nil t)))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1881
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1882 (defun handle-post-motion-command ()
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1883 (if
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1884 (and
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1885 (handle-pre-motion-command-current-command-is-motion)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1886 zmacs-regions
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1887 (region-active-p))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1888 (cond ((memq 'shift (event-modifiers last-input-event))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1889 (if shifted-motion-keys-select-region
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1890 (putf this-command-properties 'shifted-motion-command t))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1891 (setq zmacs-region-stays t))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1892 ((and (getf last-command-properties 'shifted-motion-command)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1893 unshifted-motion-keys-deselect-region)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1894 (setq zmacs-region-stays nil))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1895 (t
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1896 (setq zmacs-region-stays t)))))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1897
265
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1898 (defun forward-char-command (&optional arg buffer)
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1899 "Move point right ARG characters (left if ARG negative) in BUFFER.
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1900 On attempt to pass end of buffer, stop and signal `end-of-buffer'.
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1901 On attempt to pass beginning of buffer, stop and signal `beginning-of-buffer'.
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1902 Error signaling is suppressed if `signal-error-on-buffer-boundary'
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1903 is nil. If BUFFER is nil, the current buffer is assumed."
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1904 (interactive "_p")
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1905 (if signal-error-on-buffer-boundary
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1906 (forward-char arg buffer)
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1907 (condition-case nil
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1908 (forward-char arg buffer)
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1909 (beginning-of-buffer nil)
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1910 (end-of-buffer nil))))
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1911
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1912 (defun backward-char-command (&optional arg buffer)
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1913 "Move point left ARG characters (right if ARG negative) in BUFFER.
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1914 On attempt to pass end of buffer, stop and signal `end-of-buffer'.
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1915 On attempt to pass beginning of buffer, stop and signal `beginning-of-buffer'.
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1916 Error signaling is suppressed if `signal-error-on-buffer-boundary'
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1917 is nil. If BUFFER is nil, the current buffer is assumed."
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1918 (interactive "_p")
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1919 (if signal-error-on-buffer-boundary
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1920 (backward-char arg buffer)
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1921 (condition-case nil
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1922 (backward-char arg buffer)
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1923 (beginning-of-buffer nil)
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1924 (end-of-buffer nil))))
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1925
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1926 (defun scroll-up-command (&optional n)
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1927 "Scroll text of current window upward ARG lines; or near full screen if no ARG.
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1928 A near full screen is `next-screen-context-lines' less than a full screen.
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1929 Negative ARG means scroll downward.
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1930 When calling from a program, supply a number as argument or nil.
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1931 On attempt to scroll past end of buffer, `end-of-buffer' is signaled.
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1932 On attempt to scroll past beginning of buffer, `beginning-of-buffer' is
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1933 signaled.
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1934
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1935 If `signal-error-on-buffer-boundary' is nil, attempts to scroll past buffer
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1936 boundaries do not cause an error to be signaled."
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1937 (interactive "_P")
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1938 (if signal-error-on-buffer-boundary
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1939 (scroll-up n)
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1940 (condition-case nil
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1941 (scroll-up n)
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1942 (beginning-of-buffer nil)
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1943 (end-of-buffer nil))))
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1944
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1945 (defun scroll-down-command (&optional n)
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1946 "Scroll text of current window downward ARG lines; or near full screen if no ARG.
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1947 A near full screen is `next-screen-context-lines' less than a full screen.
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1948 Negative ARG means scroll upward.
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1949 When calling from a program, supply a number as argument or nil.
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1950 On attempt to scroll past end of buffer, `end-of-buffer' is signaled.
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1951 On attempt to scroll past beginning of buffer, `beginning-of-buffer' is
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1952 signaled.
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1953
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1954 If `signal-error-on-buffer-boundary' is nil, attempts to scroll past buffer
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1955 boundaries do not cause an error to be signaled."
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1956 (interactive "_P")
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1957 (if signal-error-on-buffer-boundary
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1958 (scroll-down n)
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1959 (condition-case nil
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1960 (scroll-down n)
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1961 (beginning-of-buffer nil)
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1962 (end-of-buffer nil))))
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
1963
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1964 (defun next-line (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1965 "Move cursor vertically down ARG lines.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1966 If there is no character in the target line exactly under the current column,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1967 the cursor is positioned after the character in that line which spans this
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1968 column, or at the end of the line if it is not long enough.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1969
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1970 If there is no line in the buffer after this one, behavior depends on the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1971 value of `next-line-add-newlines'. If non-nil, it inserts a newline character
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1972 to create a line, and moves the cursor to that line. Otherwise it moves the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1973 cursor to the end of the buffer.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1974
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1975 The command \\[set-goal-column] can be used to create
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1976 a semipermanent goal column to which this command always moves.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1977 Then it does not try to move vertically. This goal column is stored
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1978 in `goal-column', which is nil when there is none.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1979
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1980 If you are thinking of using this in a Lisp program, consider
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1981 using `forward-line' instead. It is usually easier to use
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1982 and more reliable (no dependence on goal column, etc.)."
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
1983 (interactive "_p")
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1984 (if (and next-line-add-newlines (= arg 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1985 (let ((opoint (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1986 (end-of-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1987 (if (eobp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1988 (newline 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1989 (goto-char opoint)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1990 (line-move arg)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1991 (if (interactive-p)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1992 ;; XEmacs: Not sure what to do about this. It's inconsistent. -sb
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1993 (condition-case nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1994 (line-move arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1995 ((beginning-of-buffer end-of-buffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1996 (when signal-error-on-buffer-boundary
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1997 (ding nil 'buffer-bound))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1998 (line-move arg)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1999 nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2000
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2001 (defun previous-line (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2002 "Move cursor vertically up ARG lines.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2003 If there is no character in the target line exactly over the current column,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2004 the cursor is positioned after the character in that line which spans this
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2005 column, or at the end of the line if it is not long enough.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2006
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2007 The command \\[set-goal-column] can be used to create
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2008 a semipermanent goal column to which this command always moves.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2009 Then it does not try to move vertically.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2010
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2011 If you are thinking of using this in a Lisp program, consider using
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2012 `forward-line' with a negative argument instead. It is usually easier
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2013 to use and more reliable (no dependence on goal column, etc.)."
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
2014 (interactive "_p")
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2015 (if (interactive-p)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2016 (condition-case nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2017 (line-move (- arg))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2018 ((beginning-of-buffer end-of-buffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2019 (when signal-error-on-buffer-boundary ; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2020 (ding nil 'buffer-bound))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2021 (line-move (- arg)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2022 nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2023
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
2024 (defcustom block-movement-size 6
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
2025 "*Number of lines that \"block movement\" commands (\\[forward-block-of-lines], \\[backward-block-of-lines]) move by."
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
2026 :type 'integer
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
2027 :group 'editing-basics)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
2028
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
2029 (defun backward-block-of-lines ()
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
2030 "Move backward by one \"block\" of lines.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
2031 The number of lines that make up a block is controlled by
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
2032 `block-movement-size', which defaults to 6."
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
2033 (interactive "_")
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
2034 (forward-line (- block-movement-size)))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
2035
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
2036 (defun forward-block-of-lines ()
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
2037 "Move forward by one \"block\" of lines.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
2038 The number of lines that make up a block is controlled by
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
2039 `block-movement-size', which defaults to 6."
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
2040 (interactive "_")
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
2041 (forward-line block-movement-size))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
2042
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2043 (defcustom track-eol nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2044 "*Non-nil means vertical motion starting at end of line keeps to ends of lines.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2045 This means moving to the end of each line moved onto.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2046 The beginning of a blank line does not count as the end of a line."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2047 :type 'boolean
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2048 :group 'editing-basics)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2049
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2050 (defcustom goal-column nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2051 "*Semipermanent goal column for vertical motion, as set by \\[set-goal-column], or nil."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2052 :type '(choice integer (const :tag "None" nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2053 :group 'editing-basics)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2054 (make-variable-buffer-local 'goal-column)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2055
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2056 (defvar temporary-goal-column 0
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2057 "Current goal column for vertical motion.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2058 It is the column where point was
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2059 at the start of current run of vertical motion commands.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2060 When the `track-eol' feature is doing its job, the value is 9999.")
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
2061 (make-variable-buffer-local 'temporary-goal-column)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2062
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2063 ;XEmacs: not yet ported, so avoid compiler warnings
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2064 (eval-when-compile
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2065 (defvar inhibit-point-motion-hooks))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2066
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2067 (defcustom line-move-ignore-invisible nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2068 "*Non-nil means \\[next-line] and \\[previous-line] ignore invisible lines.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2069 Use with care, as it slows down movement significantly. Outline mode sets this."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2070 :type 'boolean
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2071 :group 'editing-basics)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2072
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2073 ;; This is the guts of next-line and previous-line.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2074 ;; Arg says how many lines to move.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2075 (defun line-move (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2076 ;; Don't run any point-motion hooks, and disregard intangibility,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2077 ;; for intermediate positions.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2078 (let ((inhibit-point-motion-hooks t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2079 (opoint (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2080 new)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2081 (unwind-protect
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2082 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2083 (if (not (or (eq last-command 'next-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2084 (eq last-command 'previous-line)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2085 (setq temporary-goal-column
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2086 (if (and track-eol (eolp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2087 ;; Don't count beg of empty line as end of line
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2088 ;; unless we just did explicit end-of-line.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2089 (or (not (bolp)) (eq last-command 'end-of-line)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2090 9999
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2091 (current-column))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2092 (if (and (not (integerp selective-display))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2093 (not line-move-ignore-invisible))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2094 ;; Use just newline characters.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2095 (or (if (> arg 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2096 (progn (if (> arg 1) (forward-line (1- arg)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2097 ;; This way of moving forward ARG lines
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2098 ;; verifies that we have a newline after the last one.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2099 ;; It doesn't get confused by intangible text.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2100 (end-of-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2101 (zerop (forward-line 1)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2102 (and (zerop (forward-line arg))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2103 (bolp)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2104 (signal (if (< arg 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2105 'beginning-of-buffer
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2106 'end-of-buffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2107 nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2108 ;; Move by arg lines, but ignore invisible ones.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2109 (while (> arg 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2110 (end-of-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2111 (and (zerop (vertical-motion 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2112 (signal 'end-of-buffer nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2113 ;; If the following character is currently invisible,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2114 ;; skip all characters with that same `invisible' property value.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2115 (while (and (not (eobp))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2116 (let ((prop
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2117 (get-char-property (point) 'invisible)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2118 (if (eq buffer-invisibility-spec t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2119 prop
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2120 (or (memq prop buffer-invisibility-spec)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2121 (assq prop buffer-invisibility-spec)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2122 (if (get-text-property (point) 'invisible)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2123 (goto-char (next-single-property-change (point) 'invisible))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2124 (goto-char (next-extent-change (point))))) ; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2125 (setq arg (1- arg)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2126 (while (< arg 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2127 (beginning-of-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2128 (and (zerop (vertical-motion -1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2129 (signal 'beginning-of-buffer nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2130 (while (and (not (bobp))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2131 (let ((prop
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2132 (get-char-property (1- (point)) 'invisible)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2133 (if (eq buffer-invisibility-spec t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2134 prop
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2135 (or (memq prop buffer-invisibility-spec)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2136 (assq prop buffer-invisibility-spec)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2137 (if (get-text-property (1- (point)) 'invisible)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2138 (goto-char (previous-single-property-change (point) 'invisible))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2139 (goto-char (previous-extent-change (point))))) ; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2140 (setq arg (1+ arg))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2141 (move-to-column (or goal-column temporary-goal-column)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2142 ;; Remember where we moved to, go back home,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2143 ;; then do the motion over again
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2144 ;; in just one step, with intangibility and point-motion hooks
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2145 ;; enabled this time.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2146 (setq new (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2147 (goto-char opoint)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2148 (setq inhibit-point-motion-hooks nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2149 (goto-char new)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2150 nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2151
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2152 ;;; Many people have said they rarely use this feature, and often type
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2153 ;;; it by accident. Maybe it shouldn't even be on a key.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2154 ;; It's not on a key, as of 20.2. So no need for this.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2155 ;(put 'set-goal-column 'disabled t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2156
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2157 (defun set-goal-column (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2158 "Set the current horizontal position as a goal for \\[next-line] and \\[previous-line].
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2159 Those commands will move to this position in the line moved to
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2160 rather than trying to keep the same horizontal position.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2161 With a non-nil argument, clears out the goal column
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2162 so that \\[next-line] and \\[previous-line] resume vertical motion.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2163 The goal column is stored in the variable `goal-column'."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2164 (interactive "_P") ; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2165 (if arg
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2166 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2167 (setq goal-column nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2168 (display-message 'command "No goal column"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2169 (setq goal-column (current-column))
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2170 (lmessage 'command
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2171 "Goal column %d (use %s with an arg to unset it)"
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2172 goal-column
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2173 (substitute-command-keys "\\[set-goal-column]")))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2174 nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2175
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2176 ;; deleted FSFmacs terminal randomness hscroll-point-visible stuff.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2177 ;; hscroll-step
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2178 ;; hscroll-point-visible
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2179 ;; hscroll-window-column
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2180 ;; right-arrow
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2181 ;; left-arrow
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2182
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2183 (defun scroll-other-window-down (lines)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2184 "Scroll the \"other window\" down.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2185 For more details, see the documentation for `scroll-other-window'."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2186 (interactive "P")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2187 (scroll-other-window
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2188 ;; Just invert the argument's meaning.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2189 ;; We can do that without knowing which window it will be.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2190 (if (eq lines '-) nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2191 (if (null lines) '-
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2192 (- (prefix-numeric-value lines))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2193 ;(define-key esc-map [?\C-\S-v] 'scroll-other-window-down)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2194
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2195 (defun beginning-of-buffer-other-window (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2196 "Move point to the beginning of the buffer in the other window.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2197 Leave mark at previous position.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2198 With arg N, put point N/10 of the way from the true beginning."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2199 (interactive "P")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2200 (let ((orig-window (selected-window))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2201 (window (other-window-for-scrolling)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2202 ;; We use unwind-protect rather than save-window-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2203 ;; because the latter would preserve the things we want to change.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2204 (unwind-protect
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2205 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2206 (select-window window)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2207 ;; Set point and mark in that window's buffer.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2208 (beginning-of-buffer arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2209 ;; Set point accordingly.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2210 (recenter '(t)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2211 (select-window orig-window))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2212
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2213 (defun end-of-buffer-other-window (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2214 "Move point to the end of the buffer in the other window.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2215 Leave mark at previous position.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2216 With arg N, put point N/10 of the way from the true end."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2217 (interactive "P")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2218 ;; See beginning-of-buffer-other-window for comments.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2219 (let ((orig-window (selected-window))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2220 (window (other-window-for-scrolling)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2221 (unwind-protect
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2222 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2223 (select-window window)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2224 (end-of-buffer arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2225 (recenter '(t)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2226 (select-window orig-window))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2227
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2228 (defun transpose-chars (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2229 "Interchange characters around point, moving forward one character.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2230 With prefix arg ARG, effect is to take character before point
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2231 and drag it forward past ARG other characters (backward if ARG negative).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2232 If no argument and at end of line, the previous two chars are exchanged."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2233 (interactive "*P")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2234 (and (null arg) (eolp) (forward-char -1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2235 (transpose-subr 'forward-char (prefix-numeric-value arg)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2236
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2237 ;;; A very old implementation of transpose-chars from the old days ...
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2238 (defun transpose-preceding-chars (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2239 "Interchange characters before point.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2240 With prefix arg ARG, effect is to take character before point
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2241 and drag it forward past ARG other characters (backward if ARG negative).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2242 If no argument and not at start of line, the previous two chars are exchanged."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2243 (interactive "*P")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2244 (and (null arg) (not (bolp)) (forward-char -1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2245 (transpose-subr 'forward-char (prefix-numeric-value arg)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2246
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2247
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2248 (defun transpose-words (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2249 "Interchange words around point, leaving point at end of them.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2250 With prefix arg ARG, effect is to take word before or around point
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2251 and drag it forward past ARG other words (backward if ARG negative).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2252 If ARG is zero, the words around or after point and around or after mark
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2253 are interchanged."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2254 (interactive "*p")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2255 (transpose-subr 'forward-word arg))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2256
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2257 (defun transpose-sexps (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2258 "Like \\[transpose-words] but applies to sexps.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2259 Does not work on a sexp that point is in the middle of
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2260 if it is a list or string."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2261 (interactive "*p")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2262 (transpose-subr 'forward-sexp arg))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2263
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2264 (defun transpose-lines (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2265 "Exchange current line and previous line, leaving point after both.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2266 With argument ARG, takes previous line and moves it past ARG lines.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2267 With argument 0, interchanges line point is in with line mark is in."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2268 (interactive "*p")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2269 (transpose-subr #'(lambda (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2270 (if (= arg 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2271 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2272 ;; Move forward over a line,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2273 ;; but create a newline if none exists yet.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2274 (end-of-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2275 (if (eobp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2276 (newline)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2277 (forward-char 1)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2278 (forward-line arg)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2279 arg))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2280
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2281 (eval-when-compile
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2282 ;; avoid byte-compiler warnings...
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2283 (defvar start1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2284 (defvar start2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2285 (defvar end1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2286 (defvar end2))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2287
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2288 ; start[12] and end[12] used in transpose-subr-1 below
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2289 (defun transpose-subr (mover arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2290 (let (start1 end1 start2 end2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2291 (if (= arg 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2292 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2293 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2294 (funcall mover 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2295 (setq end2 (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2296 (funcall mover -1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2297 (setq start2 (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2298 (goto-char (mark t)) ; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2299 (funcall mover 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2300 (setq end1 (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2301 (funcall mover -1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2302 (setq start1 (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2303 (transpose-subr-1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2304 (exchange-point-and-mark t))) ; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2305 (while (> arg 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2306 (funcall mover -1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2307 (setq start1 (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2308 (funcall mover 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2309 (setq end1 (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2310 (funcall mover 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2311 (setq end2 (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2312 (funcall mover -1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2313 (setq start2 (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2314 (transpose-subr-1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2315 (goto-char end2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2316 (setq arg (1- arg)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2317 (while (< arg 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2318 (funcall mover -1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2319 (setq start2 (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2320 (funcall mover -1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2321 (setq start1 (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2322 (funcall mover 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2323 (setq end1 (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2324 (funcall mover 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2325 (setq end2 (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2326 (transpose-subr-1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2327 (setq arg (1+ arg)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2328
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2329 ; start[12] and end[12] used free
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2330 (defun transpose-subr-1 ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2331 (if (> (min end1 end2) (max start1 start2))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2332 (error "Don't have two things to transpose"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2333 (let ((word1 (buffer-substring start1 end1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2334 (word2 (buffer-substring start2 end2)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2335 (delete-region start2 end2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2336 (goto-char start2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2337 (insert word1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2338 (goto-char (if (< start1 start2) start1
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2339 (+ start1 (- (length word1) (length word2)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2340 (delete-char (length word1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2341 (insert word2)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2342
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2343 (defcustom comment-column 32
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2344 "*Column to indent right-margin comments to.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2345 Setting this variable automatically makes it local to the current buffer.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2346 Each mode establishes a different default value for this variable; you
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2347 can set the value for a particular mode using that mode's hook."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2348 :type 'integer
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2349 :group 'fill-comments)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2350 (make-variable-buffer-local 'comment-column)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2351
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2352 (defcustom comment-start nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2353 "*String to insert to start a new comment, or nil if no comment syntax."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2354 :type '(choice (const :tag "None" nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2355 string)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2356 :group 'fill-comments)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2357
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2358 (defcustom comment-start-skip nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2359 "*Regexp to match the start of a comment plus everything up to its body.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2360 If there are any \\(...\\) pairs, the comment delimiter text is held to begin
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2361 at the place matched by the close of the first pair."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2362 :type '(choice (const :tag "None" nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2363 regexp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2364 :group 'fill-comments)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2365
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2366 (defcustom comment-end ""
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2367 "*String to insert to end a new comment.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2368 Should be an empty string if comments are terminated by end-of-line."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2369 :type 'string
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2370 :group 'fill-comments)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2371
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2372 (defconst comment-indent-hook nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2373 "Obsolete variable for function to compute desired indentation for a comment.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2374 Use `comment-indent-function' instead.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2375 This function is called with no args with point at the beginning of
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2376 the comment's starting delimiter.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2377
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2378 (defconst comment-indent-function
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2379 ;; XEmacs - add at least one space after the end of the text on the
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
2380 ;; current line...
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2381 (lambda ()
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
2382 (save-excursion
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
2383 (beginning-of-line)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2384 (let ((eol (save-excursion (end-of-line) (point))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2385 (and comment-start-skip
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2386 (re-search-forward comment-start-skip eol t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2387 (setq eol (match-beginning 0)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2388 (goto-char eol)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2389 (skip-chars-backward " \t")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2390 (max comment-column (1+ (current-column))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2391 "Function to compute desired indentation for a comment.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2392 This function is called with no args with point at the beginning of
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2393 the comment's starting delimiter.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2394
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2395 (defcustom block-comment-start nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2396 "*String to insert to start a new comment on a line by itself.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2397 If nil, use `comment-start' instead.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2398 Note that the regular expression `comment-start-skip' should skip this string
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2399 as well as the `comment-start' string."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2400 :type '(choice (const :tag "Use `comment-start'" nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2401 string)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2402 :group 'fill-comments)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2403
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2404 (defcustom block-comment-end nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2405 "*String to insert to end a new comment on a line by itself.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2406 Should be an empty string if comments are terminated by end-of-line.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2407 If nil, use `comment-end' instead."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2408 :type '(choice (const :tag "Use `comment-end'" nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2409 string)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2410 :group 'fill-comments)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2411
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2412 (defun indent-for-comment ()
371
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
2413 "Indent this line's comment to comment column, or insert an empty comment."
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2414 (interactive "*")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2415 (let* ((empty (save-excursion (beginning-of-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2416 (looking-at "[ \t]*$")))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2417 (starter (or (and empty block-comment-start) comment-start))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2418 (ender (or (and empty block-comment-end) comment-end)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2419 (if (null starter)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2420 (error "No comment syntax defined")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2421 (let* ((eolpos (save-excursion (end-of-line) (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2422 cpos indent begpos)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2423 (beginning-of-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2424 (if (re-search-forward comment-start-skip eolpos 'move)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2425 (progn (setq cpos (point-marker))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2426 ;; Find the start of the comment delimiter.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2427 ;; If there were paren-pairs in comment-start-skip,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2428 ;; position at the end of the first pair.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2429 (if (match-end 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2430 (goto-char (match-end 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2431 ;; If comment-start-skip matched a string with
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2432 ;; internal whitespace (not final whitespace) then
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2433 ;; the delimiter start at the end of that
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2434 ;; whitespace. Otherwise, it starts at the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2435 ;; beginning of what was matched.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2436 (skip-syntax-backward " " (match-beginning 0))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2437 (skip-syntax-backward "^ " (match-beginning 0)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2438 (setq begpos (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2439 ;; Compute desired indent.
371
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
2440 (if (= (current-column)
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
2441 (setq indent (funcall comment-indent-function)))
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
2442 (goto-char begpos)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2443 ;; If that's different from current, change it.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2444 (skip-chars-backward " \t")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2445 (delete-region (point) begpos)
371
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
2446 (indent-to indent))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2447 ;; An existing comment?
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
2448 (if cpos
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2449 (progn (goto-char cpos)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2450 (set-marker cpos nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2451 ;; No, insert one.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2452 (insert starter)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2453 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2454 (insert ender)))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2455
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2456 (defun set-comment-column (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2457 "Set the comment column based on point.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2458 With no arg, set the comment column to the current column.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2459 With just minus as arg, kill any comment on this line.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2460 With any other arg, set comment column to indentation of the previous comment
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2461 and then align or create a comment on this line at that column."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2462 (interactive "P")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2463 (if (eq arg '-)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2464 (kill-comment nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2465 (if arg
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2466 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2467 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2468 (beginning-of-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2469 (re-search-backward comment-start-skip)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2470 (beginning-of-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2471 (re-search-forward comment-start-skip)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2472 (goto-char (match-beginning 0))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2473 (setq comment-column (current-column))
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
2474 (lmessage 'command "Comment column set to %d" comment-column))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2475 (indent-for-comment))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2476 (setq comment-column (current-column))
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
2477 (lmessage 'command "Comment column set to %d" comment-column))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2478
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2479 (defun kill-comment (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2480 "Kill the comment on this line, if any.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2481 With argument, kill comments on that many lines starting with this one."
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 375
diff changeset
2482 ;; this function loses in a lot of situations. it incorrectly recognizes
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2483 ;; comment delimiters sometimes (ergo, inside a string), doesn't work
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2484 ;; with multi-line comments, can kill extra whitespace if comment wasn't
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2485 ;; through end-of-line, et cetera.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2486 (interactive "*P")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2487 (or comment-start-skip (error "No comment syntax defined"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2488 (let ((count (prefix-numeric-value arg)) endc)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2489 (while (> count 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2490 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2491 (end-of-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2492 (setq endc (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2493 (beginning-of-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2494 (and (string< "" comment-end)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2495 (setq endc
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2496 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2497 (re-search-forward (regexp-quote comment-end) endc 'move)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2498 (skip-chars-forward " \t")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2499 (point))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2500 (beginning-of-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2501 (if (re-search-forward comment-start-skip endc t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2502 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2503 (goto-char (match-beginning 0))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2504 (skip-chars-backward " \t")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2505 (kill-region (point) endc)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2506 ;; to catch comments a line beginnings
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2507 (indent-according-to-mode))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2508 (if arg (forward-line 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2509 (setq count (1- count)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2510
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2511 (defun comment-region (beg end &optional arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2512 "Comment or uncomment each line in the region.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2513 With just C-u prefix arg, uncomment each line in region.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2514 Numeric prefix arg ARG means use ARG comment characters.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2515 If ARG is negative, delete that many comment characters instead.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2516 Comments are terminated on each line, even for syntax in which newline does
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2517 not end the comment. Blank lines do not get comments."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2518 ;; if someone wants it to only put a comment-start at the beginning and
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2519 ;; comment-end at the end then typing it, C-x C-x, closing it, C-x C-x
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2520 ;; is easy enough. No option is made here for other than commenting
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2521 ;; every line.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2522 (interactive "r\nP")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2523 (or comment-start (error "No comment syntax is defined"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2524 (if (> beg end) (let (mid) (setq mid beg beg end end mid)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2525 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2526 (save-restriction
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2527 (let ((cs comment-start) (ce comment-end)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2528 numarg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2529 (if (consp arg) (setq numarg t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2530 (setq numarg (prefix-numeric-value arg))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2531 ;; For positive arg > 1, replicate the comment delims now,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2532 ;; then insert the replicated strings just once.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2533 (while (> numarg 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2534 (setq cs (concat cs comment-start)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2535 ce (concat ce comment-end))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2536 (setq numarg (1- numarg))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2537 ;; Loop over all lines from BEG to END.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2538 (narrow-to-region beg end)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2539 (goto-char beg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2540 (while (not (eobp))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2541 (if (or (eq numarg t) (< numarg 0))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2542 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2543 ;; Delete comment start from beginning of line.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2544 (if (eq numarg t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2545 (while (looking-at (regexp-quote cs))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2546 (delete-char (length cs)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2547 (let ((count numarg))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2548 (while (and (> 1 (setq count (1+ count)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2549 (looking-at (regexp-quote cs)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2550 (delete-char (length cs)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2551 ;; Delete comment end from end of line.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2552 (if (string= "" ce)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2553 nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2554 (if (eq numarg t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2555 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2556 (end-of-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2557 ;; This is questionable if comment-end ends in
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2558 ;; whitespace. That is pretty brain-damaged,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2559 ;; though.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2560 (skip-chars-backward " \t")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2561 (if (and (>= (- (point) (point-min)) (length ce))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2562 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2563 (backward-char (length ce))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2564 (looking-at (regexp-quote ce))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2565 (delete-char (- (length ce)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2566 (let ((count numarg))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2567 (while (> 1 (setq count (1+ count)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2568 (end-of-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2569 ;; This is questionable if comment-end ends in
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2570 ;; whitespace. That is pretty brain-damaged though
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2571 (skip-chars-backward " \t")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2572 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2573 (backward-char (length ce))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2574 (if (looking-at (regexp-quote ce))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2575 (delete-char (length ce))))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2576 (forward-line 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2577 ;; Insert at beginning and at end.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2578 (if (looking-at "[ \t]*$") ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2579 (insert cs)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2580 (if (string= "" ce) ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2581 (end-of-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2582 (insert ce)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2583 (search-forward "\n" nil 'move)))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2584
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2585 ;; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2586 (defun prefix-region (prefix)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2587 "Add a prefix string to each line between mark and point."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2588 (interactive "sPrefix string: ")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2589 (if prefix
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2590 (let ((count (count-lines (mark) (point))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2591 (goto-char (min (mark) (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2592 (while (> count 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2593 (setq count (1- count))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2594 (beginning-of-line 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2595 (insert prefix)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2596 (end-of-line 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2597 (forward-char 1)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2598
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2599
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2600 ;; XEmacs - extra parameter
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2601 (defun backward-word (arg &optional buffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2602 "Move backward until encountering the end of a word.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2603 With argument, do this that many times.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2604 In programs, it is faster to call `forward-word' with negative arg."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2605 (interactive "_p") ; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2606 (forward-word (- arg) buffer))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2607
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2608 (defun mark-word (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2609 "Set mark arg words away from point."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2610 (interactive "p")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2611 (mark-something 'mark-word 'forward-word arg))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2612
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2613 ;; XEmacs modified
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2614 (defun kill-word (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2615 "Kill characters forward until encountering the end of a word.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2616 With argument, do this that many times."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2617 (interactive "*p")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2618 (kill-region (point) (save-excursion (forward-word arg) (point))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2619
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2620 (defun backward-kill-word (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2621 "Kill characters backward until encountering the end of a word.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2622 With argument, do this that many times."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2623 (interactive "*p") ; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2624 (kill-word (- arg)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2625
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2626 (defun current-word (&optional strict)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2627 "Return the word point is on (or a nearby word) as a string.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2628 If optional arg STRICT is non-nil, return nil unless point is within
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2629 or adjacent to a word.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2630 If point is not between two word-constituent characters, but immediately
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2631 follows one, move back first.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2632 Otherwise, if point precedes a word constituent, move forward first.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2633 Otherwise, move backwards until a word constituent is found and get that word;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2634 if you a newlines is reached first, move forward instead."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2635 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2636 (let ((oldpoint (point)) (start (point)) (end (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2637 (skip-syntax-backward "w_") (setq start (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2638 (goto-char oldpoint)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2639 (skip-syntax-forward "w_") (setq end (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2640 (if (and (eq start oldpoint) (eq end oldpoint))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2641 ;; Point is neither within nor adjacent to a word.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2642 (and (not strict)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2643 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2644 ;; Look for preceding word in same line.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2645 (skip-syntax-backward "^w_"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2646 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2647 (beginning-of-line) (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2648 (if (bolp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2649 ;; No preceding word in same line.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2650 ;; Look for following word in same line.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2651 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2652 (skip-syntax-forward "^w_"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2653 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2654 (end-of-line) (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2655 (setq start (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2656 (skip-syntax-forward "w_")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2657 (setq end (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2658 (setq end (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2659 (skip-syntax-backward "w_")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2660 (setq start (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2661 (buffer-substring start end)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2662 (buffer-substring start end)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2663
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2664 (defcustom fill-prefix nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2665 "*String for filling to insert at front of new line, or nil for none.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2666 Setting this variable automatically makes it local to the current buffer."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2667 :type '(choice (const :tag "None" nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2668 string)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2669 :group 'fill)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2670 (make-variable-buffer-local 'fill-prefix)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2671
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2672 (defcustom auto-fill-inhibit-regexp nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2673 "*Regexp to match lines which should not be auto-filled."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2674 :type '(choice (const :tag "None" nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2675 regexp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2676 :group 'fill)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2677
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2678 (defvar comment-line-break-function 'indent-new-comment-line
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2679 "*Mode-specific function which line breaks and continues a comment.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2680
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2681 This function is only called during auto-filling of a comment section.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2682 The function should take a single optional argument which is a flag
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2683 indicating whether soft newlines should be inserted.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2684
265
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
2685 ;; defined in mule-base/mule-category.el
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
2686 (defvar word-across-newline)
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 259
diff changeset
2687
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2688 ;; This function is the auto-fill-function of a buffer
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2689 ;; when Auto-Fill mode is enabled.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2690 ;; It returns t if it really did any work.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2691 ;; XEmacs: This function is totally different.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2692 (defun do-auto-fill ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2693 (let (give-up)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2694 (or (and auto-fill-inhibit-regexp
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2695 (save-excursion (beginning-of-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2696 (looking-at auto-fill-inhibit-regexp)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2697 (while (and (not give-up) (> (current-column) fill-column))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2698 ;; Determine where to split the line.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2699 (let ((fill-prefix fill-prefix)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2700 (fill-point
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2701 (let ((opoint (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2702 bounce
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2703 ;; 97/3/14 jhod: Kinsoku
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2704 (re-break-point (if (featurep 'mule)
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2705 (concat "[ \t\n]\\|" word-across-newline
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2706 ".\\|." word-across-newline)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2707 "[ \t\n]"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2708 ;; end patch
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2709 (first t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2710 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2711 (move-to-column (1+ fill-column))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2712 ;; Move back to a word boundary.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2713 (while (or first
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2714 ;; If this is after period and a single space,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2715 ;; move back once more--we don't want to break
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2716 ;; the line there and make it look like a
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2717 ;; sentence end.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2718 (and (not (bobp))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2719 (not bounce)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2720 sentence-end-double-space
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2721 (save-excursion (forward-char -1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2722 (and (looking-at "\\. ")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2723 (not (looking-at "\\. "))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2724 (setq first nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2725 ;; 97/3/14 jhod: Kinsoku
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2726 ; (skip-chars-backward "^ \t\n"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2727 (fill-move-backward-to-break-point re-break-point)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2728 ;; end patch
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2729 ;; If we find nowhere on the line to break it,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2730 ;; break after one word. Set bounce to t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2731 ;; so we will not keep going in this while loop.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2732 (if (bolp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2733 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2734 ;; 97/3/14 jhod: Kinsoku
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2735 ; (re-search-forward "[ \t]" opoint t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2736 (fill-move-forward-to-break-point re-break-point
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2737 opoint)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2738 ;; end patch
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2739 (setq bounce t)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2740 (skip-chars-backward " \t"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2741 (if (and (featurep 'mule)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2742 (or bounce (bolp))) (kinsoku-process)) ;; 97/3/14 jhod: Kinsoku
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2743 ;; Let fill-point be set to the place where we end up.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2744 (point)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2745
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2746 ;; I'm not sure why Stig made this change but it breaks
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2747 ;; auto filling in at least C mode so I'm taking it back
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2748 ;; out. --cet
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2749 ;; XEmacs - adaptive fill.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2750 ;;(maybe-adapt-fill-prefix
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2751 ;; (or from (setq from (save-excursion (beginning-of-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2752 ;; (point))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2753 ;; (or to (setq to (save-excursion (beginning-of-line 2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2754 ;; (point))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2755 ;; t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2756
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2757 ;; If that place is not the beginning of the line,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2758 ;; break the line there.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2759 (if (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2760 (goto-char fill-point)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2761 (not (or (bolp) (eolp)))) ; 97/3/14 jhod: during kinsoku processing it is possible to move beyond
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2762 (let ((prev-column (current-column)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2763 ;; If point is at the fill-point, do not `save-excursion'.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2764 ;; Otherwise, if a comment prefix or fill-prefix is inserted,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2765 ;; point will end up before it rather than after it.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2766 (if (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2767 (skip-chars-backward " \t")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2768 (= (point) fill-point))
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2769 ;; 1999-09-17 hniksic: turn off Kinsoku until
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2770 ;; it's debugged.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2771 (indent-new-comment-line)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2772 ;; 97/3/14 jhod: Kinsoku processing
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2773 ; ;(indent-new-comment-line)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2774 ; (let ((spacep (memq (char-before (point)) '(?\ ?\t))))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2775 ; (funcall comment-line-break-function)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2776 ; ;; if user type space explicitly, leave SPC
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2777 ; ;; even if there is no WAN.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2778 ; (if spacep
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2779 ; (save-excursion
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2780 ; (goto-char fill-point)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2781 ; ;; put SPC except that there is SPC
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2782 ; ;; already or there is sentence end.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2783 ; (or (memq (char-after (point)) '(?\ ?\t))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2784 ; (fill-end-of-sentence-p)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2785 ; (insert ?\ )))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2786 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2787 (goto-char fill-point)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2788 (funcall comment-line-break-function)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2789 ;; If making the new line didn't reduce the hpos of
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2790 ;; the end of the line, then give up now;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2791 ;; trying again will not help.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2792 (if (>= (current-column) prev-column)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2793 (setq give-up t)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2794 ;; No place to break => stop trying.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2795 (setq give-up t)))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2796
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2797 ;; Put FSF one in until I can one or the other working properly, then the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2798 ;; other one is history.
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2799 ;(defun fsf:do-auto-fill ()
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2800 ; (let (fc justify
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2801 ; ;; bol
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2802 ; give-up
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2803 ; (fill-prefix fill-prefix))
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2804 ; (if (or (not (setq justify (current-justification)))
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2805 ; (null (setq fc (current-fill-column)))
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2806 ; (and (eq justify 'left)
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2807 ; (<= (current-column) fc))
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
2808 ; (save-excursion (beginning-of-line)
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2809 ; ;; (setq bol (point))
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2810 ; (and auto-fill-inhibit-regexp
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2811 ; (looking-at auto-fill-inhibit-regexp))))
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2812 ; nil ;; Auto-filling not required
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2813 ; (if (memq justify '(full center right))
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2814 ; (save-excursion (unjustify-current-line)))
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2815
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2816 ; ;; Choose a fill-prefix automatically.
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2817 ; (if (and adaptive-fill-mode
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2818 ; (or (null fill-prefix) (string= fill-prefix "")))
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2819 ; (let ((prefix
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2820 ; (fill-context-prefix
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2821 ; (save-excursion (backward-paragraph 1) (point))
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2822 ; (save-excursion (forward-paragraph 1) (point))
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2823 ; ;; Don't accept a non-whitespace fill prefix
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2824 ; ;; from the first line of a paragraph.
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2825 ; "^[ \t]*$")))
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2826 ; (and prefix (not (equal prefix ""))
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2827 ; (setq fill-prefix prefix))))
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2828
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2829 ; (while (and (not give-up) (> (current-column) fc))
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2830 ; ;; Determine where to split the line.
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2831 ; (let ((fill-point
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2832 ; (let ((opoint (point))
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2833 ; bounce
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2834 ; (first t))
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2835 ; (save-excursion
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2836 ; (move-to-column (1+ fc))
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2837 ; ;; Move back to a word boundary.
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2838 ; (while (or first
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2839 ; ;; If this is after period and a single space,
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2840 ; ;; move back once more--we don't want to break
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2841 ; ;; the line there and make it look like a
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2842 ; ;; sentence end.
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2843 ; (and (not (bobp))
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2844 ; (not bounce)
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2845 ; sentence-end-double-space
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2846 ; (save-excursion (forward-char -1)
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2847 ; (and (looking-at "\\. ")
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2848 ; (not (looking-at "\\. "))))))
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2849 ; (setq first nil)
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2850 ; (skip-chars-backward "^ \t\n")
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2851 ; ;; If we find nowhere on the line to break it,
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2852 ; ;; break after one word. Set bounce to t
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2853 ; ;; so we will not keep going in this while loop.
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2854 ; (if (bolp)
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2855 ; (progn
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2856 ; (re-search-forward "[ \t]" opoint t)
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2857 ; (setq bounce t)))
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2858 ; (skip-chars-backward " \t"))
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2859 ; ;; Let fill-point be set to the place where we end up.
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2860 ; (point)))))
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2861 ; ;; If that place is not the beginning of the line,
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2862 ; ;; break the line there.
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2863 ; (if (save-excursion
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2864 ; (goto-char fill-point)
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2865 ; (not (bolp)))
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2866 ; (let ((prev-column (current-column)))
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2867 ; ;; If point is at the fill-point, do not `save-excursion'.
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2868 ; ;; Otherwise, if a comment prefix or fill-prefix is inserted,
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2869 ; ;; point will end up before it rather than after it.
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2870 ; (if (save-excursion
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2871 ; (skip-chars-backward " \t")
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2872 ; (= (point) fill-point))
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2873 ; (funcall comment-line-break-function t)
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2874 ; (save-excursion
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2875 ; (goto-char fill-point)
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2876 ; (funcall comment-line-break-function t)))
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2877 ; ;; Now do justification, if required
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2878 ; (if (not (eq justify 'left))
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
2879 ; (save-excursion
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2880 ; (end-of-line 0)
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2881 ; (justify-current-line justify nil t)))
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2882 ; ;; If making the new line didn't reduce the hpos of
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2883 ; ;; the end of the line, then give up now;
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2884 ; ;; trying again will not help.
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2885 ; (if (>= (current-column) prev-column)
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2886 ; (setq give-up t)))
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2887 ; ;; No place to break => stop trying.
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2888 ; (setq give-up t))))
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2889 ; ;; Justify last line.
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2890 ; (justify-current-line justify t t)
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
2891 ; t)))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2892
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2893 (defvar normal-auto-fill-function 'do-auto-fill
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2894 "The function to use for `auto-fill-function' if Auto Fill mode is turned on.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2895 Some major modes set this.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2896
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2897 (defun auto-fill-mode (&optional arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2898 "Toggle auto-fill mode.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2899 With arg, turn auto-fill mode on if and only if arg is positive.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2900 In Auto-Fill mode, inserting a space at a column beyond `current-fill-column'
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2901 automatically breaks the line at a previous space.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2902
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2903 The value of `normal-auto-fill-function' specifies the function to use
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2904 for `auto-fill-function' when turning Auto Fill mode on."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2905 (interactive "P")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2906 (prog1 (setq auto-fill-function
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2907 (if (if (null arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2908 (not auto-fill-function)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2909 (> (prefix-numeric-value arg) 0))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2910 normal-auto-fill-function
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2911 nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2912 (redraw-modeline)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2913
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2914 ;; This holds a document string used to document auto-fill-mode.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2915 (defun auto-fill-function ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2916 "Automatically break line at a previous space, in insertion of text."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2917 nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2918
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2919 (defun turn-on-auto-fill ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2920 "Unconditionally turn on Auto Fill mode."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2921 (auto-fill-mode 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2922
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2923 (defun set-fill-column (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2924 "Set `fill-column' to specified argument.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2925 Just \\[universal-argument] as argument means to use the current column
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2926 The variable `fill-column' has a separate value for each buffer."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2927 (interactive "_P") ; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2928 (cond ((integerp arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2929 (setq fill-column arg))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2930 ((consp arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2931 (setq fill-column (current-column)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2932 ;; Disallow missing argument; it's probably a typo for C-x C-f.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2933 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2934 (error "set-fill-column requires an explicit argument")))
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
2935 (lmessage 'command "fill-column set to %d" fill-column))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2936
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2937 (defcustom comment-multi-line t ; XEmacs - this works well with adaptive fill
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2938 "*Non-nil means \\[indent-new-comment-line] should continue same comment
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2939 on new line, with no new terminator or starter.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2940 This is obsolete because you might as well use \\[newline-and-indent]."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2941 :type 'boolean
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2942 :group 'fill-comments)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2943
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2944 (defun indent-new-comment-line (&optional soft)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2945 "Break line at point and indent, continuing comment if within one.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2946 This indents the body of the continued comment
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2947 under the previous comment line.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2948
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2949 This command is intended for styles where you write a comment per line,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2950 starting a new comment (and terminating it if necessary) on each line.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2951 If you want to continue one comment across several lines, use \\[newline-and-indent].
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2952
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2953 If a fill column is specified, it overrides the use of the comment column
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2954 or comment indentation.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2955
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
2956 The inserted newline is marked hard if `use-hard-newlines' is true,
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2957 unless optional argument SOFT is non-nil."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2958 (interactive)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2959 (let (comcol comstart)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2960 (skip-chars-backward " \t")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2961 ;; 97/3/14 jhod: Kinsoku processing
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2962 (if (featurep 'mule)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2963 (kinsoku-process))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2964 (delete-region (point)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2965 (progn (skip-chars-forward " \t")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2966 (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2967 (if soft (insert ?\n) (newline 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2968 (if fill-prefix
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2969 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2970 (indent-to-left-margin)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2971 (insert fill-prefix))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2972 ;; #### - Eric Eide reverts to v18 semantics for this function in
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2973 ;; fa-extras, which I'm not gonna do. His changes are to (1) execute
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2974 ;; the save-excursion below unconditionally, and (2) uncomment the check
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
2975 ;; for (not comment-multi-line) further below. --Stig
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
2976 ;;#### jhod: probably need to fix this for kinsoku processing
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2977 (if (not comment-multi-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2978 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2979 (if (and comment-start-skip
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2980 (let ((opoint (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2981 (forward-line -1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2982 (re-search-forward comment-start-skip opoint t)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2983 ;; The old line is a comment.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2984 ;; Set WIN to the pos of the comment-start.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2985 ;; But if the comment is empty, look at preceding lines
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2986 ;; to find one that has a nonempty comment.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2987
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2988 ;; If comment-start-skip contains a \(...\) pair,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2989 ;; the real comment delimiter starts at the end of that pair.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2990 (let ((win (or (match-end 1) (match-beginning 0))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2991 (while (and (eolp) (not (bobp))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2992 (let (opoint)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2993 (beginning-of-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2994 (setq opoint (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2995 (forward-line -1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2996 (re-search-forward comment-start-skip opoint t)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2997 (setq win (or (match-end 1) (match-beginning 0))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2998 ;; Indent this line like what we found.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2999 (goto-char win)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3000 (setq comcol (current-column))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3001 (setq comstart
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3002 (buffer-substring (point) (match-end 0)))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3003 (if (and comcol (not fill-prefix)) ; XEmacs - (ENE) from fa-extras.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3004 (let ((comment-column comcol)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3005 (comment-start comstart)
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3006 (block-comment-start comstart)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3007 (comment-end comment-end))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3008 (and comment-end (not (equal comment-end ""))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3009 ; (if (not comment-multi-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3010 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3011 (forward-char -1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3012 (insert comment-end)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3013 (forward-char 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3014 ; (setq comment-column (+ comment-column (length comment-start))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3015 ; comment-start "")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3016 ; )
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3017 )
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3018 (if (not (eolp))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3019 (setq comment-end ""))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3020 (insert ?\n)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3021 (forward-char -1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3022 (indent-for-comment)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3023 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3024 ;; Make sure we delete the newline inserted above.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3025 (end-of-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3026 (delete-char 1)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3027 (indent-according-to-mode)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3028
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3029
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3030 (defun set-selective-display (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3031 "Set `selective-display' to ARG; clear it if no arg.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3032 When the value of `selective-display' is a number > 0,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3033 lines whose indentation is >= that value are not displayed.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3034 The variable `selective-display' has a separate value for each buffer."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3035 (interactive "P")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3036 (if (eq selective-display t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3037 (error "selective-display already in use for marked lines"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3038 (let ((current-vpos
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3039 (save-restriction
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3040 (narrow-to-region (point-min) (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3041 (goto-char (window-start))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3042 (vertical-motion (window-height)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3043 (setq selective-display
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3044 (and arg (prefix-numeric-value arg)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3045 (recenter current-vpos))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3046 (set-window-start (selected-window) (window-start (selected-window)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3047 ;; #### doesn't localize properly:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3048 (princ "selective-display set to " t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3049 (prin1 selective-display t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3050 (princ "." t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3051
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3052 ;; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3053 (defun nuke-selective-display ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3054 "Ensure that the buffer is not in selective-display mode.
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
3055 If `selective-display' is t, then restore the buffer text to its original
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
3056 state before disabling selective display."
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3057 ;; by Stig@hackvan.com
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3058 (interactive)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3059 (and (eq t selective-display)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3060 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3061 (save-restriction
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3062 (widen)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3063 (goto-char (point-min))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3064 (let ((mod-p (buffer-modified-p))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3065 (buffer-read-only nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3066 (while (search-forward "\r" nil t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3067 (delete-char -1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3068 (insert "\n"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3069 (set-buffer-modified-p mod-p)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3070 ))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3071 (setq selective-display nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3072
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3073 (add-hook 'change-major-mode-hook 'nuke-selective-display)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3074
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3075 (defconst overwrite-mode-textual (purecopy " Ovwrt")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3076 "The string displayed in the mode line when in overwrite mode.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3077 (defconst overwrite-mode-binary (purecopy " Bin Ovwrt")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3078 "The string displayed in the mode line when in binary overwrite mode.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3079
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3080 (defun overwrite-mode (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3081 "Toggle overwrite mode.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3082 With arg, turn overwrite mode on iff arg is positive.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3083 In overwrite mode, printing characters typed in replace existing text
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3084 on a one-for-one basis, rather than pushing it to the right. At the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3085 end of a line, such characters extend the line. Before a tab,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3086 such characters insert until the tab is filled in.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3087 \\[quoted-insert] still inserts characters in overwrite mode; this
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3088 is supposed to make it easier to insert characters when necessary."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3089 (interactive "P")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3090 (setq overwrite-mode
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3091 (if (if (null arg) (not overwrite-mode)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3092 (> (prefix-numeric-value arg) 0))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3093 'overwrite-mode-textual))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3094 (redraw-modeline))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3095
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3096 (defun binary-overwrite-mode (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3097 "Toggle binary overwrite mode.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3098 With arg, turn binary overwrite mode on iff arg is positive.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3099 In binary overwrite mode, printing characters typed in replace
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3100 existing text. Newlines are not treated specially, so typing at the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3101 end of a line joins the line to the next, with the typed character
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3102 between them. Typing before a tab character simply replaces the tab
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3103 with the character typed.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3104 \\[quoted-insert] replaces the text at the cursor, just as ordinary
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3105 typing characters do.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3106
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3107 Note that binary overwrite mode is not its own minor mode; it is a
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3108 specialization of overwrite-mode, entered by setting the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3109 `overwrite-mode' variable to `overwrite-mode-binary'."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3110 (interactive "P")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3111 (setq overwrite-mode
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3112 (if (if (null arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3113 (not (eq overwrite-mode 'overwrite-mode-binary))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3114 (> (prefix-numeric-value arg) 0))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3115 'overwrite-mode-binary))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3116 (redraw-modeline))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3117
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3118 (defcustom line-number-mode nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3119 "*Non-nil means display line number in modeline."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3120 :type 'boolean
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3121 :group 'editing-basics)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3122
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3123 (defun line-number-mode (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3124 "Toggle Line Number mode.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3125 With arg, turn Line Number mode on iff arg is positive.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3126 When Line Number mode is enabled, the line number appears
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3127 in the mode line."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3128 (interactive "P")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3129 (setq line-number-mode
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3130 (if (null arg) (not line-number-mode)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3131 (> (prefix-numeric-value arg) 0)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3132 (redraw-modeline))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3133
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3134 (defcustom column-number-mode nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3135 "*Non-nil means display column number in mode line."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3136 :type 'boolean
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3137 :group 'editing-basics)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3138
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3139 (defun column-number-mode (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3140 "Toggle Column Number mode.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3141 With arg, turn Column Number mode on iff arg is positive.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3142 When Column Number mode is enabled, the column number appears
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3143 in the mode line."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3144 (interactive "P")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3145 (setq column-number-mode
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3146 (if (null arg) (not column-number-mode)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3147 (> (prefix-numeric-value arg) 0)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3148 (redraw-modeline))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3149
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3150
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3151 (defcustom blink-matching-paren t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3152 "*Non-nil means show matching open-paren when close-paren is inserted."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3153 :type 'boolean
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3154 :group 'paren-blinking)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3155
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3156 (defcustom blink-matching-paren-on-screen t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3157 "*Non-nil means show matching open-paren when it is on screen.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3158 nil means don't show it (but the open-paren can still be shown
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3159 when it is off screen."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3160 :type 'boolean
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3161 :group 'paren-blinking)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3162
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3163 (defcustom blink-matching-paren-distance 12000
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3164 "*If non-nil, is maximum distance to search for matching open-paren."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3165 :type '(choice integer (const nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3166 :group 'paren-blinking)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3167
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3168 (defcustom blink-matching-delay 1
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3169 "*The number of seconds that `blink-matching-open' will delay at a match."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3170 :type 'number
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3171 :group 'paren-blinking)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3172
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3173 (defcustom blink-matching-paren-dont-ignore-comments nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3174 "*Non-nil means `blink-matching-paren' should not ignore comments."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3175 :type 'boolean
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3176 :group 'paren-blinking)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3177
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3178 (defun blink-matching-open ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3179 "Move cursor momentarily to the beginning of the sexp before point."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3180 (interactive "_") ; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3181 (and (> (point) (1+ (point-min)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3182 blink-matching-paren
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3183 ;; Verify an even number of quoting characters precede the close.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3184 (= 1 (logand 1 (- (point)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3185 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3186 (forward-char -1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3187 (skip-syntax-backward "/\\")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3188 (point)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3189 (let* ((oldpos (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3190 (blinkpos)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3191 (mismatch))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3192 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3193 (save-restriction
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3194 (if blink-matching-paren-distance
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3195 (narrow-to-region (max (point-min)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3196 (- (point) blink-matching-paren-distance))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3197 oldpos))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3198 (condition-case ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3199 (let ((parse-sexp-ignore-comments
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3200 (and parse-sexp-ignore-comments
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3201 (not blink-matching-paren-dont-ignore-comments))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3202 (setq blinkpos (scan-sexps oldpos -1)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3203 (error nil)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3204 (and blinkpos
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3205 (/= (char-syntax (char-after blinkpos))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3206 ?\$)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3207 (setq mismatch
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3208 (or (null (matching-paren (char-after blinkpos)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3209 (/= (char-after (1- oldpos))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3210 (matching-paren (char-after blinkpos))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3211 (if mismatch (setq blinkpos nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3212 (if blinkpos
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3213 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3214 (goto-char blinkpos)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3215 (if (pos-visible-in-window-p)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3216 (and blink-matching-paren-on-screen
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3217 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3218 (auto-show-make-point-visible)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3219 (sit-for blink-matching-delay)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3220 (goto-char blinkpos)
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
3221 (lmessage 'command "Matches %s"
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3222 ;; Show what precedes the open in its line, if anything.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3223 (if (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3224 (skip-chars-backward " \t")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3225 (not (bolp)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3226 (buffer-substring (progn (beginning-of-line) (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3227 (1+ blinkpos))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3228 ;; Show what follows the open in its line, if anything.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3229 (if (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3230 (forward-char 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3231 (skip-chars-forward " \t")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3232 (not (eolp)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3233 (buffer-substring blinkpos
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3234 (progn (end-of-line) (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3235 ;; Otherwise show the previous nonblank line,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3236 ;; if there is one.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3237 (if (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3238 (skip-chars-backward "\n \t")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3239 (not (bobp)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3240 (concat
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3241 (buffer-substring (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3242 (skip-chars-backward "\n \t")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3243 (beginning-of-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3244 (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3245 (progn (end-of-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3246 (skip-chars-backward " \t")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3247 (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3248 ;; Replace the newline and other whitespace with `...'.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3249 "..."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3250 (buffer-substring blinkpos (1+ blinkpos)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3251 ;; There is nothing to show except the char itself.
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
3252 (buffer-substring blinkpos (1+ blinkpos))))))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3253 (cond (mismatch
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3254 (display-message 'no-log "Mismatched parentheses"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3255 ((not blink-matching-paren-distance)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3256 (display-message 'no-log "Unmatched parenthesis"))))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3257
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3258 ;Turned off because it makes dbx bomb out.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3259 (setq blink-paren-function 'blink-matching-open)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3260
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3261 (eval-when-compile (defvar myhelp)) ; suppress compiler warning
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3262
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3263 ;; XEmacs: Some functions moved to cmdloop.el:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3264 ;; keyboard-quit
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3265 ;; buffer-quit-function
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3266 ;; keyboard-escape-quit
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3267
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3268 (defun assoc-ignore-case (key alist)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3269 "Like `assoc', but assumes KEY is a string and ignores case when comparing."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3270 (setq key (downcase key))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3271 (let (element)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3272 (while (and alist (not element))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3273 (if (equal key (downcase (car (car alist))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3274 (setq element (car alist)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3275 (setq alist (cdr alist)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3276 element))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3277
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3278
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3279 (defcustom mail-user-agent 'sendmail-user-agent
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3280 "*Your preference for a mail composition package.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3281 Various Emacs Lisp packages (e.g. reporter) require you to compose an
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3282 outgoing email message. This variable lets you specify which
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3283 mail-sending package you prefer.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3284
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3285 Valid values include:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3286
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3287 sendmail-user-agent -- use the default Emacs Mail package
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3288 mh-e-user-agent -- use the Emacs interface to the MH mail system
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3289 message-user-agent -- use the GNUS mail sending package
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3290
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3291 Additional valid symbols may be available; check with the author of
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3292 your package for details."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3293 :type '(radio (function-item :tag "Default Emacs mail"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3294 :format "%t\n"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3295 sendmail-user-agent)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3296 (function-item :tag "Gnus mail sending package"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3297 :format "%t\n"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3298 message-user-agent)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3299 (function :tag "Other"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3300 :group 'mail)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3301
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3302 (defun define-mail-user-agent (symbol composefunc sendfunc
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3303 &optional abortfunc hookvar)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3304 "Define a symbol to identify a mail-sending package for `mail-user-agent'.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3305
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3306 SYMBOL can be any Lisp symbol. Its function definition and/or
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3307 value as a variable do not matter for this usage; we use only certain
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3308 properties on its property list, to encode the rest of the arguments.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3309
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3310 COMPOSEFUNC is program callable function that composes an outgoing
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3311 mail message buffer. This function should set up the basics of the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3312 buffer without requiring user interaction. It should populate the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3313 standard mail headers, leaving the `to:' and `subject:' headers blank
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3314 by default.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3315
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3316 COMPOSEFUNC should accept several optional arguments--the same
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3317 arguments that `compose-mail' takes. See that function's documentation.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3318
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3319 SENDFUNC is the command a user would run to send the message.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3320
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3321 Optional ABORTFUNC is the command a user would run to abort the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3322 message. For mail packages that don't have a separate abort function,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3323 this can be `kill-buffer' (the equivalent of omitting this argument).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3324
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3325 Optional HOOKVAR is a hook variable that gets run before the message
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3326 is actually sent. Callers that use the `mail-user-agent' may
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3327 install a hook function temporarily on this hook variable.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3328 If HOOKVAR is nil, `mail-send-hook' is used.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3329
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3330 The properties used on SYMBOL are `composefunc', `sendfunc',
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3331 `abortfunc', and `hookvar'."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3332 (put symbol 'composefunc composefunc)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3333 (put symbol 'sendfunc sendfunc)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3334 (put symbol 'abortfunc (or abortfunc 'kill-buffer))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3335 (put symbol 'hookvar (or hookvar 'mail-send-hook)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3336
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3337 (define-mail-user-agent 'sendmail-user-agent
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3338 'sendmail-user-agent-compose 'mail-send-and-exit)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3339
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3340 (define-mail-user-agent 'message-user-agent
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3341 'message-mail 'message-send-and-exit
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3342 'message-kill-buffer 'message-send-hook)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3343
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3344 (defun sendmail-user-agent-compose (&optional to subject other-headers continue
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3345 switch-function yank-action
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3346 send-actions)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3347 (if switch-function
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3348 (let ((special-display-buffer-names nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3349 (special-display-regexps nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3350 (same-window-buffer-names nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3351 (same-window-regexps nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3352 (funcall switch-function "*mail*")))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3353 (let ((cc (cdr (assoc-ignore-case "cc" other-headers)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3354 (in-reply-to (cdr (assoc-ignore-case "in-reply-to" other-headers))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3355 (or (mail continue to subject in-reply-to cc yank-action send-actions)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3356 continue
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3357 (error "Message aborted"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3358 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3359 (goto-char (point-min))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3360 (search-forward mail-header-separator)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3361 (beginning-of-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3362 (while other-headers
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3363 (if (not (member (car (car other-headers)) '("in-reply-to" "cc")))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3364 (insert (car (car other-headers)) ": "
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3365 (cdr (car other-headers)) "\n"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3366 (setq other-headers (cdr other-headers)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3367 t)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3368
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3369 (define-mail-user-agent 'mh-e-user-agent
239
41f2f0e326e9 Import from CVS: tag r20-5b18
cvs
parents: 235
diff changeset
3370 'mh-user-agent-compose 'mh-send-letter 'mh-fully-kill-draft
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3371 'mh-before-send-letter-hook)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3372
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3373 (defun compose-mail (&optional to subject other-headers continue
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3374 switch-function yank-action send-actions)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3375 "Start composing a mail message to send.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3376 This uses the user's chosen mail composition package
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3377 as selected with the variable `mail-user-agent'.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3378 The optional arguments TO and SUBJECT specify recipients
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3379 and the initial Subject field, respectively.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3380
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3381 OTHER-HEADERS is an alist specifying additional
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3382 header fields. Elements look like (HEADER . VALUE) where both
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3383 HEADER and VALUE are strings.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3384
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3385 CONTINUE, if non-nil, says to continue editing a message already
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3386 being composed.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3387
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3388 SWITCH-FUNCTION, if non-nil, is a function to use to
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3389 switch to and display the buffer used for mail composition.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3390
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3391 YANK-ACTION, if non-nil, is an action to perform, if and when necessary,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3392 to insert the raw text of the message being replied to.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3393 It has the form (FUNCTION . ARGS). The user agent will apply
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3394 FUNCTION to ARGS, to insert the raw text of the original message.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3395 \(The user agent will also run `mail-citation-hook', *after* the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3396 original text has been inserted in this way.)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3397
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3398 SEND-ACTIONS is a list of actions to call when the message is sent.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3399 Each action has the form (FUNCTION . ARGS)."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3400 (interactive
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3401 (list nil nil nil current-prefix-arg))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3402 (let ((function (get mail-user-agent 'composefunc)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3403 (funcall function to subject other-headers continue
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3404 switch-function yank-action send-actions)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3405
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3406 (defun compose-mail-other-window (&optional to subject other-headers continue
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3407 yank-action send-actions)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3408 "Like \\[compose-mail], but edit the outgoing message in another window."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3409 (interactive
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3410 (list nil nil nil current-prefix-arg))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3411 (compose-mail to subject other-headers continue
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3412 'switch-to-buffer-other-window yank-action send-actions))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3413
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3414
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3415 (defun compose-mail-other-frame (&optional to subject other-headers continue
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3416 yank-action send-actions)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3417 "Like \\[compose-mail], but edit the outgoing message in another frame."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3418 (interactive
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3419 (list nil nil nil current-prefix-arg))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3420 (compose-mail to subject other-headers continue
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3421 'switch-to-buffer-other-frame yank-action send-actions))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3422
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3423
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3424 (defun set-variable (var val)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3425 "Set VARIABLE to VALUE. VALUE is a Lisp object.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3426 When using this interactively, supply a Lisp expression for VALUE.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3427 If you want VALUE to be a string, you must surround it with doublequotes.
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 265
diff changeset
3428 If VARIABLE is a specifier, VALUE is added to it as an instantiator in
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 265
diff changeset
3429 the 'global locale with nil tag set (see `set-specifier').
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3430
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3431 If VARIABLE has a `variable-interactive' property, that is used as if
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3432 it were the arg to `interactive' (which see) to interactively read the value."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3433 (interactive
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3434 (let* ((var (read-variable "Set variable: "))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3435 ;; #### - yucky code replication here. This should use something
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
3436 ;; from help.el or hyper-apropos.el
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3437 (minibuffer-help-form
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3438 '(funcall myhelp))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3439 (myhelp
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3440 #'(lambda ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3441 (with-output-to-temp-buffer "*Help*"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3442 (prin1 var)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3443 (princ "\nDocumentation:\n")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3444 (princ (substring (documentation-property var 'variable-documentation)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3445 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3446 (if (boundp var)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3447 (let ((print-length 20))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3448 (princ "\n\nCurrent value: ")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3449 (prin1 (symbol-value var))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3450 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3451 (set-buffer standard-output)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3452 (help-mode))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3453 nil))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3454 (list var
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3455 (let ((prop (get var 'variable-interactive)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3456 (if prop
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3457 ;; Use VAR's `variable-interactive' property
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3458 ;; as an interactive spec for prompting.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3459 (call-interactively (list 'lambda '(arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3460 (list 'interactive prop)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3461 'arg))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3462 (eval-minibuffer (format "Set %s to value: " var)))))))
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
3463 (if (and (boundp var) (specifierp (symbol-value var)))
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 265
diff changeset
3464 (set-specifier (symbol-value var) val)
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 265
diff changeset
3465 (set var val)))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3466
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3467 ;; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3468 (defun activate-region ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3469 "Activate the region, if `zmacs-regions' is true.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3470 Setting `zmacs-regions' to true causes LISPM-style active regions to be used.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3471 This function has no effect if `zmacs-regions' is false."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3472 (interactive)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3473 (and zmacs-regions (zmacs-activate-region)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3474
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3475 ;; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3476 (defsubst region-exists-p ()
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
3477 "Return t if the region exists.
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3478 If active regions are in use (i.e. `zmacs-regions' is true), this means that
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3479 the region is active. Otherwise, this means that the user has pushed
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3480 a mark in this buffer at some point in the past.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3481 The functions `region-beginning' and `region-end' can be used to find the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3482 limits of the region."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3483 (not (null (mark))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3484
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3485 ;; XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3486 (defun region-active-p ()
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
3487 "Return non-nil if the region is active.
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3488 If `zmacs-regions' is true, this is equivalent to `region-exists-p'.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3489 Otherwise, this function always returns false."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3490 (and zmacs-regions zmacs-region-extent))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3491
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3492 ;; A bunch of stuff was moved elsewhere:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3493 ;; completion-list-mode-map
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3494 ;; completion-reference-buffer
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3495 ;; completion-base-size
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3496 ;; delete-completion-window
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3497 ;; previous-completion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3498 ;; next-completion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3499 ;; choose-completion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3500 ;; choose-completion-delete-max-match
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3501 ;; choose-completion-string
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3502 ;; completion-list-mode
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3503 ;; completion-fixup-function
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3504 ;; completion-setup-function
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3505 ;; switch-to-completions
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3506 ;; event stuffs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3507 ;; keypad stuffs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3508
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3509 ;; The rest of this file is not in Lisp in FSF
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3510 (defun capitalize-region-or-word (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3511 "Capitalize the selected region or the following word (or ARG words)."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3512 (interactive "p")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3513 (if (region-active-p)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3514 (capitalize-region (region-beginning) (region-end))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3515 (capitalize-word arg)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3516
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3517 (defun upcase-region-or-word (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3518 "Upcase the selected region or the following word (or ARG words)."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3519 (interactive "p")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3520 (if (region-active-p)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3521 (upcase-region (region-beginning) (region-end))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3522 (upcase-word arg)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3523
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3524 (defun downcase-region-or-word (arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3525 "Downcase the selected region or the following word (or ARG words)."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3526 (interactive "p")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3527 (if (region-active-p)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3528 (downcase-region (region-beginning) (region-end))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3529 (downcase-word arg)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3530
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
3531 ;; #### not localized
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
3532 (defvar uncapitalized-title-words
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
3533 '("the" "a" "an" "in" "of" "for" "to" "and" "but" "at" "on" "as" "by"))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
3534
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
3535 (defvar uncapitalized-title-word-regexp
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
3536 (concat "[ \t]*\\(" (mapconcat #'identity uncapitalized-title-words "\\|")
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
3537 "\\)\\>"))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
3538
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
3539 (defun capitalize-string-as-title (string)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
3540 "Capitalize the words in the string, except for small words (as in titles).
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
3541 The words not capitalized are specified in `uncapitalized-title-words'."
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
3542 (let ((buffer (get-buffer-create " *capitalize-string-as-title*")))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
3543 (unwind-protect
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
3544 (progn
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
3545 (insert-string string buffer)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
3546 (capitalize-region-as-title 1 (point-max buffer) buffer)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
3547 (buffer-string buffer))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
3548 (kill-buffer buffer))))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
3549
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
3550 (defun capitalize-region-as-title (b e &optional buffer)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
3551 "Capitalize the words in the region, except for small words (as in titles).
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
3552 The words not capitalized are specified in `uncapitalized-title-words'."
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
3553 (interactive "r")
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
3554 (save-excursion
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
3555 (and buffer
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
3556 (set-buffer buffer))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
3557 (save-restriction
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
3558 (narrow-to-region b e)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
3559 (goto-char (point-min))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
3560 (let ((first t))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
3561 (while (< (point) (point-max))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
3562 (if (or first
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
3563 (not (looking-at uncapitalized-title-word-regexp)))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
3564 (capitalize-word 1)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
3565 (forward-word 1))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
3566 (setq first nil))))))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
3567
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3568 ;; Most of the zmacs code is now in elisp. The only thing left in C
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3569 ;; are the variables zmacs-regions, zmacs-region-active-p and
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3570 ;; zmacs-region-stays plus the function zmacs_update_region which
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3571 ;; simply calls the lisp level zmacs-update-region. It must remain
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3572 ;; for convenience, since it is called by core C code.
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3573
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3574 (defvar zmacs-activate-region-hook nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3575 "Function or functions called when the region becomes active;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3576 see the variable `zmacs-regions'.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3577
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3578 (defvar zmacs-deactivate-region-hook nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3579 "Function or functions called when the region becomes inactive;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3580 see the variable `zmacs-regions'.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3581
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3582 (defvar zmacs-update-region-hook nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3583 "Function or functions called when the active region changes.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3584 This is called after each command that sets `zmacs-region-stays' to t.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3585 See the variable `zmacs-regions'.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3586
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3587 (defvar zmacs-region-extent nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3588 "The extent of the zmacs region; don't use this.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3589
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3590 (defvar zmacs-region-rectangular-p nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3591 "Whether the zmacs region is a rectangle; don't use this.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3592
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3593 (defun zmacs-make-extent-for-region (region)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3594 ;; Given a region, this makes an extent in the buffer which holds that
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3595 ;; region, for highlighting purposes. If the region isn't associated
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3596 ;; with a buffer, this does nothing.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3597 (let ((buffer nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3598 (valid (and (extentp zmacs-region-extent)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3599 (extent-object zmacs-region-extent)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3600 (buffer-live-p (extent-object zmacs-region-extent))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3601 start end)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3602 (cond ((consp region)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3603 (setq start (min (car region) (cdr region))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3604 end (max (car region) (cdr region))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3605 valid (and valid
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3606 (eq (marker-buffer (car region))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3607 (extent-object zmacs-region-extent)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3608 buffer (marker-buffer (car region))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3609 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3610 (signal 'error (list "Invalid region" region))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3611
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3612 (if valid
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3613 nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3614 ;; The condition case is in case any of the extents are dead or
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3615 ;; otherwise incapacitated.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3616 (condition-case ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3617 (if (listp zmacs-region-extent)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3618 (mapc 'delete-extent zmacs-region-extent)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3619 (delete-extent zmacs-region-extent))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3620 (error nil)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3621
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3622 (if valid
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3623 (set-extent-endpoints zmacs-region-extent start end)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3624 (setq zmacs-region-extent (make-extent start end buffer))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3625
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3626 ;; Make the extent be closed on the right, which means that if
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3627 ;; characters are inserted exactly at the end of the extent, the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3628 ;; extent will grow to cover them. This is important for shell
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3629 ;; buffers - suppose one makes a region, and one end is at point-max.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3630 ;; If the shell produces output, that marker will remain at point-max
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3631 ;; (its position will increase). So it's important that the extent
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3632 ;; exhibit the same behavior, lest the region covered by the extent
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3633 ;; (the visual indication), and the region between point and mark
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3634 ;; (the actual region value) become different!
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3635 (set-extent-property zmacs-region-extent 'end-open nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3636
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3637 ;; use same priority as mouse-highlighting so that conflicts between
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3638 ;; the region extent and a mouse-highlighted extent are resolved by
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3639 ;; the usual size-and-endpoint-comparison method.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3640 (set-extent-priority zmacs-region-extent mouse-highlight-priority)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3641 (set-extent-face zmacs-region-extent 'zmacs-region)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3642
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3643 ;; #### It might be better to actually break
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3644 ;; default-mouse-track-next-move-rect out of mouse.el so that we
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3645 ;; can use its logic here.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3646 (cond
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3647 (zmacs-region-rectangular-p
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3648 (setq zmacs-region-extent (list zmacs-region-extent))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3649 (default-mouse-track-next-move-rect start end zmacs-region-extent)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3650 ))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3651
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3652 zmacs-region-extent)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3653
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3654 (defun zmacs-region-buffer ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3655 "Return the buffer containing the zmacs region, or nil."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3656 ;; #### this is horrible and kludgy! This stuff needs to be rethought.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3657 (and zmacs-regions zmacs-region-active-p
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3658 (or (marker-buffer (mark-marker t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3659 (and (extent-live-p zmacs-region-extent)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3660 (buffer-live-p (extent-object zmacs-region-extent))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3661 (extent-object zmacs-region-extent)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3662
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3663 (defun zmacs-activate-region ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3664 "Make the region between `point' and `mark' be active (highlighted),
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3665 if `zmacs-regions' is true. Only a very small number of commands
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3666 should ever do this. Calling this function will call the hook
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3667 `zmacs-activate-region-hook', if the region was previously inactive.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3668 Calling this function ensures that the region stays active after the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3669 current command terminates, even if `zmacs-region-stays' is not set.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3670 Returns t if the region was activated (i.e. if `zmacs-regions' if t)."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3671 (if (not zmacs-regions)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3672 nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3673 (setq zmacs-region-active-p t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3674 zmacs-region-stays t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3675 zmacs-region-rectangular-p (and (boundp 'mouse-track-rectangle-p)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3676 mouse-track-rectangle-p))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3677 (if (marker-buffer (mark-marker t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3678 (zmacs-make-extent-for-region (cons (point-marker t) (mark-marker t))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3679 (run-hooks 'zmacs-activate-region-hook)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3680 t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3681
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3682 (defun zmacs-deactivate-region ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3683 "Make the region between `point' and `mark' no longer be active,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3684 if `zmacs-regions' is true. You shouldn't need to call this; the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3685 command loop calls it when appropriate. Calling this function will
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3686 call the hook `zmacs-deactivate-region-hook', if the region was
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3687 previously active. Returns t if the region had been active, nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3688 otherwise."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3689 (if (not zmacs-region-active-p)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3690 nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3691 (setq zmacs-region-active-p nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3692 zmacs-region-stays nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3693 zmacs-region-rectangular-p nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3694 (if zmacs-region-extent
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3695 (let ((inhibit-quit t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3696 (if (listp zmacs-region-extent)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3697 (mapc 'delete-extent zmacs-region-extent)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3698 (delete-extent zmacs-region-extent))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3699 (setq zmacs-region-extent nil)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3700 (run-hooks 'zmacs-deactivate-region-hook)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3701 t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3702
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3703 (defun zmacs-update-region ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3704 "Update the highlighted region between `point' and `mark'.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3705 You shouldn't need to call this; the command loop calls it
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3706 when appropriate. Calling this function will call the hook
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3707 `zmacs-update-region-hook', if the region is active."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3708 (when zmacs-region-active-p
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3709 (when (marker-buffer (mark-marker t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3710 (zmacs-make-extent-for-region (cons (point-marker t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3711 (mark-marker t))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3712 (run-hooks 'zmacs-update-region-hook)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3713
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3714 ;;;;;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3715 ;;;;;; echo area stuff
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3716 ;;;;;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3717
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3718 ;;; #### Should this be moved to a separate file, for clarity?
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3719 ;;; -hniksic
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3720
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3721 ;;; The `message-stack' is an alist of labels with messages; the first
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3722 ;;; message in this list is always in the echo area. A call to
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3723 ;;; `display-message' inserts a label/message pair at the head of the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3724 ;;; list, and removes any other pairs with that label. Calling
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3725 ;;; `clear-message' causes any pair with matching label to be removed,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3726 ;;; and this may cause the displayed message to change or vanish. If
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3727 ;;; the label arg is nil, the entire message stack is cleared.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3728 ;;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3729 ;;; Message/error filtering will be a little tricker to implement than
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3730 ;;; logging, since messages can be built up incrementally
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3731 ;;; using clear-message followed by repeated calls to append-message
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3732 ;;; (this happens with error messages). For messages which aren't
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3733 ;;; created this way, filtering could be implemented at display-message
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3734 ;;; very easily.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3735 ;;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3736 ;;; Bits of the logging code are borrowed from log-messages.el by
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3737 ;;; Robert Potter (rpotter@grip.cis.upenn.edu).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3738
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3739 ;; need this to terminate the currently-displayed message
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3740 ;; ("Loading simple ...")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3741 (when (and
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3742 (not (fboundp 'display-message))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3743 (not (featurep 'debug)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3744 (send-string-to-terminal "\n"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3745
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3746 (defvar message-stack nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3747 "An alist of label/string pairs representing active echo-area messages.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3748 The first element in the list is currently displayed in the echo area.
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
3749 Do not modify this directly--use the `message' or
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3750 `display-message'/`clear-message' functions.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3751
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3752 (defvar remove-message-hook 'log-message
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3753 "A function or list of functions to be called when a message is removed
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3754 from the echo area at the bottom of the frame. The label of the removed
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3755 message is passed as the first argument, and the text of the message
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3756 as the second argument.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3757
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3758 (defcustom log-message-max-size 50000
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3759 "Maximum size of the \" *Message-Log*\" buffer. See `log-message'."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3760 :type 'integer
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3761 :group 'log-message)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3762 (make-compatible-variable 'message-log-max 'log-message-max-size)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3763
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3764 ;; We used to reject quite a lot of stuff here, but it was a bad idea,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3765 ;; for two reasons:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3766 ;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3767 ;; a) In most circumstances, you *want* to see the message in the log.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3768 ;; The explicitly non-loggable messages should be marked as such by
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3769 ;; the issuer. Gratuitous non-displaying of random regexps made
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3770 ;; debugging harder, too (because various reasonable debugging
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3771 ;; messages would get eaten).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3772 ;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3773 ;; b) It slowed things down. Yes, visibly.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3774 ;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3775 ;; So, I left only a few of the really useless ones on this kill-list.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3776 ;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3777 ;; --hniksic
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3778 (defcustom log-message-ignore-regexps
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3779 '(;; Note: adding entries to this list slows down messaging
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3780 ;; significantly. Wherever possible, use message labels.
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3781
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3782 ;; Often-seen messages
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3783 "\\`\\'" ; empty message
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3784 "\\`\\(Beginning\\|End\\) of buffer\\'"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3785 ;;"^Quit$"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3786 ;; completions
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3787 ;; Many packages print this -- impossible to categorize
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3788 ;;"^Making completion list"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3789 ;; Gnus
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3790 ;; "^No news is no news$"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3791 ;; "^No more\\( unread\\)? newsgroups$"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3792 ;; "^Opening [^ ]+ server\\.\\.\\."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3793 ;; "^[^:]+: Reading incoming mail"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3794 ;; "^Getting mail from "
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3795 ;; "^\\(Generating Summary\\|Sorting threads\\|Making sparse threads\\|Scoring\\|Checking new news\\|Expiring articles\\|Sending\\)\\.\\.\\."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3796 ;; "^\\(Fetching headers for\\|Retrieving newsgroup\\|Reading active file\\)"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3797 ;; "^No more\\( unread\\)? articles"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3798 ;; "^Deleting article "
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3799 ;; W3
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3800 ;; "^Parsed [0-9]+ of [0-9]+ ([0-9]+%)"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3801 )
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3802 "List of regular expressions matching messages which shouldn't be logged.
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
3803 See `log-message'.
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3804
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3805 Ideally, packages which generate messages which might need to be ignored
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
3806 should label them with 'progress, 'prompt, or 'no-log, so they can be
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3807 filtered by the log-message-ignore-labels."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3808 :type '(repeat regexp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3809 :group 'log-message)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3810
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
3811 (defcustom log-message-ignore-labels
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3812 '(help-echo command progress prompt no-log garbage-collecting auto-saving)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3813 "List of symbols indicating labels of messages which shouldn't be logged.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3814 See `display-message' for some common labels. See also `log-message'."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3815 :type '(repeat (symbol :tag "Label"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3816 :group 'log-message)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3817
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3818 ;;Subsumed by view-lossage
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3819 ;; Not really, I'm adding it back by popular demand. -slb
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3820 (defun show-message-log ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3821 "Show the \" *Message-Log*\" buffer, which contains old messages and errors."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3822 (interactive)
215
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 209
diff changeset
3823 (pop-to-buffer (get-buffer-create " *Message-Log*")))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3824
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3825 (defvar log-message-filter-function 'log-message-filter
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
3826 "Value must be a function of two arguments: a symbol (label) and
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3827 a string (message). It should return non-nil to indicate a message
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3828 should be logged. Possible values include 'log-message-filter and
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3829 'log-message-filter-errors-only.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3830
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3831 (defun log-message-filter (label message)
235
85a06df23a9a Import from CVS: tag r20-5b16
cvs
parents: 223
diff changeset
3832 "Default value of `log-message-filter-function'.
85a06df23a9a Import from CVS: tag r20-5b16
cvs
parents: 223
diff changeset
3833 Messages whose text matches one of the `log-message-ignore-regexps'
85a06df23a9a Import from CVS: tag r20-5b16
cvs
parents: 223
diff changeset
3834 or whose label appears in `log-message-ignore-labels' are not saved."
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3835 (let ((r log-message-ignore-regexps)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3836 (ok (not (memq label log-message-ignore-labels))))
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
3837 (save-match-data
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
3838 (while (and r ok)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
3839 (when (string-match (car r) message)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3840 (setq ok nil))
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
3841 (setq r (cdr r))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3842 ok))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3843
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3844 (defun log-message-filter-errors-only (label message)
235
85a06df23a9a Import from CVS: tag r20-5b16
cvs
parents: 223
diff changeset
3845 "For use as the `log-message-filter-function'. Only logs error messages."
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3846 (eq label 'error))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3847
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3848 (defun log-message (label message)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3849 "Stuff a copy of the message into the \" *Message-Log*\" buffer,
235
85a06df23a9a Import from CVS: tag r20-5b16
cvs
parents: 223
diff changeset
3850 if it satisfies the `log-message-filter-function'.
85a06df23a9a Import from CVS: tag r20-5b16
cvs
parents: 223
diff changeset
3851
85a06df23a9a Import from CVS: tag r20-5b16
cvs
parents: 223
diff changeset
3852 For use on `remove-message-hook'."
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
3853 (when (and (not noninteractive)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
3854 (funcall log-message-filter-function label message))
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
3855 ;; Use save-excursion rather than save-current-buffer because we
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
3856 ;; change the value of point.
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
3857 (save-excursion
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
3858 (set-buffer (get-buffer-create " *Message-Log*"))
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
3859 (goto-char (point-max))
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
3860 ;(insert (concat (upcase (symbol-name label)) ": " message "\n"))
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
3861 (let (extent)
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
3862 ;; Mark multiline message with an extent, which `view-lossage'
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
3863 ;; will recognize.
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
3864 (when (string-match "\n" message)
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
3865 (setq extent (make-extent (point) (point)))
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
3866 (set-extent-properties extent '(end-open nil message-multiline t)))
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
3867 (insert message "\n")
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
3868 (when extent
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
3869 (set-extent-property extent 'end-open t)))
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
3870 (when (> (point-max) (max log-message-max-size (point-min)))
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
3871 ;; Trim log to ~90% of max size.
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
3872 (goto-char (max (- (point-max)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
3873 (truncate (* 0.9 log-message-max-size)))
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
3874 (point-min)))
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
3875 (forward-line 1)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
3876 (delete-region (point-min) (point))))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3877
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3878 (defun message-displayed-p (&optional return-string frame)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3879 "Return a non-nil value if a message is presently displayed in the\n\
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3880 minibuffer's echo area. If optional argument RETURN-STRING is non-nil,\n\
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3881 return a string containing the message, otherwise just return t."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3882 ;; by definition, a message is displayed if the echo area buffer is
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3883 ;; non-empty (see also echo_area_active()). It had better also
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3884 ;; be the case that message-stack is nil exactly when the echo area
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3885 ;; is non-empty.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3886 (let ((buffer (get-buffer " *Echo Area*")))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3887 (and (< (point-min buffer) (point-max buffer))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3888 (if return-string
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3889 (buffer-substring nil nil buffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3890 t))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3891
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3892 ;;; Returns the string which remains in the echo area, or nil if none.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3893 ;;; If label is nil, the whole message stack is cleared.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3894 (defun clear-message (&optional label frame stdout-p no-restore)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3895 "Remove any message with the given LABEL from the message-stack,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3896 erasing it from the echo area if it's currently displayed there.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3897 If a message remains at the head of the message-stack and NO-RESTORE
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3898 is nil, it will be displayed. The string which remains in the echo
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3899 area will be returned, or nil if the message-stack is now empty.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3900 If LABEL is nil, the entire message-stack is cleared.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3901
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3902 Unless you need the return value or you need to specify a label,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3903 you should just use (message nil)."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3904 (or frame (setq frame (selected-frame)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3905 (let ((clear-stream (and message-stack (eq 'stream (frame-type frame)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3906 (remove-message label frame)
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
3907 (let ((inhibit-read-only t)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3908 (zmacs-region-stays zmacs-region-stays)) ; preserve from change
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
3909 (erase-buffer " *Echo Area*"))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3910 (if clear-stream
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3911 (send-string-to-terminal ?\n stdout-p))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3912 (if no-restore
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3913 nil ; just preparing to put another msg up
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3914 (if message-stack
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
3915 (let ((oldmsg (cdr (car message-stack))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3916 (raw-append-message oldmsg frame stdout-p)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3917 oldmsg)
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
3918 ;; #### Should we (redisplay-echo-area) here? Messes some
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
3919 ;; things up.
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3920 nil))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3921
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3922 (defun remove-message (&optional label frame)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3923 ;; If label is nil, we want to remove all matching messages.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3924 ;; Must reverse the stack first to log them in the right order.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3925 (let ((log nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3926 (while (and message-stack
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3927 (or (null label) ; null label means clear whole stack
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3928 (eq label (car (car message-stack)))))
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
3929 (push (car message-stack) log)
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
3930 (setq message-stack (cdr message-stack)))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3931 (let ((s message-stack))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3932 (while (cdr s)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3933 (let ((msg (car (cdr s))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3934 (if (eq label (car msg))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3935 (progn
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
3936 (push msg log)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3937 (setcdr s (cdr (cdr s))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3938 (setq s (cdr s))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3939 ;; (possibly) log each removed message
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3940 (while log
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3941 (condition-case e
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3942 (run-hook-with-args 'remove-message-hook
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3943 (car (car log)) (cdr (car log)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3944 (error (setq remove-message-hook nil)
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
3945 (lwarn 'message-log 'warning
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
3946 "Error caught in `remove-message-hook': %s"
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
3947 (error-message-string e))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3948 (let ((inhibit-read-only t))
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
3949 (erase-buffer " *Echo Area*"))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3950 (signal (car e) (cdr e))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3951 (setq log (cdr log)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3952
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3953 (defun append-message (label message &optional frame stdout-p)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3954 (or frame (setq frame (selected-frame)))
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
3955 ;; Add a new entry to the message-stack, or modify an existing one
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3956 (let ((top (car message-stack)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3957 (if (eq label (car top))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3958 (setcdr top (concat (cdr top) message))
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
3959 (push (cons label message) message-stack)))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3960 (raw-append-message message frame stdout-p))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3961
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
3962 ;; Really append the message to the echo area. no fiddling with
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
3963 ;; message-stack.
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3964 (defun raw-append-message (message &optional frame stdout-p)
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
3965 (unless (equal message "")
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
3966 (let ((inhibit-read-only t)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3967 (zmacs-region-stays zmacs-region-stays)) ; preserve from change
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
3968 (insert-string message " *Echo Area*")
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3969 ;; Conditionalizing on the device type in this way is not that clean,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3970 ;; but neither is having a device method, as I originally implemented
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3971 ;; it: all non-stream devices behave in the same way. Perhaps
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3972 ;; the cleanest way is to make the concept of a "redisplayable"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3973 ;; device, which stream devices are not. Look into this more if
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3974 ;; we ever create another non-redisplayable device type (e.g.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3975 ;; processes? printers?).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3976
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3977 ;; Don't redisplay the echo area if we are executing a macro.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3978 (if (not executing-kbd-macro)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3979 (if (eq 'stream (frame-type frame))
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
3980 (send-string-to-terminal message stdout-p (frame-device frame))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3981 (redisplay-echo-area))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3982
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3983 (defun display-message (label message &optional frame stdout-p)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3984 "Print a one-line message at the bottom of the frame. First argument
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3985 LABEL is an identifier for this message. MESSAGE is the string to display.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3986 Use `clear-message' to remove a labelled message.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3987
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3988 Here are some standard labels (those marked with `*' are not logged
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3989 by default--see the `log-message-ignore-labels' variable):
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3990 message default label used by the `message' function
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3991 error default label used for reporting errors
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3992 * progress progress indicators like \"Converting... 45%\"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3993 * prompt prompt-like messages like \"I-search: foo\"
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 219
diff changeset
3994 * command helper command messages like \"Mark set\"
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3995 * no-log messages that should never be logged"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3996 (clear-message label frame stdout-p t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3997 (append-message label message frame stdout-p))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3998
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3999 (defun current-message (&optional frame)
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
4000 "Return the current message in the echo area, or nil.
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4001 The FRAME argument is currently unused."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4002 (cdr (car message-stack)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4003
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4004 ;;; may eventually be frame-dependent
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4005 (defun current-message-label (&optional frame)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4006 (car (car message-stack)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4007
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4008 (defun message (fmt &rest args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4009 "Print a one-line message at the bottom of the frame.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4010 The arguments are the same as to `format'.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4011
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4012 If the only argument is nil, clear any existing message; let the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4013 minibuffer contents show."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4014 ;; questionable junk in the C code
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4015 ;; (if (framep default-minibuffer-frame)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4016 ;; (make-frame-visible default-minibuffer-frame))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4017 (if (and (null fmt) (null args))
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
4018 (prog1 nil
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
4019 (clear-message nil))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4020 (let ((str (apply 'format fmt args)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4021 (display-message 'message str)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4022 str)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4023
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
4024 (defun lmessage (label fmt &rest args)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
4025 "Print a one-line message at the bottom of the frame.
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
4026 First argument LABEL is an identifier for this message. The rest of the
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
4027 arguments are the same as to `format'.
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
4028
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
4029 See `display-message' for a list of standard labels."
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
4030 (if (and (null fmt) (null args))
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
4031 (prog1 nil
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
4032 (clear-message label nil))
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
4033 (let ((str (apply 'format fmt args)))
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
4034 (display-message label str)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
4035 str)))
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
4036
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
4037
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4038 ;;;;;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4039 ;;;;;; warning stuff
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4040 ;;;;;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4041
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4042 (defcustom log-warning-minimum-level 'info
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4043 "Minimum level of warnings that should be logged.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4044 The warnings in levels below this are completely ignored, as if they never
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4045 happened.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4046
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4047 The recognized warning levels, in decreasing order of priority, are
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4048 'emergency, 'alert, 'critical, 'error, 'warning, 'notice, 'info, and
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4049 'debug.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4050
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4051 See also `display-warning-minimum-level'.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4052
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4053 You can also control which warnings are displayed on a class-by-class
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4054 basis. See `display-warning-suppressed-classes' and
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4055 `log-warning-suppressed-classes'."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4056 :type '(choice (const emergency) (const alert) (const critical)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4057 (const error) (const warning) (const notice)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4058 (const info) (const debug))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4059 :group 'warnings)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4060
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4061 (defcustom display-warning-minimum-level 'info
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4062 "Minimum level of warnings that should be displayed.
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
4063 The warnings in levels below this will be generated, but not
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 278
diff changeset
4064 displayed.
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4065
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4066 The recognized warning levels, in decreasing order of priority, are
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4067 'emergency, 'alert, 'critical, 'error, 'warning, 'notice, 'info, and
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4068 'debug.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4069
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4070 See also `log-warning-minimum-level'.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4071
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4072 You can also control which warnings are displayed on a class-by-class
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4073 basis. See `display-warning-suppressed-classes' and
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4074 `log-warning-suppressed-classes'."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4075 :type '(choice (const emergency) (const alert) (const critical)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4076 (const error) (const warning) (const notice)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4077 (const info) (const debug))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4078 :group 'warnings)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4079
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4080 (defvar log-warning-suppressed-classes nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4081 "List of classes of warnings that shouldn't be logged or displayed.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4082 If any of the CLASS symbols associated with a warning is the same as
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4083 any of the symbols listed here, the warning will be completely ignored,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4084 as it they never happened.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4085
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4086 NOTE: In most circumstances, you should *not* set this variable.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4087 Set `display-warning-suppressed-classes' instead. That way the suppressed
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4088 warnings are not displayed but are still unobtrusively logged.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4089
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4090 See also `log-warning-minimum-level' and `display-warning-minimum-level'.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4091
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4092 (defcustom display-warning-suppressed-classes nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4093 "List of classes of warnings that shouldn't be displayed.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4094 If any of the CLASS symbols associated with a warning is the same as
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4095 any of the symbols listed here, the warning will not be displayed.
371
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
4096 The warning will still logged in the *Warnings* buffer (unless also
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4097 contained in `log-warning-suppressed-classes'), but the buffer will
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4098 not be automatically popped up.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4099
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4100 See also `log-warning-minimum-level' and `display-warning-minimum-level'."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4101 :type '(repeat symbol)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4102 :group 'warnings)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4103
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4104 (defvar warning-count 0
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4105 "Count of the number of warning messages displayed so far.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4106
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4107 (defconst warning-level-alist '((emergency . 8)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4108 (alert . 7)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4109 (critical . 6)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4110 (error . 5)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4111 (warning . 4)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4112 (notice . 3)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4113 (info . 2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4114 (debug . 1)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4115
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4116 (defun warning-level-p (level)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4117 "Non-nil if LEVEL specifies a warning level."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4118 (and (symbolp level) (assq level warning-level-alist)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4119
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4120 ;; If you're interested in rewriting this function, be aware that it
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4121 ;; could be called at arbitrary points in a Lisp program (when a
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4122 ;; built-in function wants to issue a warning, it will call out to
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4123 ;; this function the next time some Lisp code is evaluated). Therefore,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4124 ;; this function *must* not permanently modify any global variables
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4125 ;; (e.g. the current buffer) except those that specifically apply
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4126 ;; to the warning system.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4127
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4128 (defvar before-init-deferred-warnings nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4129
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4130 (defun after-init-display-warnings ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4131 "Display warnings deferred till after the init file is run.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4132 Warnings that occur before then are deferred so that warning
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4133 suppression in the .emacs file will be honored."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4134 (while before-init-deferred-warnings
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4135 (apply 'display-warning (car before-init-deferred-warnings))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4136 (setq before-init-deferred-warnings
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4137 (cdr before-init-deferred-warnings))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4138
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 286
diff changeset
4139 (add-hook 'after-init-hook 'after-init-display-warnings)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4140
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4141 (defun display-warning (class message &optional level)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4142 "Display a warning message.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4143 CLASS should be a symbol describing what sort of warning this is, such
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4144 as `resource' or `key-mapping'. A list of such symbols is also
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4145 accepted. (Individual classes can be suppressed; see
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
4146 `display-warning-suppressed-classes'.) Optional argument LEVEL can
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4147 be used to specify a priority for the warning, other than default priority
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4148 `warning'. (See `display-warning-minimum-level'). The message is
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4149 inserted into the *Warnings* buffer, which is made visible at appropriate
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4150 times."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4151 (or level (setq level 'warning))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4152 (or (listp class) (setq class (list class)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4153 (check-argument-type 'warning-level-p level)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4154 (if (and (not (featurep 'infodock))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4155 (not init-file-loaded))
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 272
diff changeset
4156 (push (list class message level) before-init-deferred-warnings)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4157 (catch 'ignored
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4158 (let ((display-p t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4159 (level-num (cdr (assq level warning-level-alist))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4160 (if (< level-num (cdr (assq log-warning-minimum-level
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4161 warning-level-alist)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4162 (throw 'ignored nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4163 (if (intersection class log-warning-suppressed-classes)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4164 (throw 'ignored nil))
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
4165
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4166 (if (< level-num (cdr (assq display-warning-minimum-level
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4167 warning-level-alist)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4168 (setq display-p nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4169 (if (and display-p
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4170 (intersection class display-warning-suppressed-classes))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4171 (setq display-p nil))
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
4172 (let ((buffer (get-buffer-create "*Warnings*")))
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
4173 (when display-p
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
4174 ;; The C code looks at display-warning-tick to determine
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
4175 ;; when it should call `display-warning-buffer'. Change it
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
4176 ;; to get the C code's attention.
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
4177 (incf display-warning-tick))
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
4178 (with-current-buffer buffer
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4179 (goto-char (point-max))
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
4180 (incf warning-count)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4181 (princ (format "(%d) (%s/%s) "
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4182 warning-count
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4183 (mapconcat 'symbol-name class ",")
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
4184 level)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
4185 buffer)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4186 (princ message buffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4187 (terpri buffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4188 (terpri buffer)))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4189
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4190 (defun warn (&rest args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4191 "Display a warning message.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4192 The message is constructed by passing all args to `format'. The message
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4193 is placed in the *Warnings* buffer, which will be popped up at the next
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4194 redisplay. The class of the warning is `warning'. See also
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4195 `display-warning'."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4196 (display-warning 'warning (apply 'format args)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4197
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
4198 (defun lwarn (class level &rest args)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
4199 "Display a labeled warning message.
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
4200 CLASS should be a symbol describing what sort of warning this is, such
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
4201 as `resource' or `key-mapping'. A list of such symbols is also
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
4202 accepted. (Individual classes can be suppressed; see
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
4203 `display-warning-suppressed-classes'.) If non-nil, LEVEL can be used
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
4204 to specify a priority for the warning, other than default priority
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
4205 `warning'. (See `display-warning-minimum-level'). The message is
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
4206 inserted into the *Warnings* buffer, which is made visible at appropriate
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
4207 times.
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
4208
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
4209 The rest of the arguments are passed to `format'."
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
4210 (display-warning class (apply 'format args)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
4211 (or level 'warning)))
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 215
diff changeset
4212
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4213 (defvar warning-marker nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4214
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4215 ;; When this function is called by the C code, all non-local exits are
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4216 ;; trapped and C-g is inhibited; therefore, it would be a very, very
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4217 ;; bad idea for this function to get into an infinite loop.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4218
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4219 (defun display-warning-buffer ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4220 "Make the buffer that contains the warnings be visible.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4221 The C code calls this periodically, right before redisplay."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4222 (let ((buffer (get-buffer-create "*Warnings*")))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4223 (when (or (not warning-marker)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4224 (not (eq (marker-buffer warning-marker) buffer)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4225 (setq warning-marker (make-marker))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4226 (set-marker warning-marker 1 buffer))
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents: 253
diff changeset
4227 (if temp-buffer-show-function
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents: 253
diff changeset
4228 (let ((show-buffer (get-buffer-create "*Warnings-Show*")))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents: 253
diff changeset
4229 (save-excursion
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents: 253
diff changeset
4230 (set-buffer show-buffer)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents: 253
diff changeset
4231 (setq buffer-read-only nil)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents: 253
diff changeset
4232 (erase-buffer))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents: 253
diff changeset
4233 (save-excursion
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents: 253
diff changeset
4234 (set-buffer buffer)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents: 253
diff changeset
4235 (copy-to-buffer show-buffer
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents: 253
diff changeset
4236 (marker-position warning-marker)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents: 253
diff changeset
4237 (point-max)))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents: 253
diff changeset
4238 (funcall temp-buffer-show-function show-buffer))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents: 253
diff changeset
4239 (set-window-start (display-buffer buffer) warning-marker))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4240 (set-marker warning-marker (point-max buffer) buffer)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4241
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4242 (defun emacs-name ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4243 "Return the printable name of this instance of Emacs."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4244 (cond ((featurep 'infodock) "InfoDock")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4245 ((featurep 'xemacs) "XEmacs")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4246 (t "Emacs")))
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
4247
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4248 ;;; simple.el ends here