annotate lisp/simple.el @ 440:8de8e3f6228a r21-2-28

Import from CVS: tag r21-2-28
author cvs
date Mon, 13 Aug 2007 11:33:38 +0200
parents 3ecd8885ac67
children abe6d1db359e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 ;;; simple.el --- basic editing commands for XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3 ;; Copyright (C) 1985-7, 1993-5, 1997 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4 ;; Copyright (C) 1995 Tinker Systems and INS Engineering Corp.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 ;; Maintainer: XEmacs Development Team
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 ;; Keywords: lisp, extensions, internal, dumped
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 ;; This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 ;; XEmacs is free software; you can redistribute it and/or modify it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 ;; under the terms of the GNU General Public License as published by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 ;; any later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 ;; XEmacs is distributed in the hope that it will be useful, but
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 ;; General Public License for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 ;; along with XEmacs; see the file COPYING. If not, write to the Free
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 ;; 02111-1307, USA.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 ;;; Synched up with: FSF 19.34 [But not very closely].
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 ;;; Commentary:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 ;; This file is dumped with XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 ;; A grab-bag of basic XEmacs commands not specifically related to some
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 ;; major mode or to file-handling.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 ;; Changes for zmacs-style active-regions:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 ;; beginning-of-buffer, end-of-buffer, count-lines-region,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 ;; count-lines-buffer, what-line, what-cursor-position, set-goal-column,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 ;; set-fill-column, prefix-arg-internal, and line-move (which is used by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 ;; next-line and previous-line) set zmacs-region-stays to t, so that they
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 ;; don't affect the current region-hilighting state.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 ;; mark-whole-buffer, mark-word, exchange-point-and-mark, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 ;; set-mark-command (without an argument) call zmacs-activate-region.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 ;; mark takes an optional arg like the new Fmark_marker() does. When
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 ;; the region is not active, mark returns nil unless the optional arg is true.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 ;; push-mark, pop-mark, exchange-point-and-mark, and set-marker, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 ;; set-mark-command use (mark t) so that they can access the mark whether
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 ;; the region is active or not.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 ;; shell-command, shell-command-on-region, yank, and yank-pop (which all
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 ;; push a mark) have been altered to call exchange-point-and-mark with an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 ;; argument, meaning "don't activate the region". These commands only use
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 ;; exchange-point-and-mark to position the newly-pushed mark correctly, so
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 ;; this isn't a user-visible change. These functions have also been altered
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 ;; to use (mark t) for the same reason.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 ;; 97/3/14 Jareth Hein (jhod@po.iijnet.or.jp) added kinsoku processing (support
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 ;; for filling of Asian text) into the fill code. This was ripped bleeding from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 ;; Mule-2.3, and could probably use some feature additions (like additional wrap
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 ;; styles, etc)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 ;; 97/06/11 Steve Baur (steve@xemacs.org) Convert use of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 ;; (preceding|following)-char to char-(after|before).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 ;;; Code:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 (defgroup editing-basics nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 "Most basic editing variables."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 :group 'editing)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 (defgroup killing nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 "Killing and yanking commands."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 :group 'editing)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 (defgroup fill-comments nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 "Indenting and filling of comments."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 :prefix "comment-"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 :group 'fill)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 (defgroup paren-matching nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 "Highlight (un)matching of parens and expressions."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 :prefix "paren-"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 :group 'matching)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 (defgroup log-message nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 "Messages logging and display customizations."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 :group 'minibuffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 (defgroup warnings nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 "Warnings customizations."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 :group 'minibuffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 (defcustom search-caps-disable-folding t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 "*If non-nil, upper case chars disable case fold searching.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 This does not apply to \"yanked\" strings."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 :group 'editing-basics)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 ;; This is stolen (and slightly modified) from FSF emacs's
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 ;; `isearch-no-upper-case-p'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 (defun no-upper-case-p (string &optional regexp-flag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 "Return t if there are no upper case chars in STRING.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 If REGEXP-FLAG is non-nil, disregard letters preceded by `\\' (but not `\\\\')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 since they have special meaning in a regexp."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 (let ((case-fold-search nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 (not (string-match (if regexp-flag
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 "\\(^\\|\\\\\\\\\\|[^\\]\\)[A-Z]"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 "[A-Z]")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 string))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 (defmacro with-search-caps-disable-folding (string regexp-flag &rest body) "\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 Eval BODY with `case-fold-search' let to nil if `search-caps-disable-folding'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 is non-nil, and if STRING (either a string or a regular expression according
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 to REGEXP-FLAG) contains uppercase letters."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 `(let ((case-fold-search
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 (if (and case-fold-search search-caps-disable-folding)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 (no-upper-case-p ,string ,regexp-flag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 case-fold-search)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 ,@body))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 (put 'with-search-caps-disable-folding 'lisp-indent-function 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 (put 'with-search-caps-disable-folding 'edebug-form-spec
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 '(sexp sexp &rest form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 (defmacro with-interactive-search-caps-disable-folding (string regexp-flag
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 &rest body)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 "Same as `with-search-caps-disable-folding', but only in the case of a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 function called interactively."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 `(let ((case-fold-search
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 (if (and (interactive-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 case-fold-search search-caps-disable-folding)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 (no-upper-case-p ,string ,regexp-flag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 case-fold-search)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 ,@body))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 (put 'with-interactive-search-caps-disable-folding 'lisp-indent-function 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 (put 'with-interactive-search-caps-disable-folding 'edebug-form-spec
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 '(sexp sexp &rest form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 (defun newline (&optional arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 "Insert a newline, and move to left margin of the new line if it's blank.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 The newline is marked with the text-property `hard'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 With arg, insert that many newlines.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 In Auto Fill mode, if no numeric arg, break the preceding line if it's long."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 (interactive "*P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 (barf-if-buffer-read-only nil (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 ;; Inserting a newline at the end of a line produces better redisplay in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 ;; try_window_id than inserting at the beginning of a line, and the textual
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 ;; result is the same. So, if we're at beginning of line, pretend to be at
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 ;; the end of the previous line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 ;; #### Does this have any relevance in XEmacs?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 (let ((flag (and (not (bobp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 (bolp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 ;; Make sure the newline before point isn't intangible.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 (not (get-char-property (1- (point)) 'intangible))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 ;; Make sure the newline before point isn't read-only.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 (not (get-char-property (1- (point)) 'read-only))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 ;; Make sure the newline before point isn't invisible.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 (not (get-char-property (1- (point)) 'invisible))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 ;; This should probably also test for the previous char
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 ;; being the *last* character too.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 (not (get-char-property (1- (point)) 'end-open))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 ;; Make sure the newline before point has the same
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 ;; properties as the char before it (if any).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 (< (or (previous-extent-change (point)) -2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 (- (point) 2))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 (was-page-start (and (bolp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 (looking-at page-delimiter)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 (beforepos (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 (if flag (backward-char 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 ;; Call self-insert so that auto-fill, abbrev expansion etc. happens.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 ;; Set last-command-char to tell self-insert what to insert.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 (let ((last-command-char ?\n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 ;; Don't auto-fill if we have a numeric argument.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 ;; Also not if flag is true (it would fill wrong line);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 ;; there is no need to since we're at BOL.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 (auto-fill-function (if (or arg flag) nil auto-fill-function)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 (unwind-protect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 (self-insert-command (prefix-numeric-value arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 ;; If we get an error in self-insert-command, put point at right place.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 (if flag (forward-char 1))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 ;; If we did *not* get an error, cancel that forward-char.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 (if flag (backward-char 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 ;; Mark the newline(s) `hard'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 (if use-hard-newlines
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 (let* ((from (- (point) (if arg (prefix-numeric-value arg) 1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 (sticky (get-text-property from 'end-open))) ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 (put-text-property from (point) 'hard 't)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 ;; If end-open is not "t", add 'hard to end-open list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 (if (and (listp sticky) (not (memq 'hard sticky)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 (put-text-property from (point) 'end-open ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 (cons 'hard sticky)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 ;; If the newline leaves the previous line blank,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 ;; and we have a left margin, delete that from the blank line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 (or flag
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 (goto-char beforepos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 (and (looking-at "[ \t]$")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 (> (current-left-margin) 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 (delete-region (point) (progn (end-of-line) (point))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 (if flag (forward-char 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 ;; Indent the line after the newline, except in one case:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 ;; when we added the newline at the beginning of a line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 ;; which starts a page.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 (or was-page-start
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 (move-to-left-margin nil t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 (defun set-hard-newline-properties (from to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 (let ((sticky (get-text-property from 'rear-nonsticky)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 (put-text-property from to 'hard 't)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 ;; If rear-nonsticky is not "t", add 'hard to rear-nonsticky list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 (if (and (listp sticky) (not (memq 'hard sticky)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 (put-text-property from (point) 'rear-nonsticky
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 (cons 'hard sticky)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 (defun open-line (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 "Insert a newline and leave point before it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 If there is a fill prefix and/or a left-margin, insert them on the new line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 if the line would have been blank.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 With arg N, insert N newlines."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 (interactive "*p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 (let* ((do-fill-prefix (and fill-prefix (bolp)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 (do-left-margin (and (bolp) (> (current-left-margin) 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 (loc (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 (newline arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 (goto-char loc)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 (while (> arg 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 (cond ((bolp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 (if do-left-margin (indent-to (current-left-margin)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 (if do-fill-prefix (insert fill-prefix))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 (forward-line 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 (setq arg (1- arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 (goto-char loc)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 (end-of-line)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 (defun split-line ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 "Split current line, moving portion beyond point vertically down."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 (interactive "*")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 (skip-chars-forward " \t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 (let ((col (current-column))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 (pos (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 (newline 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 (indent-to col 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 (goto-char pos)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 (defun quoted-insert (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 "Read next input character and insert it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 This is useful for inserting control characters.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 You may also type up to 3 octal digits, to insert a character with that code.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 In overwrite mode, this function inserts the character anyway, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 does not handle octal digits specially. This means that if you use
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 overwrite as your normal editing mode, you can use this function to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 insert characters when necessary.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 In binary overwrite mode, this function does overwrite, and octal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 digits are interpreted as a character code. This is supposed to make
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 this function useful in editing binary files."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 (interactive "*p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 (let ((char (if (or (not overwrite-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 (eq overwrite-mode 'overwrite-mode-binary))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 (read-quoted-char)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 ;; read-char obeys C-g, so we should protect. FSF
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 ;; doesn't have the protection here, but it's a bug in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 ;; FSF.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 (let ((inhibit-quit t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 (read-char)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 (if (> arg 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 (if (eq overwrite-mode 'overwrite-mode-binary)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 (delete-char arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 (while (> arg 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 (insert char)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 (setq arg (1- arg)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 (defun delete-indentation (&optional arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 "Join this line to previous and fix up whitespace at join.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 If there is a fill prefix, delete it from the beginning of this line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 With argument, join this line to following line."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 (interactive "*P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 (if arg (forward-line 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 (if (eq (char-before (point)) ?\n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 (delete-region (point) (1- (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 ;; If the second line started with the fill prefix,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 ;; delete the prefix.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 (if (and fill-prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 (<= (+ (point) (length fill-prefix)) (point-max))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 (string= fill-prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 (buffer-substring (point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 (+ (point) (length fill-prefix)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 (delete-region (point) (+ (point) (length fill-prefix))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 (fixup-whitespace))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 (defun fixup-whitespace ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 "Fixup white space between objects around point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 Leave one space or none, according to the context."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 (interactive "*")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 (delete-horizontal-space)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 (if (or (looking-at "^\\|\\s)")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 (save-excursion (forward-char -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 (looking-at "$\\|\\s(\\|\\s'")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 (insert ?\ ))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 (defun delete-horizontal-space ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 "Delete all spaces and tabs around point."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 (interactive "*")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 (skip-chars-backward " \t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 (delete-region (point) (progn (skip-chars-forward " \t") (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 (defun just-one-space ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 "Delete all spaces and tabs around point, leaving one space."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 (interactive "*")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 (if abbrev-mode ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 (expand-abbrev))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 (skip-chars-backward " \t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 (if (eq (char-after (point)) ? ) ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 (forward-char 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 (insert ? ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 (delete-region (point) (progn (skip-chars-forward " \t") (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 (defun delete-blank-lines ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 "On blank line, delete all surrounding blank lines, leaving just one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 On isolated blank line, delete that one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 On nonblank line, delete any immediately following blank lines."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 (interactive "*")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 (let (thisblank singleblank)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 (setq thisblank (looking-at "[ \t]*$"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 ;; Set singleblank if there is just one blank line here.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 (setq singleblank
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 (and thisblank
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 (not (looking-at "[ \t]*\n[ \t]*$"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 (or (bobp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 (progn (forward-line -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 (not (looking-at "[ \t]*$")))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 ;; Delete preceding blank lines, and this one too if it's the only one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 (if thisblank
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 (if singleblank (forward-line 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 (delete-region (point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 (if (re-search-backward "[^ \t\n]" nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 (progn (forward-line 1) (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 (point-min)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 ;; Delete following blank lines, unless the current line is blank
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 ;; and there are no following blank lines.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 (if (not (and thisblank singleblank))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 (end-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 (forward-line 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 (delete-region (point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 (if (re-search-forward "[^ \t\n]" nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 (progn (beginning-of-line) (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 (point-max)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 ;; Handle the special case where point is followed by newline and eob.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 ;; Delete the line, leaving point at eob.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 (if (looking-at "^[ \t]*\n\\'")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 (delete-region (point) (point-max)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 (defun back-to-indentation ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 "Move point to the first non-whitespace character on this line."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 ;; XEmacs change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 (interactive "_")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 (beginning-of-line 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 (skip-chars-forward " \t"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 (defun newline-and-indent ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 "Insert a newline, then indent according to major mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378 Indentation is done using the value of `indent-line-function'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 In programming language modes, this is the same as TAB.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 In some text modes, where TAB inserts a tab, this command indents to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 column specified by the function `current-left-margin'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 (interactive "*")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 (delete-region (point) (progn (skip-chars-backward " \t") (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 (newline)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 (indent-according-to-mode))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 (defun reindent-then-newline-and-indent ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 "Reindent current line, insert newline, then indent the new line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 Indentation of both lines is done according to the current major mode,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 which means calling the current value of `indent-line-function'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 In programming language modes, this is the same as TAB.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 In some text modes, where TAB inserts a tab, this indents to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 column specified by the function `current-left-margin'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 (interactive "*")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 (delete-region (point) (progn (skip-chars-backward " \t") (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 (indent-according-to-mode))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 (newline)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399 (indent-according-to-mode))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 ;; Internal subroutine of delete-char
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 (defun kill-forward-chars (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 (if (listp arg) (setq arg (car arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 (if (eq arg '-) (setq arg -1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 (kill-region (point) (+ (point) arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 ;; Internal subroutine of backward-delete-char
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 (defun kill-backward-chars (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 (if (listp arg) (setq arg (car arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 (if (eq arg '-) (setq arg -1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 (kill-region (point) (- (point) arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 (defun backward-delete-char-untabify (arg &optional killp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 "Delete characters backward, changing tabs into spaces.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 Delete ARG chars, and kill (save in kill ring) if KILLP is non-nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 Interactively, ARG is the prefix arg (default 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 and KILLP is t if a prefix arg was specified."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 (interactive "*p\nP")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 (let ((count arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 (while (and (> count 0) (not (bobp)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 (if (eq (char-before (point)) ?\t) ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 (let ((col (current-column)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 (forward-char -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 (setq col (- col (current-column)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 (insert-char ?\ col)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 (delete-char 1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 (forward-char -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 (setq count (1- count)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 (delete-backward-char arg killp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 ;; XEmacs: In overwrite mode, back over columns while clearing them out,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 ;; unless at end of line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 (and overwrite-mode (not (eolp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 (save-excursion (insert-char ?\ arg))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 (defcustom delete-key-deletes-forward t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 "*If non-nil, the DEL key will erase one character forwards.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 If nil, the DEL key will erase one character backwards."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 :group 'editing-basics)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 (defcustom backward-delete-function 'backward-delete-char
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 "*Function called to delete backwards on a delete keypress.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 If `delete-key-deletes-forward' is nil, `backward-or-forward-delete-char'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 calls this function to erase one character backwards. Default value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 is 'backward-delete-char, with 'backward-delete-char-untabify being a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 popular alternate setting."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448 :type 'function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449 :group 'editing-basics)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 ;; Trash me, baby.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 (defsubst delete-forward-p ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453 (and delete-key-deletes-forward
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 (or (not (eq (device-type) 'x))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 (x-keysym-on-keyboard-sans-modifiers-p 'backspace))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 (defun backward-or-forward-delete-char (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 "Delete either one character backwards or one character forwards.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 Controlled by the state of `delete-key-deletes-forward' and whether the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 BackSpace keysym even exists on your keyboard. If you don't have a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 BackSpace keysym, the delete key should always delete one character
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 backwards."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 (interactive "*p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 (if (delete-forward-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 (delete-char arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 (funcall backward-delete-function arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 (defun backward-or-forward-kill-word (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 "Delete either one word backwards or one word forwards.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 Controlled by the state of `delete-key-deletes-forward' and whether the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 BackSpace keysym even exists on your keyboard. If you don't have a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 BackSpace keysym, the delete key should always delete one character
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 backwards."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 (interactive "*p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 (if (delete-forward-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 (kill-word arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 (backward-kill-word arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 (defun backward-or-forward-kill-sentence (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 "Delete either one sentence backwards or one sentence forwards.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 Controlled by the state of `delete-key-deletes-forward' and whether the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 BackSpace keysym even exists on your keyboard. If you don't have a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 BackSpace keysym, the delete key should always delete one character
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 backwards."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 (interactive "*P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 (if (delete-forward-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 (kill-sentence arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488 (backward-kill-sentence (prefix-numeric-value arg))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 (defun backward-or-forward-kill-sexp (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 "Delete either one sexpr backwards or one sexpr forwards.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 Controlled by the state of `delete-key-deletes-forward' and whether the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 BackSpace keysym even exists on your keyboard. If you don't have a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 BackSpace keysym, the delete key should always delete one character
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 backwards."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 (interactive "*p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497 (if (delete-forward-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 (kill-sexp arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 (backward-kill-sexp arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 (defun zap-to-char (arg char)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 "Kill up to and including ARG'th occurrence of CHAR.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503 Goes backward if ARG is negative; error if CHAR not found."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504 (interactive "*p\ncZap to char: ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505 (kill-region (point) (with-interactive-search-caps-disable-folding
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 (char-to-string char) nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507 (search-forward (char-to-string char) nil nil arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 (defun zap-up-to-char (arg char)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 "Kill up to ARG'th occurrence of CHAR.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 Goes backward if ARG is negative; error if CHAR not found."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 (interactive "*p\ncZap up to char: ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 (kill-region (point) (with-interactive-search-caps-disable-folding
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515 (char-to-string char) nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 (search-forward (char-to-string char) nil nil arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 (goto-char (if (> arg 0) (1- (point)) (1+ (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520 (defun beginning-of-buffer (&optional arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 "Move point to the beginning of the buffer; leave mark at previous position.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 With arg N, put point N/10 of the way from the beginning.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 If the buffer is narrowed, this command uses the beginning and size
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 of the accessible part of the buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 Don't use this command in Lisp programs!
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 \(goto-char (point-min)) is faster and avoids clobbering the mark."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529 ;; XEmacs change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 (interactive "_P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 (push-mark)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 (let ((size (- (point-max) (point-min))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533 (goto-char (if arg
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 (+ (point-min)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535 (if (> size 10000)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 ;; Avoid overflow for large buffer sizes!
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 (* (prefix-numeric-value arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 (/ size 10))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 (/ (+ 10 (* size (prefix-numeric-value arg))) 10)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 (point-min))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541 (if arg (forward-line 1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 (defun end-of-buffer (&optional arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 "Move point to the end of the buffer; leave mark at previous position.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 With arg N, put point N/10 of the way from the end.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 If the buffer is narrowed, this command uses the beginning and size
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 of the accessible part of the buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 Don't use this command in Lisp programs!
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 \(goto-char (point-max)) is faster and avoids clobbering the mark."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552 ;; XEmacs change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 (interactive "_P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554 (push-mark)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555 ;; XEmacs changes here.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556 (let ((scroll-to-end (not (pos-visible-in-window-p (point-max))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557 (size (- (point-max) (point-min))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558 (goto-char (if arg
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559 (- (point-max)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 (if (> size 10000)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561 ;; Avoid overflow for large buffer sizes!
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562 (* (prefix-numeric-value arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563 (/ size 10))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564 (/ (* size (prefix-numeric-value arg)) 10)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565 (point-max)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566 (cond (arg
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567 ;; If we went to a place in the middle of the buffer,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568 ;; adjust it to the beginning of a line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569 (forward-line 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570 ;; XEmacs change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571 (scroll-to-end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572 ;; If the end of the buffer is not already on the screen,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573 ;; then scroll specially to put it near, but not at, the bottom.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 (recenter -3)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 ;; XEmacs (not in FSF)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577 (defun mark-beginning-of-buffer (&optional arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578 "Push a mark at the beginning of the buffer; leave point where it is.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579 With arg N, push mark N/10 of the way from the true beginning."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
580 (interactive "P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581 (push-mark (if arg
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
582 (if (> (buffer-size) 10000)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583 ;; Avoid overflow for large buffer sizes!
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584 (* (prefix-numeric-value arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 (/ (buffer-size) 10))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586 (/ (+ 10 (* (buffer-size) (prefix-numeric-value arg))) 10))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 (point-min))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589 t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 (define-function 'mark-bob 'mark-beginning-of-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592 ;; XEmacs (not in FSF)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593 (defun mark-end-of-buffer (&optional arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594 "Push a mark at the end of the buffer; leave point where it is.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595 With arg N, push mark N/10 of the way from the true end."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
596 (interactive "P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597 (push-mark (if arg
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 (- (1+ (buffer-size))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 (if (> (buffer-size) 10000)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 ;; Avoid overflow for large buffer sizes!
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 (* (prefix-numeric-value arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 (/ (buffer-size) 10))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 (/ (* (buffer-size) (prefix-numeric-value arg)) 10)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 (point-max))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606 t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 (define-function 'mark-eob 'mark-end-of-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609 (defun mark-whole-buffer ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 "Put point at beginning and mark at end of buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 You probably should not use this function in Lisp programs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 it is usually a mistake for a Lisp function to use any subroutine
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613 that uses or sets the mark."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 (push-mark (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616 (push-mark (point-max) nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617 (goto-char (point-min)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619 ;; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620 (defun eval-current-buffer (&optional printflag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621 "Evaluate the current buffer as Lisp code.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622 Programs can pass argument PRINTFLAG which controls printing of output:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623 nil means discard it; anything else is stream for print."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625 (eval-buffer (current-buffer) printflag))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627 ;; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628 (defun count-words-buffer (&optional buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629 "Print the number of words in BUFFER.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630 If called noninteractively, the value is returned rather than printed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631 BUFFER defaults to the current buffer."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
633 (let ((words (count-words-region (point-min) (point-max) buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634 (when (interactive-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635 (message "Buffer has %d words" words))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636 words))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 ;; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
639 (defun count-words-region (start end &optional buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
640 "Print the number of words in region between START and END in BUFFER.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641 If called noninteractively, the value is returned rather than printed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642 BUFFER defaults to the current buffer."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 (interactive "_r")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645 (set-buffer (or buffer (current-buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646 (let ((words 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647 (goto-char start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648 (while (< (point) end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649 (when (forward-word 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650 (incf words)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651 (when (interactive-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652 (message "Region has %d words" words))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653 words)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655 (defun count-lines-region (start end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656 "Print number of lines and characters in the region."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657 ;; XEmacs change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658 (interactive "_r")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659 (message "Region has %d lines, %d characters"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660 (count-lines start end) (- end start)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 ;; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663 (defun count-lines-buffer (&optional buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664 "Print number of lines and characters in BUFFER."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
665 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666 (with-current-buffer (or buffer (current-buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
667 (let ((cnt (count-lines (point-min) (point-max))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668 (message "Buffer has %d lines, %d characters"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669 cnt (- (point-max) (point-min)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670 cnt)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672 ;;; Modified by Bob Weiner, 8/24/95, to print narrowed line number also.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 ;;; Expanded by Bob Weiner, BeOpen, on 02/12/1997
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674 (defun what-line ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
675 "Print the following variants of the line number of point:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676 Region line - displayed line within the active region
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
677 Collapsed line - includes only selectively displayed lines;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678 Buffer line - physical line in the buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
679 Narrowed line - line number from the start of the buffer narrowing."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
680 ;; XEmacs change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
681 (interactive "_")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682 (let ((opoint (point)) start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684 (save-restriction
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685 (if (region-active-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686 (goto-char (region-beginning))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687 (goto-char (point-min)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688 (widen)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
689 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690 (setq start (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691 (goto-char opoint)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693 (let* ((buffer-line (1+ (count-lines 1 (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694 (narrowed-p (or (/= start 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695 (/= (point-max) (1+ (buffer-size)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
696 (narrowed-line (if narrowed-p (1+ (count-lines start (point)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697 (selective-line (if selective-display
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698 (1+ (count-lines start (point) t))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699 (region-line (if (region-active-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700 (1+ (count-lines start (point) selective-display)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
701 (cond (region-line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
702 (message "Region line %d; Buffer line %d"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
703 region-line buffer-line))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704 ((and narrowed-p selective-line (/= selective-line narrowed-line))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705 ;; buffer narrowed and some lines selectively displayed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706 (message "Collapsed line %d; Buffer line %d; Narrowed line %d"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707 selective-line buffer-line narrowed-line))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708 (narrowed-p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
709 ;; buffer narrowed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
710 (message "Buffer line %d; Narrowed line %d"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711 buffer-line narrowed-line))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712 ((and selective-line (/= selective-line buffer-line))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713 ;; some lines selectively displayed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
714 (message "Collapsed line %d; Buffer line %d"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715 selective-line buffer-line))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
717 ;; give a basic line count
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
718 (message "Line %d" buffer-line)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
719 (setq zmacs-region-stays t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
720
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
721 ;;; Bob Weiner, Altrasoft, 02/12/1998
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
722 ;;; Added the 3rd arg in `count-lines' to conditionalize the counting of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
723 ;;; collapsed lines.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724 (defun count-lines (start end &optional ignore-invisible-lines-flag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
725 "Return number of lines between START and END.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
726 This is usually the number of newlines between them,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
727 but can be one more if START is not equal to END
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728 and the greater of them is not at the start of a line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
729
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730 With optional IGNORE-INVISIBLE-LINES-FLAG non-nil, lines collapsed with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731 selective-display are excluded from the line count."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733 (save-restriction
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734 (narrow-to-region start end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735 (goto-char (point-min))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736 (if (and (not ignore-invisible-lines-flag) (eq selective-display t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 (save-match-data
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738 (let ((done 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739 (while (re-search-forward "[\n\C-m]" nil t 40)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740 (setq done (+ 40 done)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741 (while (re-search-forward "[\n\C-m]" nil t 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
742 (setq done (+ 1 done)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743 (goto-char (point-max))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744 (if (and (/= start end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745 (not (bolp)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
746 (1+ done)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747 done)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
748 (- (buffer-size) (forward-line (buffer-size)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
749
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750 (defun what-cursor-position ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751 "Print info on cursor position (on screen and within buffer)."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
752 ;; XEmacs change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753 (interactive "_")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754 (let* ((char (char-after (point))) ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755 (beg (point-min))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756 (end (point-max))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757 (pos (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758 (total (buffer-size))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
759 (percent (if (> total 50000)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760 ;; Avoid overflow from multiplying by 100!
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761 (/ (+ (/ total 200) (1- pos)) (max (/ total 100) 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
762 (/ (+ (/ total 2) (* 100 (1- pos))) (max total 1))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
763 (hscroll (if (= (window-hscroll) 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764 ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765 (format " Hscroll=%d" (window-hscroll))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766 (col (+ (current-column) (if column-number-start-at-one 1 0))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767 (if (= pos end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768 (if (or (/= beg 1) (/= end (1+ total)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769 (message "point=%d of %d(%d%%) <%d - %d> column %d %s"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
770 pos total percent beg end col hscroll)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771 (message "point=%d of %d(%d%%) column %d %s"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772 pos total percent col hscroll))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773 ;; XEmacs: don't use single-key-description
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
774 (if (or (/= beg 1) (/= end (1+ total)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775 (message "Char: %s (0%o, %d, 0x%x) point=%d of %d(%d%%) <%d - %d> column %d %s"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776 (text-char-description char) char char char pos total
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777 percent beg end col hscroll)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778 (message "Char: %s (0%o, %d, 0x%x) point=%d of %d(%d%%) column %d %s"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
779 (text-char-description char) char char char pos total
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780 percent col hscroll)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782 (defun fundamental-mode ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783 "Major mode not specialized for anything in particular.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
784 Other major modes are defined by comparison with this one."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786 (kill-all-local-variables))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
787
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
788 ;; XEmacs the following are declared elsewhere
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
789 ;(defvar read-expression-map (cons 'keymap minibuffer-local-map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
790 ; "Minibuffer keymap used for reading Lisp expressions.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
791 ;(define-key read-expression-map "\M-\t" 'lisp-complete-symbol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
792
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793 ;(put 'eval-expression 'disabled t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
794
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
795 ;(defvar read-expression-history nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
796
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
797 ;; We define this, rather than making `eval' interactive,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
798 ;; for the sake of completion of names like eval-region, eval-current-buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
799 (defun eval-expression (expression &optional eval-expression-insert-value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800 "Evaluate EXPRESSION and print value in minibuffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
801 Value is also consed on to front of the variable `values'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
802 With prefix argument, insert the result to the current buffer."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803 ;(interactive "xEval: ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804 (interactive
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805 (list (read-from-minibuffer "Eval: "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806 nil read-expression-map t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807 'read-expression-history)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808 current-prefix-arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
809 (setq values (cons (eval expression) values))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
810 (prin1 (car values)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
811 (if eval-expression-insert-value (current-buffer) t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
812
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
813 ;; XEmacs -- extra parameter (variant, but equivalent logic)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
814 (defun edit-and-eval-command (prompt command &optional history)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
815 "Prompting with PROMPT, let user edit COMMAND and eval result.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
816 COMMAND is a Lisp expression. Let user edit that expression in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
817 the minibuffer, then read and evaluate the result."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818 (let ((command (read-expression prompt
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819 ;; first try to format the thing readably;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
820 ;; and if that fails, print it normally.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
821 (condition-case ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
822 (let ((print-readably t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
823 (prin1-to-string command))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
824 (error (prin1-to-string command)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
825 (or history '(command-history . 1)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
826 (or history (setq history 'command-history))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827 (if (consp history)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
828 (setq history (car history)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829 (if (eq history t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831 ;; If command was added to the history as a string,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832 ;; get rid of that. We want only evallable expressions there.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
833 (if (stringp (car (symbol-value history)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834 (set history (cdr (symbol-value history))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
835
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836 ;; If command to be redone does not match front of history,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
837 ;; add it to the history.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
838 (or (equal command (car (symbol-value history)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
839 (set history (cons command (symbol-value history)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840 (eval command)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
842 (defun repeat-complex-command (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
843 "Edit and re-evaluate last complex command, or ARGth from last.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844 A complex command is one which used the minibuffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
845 The command is placed in the minibuffer as a Lisp form for editing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846 The result is executed, repeating the command as changed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
847 If the command has been changed or is not the most recent previous command
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
848 it is added to the front of the command history.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
849 You can use the minibuffer history commands \\<minibuffer-local-map>\\[next-history-element] and \\[previous-history-element]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850 to get different commands to edit and resubmit."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
851 (interactive "p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
852 ;; XEmacs: It looks like our version is better -sb
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
853 (let ((print-level nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
854 (edit-and-eval-command "Redo: "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
855 (or (nth (1- arg) command-history)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
856 (error ""))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
857 (cons 'command-history arg))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
858
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
859 ;; XEmacs: Functions moved to minibuf.el
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
860 ;; previous-matching-history-element
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
861 ;; next-matching-history-element
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
862 ;; next-history-element
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
863 ;; previous-history-element
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
864 ;; next-complete-history-element
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
865 ;; previous-complete-history-element
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
866
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
867 (defun goto-line (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
868 "Goto line ARG, counting from line 1 at beginning of buffer."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
869 (interactive "NGoto line: ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
870 (setq arg (prefix-numeric-value arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
871 (save-restriction
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
872 (widen)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
873 (goto-char 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
874 (if (eq selective-display t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
875 (re-search-forward "[\n\C-m]" nil 'end (1- arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
876 (forward-line (1- arg)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
877
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
878 ;Put this on C-x u, so we can force that rather than C-_ into startup msg
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
879 (define-function 'advertised-undo 'undo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
880
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
881 (defun undo (&optional arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
882 "Undo some previous changes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
883 Repeat this command to undo more changes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
884 A numeric argument serves as a repeat count."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
885 (interactive "*p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
886 ;; If we don't get all the way through, make last-command indicate that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
887 ;; for the following command.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
888 (setq this-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
889 (let ((modified (buffer-modified-p))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
890 (recent-save (recent-auto-save-p)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
891 (or (eq (selected-window) (minibuffer-window))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
892 (display-message 'command "Undo!"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
893 (or (and (eq last-command 'undo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
894 (eq (current-buffer) last-undo-buffer)) ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
895 (progn (undo-start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
896 (undo-more 1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
897 (undo-more (or arg 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
898 ;; Don't specify a position in the undo record for the undo command.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
899 ;; Instead, undoing this should move point to where the change is.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
900 (let ((tail buffer-undo-list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
901 done)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
902 (while (and tail (not done) (not (null (car tail))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
903 (if (integerp (car tail))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
904 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
905 (setq done t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
906 (setq buffer-undo-list (delq (car tail) buffer-undo-list))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
907 (setq tail (cdr tail))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
908 (and modified (not (buffer-modified-p))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
909 (delete-auto-save-file-if-necessary recent-save)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
910 ;; If we do get all the way through, make this-command indicate that.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
911 (setq this-command 'undo))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
912
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
913 (defvar pending-undo-list nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
914 "Within a run of consecutive undo commands, list remaining to be undone.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
915
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
916 (defvar last-undo-buffer nil) ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
917
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
918 (defun undo-start ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
919 "Set `pending-undo-list' to the front of the undo list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
920 The next call to `undo-more' will undo the most recently made change."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
921 (if (eq buffer-undo-list t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
922 (error "No undo information in this buffer"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
923 (setq pending-undo-list buffer-undo-list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
924
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
925 (defun undo-more (count)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
926 "Undo back N undo-boundaries beyond what was already undone recently.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
927 Call `undo-start' to get ready to undo recent changes,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
928 then call `undo-more' one or more times to undo them."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
929 (or pending-undo-list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
930 (error "No further undo information"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
931 (setq pending-undo-list (primitive-undo count pending-undo-list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
932 last-undo-buffer (current-buffer))) ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
933
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
934 ;; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
935 (defun call-with-transparent-undo (fn &rest args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
936 "Apply FN to ARGS, and then undo all changes made by FN to the current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
937 buffer. The undo records are processed even if FN returns non-locally.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
938 There is no trace of the changes made by FN in the buffer's undo history.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
939
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
940 You can use this in a write-file-hooks function with continue-save-buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
941 to make the contents of a disk file differ from its in-memory buffer."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
942 (let ((buffer-undo-list nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
943 ;; Kludge to prevent undo list truncation:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
944 (undo-high-threshold -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
945 (undo-threshold -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
946 (obuffer (current-buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
947 (unwind-protect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
948 (apply fn args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
949 ;; Go to the buffer we will restore and make it writable:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
950 (set-buffer obuffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
951 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
952 (let ((buffer-read-only nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
953 (save-restriction
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
954 (widen)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
955 ;; Perform all undos, with further undo logging disabled:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
956 (let ((tail buffer-undo-list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
957 (setq buffer-undo-list t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
958 (while tail
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
959 (setq tail (primitive-undo (length tail) tail))))))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
960
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
961 ;; XEmacs: The following are in other files
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
962 ;; shell-command-history
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
963 ;; shell-command-switch
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
964 ;; shell-command
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
965 ;; shell-command-sentinel
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
966
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
967
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
968 (defconst universal-argument-map
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
969 (let ((map (make-sparse-keymap)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
970 (set-keymap-default-binding map 'universal-argument-other-key)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
971 ;FSFmacs (define-key map [switch-frame] nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
972 (define-key map [(t)] 'universal-argument-other-key)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
973 (define-key map [(meta t)] 'universal-argument-other-key)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
974 (define-key map [(control u)] 'universal-argument-more)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
975 (define-key map [?-] 'universal-argument-minus)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
976 (define-key map [?0] 'digit-argument)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
977 (define-key map [?1] 'digit-argument)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
978 (define-key map [?2] 'digit-argument)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
979 (define-key map [?3] 'digit-argument)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
980 (define-key map [?4] 'digit-argument)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
981 (define-key map [?5] 'digit-argument)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
982 (define-key map [?6] 'digit-argument)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
983 (define-key map [?7] 'digit-argument)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
984 (define-key map [?8] 'digit-argument)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
985 (define-key map [?9] 'digit-argument)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
986 map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
987 "Keymap used while processing \\[universal-argument].")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
988
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
989 (defvar universal-argument-num-events nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
990 "Number of argument-specifying events read by `universal-argument'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
991 `universal-argument-other-key' uses this to discard those events
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
992 from (this-command-keys), and reread only the final command.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
993
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
994 (defun universal-argument ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
995 "Begin a numeric argument for the following command.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
996 Digits or minus sign following \\[universal-argument] make up the numeric argument.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
997 \\[universal-argument] following the digits or minus sign ends the argument.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
998 \\[universal-argument] without digits or minus sign provides 4 as argument.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
999 Repeating \\[universal-argument] without digits or minus sign
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1000 multiplies the argument by 4 each time."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1001 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1002 (setq prefix-arg (list 4))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1003 (setq zmacs-region-stays t) ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1004 (setq universal-argument-num-events (length (this-command-keys)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1005 (setq overriding-terminal-local-map universal-argument-map))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1006
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1007 ;; A subsequent C-u means to multiply the factor by 4 if we've typed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1008 ;; nothing but C-u's; otherwise it means to terminate the prefix arg.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1009 (defun universal-argument-more (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1010 (interactive "_P") ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1011 (if (consp arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1012 (setq prefix-arg (list (* 4 (car arg))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1013 (setq prefix-arg arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1014 (setq overriding-terminal-local-map nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1015 (setq universal-argument-num-events (length (this-command-keys))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1016
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1017 (defun negative-argument (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1018 "Begin a negative numeric argument for the next command.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1019 \\[universal-argument] following digits or minus sign ends the argument."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1020 (interactive "_P") ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1021 (cond ((integerp arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1022 (setq prefix-arg (- arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1023 ((eq arg '-)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1024 (setq prefix-arg nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1025 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1026 (setq prefix-arg '-)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1027 (setq universal-argument-num-events (length (this-command-keys)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1028 (setq overriding-terminal-local-map universal-argument-map))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1029
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1030 ;; XEmacs: This function not synched with FSF
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1031 (defun digit-argument (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1032 "Part of the numeric argument for the next command.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1033 \\[universal-argument] following digits or minus sign ends the argument."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1034 (interactive "_P") ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1035 (let* ((event last-command-event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1036 (key (and (key-press-event-p event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1037 (event-key event)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1038 (digit (and key (characterp key) (>= key ?0) (<= key ?9)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1039 (- key ?0))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1040 (if (null digit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1041 (universal-argument-other-key arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1042 (cond ((integerp arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1043 (setq prefix-arg (+ (* arg 10)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1044 (if (< arg 0) (- digit) digit))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1045 ((eq arg '-)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1046 ;; Treat -0 as just -, so that -01 will work.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1047 (setq prefix-arg (if (zerop digit) '- (- digit))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1048 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1049 (setq prefix-arg digit)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1050 (setq universal-argument-num-events (length (this-command-keys)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1051 (setq overriding-terminal-local-map universal-argument-map))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1052
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1053 ;; For backward compatibility, minus with no modifiers is an ordinary
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1054 ;; command if digits have already been entered.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1055 (defun universal-argument-minus (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1056 (interactive "_P") ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1057 (if (integerp arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1058 (universal-argument-other-key arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1059 (negative-argument arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1060
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1061 ;; Anything else terminates the argument and is left in the queue to be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1062 ;; executed as a command.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1063 (defun universal-argument-other-key (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1064 (interactive "_P") ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1065 (setq prefix-arg arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1066 (let* ((key (this-command-keys))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1067 ;; FSF calls silly function `listify-key-sequence' here.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1068 (keylist (append key nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1069 (setq unread-command-events
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1070 (append (nthcdr universal-argument-num-events keylist)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1071 unread-command-events)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1072 (reset-this-command-lengths)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1073 (setq overriding-terminal-local-map nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1074
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1075
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1076 ;; XEmacs -- keep zmacs-region active.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1077 (defun forward-to-indentation (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1078 "Move forward ARG lines and position at first nonblank character."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1079 (interactive "_p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1080 (forward-line arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1081 (skip-chars-forward " \t"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1082
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1083 (defun backward-to-indentation (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1084 "Move backward ARG lines and position at first nonblank character."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1085 (interactive "_p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1086 (forward-line (- arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1087 (skip-chars-forward " \t"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1088
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1089 (defcustom kill-whole-line nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1090 "*If non-nil, `kill-line' with no arg at beg of line kills the whole line."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1091 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1092 :group 'killing)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1093
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1094 (defun kill-line (&optional arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1095 "Kill the rest of the current line; if no nonblanks there, kill thru newline.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1096 With prefix argument, kill that many lines from point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1097 Negative arguments kill lines backward.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1098
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1099 When calling from a program, nil means \"no arg\",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1100 a number counts as a prefix arg.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1101
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1102 If `kill-whole-line' is non-nil, then kill the whole line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1103 when given no argument at the beginning of a line."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1104 (interactive "*P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1105 (kill-region (point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1106 ;; Don't shift point before doing the delete; that way,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1107 ;; undo will record the right position of point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1108 ;; FSF
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1109 ; ;; It is better to move point to the other end of the kill
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1110 ; ;; before killing. That way, in a read-only buffer, point
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1111 ; ;; moves across the text that is copied to the kill ring.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1112 ; ;; The choice has no effect on undo now that undo records
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1113 ; ;; the value of point from before the command was run.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1114 ; (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1115 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1116 (if arg
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1117 (forward-line (prefix-numeric-value arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1118 (if (eobp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1119 (signal 'end-of-buffer nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1120 (if (or (looking-at "[ \t]*$") (and kill-whole-line (bolp)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1121 (forward-line 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1122 (end-of-line)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1123 (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1124
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1125 ;; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1126 (defun backward-kill-line nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1127 "Kill back to the beginning of the line."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1128 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1129 (let ((point (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1130 (beginning-of-line nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1131 (kill-region (point) point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1132
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1133
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1134 ;;;; Window system cut and paste hooks.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1135 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1136 ;;; I think that kill-hooks is a better name and more general mechanism
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1137 ;;; than interprogram-cut-function (from FSFmacs). I don't like the behavior
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1138 ;;; of interprogram-paste-function: ^Y should always come from the kill ring,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1139 ;;; not the X selection. But if that were provided, it should be called (and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1140 ;;; behave as) yank-hooks instead. -- jwz
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1141
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1142 ;; [... code snipped ...]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1143
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1144 (defcustom kill-hooks nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1145 "*Functions run when something is added to the XEmacs kill ring.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1146 These functions are called with one argument, the string most recently
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1147 cut or copied. You can use this to, for example, make the most recent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1148 kill become the X Clipboard selection."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1149 :type 'hook
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1150 :group 'killing)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1151
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1152 ;;; `kill-hooks' seems not sufficient because
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1153 ;;; `interprogram-cut-function' requires more variable about to rotate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1154 ;;; the cut buffers. I'm afraid to change interface of `kill-hooks',
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1155 ;;; so I add it. (1997-11-03 by MORIOKA Tomohiko)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1156
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1157 (defvar interprogram-cut-function nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1158 "Function to call to make a killed region available to other programs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1159
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1160 Most window systems provide some sort of facility for cutting and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1161 pasting text between the windows of different programs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1162 This variable holds a function that Emacs calls whenever text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1163 is put in the kill ring, to make the new kill available to other
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1164 programs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1165
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1166 The function takes one or two arguments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1167 The first argument, TEXT, is a string containing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1168 the text which should be made available.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1169 The second, PUSH, if non-nil means this is a \"new\" kill;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1170 nil means appending to an \"old\" kill.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1171
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1172 (defvar interprogram-paste-function nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1173 "Function to call to get text cut from other programs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1174
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1175 Most window systems provide some sort of facility for cutting and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1176 pasting text between the windows of different programs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1177 This variable holds a function that Emacs calls to obtain
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1178 text that other programs have provided for pasting.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1179
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1180 The function should be called with no arguments. If the function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1181 returns nil, then no other program has provided such text, and the top
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1182 of the Emacs kill ring should be used. If the function returns a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1183 string, that string should be put in the kill ring as the latest kill.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1184
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1185 Note that the function should return a string only if a program other
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1186 than Emacs has provided a string for pasting; if Emacs provided the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1187 most recent string, the function should return nil. If it is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1188 difficult to tell whether Emacs or some other program provided the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1189 current string, it is probably good enough to return nil if the string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1190 is equal (according to `string=') to the last text Emacs provided.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1191
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1192
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1193 ;;;; The kill ring data structure.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1194
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1195 (defvar kill-ring nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1196 "List of killed text sequences.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1197 Since the kill ring is supposed to interact nicely with cut-and-paste
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1198 facilities offered by window systems, use of this variable should
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1199 interact nicely with `interprogram-cut-function' and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1200 `interprogram-paste-function'. The functions `kill-new',
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1201 `kill-append', and `current-kill' are supposed to implement this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1202 interaction; you may want to use them instead of manipulating the kill
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1203 ring directly.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1204
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1205 (defcustom kill-ring-max 30
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1206 "*Maximum length of kill ring before oldest elements are thrown away."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1207 :type 'integer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1208 :group 'killing)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1209
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1210 (defvar kill-ring-yank-pointer nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1211 "The tail of the kill ring whose car is the last thing yanked.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1212
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1213 (defun kill-new (string &optional replace)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1214 "Make STRING the latest kill in the kill ring.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1215 Set the kill-ring-yank pointer to point to it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1216 Run `kill-hooks'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1217 Optional second argument REPLACE non-nil means that STRING will replace
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1218 the front of the kill ring, rather than being added to the list."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1219 ; (and (fboundp 'menu-bar-update-yank-menu)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1220 ; (menu-bar-update-yank-menu string (and replace (car kill-ring))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1221 (if replace
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1222 (setcar kill-ring string)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1223 (setq kill-ring (cons string kill-ring))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1224 (if (> (length kill-ring) kill-ring-max)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1225 (setcdr (nthcdr (1- kill-ring-max) kill-ring) nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1226 (setq kill-ring-yank-pointer kill-ring)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1227 (if interprogram-cut-function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1228 (funcall interprogram-cut-function string (not replace)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1229 (run-hook-with-args 'kill-hooks string))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1230
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1231 (defun kill-append (string before-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1232 "Append STRING to the end of the latest kill in the kill ring.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1233 If BEFORE-P is non-nil, prepend STRING to the kill.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1234 Run `kill-hooks'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1235 (kill-new (if before-p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1236 (concat string (car kill-ring))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1237 (concat (car kill-ring) string)) t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1238
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1239 (defun current-kill (n &optional do-not-move)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1240 "Rotate the yanking point by N places, and then return that kill.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1241 If N is zero, `interprogram-paste-function' is set, and calling it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1242 returns a string, then that string is added to the front of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1243 kill ring and returned as the latest kill.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1244 If optional arg DO-NOT-MOVE is non-nil, then don't actually move the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1245 yanking point\; just return the Nth kill forward."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1246 (let ((interprogram-paste (and (= n 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1247 interprogram-paste-function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1248 (funcall interprogram-paste-function))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1249 (if interprogram-paste
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1250 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1251 ;; Disable the interprogram cut function when we add the new
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1252 ;; text to the kill ring, so Emacs doesn't try to own the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1253 ;; selection, with identical text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1254 (let ((interprogram-cut-function nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1255 (kill-new interprogram-paste))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1256 interprogram-paste)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1257 (or kill-ring (error "Kill ring is empty"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1258 (let* ((tem (nthcdr (mod (- n (length kill-ring-yank-pointer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1259 (length kill-ring))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1260 kill-ring)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1261 (or do-not-move
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1262 (setq kill-ring-yank-pointer tem))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1263 (car tem)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1264
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1265
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1266
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1267 ;;;; Commands for manipulating the kill ring.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1268
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1269 ;; In FSF killing read-only text just pastes it into kill-ring. Which
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1270 ;; is a very bad idea -- see Jamie's comment below.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1271
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1272 ;(defvar kill-read-only-ok nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1273 ; "*Non-nil means don't signal an error for killing read-only text.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1274
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1275 (defun kill-region (beg end &optional verbose) ; verbose is XEmacs addition
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1276 "Kill between point and mark.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1277 The text is deleted but saved in the kill ring.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1278 The command \\[yank] can retrieve it from there.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1279 \(If you want to kill and then yank immediately, use \\[copy-region-as-kill].)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1280
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1281 This is the primitive for programs to kill text (as opposed to deleting it).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1282 Supply two arguments, character numbers indicating the stretch of text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1283 to be killed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1284 Any command that calls this function is a \"kill command\".
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1285 If the previous command was also a kill command,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1286 the text killed this time appends to the text killed last time
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1287 to make one entry in the kill ring."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1288 (interactive "*r\np")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1289 ; (interactive
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1290 ; (let ((region-hack (and zmacs-regions (eq last-command 'yank))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1291 ; ;; This lets "^Y^W" work. I think this is dumb, but zwei did it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1292 ; (if region-hack (zmacs-activate-region))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1293 ; (prog1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1294 ; (list (point) (mark) current-prefix-arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1295 ; (if region-hack (zmacs-deactivate-region)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1296 ;; beg and end can be markers but the rest of this function is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1297 ;; written as if they are only integers
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1298 (if (markerp beg) (setq beg (marker-position beg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1299 (if (markerp end) (setq end (marker-position end)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1300 (or (and beg end) (if zmacs-regions ;; rewritten for I18N3 snarfing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1301 (error "The region is not active now")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1302 (error "The mark is not set now")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1303 (if verbose (if buffer-read-only
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1304 (lmessage 'command "Copying %d characters"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1305 (- (max beg end) (min beg end)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1306 (lmessage 'command "Killing %d characters"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1307 (- (max beg end) (min beg end)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1308 (cond
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1309
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1310 ;; I don't like this large change in behavior -- jwz
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1311 ;; Read-Only text means it shouldn't be deleted, so I'm restoring
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1312 ;; this code, but only for text-properties and not full extents. -sb
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1313 ;; If the buffer is read-only, we should beep, in case the person
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1314 ;; just isn't aware of this. However, there's no harm in putting
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1315 ;; the region's text in the kill ring, anyway.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1316 ((or (and buffer-read-only (not inhibit-read-only))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1317 (text-property-not-all (min beg end) (max beg end) 'read-only nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1318 ;; This is redundant.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1319 ;; (if verbose (message "Copying %d characters"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1320 ;; (- (max beg end) (min beg end))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1321 (copy-region-as-kill beg end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1322 ;; ;; This should always barf, and give us the correct error.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1323 ;; (if kill-read-only-ok
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1324 ;; (message "Read only text copied to kill ring")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1325 (setq this-command 'kill-region)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1326 (barf-if-buffer-read-only)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1327 (signal 'buffer-read-only (list (current-buffer))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1328
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1329 ;; In certain cases, we can arrange for the undo list and the kill
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1330 ;; ring to share the same string object. This code does that.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1331 ((not (or (eq buffer-undo-list t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1332 (eq last-command 'kill-region)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1333 ;; Use = since positions may be numbers or markers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1334 (= beg end)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1335 ;; Don't let the undo list be truncated before we can even access it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1336 ;; FSF calls this `undo-strong-limit'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1337 (let ((undo-high-threshold (+ (- end beg) 100))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1338 ;(old-list buffer-undo-list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1339 tail)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1340 (delete-region beg end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1341 ;; Search back in buffer-undo-list for this string,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1342 ;; in case a change hook made property changes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1343 (setq tail buffer-undo-list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1344 (while (and tail
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1345 (not (stringp (car-safe (car-safe tail))))) ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1346 (pop tail))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1347 ;; Take the same string recorded for undo
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1348 ;; and put it in the kill-ring.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1349 (and tail
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1350 (kill-new (car (car tail))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1351
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1352 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1353 ;; if undo is not kept, grab the string then delete it (which won't
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1354 ;; add another string to the undo list).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1355 (copy-region-as-kill beg end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1356 (delete-region beg end)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1357 (setq this-command 'kill-region))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1358
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1359 ;; copy-region-as-kill no longer sets this-command, because it's confusing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1360 ;; to get two copies of the text when the user accidentally types M-w and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1361 ;; then corrects it with the intended C-w.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1362 (defun copy-region-as-kill (beg end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1363 "Save the region as if killed, but don't kill it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1364 Run `kill-hooks'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1365 (interactive "r")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1366 (if (eq last-command 'kill-region)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1367 (kill-append (buffer-substring beg end) (< end beg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1368 (kill-new (buffer-substring beg end)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1369 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1370
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1371 (defun kill-ring-save (beg end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1372 "Save the region as if killed, but don't kill it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1373 This command is similar to `copy-region-as-kill', except that it gives
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1374 visual feedback indicating the extent of the region being copied."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1375 (interactive "r")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1376 (copy-region-as-kill beg end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1377 ;; copy before delay, for xclipboard's benefit
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1378 (if (interactive-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1379 (let ((other-end (if (= (point) beg) end beg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1380 (opoint (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1381 ;; Inhibit quitting so we can make a quit here
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1382 ;; look like a C-g typed as a command.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1383 (inhibit-quit t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1384 (if (pos-visible-in-window-p other-end (selected-window))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1385 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1386 ;; FSF (I'm not sure what this does -sb)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1387 ; ;; Swap point and mark.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1388 ; (set-marker (mark-marker) (point) (current-buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1389 (goto-char other-end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1390 (sit-for 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1391 ; ;; Swap back.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1392 ; (set-marker (mark-marker) other-end (current-buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1393 (goto-char opoint)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1394 ;; If user quit, deactivate the mark
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1395 ;; as C-g would as a command.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1396 (and quit-flag (mark)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1397 (zmacs-deactivate-region)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1398 ;; too noisy. -- jwz
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1399 ; (let* ((killed-text (current-kill 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1400 ; (message-len (min (length killed-text) 40)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1401 ; (if (= (point) beg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1402 ; ;; Don't say "killed"; that is misleading.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1403 ; (message "Saved text until \"%s\""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1404 ; (substring killed-text (- message-len)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1405 ; (message "Saved text from \"%s\""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1406 ; (substring killed-text 0 message-len))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1407 ))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1408
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1409 (defun append-next-kill ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1410 "Cause following command, if it kills, to append to previous kill."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1411 ;; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1412 (interactive "_")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1413 (if (interactive-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1414 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1415 (setq this-command 'kill-region)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1416 (display-message 'command
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1417 "If the next command is a kill, it will append"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1418 (setq last-command 'kill-region)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1419
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1420 (defun yank-pop (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1421 "Replace just-yanked stretch of killed text with a different stretch.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1422 This command is allowed only immediately after a `yank' or a `yank-pop'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1423 At such a time, the region contains a stretch of reinserted
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1424 previously-killed text. `yank-pop' deletes that text and inserts in its
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1425 place a different stretch of killed text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1426
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1427 With no argument, the previous kill is inserted.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1428 With argument N, insert the Nth previous kill.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1429 If N is negative, this is a more recent kill.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1430
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1431 The sequence of kills wraps around, so that after the oldest one
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1432 comes the newest one."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1433 (interactive "*p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1434 (if (not (eq last-command 'yank))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1435 (error "Previous command was not a yank"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1436 (setq this-command 'yank)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1437 (let ((inhibit-read-only t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1438 (before (< (point) (mark t))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1439 (delete-region (point) (mark t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1440 ;;(set-marker (mark-marker) (point) (current-buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1441 (set-mark (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1442 (insert (current-kill arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1443 (if before
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1444 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1445 ;; It is cleaner to avoid activation, even though the command
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1446 ;; loop would deactivate the mark because we inserted text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1447 (goto-char (prog1 (mark t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1448 (set-marker (mark-marker t) (point) (current-buffer))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1449 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1450
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1451
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1452 (defun yank (&optional arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1453 "Reinsert the last stretch of killed text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1454 More precisely, reinsert the stretch of killed text most recently
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1455 killed OR yanked. Put point at end, and set mark at beginning.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1456 With just C-u as argument, same but put point at beginning (and mark at end).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1457 With argument N, reinsert the Nth most recently killed stretch of killed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1458 text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1459 See also the command \\[yank-pop]."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1460 (interactive "*P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1461 ;; If we don't get all the way through, make last-command indicate that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1462 ;; for the following command.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1463 (setq this-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1464 (push-mark (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1465 (insert (current-kill (cond
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1466 ((listp arg) 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1467 ((eq arg '-) -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1468 (t (1- arg)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1469 (if (consp arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1470 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1471 ;; It is cleaner to avoid activation, even though the command
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1472 ;; loop would deactivate the mark because we inserted text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1473 ;; (But it's an unnecessary kludge in XEmacs.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1474 ;(goto-char (prog1 (mark t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1475 ;(set-marker (mark-marker) (point) (current-buffer)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1476 (exchange-point-and-mark t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1477 ;; If we do get all the way thru, make this-command indicate that.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1478 (setq this-command 'yank)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1479 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1480
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1481 (defun rotate-yank-pointer (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1482 "Rotate the yanking point in the kill ring.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1483 With argument, rotate that many kills forward (or backward, if negative)."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1484 (interactive "p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1485 (current-kill arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1486
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1487
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1488 (defun insert-buffer (buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1489 "Insert after point the contents of BUFFER.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1490 Puts mark after the inserted text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1491 BUFFER may be a buffer or a buffer name."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1492 (interactive
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1493 (list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1494 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1495 (barf-if-buffer-read-only)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1496 (read-buffer "Insert buffer: "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1497 ;; XEmacs: we have different args
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1498 (other-buffer (current-buffer) nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1499 t))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1500 (or (bufferp buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1501 (setq buffer (get-buffer buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1502 (let (start end newmark)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1503 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1504 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1505 (set-buffer buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1506 (setq start (point-min) end (point-max)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1507 (insert-buffer-substring buffer start end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1508 (setq newmark (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1509 (push-mark newmark))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1510 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1511
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1512 (defun append-to-buffer (buffer start end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1513 "Append to specified buffer the text of the region.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1514 It is inserted into that buffer before its point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1515
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1516 When calling from a program, give three arguments:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1517 BUFFER (or buffer name), START and END.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1518 START and END specify the portion of the current buffer to be copied."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1519 (interactive
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1520 ;; XEmacs: we have different args to other-buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1521 (list (read-buffer "Append to buffer: " (other-buffer (current-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1522 nil t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1523 (region-beginning) (region-end)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1524 (let ((oldbuf (current-buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1525 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1526 (set-buffer (get-buffer-create buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1527 (insert-buffer-substring oldbuf start end))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1528
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1529 (defun prepend-to-buffer (buffer start end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1530 "Prepend to specified buffer the text of the region.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1531 It is inserted into that buffer after its point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1532
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1533 When calling from a program, give three arguments:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1534 BUFFER (or buffer name), START and END.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1535 START and END specify the portion of the current buffer to be copied."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1536 (interactive "BPrepend to buffer: \nr")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1537 (let ((oldbuf (current-buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1538 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1539 (set-buffer (get-buffer-create buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1540 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1541 (insert-buffer-substring oldbuf start end)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1542
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1543 (defun copy-to-buffer (buffer start end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1544 "Copy to specified buffer the text of the region.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1545 It is inserted into that buffer, replacing existing text there.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1546
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1547 When calling from a program, give three arguments:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1548 BUFFER (or buffer name), START and END.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1549 START and END specify the portion of the current buffer to be copied."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1550 (interactive "BCopy to buffer: \nr")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1551 (let ((oldbuf (current-buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1552 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1553 (set-buffer (get-buffer-create buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1554 (erase-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1555 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1556 (insert-buffer-substring oldbuf start end)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1557
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1558 ;FSFmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1559 ;(put 'mark-inactive 'error-conditions '(mark-inactive error))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1560 ;(put 'mark-inactive 'error-message "The mark is not active now")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1561
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1562 (defun mark (&optional force buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1563 "Return this buffer's mark value as integer, or nil if no mark.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1564
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1565 If `zmacs-regions' is true, then this returns nil unless the region is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1566 currently in the active (highlighted) state. With an argument of t, this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1567 returns the mark (if there is one) regardless of the active-region state.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1568 You should *generally* not use the mark unless the region is active, if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1569 the user has expressed a preference for the active-region model.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1570
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1571 If you are using this in an editing command, you are most likely making
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1572 a mistake; see the documentation of `set-mark'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1573 (setq buffer (decode-buffer buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1574 ;FSFmacs version:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1575 ; (if (or force (not transient-mark-mode) mark-active mark-even-if-inactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1576 ; (marker-position (mark-marker))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1577 ; (signal 'mark-inactive nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1578 (let ((m (mark-marker force buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1579 (and m (marker-position m))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1580
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1581 ;;;#### FSFmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1582 ;;; Many places set mark-active directly, and several of them failed to also
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1583 ;;; run deactivate-mark-hook. This shorthand should simplify.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1584 ;(defsubst deactivate-mark ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1585 ; "Deactivate the mark by setting `mark-active' to nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1586 ;\(That makes a difference only in Transient Mark mode.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1587 ;Also runs the hook `deactivate-mark-hook'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1588 ; (if transient-mark-mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1589 ; (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1590 ; (setq mark-active nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1591 ; (run-hooks 'deactivate-mark-hook))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1592
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1593 (defun set-mark (pos &optional buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1594 "Set this buffer's mark to POS. Don't use this function!
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1595 That is to say, don't use this function unless you want
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1596 the user to see that the mark has moved, and you want the previous
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1597 mark position to be lost.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1598
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1599 Normally, when a new mark is set, the old one should go on the stack.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1600 This is why most applications should use push-mark, not set-mark.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1601
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1602 Novice Emacs Lisp programmers often try to use the mark for the wrong
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1603 purposes. The mark saves a location for the user's convenience.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1604 Most editing commands should not alter the mark.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1605 To remember a location for internal use in the Lisp program,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1606 store it in a Lisp variable. Example:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1607
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1608 (let ((beg (point))) (forward-line 1) (delete-region beg (point)))."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1609
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1610 (setq buffer (decode-buffer buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1611 (set-marker (mark-marker t buffer) pos buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1612 ;; FSF
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1613 ; (if pos
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1614 ; (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1615 ; (setq mark-active t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1616 ; (run-hooks 'activate-mark-hook)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1617 ; (set-marker (mark-marker) pos (current-buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1618 ; ;; Normally we never clear mark-active except in Transient Mark mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1619 ; ;; But when we actually clear out the mark value too,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1620 ; ;; we must clear mark-active in any mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1621 ; (setq mark-active nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1622 ; (run-hooks 'deactivate-mark-hook)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1623 ; (set-marker (mark-marker) nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1624
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1625 (defvar mark-ring nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1626 "The list of former marks of the current buffer, most recent first.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1627 (make-variable-buffer-local 'mark-ring)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1628 (put 'mark-ring 'permanent-local t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1629
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1630 (defcustom mark-ring-max 16
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1631 "*Maximum size of mark ring. Start discarding off end if gets this big."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1632 :type 'integer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1633 :group 'killing)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1634
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1635 (defvar global-mark-ring nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1636 "The list of saved global marks, most recent first.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1637
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1638 (defcustom global-mark-ring-max 16
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1639 "*Maximum size of global mark ring. \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1640 Start discarding off end if gets this big."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1641 :type 'integer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1642 :group 'killing)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1643
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1644 (defun set-mark-command (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1645 "Set mark at where point is, or jump to mark.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1646 With no prefix argument, set mark, push old mark position on local mark
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1647 ring, and push mark on global mark ring.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1648 With argument, jump to mark, and pop a new position for mark off the ring
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1649 \(does not affect global mark ring\).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1650
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1651 Novice Emacs Lisp programmers often try to use the mark for the wrong
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1652 purposes. See the documentation of `set-mark' for more information."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1653 (interactive "P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1654 (if (null arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1655 (push-mark nil nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1656 (if (null (mark t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1657 (error "No mark set in this buffer")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1658 (goto-char (mark t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1659 (pop-mark))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1660
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1661 ;; XEmacs: Extra parameter
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1662 (defun push-mark (&optional location nomsg activate-region buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1663 "Set mark at LOCATION (point, by default) and push old mark on mark ring.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1664 If the last global mark pushed was not in the current buffer,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1665 also push LOCATION on the global mark ring.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1666 Display `Mark set' unless the optional second arg NOMSG is non-nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1667 Activate mark if optional third arg ACTIVATE-REGION non-nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1668
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1669 Novice Emacs Lisp programmers often try to use the mark for the wrong
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1670 purposes. See the documentation of `set-mark' for more information."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1671 (setq buffer (decode-buffer buffer)) ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1672 (if (null (mark t buffer)) ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1673 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1674 ;; The save-excursion / set-buffer is necessary because mark-ring
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1675 ;; is a buffer local variable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1676 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1677 (set-buffer buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1678 (setq mark-ring (cons (copy-marker (mark-marker t buffer)) mark-ring))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1679 (if (> (length mark-ring) mark-ring-max)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1680 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1681 (move-marker (car (nthcdr mark-ring-max mark-ring)) nil buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1682 (setcdr (nthcdr (1- mark-ring-max) mark-ring) nil)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1683 (set-mark (or location (point buffer)) buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1684 ; (set-marker (mark-marker) (or location (point)) (current-buffer)) ; FSF
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1685 ;; Now push the mark on the global mark ring.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1686 (if (or (null global-mark-ring)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1687 (not (eq (marker-buffer (car global-mark-ring)) buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1688 ;; The last global mark pushed wasn't in this same buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1689 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1690 (setq global-mark-ring (cons (copy-marker (mark-marker t buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1691 global-mark-ring))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1692 (if (> (length global-mark-ring) global-mark-ring-max)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1693 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1694 (move-marker (car (nthcdr global-mark-ring-max global-mark-ring))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1695 nil buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1696 (setcdr (nthcdr (1- global-mark-ring-max) global-mark-ring) nil)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1697 (or nomsg executing-kbd-macro (> (minibuffer-depth) 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1698 (display-message 'command "Mark set"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1699 (if activate-region
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1700 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1701 (setq zmacs-region-stays t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1702 (zmacs-activate-region)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1703 ; (if (or activate (not transient-mark-mode)) ; FSF
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1704 ; (set-mark (mark t))) ; FSF
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1705 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1706
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1707 (defun pop-mark ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1708 "Pop off mark ring into the buffer's actual mark.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1709 Does not set point. Does nothing if mark ring is empty."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1710 (if mark-ring
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1711 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1712 (setq mark-ring (nconc mark-ring (list (copy-marker (mark-marker t)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1713 (set-mark (car mark-ring))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1714 (move-marker (car mark-ring) nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1715 (if (null (mark t)) (ding))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1716 (setq mark-ring (cdr mark-ring)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1717
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1718 (define-function 'exchange-dot-and-mark 'exchange-point-and-mark)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1719 (defun exchange-point-and-mark (&optional dont-activate-region)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1720 "Put the mark where point is now, and point where the mark is now.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1721 The mark is activated unless DONT-ACTIVATE-REGION is non-nil."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1722 (interactive nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1723 (let ((omark (mark t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1724 (if (null omark)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1725 (error "No mark set in this buffer"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1726 (set-mark (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1727 (goto-char omark)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1728 (or dont-activate-region (zmacs-activate-region)) ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1729 nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1730
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1731 ;; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1732 (defun mark-something (mark-fn movement-fn arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1733 "internal function used by mark-sexp, mark-word, etc."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1734 (let (newmark (pushp t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1735 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1736 (if (and (eq last-command mark-fn) (mark))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1737 ;; Extend the previous state in the same direction:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1738 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1739 (if (< (mark) (point)) (setq arg (- arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1740 (goto-char (mark))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1741 (setq pushp nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1742 (funcall movement-fn arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1743 (setq newmark (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1744 (if pushp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1745 (push-mark newmark nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1746 ;; Do not mess with the mark stack, but merely adjust the previous state:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1747 (set-mark newmark)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1748 (activate-region))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1749
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1750 ;(defun transient-mark-mode (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1751 ; "Toggle Transient Mark mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1752 ;With arg, turn Transient Mark mode on if arg is positive, off otherwise.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1753 ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1754 ;In Transient Mark mode, when the mark is active, the region is highlighted.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1755 ;Changing the buffer \"deactivates\" the mark.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1756 ;So do certain other operations that set the mark
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1757 ;but whose main purpose is something else--for example,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1758 ;incremental search, \\[beginning-of-buffer], and \\[end-of-buffer]."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1759 ; (interactive "P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1760 ; (setq transient-mark-mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1761 ; (if (null arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1762 ; (not transient-mark-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1763 ; (> (prefix-numeric-value arg) 0))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1764
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1765 (defun pop-global-mark ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1766 "Pop off global mark ring and jump to the top location."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1767 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1768 ;; Pop entries which refer to non-existent buffers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1769 (while (and global-mark-ring (not (marker-buffer (car global-mark-ring))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1770 (setq global-mark-ring (cdr global-mark-ring)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1771 (or global-mark-ring
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1772 (error "No global mark set"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1773 (let* ((marker (car global-mark-ring))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1774 (buffer (marker-buffer marker))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1775 (position (marker-position marker)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1776 (setq global-mark-ring (nconc (cdr global-mark-ring)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1777 (list (car global-mark-ring))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1778 (set-buffer buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1779 (or (and (>= position (point-min))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1780 (<= position (point-max)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1781 (widen))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1782 (goto-char position)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1783 (switch-to-buffer buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1784
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1785
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1786 (defcustom signal-error-on-buffer-boundary t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1787 "*Non-nil value causes XEmacs to beep or signal an error when certain interactive commands would move point past (point-min) or (point-max).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1788 The commands that honor this variable are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1789
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1790 forward-char-command
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1791 backward-char-command
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1792 next-line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1793 previous-line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1794 scroll-up-command
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1795 scroll-down-command"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1796 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1797 :group 'editing-basics)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1798
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1799 ;;; After 8 years of waiting ... -sb
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1800 (defcustom next-line-add-newlines nil ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1801 "*If non-nil, `next-line' inserts newline when the point is at end of buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1802 This behavior used to be the default, and is still default in FSF Emacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1803 We think it is an unnecessary and unwanted side-effect."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1804 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1805 :group 'editing-basics)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1806
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1807 (defun forward-char-command (&optional arg buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1808 "Move point right ARG characters (left if ARG negative) in BUFFER.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1809 On attempt to pass end of buffer, stop and signal `end-of-buffer'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1810 On attempt to pass beginning of buffer, stop and signal `beginning-of-buffer'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1811 Error signaling is suppressed if `signal-error-on-buffer-boundary'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1812 is nil. If BUFFER is nil, the current buffer is assumed."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1813 (interactive "_p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1814 (if signal-error-on-buffer-boundary
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1815 (forward-char arg buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1816 (condition-case nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1817 (forward-char arg buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1818 (beginning-of-buffer nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1819 (end-of-buffer nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1820
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1821 (defun backward-char-command (&optional arg buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1822 "Move point left ARG characters (right if ARG negative) in BUFFER.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1823 On attempt to pass end of buffer, stop and signal `end-of-buffer'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1824 On attempt to pass beginning of buffer, stop and signal `beginning-of-buffer'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1825 Error signaling is suppressed if `signal-error-on-buffer-boundary'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1826 is nil. If BUFFER is nil, the current buffer is assumed."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1827 (interactive "_p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1828 (if signal-error-on-buffer-boundary
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1829 (backward-char arg buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1830 (condition-case nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1831 (backward-char arg buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1832 (beginning-of-buffer nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1833 (end-of-buffer nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1834
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1835 (defun scroll-up-command (&optional n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1836 "Scroll text of current window upward ARG lines; or near full screen if no ARG.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1837 A near full screen is `next-screen-context-lines' less than a full screen.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1838 Negative ARG means scroll downward.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1839 When calling from a program, supply a number as argument or nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1840 On attempt to scroll past end of buffer, `end-of-buffer' is signaled.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1841 On attempt to scroll past beginning of buffer, `beginning-of-buffer' is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1842 signaled.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1843
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1844 If `signal-error-on-buffer-boundary' is nil, attempts to scroll past buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1845 boundaries do not cause an error to be signaled."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1846 (interactive "_P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1847 (if signal-error-on-buffer-boundary
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1848 (scroll-up n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1849 (condition-case nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1850 (scroll-up n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1851 (beginning-of-buffer nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1852 (end-of-buffer nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1853
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1854 (defun scroll-down-command (&optional n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1855 "Scroll text of current window downward ARG lines; or near full screen if no ARG.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1856 A near full screen is `next-screen-context-lines' less than a full screen.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1857 Negative ARG means scroll upward.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1858 When calling from a program, supply a number as argument or nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1859 On attempt to scroll past end of buffer, `end-of-buffer' is signaled.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1860 On attempt to scroll past beginning of buffer, `beginning-of-buffer' is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1861 signaled.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1862
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1863 If `signal-error-on-buffer-boundary' is nil, attempts to scroll past buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1864 boundaries do not cause an error to be signaled."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1865 (interactive "_P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1866 (if signal-error-on-buffer-boundary
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1867 (scroll-down n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1868 (condition-case nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1869 (scroll-down n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1870 (beginning-of-buffer nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1871 (end-of-buffer nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1872
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1873 (defun next-line (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1874 "Move cursor vertically down ARG lines.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1875 If there is no character in the target line exactly under the current column,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1876 the cursor is positioned after the character in that line which spans this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1877 column, or at the end of the line if it is not long enough.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1878
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1879 If there is no line in the buffer after this one, behavior depends on the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1880 value of `next-line-add-newlines'. If non-nil, it inserts a newline character
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1881 to create a line, and moves the cursor to that line. Otherwise it moves the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1882 cursor to the end of the buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1883
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1884 The command \\[set-goal-column] can be used to create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1885 a semipermanent goal column to which this command always moves.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1886 Then it does not try to move vertically. This goal column is stored
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1887 in `goal-column', which is nil when there is none.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1888
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1889 If you are thinking of using this in a Lisp program, consider
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1890 using `forward-line' instead. It is usually easier to use
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1891 and more reliable (no dependence on goal column, etc.)."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1892 (interactive "_p") ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1893 (if (and next-line-add-newlines (= arg 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1894 (let ((opoint (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1895 (end-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1896 (if (eobp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1897 (newline 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1898 (goto-char opoint)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1899 (line-move arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1900 (if (interactive-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1901 ;; XEmacs: Not sure what to do about this. It's inconsistent. -sb
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1902 (condition-case nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1903 (line-move arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1904 ((beginning-of-buffer end-of-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1905 (when signal-error-on-buffer-boundary
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1906 (ding nil 'buffer-bound))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1907 (line-move arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1908 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1909
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1910 (defun previous-line (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1911 "Move cursor vertically up ARG lines.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1912 If there is no character in the target line exactly over the current column,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1913 the cursor is positioned after the character in that line which spans this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1914 column, or at the end of the line if it is not long enough.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1915
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1916 The command \\[set-goal-column] can be used to create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1917 a semipermanent goal column to which this command always moves.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1918 Then it does not try to move vertically.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1919
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1920 If you are thinking of using this in a Lisp program, consider using
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1921 `forward-line' with a negative argument instead. It is usually easier
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1922 to use and more reliable (no dependence on goal column, etc.)."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1923 (interactive "_p") ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1924 (if (interactive-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1925 (condition-case nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1926 (line-move (- arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1927 ((beginning-of-buffer end-of-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1928 (when signal-error-on-buffer-boundary ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1929 (ding nil 'buffer-bound))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1930 (line-move (- arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1931 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1932
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1933 (defcustom track-eol nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1934 "*Non-nil means vertical motion starting at end of line keeps to ends of lines.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1935 This means moving to the end of each line moved onto.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1936 The beginning of a blank line does not count as the end of a line."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1937 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1938 :group 'editing-basics)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1939
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1940 (defcustom goal-column nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1941 "*Semipermanent goal column for vertical motion, as set by \\[set-goal-column], or nil."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1942 :type '(choice integer (const :tag "None" nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1943 :group 'editing-basics)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1944 (make-variable-buffer-local 'goal-column)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1945
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1946 (defvar temporary-goal-column 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1947 "Current goal column for vertical motion.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1948 It is the column where point was
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1949 at the start of current run of vertical motion commands.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1950 When the `track-eol' feature is doing its job, the value is 9999.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1951 (make-variable-buffer-local 'temporary-goal-column)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1952
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1953 ;XEmacs: not yet ported, so avoid compiler warnings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1954 (eval-when-compile
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1955 (defvar inhibit-point-motion-hooks))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1956
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1957 (defcustom line-move-ignore-invisible nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1958 "*Non-nil means \\[next-line] and \\[previous-line] ignore invisible lines.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1959 Use with care, as it slows down movement significantly. Outline mode sets this."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1960 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1961 :group 'editing-basics)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1962
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1963 ;; This is the guts of next-line and previous-line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1964 ;; Arg says how many lines to move.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1965 (defun line-move (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1966 ;; Don't run any point-motion hooks, and disregard intangibility,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1967 ;; for intermediate positions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1968 (let ((inhibit-point-motion-hooks t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1969 (opoint (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1970 new)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1971 (unwind-protect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1972 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1973 (if (not (or (eq last-command 'next-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1974 (eq last-command 'previous-line)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1975 (setq temporary-goal-column
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1976 (if (and track-eol (eolp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1977 ;; Don't count beg of empty line as end of line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1978 ;; unless we just did explicit end-of-line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1979 (or (not (bolp)) (eq last-command 'end-of-line)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1980 9999
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1981 (current-column))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1982 (if (and (not (integerp selective-display))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1983 (not line-move-ignore-invisible))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1984 ;; Use just newline characters.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1985 (or (if (> arg 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1986 (progn (if (> arg 1) (forward-line (1- arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1987 ;; This way of moving forward ARG lines
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1988 ;; verifies that we have a newline after the last one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1989 ;; It doesn't get confused by intangible text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1990 (end-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1991 (zerop (forward-line 1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1992 (and (zerop (forward-line arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1993 (bolp)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1994 (signal (if (< arg 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1995 'beginning-of-buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1996 'end-of-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1997 nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1998 ;; Move by arg lines, but ignore invisible ones.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1999 (while (> arg 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2000 (end-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2001 (and (zerop (vertical-motion 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2002 (signal 'end-of-buffer nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2003 ;; If the following character is currently invisible,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2004 ;; skip all characters with that same `invisible' property value.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2005 (while (and (not (eobp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2006 (let ((prop
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2007 (get-char-property (point) 'invisible)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2008 (if (eq buffer-invisibility-spec t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2009 prop
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2010 (or (memq prop buffer-invisibility-spec)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2011 (assq prop buffer-invisibility-spec)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2012 (if (get-text-property (point) 'invisible)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2013 (goto-char (next-single-property-change (point) 'invisible))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2014 (goto-char (next-extent-change (point))))) ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2015 (setq arg (1- arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2016 (while (< arg 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2017 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2018 (and (zerop (vertical-motion -1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2019 (signal 'beginning-of-buffer nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2020 (while (and (not (bobp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2021 (let ((prop
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2022 (get-char-property (1- (point)) 'invisible)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2023 (if (eq buffer-invisibility-spec t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2024 prop
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2025 (or (memq prop buffer-invisibility-spec)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2026 (assq prop buffer-invisibility-spec)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2027 (if (get-text-property (1- (point)) 'invisible)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2028 (goto-char (previous-single-property-change (point) 'invisible))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2029 (goto-char (previous-extent-change (point))))) ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2030 (setq arg (1+ arg))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2031 (move-to-column (or goal-column temporary-goal-column)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2032 ;; Remember where we moved to, go back home,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2033 ;; then do the motion over again
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2034 ;; in just one step, with intangibility and point-motion hooks
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2035 ;; enabled this time.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2036 (setq new (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2037 (goto-char opoint)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2038 (setq inhibit-point-motion-hooks nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2039 (goto-char new)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2040 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2041
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2042 ;;; Many people have said they rarely use this feature, and often type
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2043 ;;; it by accident. Maybe it shouldn't even be on a key.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2044 ;; It's not on a key, as of 20.2. So no need for this.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2045 ;(put 'set-goal-column 'disabled t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2046
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2047 (defun set-goal-column (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2048 "Set the current horizontal position as a goal for \\[next-line] and \\[previous-line].
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2049 Those commands will move to this position in the line moved to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2050 rather than trying to keep the same horizontal position.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2051 With a non-nil argument, clears out the goal column
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2052 so that \\[next-line] and \\[previous-line] resume vertical motion.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2053 The goal column is stored in the variable `goal-column'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2054 (interactive "_P") ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2055 (if arg
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2056 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2057 (setq goal-column nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2058 (display-message 'command "No goal column"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2059 (setq goal-column (current-column))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2060 (lmessage 'command
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2061 "Goal column %d (use %s with an arg to unset it)"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2062 goal-column
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2063 (substitute-command-keys "\\[set-goal-column]")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2064 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2065
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2066 ;; deleted FSFmacs terminal randomness hscroll-point-visible stuff.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2067 ;; hscroll-step
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2068 ;; hscroll-point-visible
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2069 ;; hscroll-window-column
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2070 ;; right-arrow
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2071 ;; left-arrow
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2072
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2073 (defun scroll-other-window-down (lines)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2074 "Scroll the \"other window\" down.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2075 For more details, see the documentation for `scroll-other-window'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2076 (interactive "P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2077 (scroll-other-window
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2078 ;; Just invert the argument's meaning.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2079 ;; We can do that without knowing which window it will be.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2080 (if (eq lines '-) nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2081 (if (null lines) '-
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2082 (- (prefix-numeric-value lines))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2083 ;(define-key esc-map [?\C-\S-v] 'scroll-other-window-down)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2084
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2085 (defun beginning-of-buffer-other-window (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2086 "Move point to the beginning of the buffer in the other window.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2087 Leave mark at previous position.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2088 With arg N, put point N/10 of the way from the true beginning."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2089 (interactive "P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2090 (let ((orig-window (selected-window))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2091 (window (other-window-for-scrolling)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2092 ;; We use unwind-protect rather than save-window-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2093 ;; because the latter would preserve the things we want to change.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2094 (unwind-protect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2095 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2096 (select-window window)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2097 ;; Set point and mark in that window's buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2098 (beginning-of-buffer arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2099 ;; Set point accordingly.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2100 (recenter '(t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2101 (select-window orig-window))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2102
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2103 (defun end-of-buffer-other-window (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2104 "Move point to the end of the buffer in the other window.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2105 Leave mark at previous position.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2106 With arg N, put point N/10 of the way from the true end."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2107 (interactive "P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2108 ;; See beginning-of-buffer-other-window for comments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2109 (let ((orig-window (selected-window))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2110 (window (other-window-for-scrolling)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2111 (unwind-protect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2112 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2113 (select-window window)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2114 (end-of-buffer arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2115 (recenter '(t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2116 (select-window orig-window))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2117
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2118 (defun transpose-chars (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2119 "Interchange characters around point, moving forward one character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2120 With prefix arg ARG, effect is to take character before point
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2121 and drag it forward past ARG other characters (backward if ARG negative).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2122 If no argument and at end of line, the previous two chars are exchanged."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2123 (interactive "*P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2124 (and (null arg) (eolp) (forward-char -1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2125 (transpose-subr 'forward-char (prefix-numeric-value arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2126
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2127 ;;; A very old implementation of transpose-chars from the old days ...
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2128 (defun transpose-preceding-chars (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2129 "Interchange characters before point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2130 With prefix arg ARG, effect is to take character before point
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2131 and drag it forward past ARG other characters (backward if ARG negative).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2132 If no argument and not at start of line, the previous two chars are exchanged."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2133 (interactive "*P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2134 (and (null arg) (not (bolp)) (forward-char -1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2135 (transpose-subr 'forward-char (prefix-numeric-value arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2136
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2137
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2138 (defun transpose-words (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2139 "Interchange words around point, leaving point at end of them.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2140 With prefix arg ARG, effect is to take word before or around point
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2141 and drag it forward past ARG other words (backward if ARG negative).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2142 If ARG is zero, the words around or after point and around or after mark
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2143 are interchanged."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2144 (interactive "*p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2145 (transpose-subr 'forward-word arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2146
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2147 (defun transpose-sexps (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2148 "Like \\[transpose-words] but applies to sexps.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2149 Does not work on a sexp that point is in the middle of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2150 if it is a list or string."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2151 (interactive "*p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2152 (transpose-subr 'forward-sexp arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2153
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2154 (defun transpose-lines (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2155 "Exchange current line and previous line, leaving point after both.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2156 With argument ARG, takes previous line and moves it past ARG lines.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2157 With argument 0, interchanges line point is in with line mark is in."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2158 (interactive "*p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2159 (transpose-subr #'(lambda (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2160 (if (= arg 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2161 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2162 ;; Move forward over a line,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2163 ;; but create a newline if none exists yet.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2164 (end-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2165 (if (eobp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2166 (newline)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2167 (forward-char 1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2168 (forward-line arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2169 arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2170
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2171 (eval-when-compile
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2172 ;; avoid byte-compiler warnings...
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2173 (defvar start1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2174 (defvar start2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2175 (defvar end1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2176 (defvar end2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2177
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2178 ; start[12] and end[12] used in transpose-subr-1 below
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2179 (defun transpose-subr (mover arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2180 (let (start1 end1 start2 end2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2181 (if (= arg 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2182 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2183 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2184 (funcall mover 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2185 (setq end2 (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2186 (funcall mover -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2187 (setq start2 (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2188 (goto-char (mark t)) ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2189 (funcall mover 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2190 (setq end1 (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2191 (funcall mover -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2192 (setq start1 (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2193 (transpose-subr-1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2194 (exchange-point-and-mark t))) ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2195 (while (> arg 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2196 (funcall mover -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2197 (setq start1 (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2198 (funcall mover 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2199 (setq end1 (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2200 (funcall mover 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2201 (setq end2 (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2202 (funcall mover -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2203 (setq start2 (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2204 (transpose-subr-1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2205 (goto-char end2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2206 (setq arg (1- arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2207 (while (< arg 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2208 (funcall mover -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2209 (setq start2 (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2210 (funcall mover -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2211 (setq start1 (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2212 (funcall mover 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2213 (setq end1 (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2214 (funcall mover 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2215 (setq end2 (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2216 (transpose-subr-1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2217 (setq arg (1+ arg)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2218
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2219 ; start[12] and end[12] used free
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2220 (defun transpose-subr-1 ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2221 (if (> (min end1 end2) (max start1 start2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2222 (error "Don't have two things to transpose"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2223 (let ((word1 (buffer-substring start1 end1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2224 (word2 (buffer-substring start2 end2)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2225 (delete-region start2 end2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2226 (goto-char start2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2227 (insert word1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2228 (goto-char (if (< start1 start2) start1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2229 (+ start1 (- (length word1) (length word2)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2230 (delete-char (length word1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2231 (insert word2)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2232
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2233 (defcustom comment-column 32
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2234 "*Column to indent right-margin comments to.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2235 Setting this variable automatically makes it local to the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2236 Each mode establishes a different default value for this variable; you
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2237 can set the value for a particular mode using that mode's hook."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2238 :type 'integer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2239 :group 'fill-comments)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2240 (make-variable-buffer-local 'comment-column)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2241
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2242 (defcustom comment-start nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2243 "*String to insert to start a new comment, or nil if no comment syntax."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2244 :type '(choice (const :tag "None" nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2245 string)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2246 :group 'fill-comments)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2247
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2248 (defcustom comment-start-skip nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2249 "*Regexp to match the start of a comment plus everything up to its body.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2250 If there are any \\(...\\) pairs, the comment delimiter text is held to begin
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2251 at the place matched by the close of the first pair."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2252 :type '(choice (const :tag "None" nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2253 regexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2254 :group 'fill-comments)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2255
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2256 (defcustom comment-end ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2257 "*String to insert to end a new comment.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2258 Should be an empty string if comments are terminated by end-of-line."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2259 :type 'string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2260 :group 'fill-comments)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2261
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2262 (defconst comment-indent-hook nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2263 "Obsolete variable for function to compute desired indentation for a comment.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2264 Use `comment-indent-function' instead.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2265 This function is called with no args with point at the beginning of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2266 the comment's starting delimiter.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2267
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2268 (defconst comment-indent-function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2269 ;; XEmacs - add at least one space after the end of the text on the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2270 ;; current line...
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2271 (lambda ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2272 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2273 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2274 (let ((eol (save-excursion (end-of-line) (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2275 (and comment-start-skip
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2276 (re-search-forward comment-start-skip eol t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2277 (setq eol (match-beginning 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2278 (goto-char eol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2279 (skip-chars-backward " \t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2280 (max comment-column (1+ (current-column))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2281 "Function to compute desired indentation for a comment.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2282 This function is called with no args with point at the beginning of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2283 the comment's starting delimiter.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2284
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2285 (defcustom block-comment-start nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2286 "*String to insert to start a new comment on a line by itself.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2287 If nil, use `comment-start' instead.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2288 Note that the regular expression `comment-start-skip' should skip this string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2289 as well as the `comment-start' string."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2290 :type '(choice (const :tag "Use `comment-start'" nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2291 string)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2292 :group 'fill-comments)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2293
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2294 (defcustom block-comment-end nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2295 "*String to insert to end a new comment on a line by itself.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2296 Should be an empty string if comments are terminated by end-of-line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2297 If nil, use `comment-end' instead."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2298 :type '(choice (const :tag "Use `comment-end'" nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2299 string)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2300 :group 'fill-comments)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2301
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2302 (defun indent-for-comment ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2303 "Indent this line's comment to comment column, or insert an empty comment."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2304 (interactive "*")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2305 (let* ((empty (save-excursion (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2306 (looking-at "[ \t]*$")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2307 (starter (or (and empty block-comment-start) comment-start))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2308 (ender (or (and empty block-comment-end) comment-end)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2309 (if (null starter)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2310 (error "No comment syntax defined")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2311 (let* ((eolpos (save-excursion (end-of-line) (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2312 cpos indent begpos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2313 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2314 (if (re-search-forward comment-start-skip eolpos 'move)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2315 (progn (setq cpos (point-marker))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2316 ;; Find the start of the comment delimiter.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2317 ;; If there were paren-pairs in comment-start-skip,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2318 ;; position at the end of the first pair.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2319 (if (match-end 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2320 (goto-char (match-end 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2321 ;; If comment-start-skip matched a string with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2322 ;; internal whitespace (not final whitespace) then
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2323 ;; the delimiter start at the end of that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2324 ;; whitespace. Otherwise, it starts at the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2325 ;; beginning of what was matched.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2326 (skip-syntax-backward " " (match-beginning 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2327 (skip-syntax-backward "^ " (match-beginning 0)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2328 (setq begpos (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2329 ;; Compute desired indent.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2330 (if (= (current-column)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2331 (setq indent (funcall comment-indent-function)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2332 (goto-char begpos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2333 ;; If that's different from current, change it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2334 (skip-chars-backward " \t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2335 (delete-region (point) begpos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2336 (indent-to indent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2337 ;; An existing comment?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2338 (if cpos
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2339 (progn (goto-char cpos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2340 (set-marker cpos nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2341 ;; No, insert one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2342 (insert starter)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2343 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2344 (insert ender)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2345
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2346 (defun set-comment-column (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2347 "Set the comment column based on point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2348 With no arg, set the comment column to the current column.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2349 With just minus as arg, kill any comment on this line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2350 With any other arg, set comment column to indentation of the previous comment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2351 and then align or create a comment on this line at that column."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2352 (interactive "P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2353 (if (eq arg '-)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2354 (kill-comment nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2355 (if arg
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2356 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2357 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2358 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2359 (re-search-backward comment-start-skip)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2360 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2361 (re-search-forward comment-start-skip)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2362 (goto-char (match-beginning 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2363 (setq comment-column (current-column))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2364 (lmessage 'command "Comment column set to %d" comment-column))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2365 (indent-for-comment))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2366 (setq comment-column (current-column))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2367 (lmessage 'command "Comment column set to %d" comment-column))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2368
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2369 (defun kill-comment (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2370 "Kill the comment on this line, if any.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2371 With argument, kill comments on that many lines starting with this one."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2372 ;; this function loses in a lot of situations. it incorrectly recognizes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2373 ;; comment delimiters sometimes (ergo, inside a string), doesn't work
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2374 ;; with multi-line comments, can kill extra whitespace if comment wasn't
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2375 ;; through end-of-line, et cetera.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2376 (interactive "*P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2377 (or comment-start-skip (error "No comment syntax defined"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2378 (let ((count (prefix-numeric-value arg)) endc)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2379 (while (> count 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2380 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2381 (end-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2382 (setq endc (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2383 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2384 (and (string< "" comment-end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2385 (setq endc
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2386 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2387 (re-search-forward (regexp-quote comment-end) endc 'move)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2388 (skip-chars-forward " \t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2389 (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2390 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2391 (if (re-search-forward comment-start-skip endc t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2392 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2393 (goto-char (match-beginning 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2394 (skip-chars-backward " \t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2395 (kill-region (point) endc)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2396 ;; to catch comments a line beginnings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2397 (indent-according-to-mode))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2398 (if arg (forward-line 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2399 (setq count (1- count)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2400
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2401 (defun comment-region (beg end &optional arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2402 "Comment or uncomment each line in the region.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2403 With just C-u prefix arg, uncomment each line in region.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2404 Numeric prefix arg ARG means use ARG comment characters.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2405 If ARG is negative, delete that many comment characters instead.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2406 Comments are terminated on each line, even for syntax in which newline does
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2407 not end the comment. Blank lines do not get comments."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2408 ;; if someone wants it to only put a comment-start at the beginning and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2409 ;; comment-end at the end then typing it, C-x C-x, closing it, C-x C-x
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2410 ;; is easy enough. No option is made here for other than commenting
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2411 ;; every line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2412 (interactive "r\nP")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2413 (or comment-start (error "No comment syntax is defined"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2414 (if (> beg end) (let (mid) (setq mid beg beg end end mid)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2415 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2416 (save-restriction
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2417 (let ((cs comment-start) (ce comment-end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2418 numarg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2419 (if (consp arg) (setq numarg t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2420 (setq numarg (prefix-numeric-value arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2421 ;; For positive arg > 1, replicate the comment delims now,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2422 ;; then insert the replicated strings just once.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2423 (while (> numarg 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2424 (setq cs (concat cs comment-start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2425 ce (concat ce comment-end))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2426 (setq numarg (1- numarg))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2427 ;; Loop over all lines from BEG to END.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2428 (narrow-to-region beg end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2429 (goto-char beg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2430 (while (not (eobp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2431 (if (or (eq numarg t) (< numarg 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2432 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2433 ;; Delete comment start from beginning of line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2434 (if (eq numarg t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2435 (while (looking-at (regexp-quote cs))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2436 (delete-char (length cs)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2437 (let ((count numarg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2438 (while (and (> 1 (setq count (1+ count)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2439 (looking-at (regexp-quote cs)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2440 (delete-char (length cs)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2441 ;; Delete comment end from end of line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2442 (if (string= "" ce)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2443 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2444 (if (eq numarg t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2445 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2446 (end-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2447 ;; This is questionable if comment-end ends in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2448 ;; whitespace. That is pretty brain-damaged,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2449 ;; though.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2450 (skip-chars-backward " \t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2451 (if (and (>= (- (point) (point-min)) (length ce))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2452 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2453 (backward-char (length ce))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2454 (looking-at (regexp-quote ce))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2455 (delete-char (- (length ce)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2456 (let ((count numarg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2457 (while (> 1 (setq count (1+ count)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2458 (end-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2459 ;; This is questionable if comment-end ends in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2460 ;; whitespace. That is pretty brain-damaged though
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2461 (skip-chars-backward " \t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2462 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2463 (backward-char (length ce))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2464 (if (looking-at (regexp-quote ce))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2465 (delete-char (length ce))))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2466 (forward-line 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2467 ;; Insert at beginning and at end.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2468 (if (looking-at "[ \t]*$") ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2469 (insert cs)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2470 (if (string= "" ce) ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2471 (end-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2472 (insert ce)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2473 (search-forward "\n" nil 'move)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2474
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2475 ;; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2476 (defun prefix-region (prefix)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2477 "Add a prefix string to each line between mark and point."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2478 (interactive "sPrefix string: ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2479 (if prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2480 (let ((count (count-lines (mark) (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2481 (goto-char (min (mark) (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2482 (while (> count 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2483 (setq count (1- count))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2484 (beginning-of-line 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2485 (insert prefix)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2486 (end-of-line 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2487 (forward-char 1)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2488
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2489
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2490 ;; XEmacs - extra parameter
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2491 (defun backward-word (arg &optional buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2492 "Move backward until encountering the end of a word.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2493 With argument, do this that many times.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2494 In programs, it is faster to call `forward-word' with negative arg."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2495 (interactive "_p") ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2496 (forward-word (- arg) buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2497
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2498 (defun mark-word (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2499 "Set mark arg words away from point."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2500 (interactive "p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2501 (mark-something 'mark-word 'forward-word arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2502
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2503 ;; XEmacs modified
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2504 (defun kill-word (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2505 "Kill characters forward until encountering the end of a word.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2506 With argument, do this that many times."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2507 (interactive "*p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2508 (kill-region (point) (save-excursion (forward-word arg) (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2509
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2510 (defun backward-kill-word (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2511 "Kill characters backward until encountering the end of a word.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2512 With argument, do this that many times."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2513 (interactive "*p") ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2514 (kill-word (- arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2515
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2516 (defun current-word (&optional strict)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2517 "Return the word point is on (or a nearby word) as a string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2518 If optional arg STRICT is non-nil, return nil unless point is within
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2519 or adjacent to a word.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2520 If point is not between two word-constituent characters, but immediately
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2521 follows one, move back first.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2522 Otherwise, if point precedes a word constituent, move forward first.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2523 Otherwise, move backwards until a word constituent is found and get that word;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2524 if you a newlines is reached first, move forward instead."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2525 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2526 (let ((oldpoint (point)) (start (point)) (end (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2527 (skip-syntax-backward "w_") (setq start (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2528 (goto-char oldpoint)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2529 (skip-syntax-forward "w_") (setq end (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2530 (if (and (eq start oldpoint) (eq end oldpoint))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2531 ;; Point is neither within nor adjacent to a word.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2532 (and (not strict)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2533 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2534 ;; Look for preceding word in same line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2535 (skip-syntax-backward "^w_"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2536 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2537 (beginning-of-line) (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2538 (if (bolp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2539 ;; No preceding word in same line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2540 ;; Look for following word in same line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2541 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2542 (skip-syntax-forward "^w_"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2543 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2544 (end-of-line) (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2545 (setq start (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2546 (skip-syntax-forward "w_")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2547 (setq end (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2548 (setq end (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2549 (skip-syntax-backward "w_")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2550 (setq start (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2551 (buffer-substring start end)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2552 (buffer-substring start end)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2553
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2554 (defcustom fill-prefix nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2555 "*String for filling to insert at front of new line, or nil for none.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2556 Setting this variable automatically makes it local to the current buffer."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2557 :type '(choice (const :tag "None" nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2558 string)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2559 :group 'fill)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2560 (make-variable-buffer-local 'fill-prefix)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2561
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2562 (defcustom auto-fill-inhibit-regexp nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2563 "*Regexp to match lines which should not be auto-filled."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2564 :type '(choice (const :tag "None" nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2565 regexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2566 :group 'fill)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2567
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2568 (defvar comment-line-break-function 'indent-new-comment-line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2569 "*Mode-specific function which line breaks and continues a comment.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2570
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2571 This function is only called during auto-filling of a comment section.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2572 The function should take a single optional argument which is a flag
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2573 indicating whether soft newlines should be inserted.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2574
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2575 ;; defined in mule-base/mule-category.el
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2576 (defvar word-across-newline)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2577
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2578 ;; This function is the auto-fill-function of a buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2579 ;; when Auto-Fill mode is enabled.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2580 ;; It returns t if it really did any work.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2581 ;; XEmacs: This function is totally different.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2582 (defun do-auto-fill ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2583 (let (give-up)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2584 (or (and auto-fill-inhibit-regexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2585 (save-excursion (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2586 (looking-at auto-fill-inhibit-regexp)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2587 (while (and (not give-up) (> (current-column) fill-column))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2588 ;; Determine where to split the line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2589 (let ((fill-prefix fill-prefix)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2590 (fill-point
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2591 (let ((opoint (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2592 bounce
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2593 ;; 97/3/14 jhod: Kinsoku
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2594 (re-break-point (if (featurep 'mule)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2595 (concat "[ \t\n]\\|" word-across-newline
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2596 ".\\|." word-across-newline)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2597 "[ \t\n]"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2598 ;; end patch
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2599 (first t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2600 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2601 (move-to-column (1+ fill-column))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2602 ;; Move back to a word boundary.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2603 (while (or first
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2604 ;; If this is after period and a single space,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2605 ;; move back once more--we don't want to break
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2606 ;; the line there and make it look like a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2607 ;; sentence end.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2608 (and (not (bobp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2609 (not bounce)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2610 sentence-end-double-space
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2611 (save-excursion (forward-char -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2612 (and (looking-at "\\. ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2613 (not (looking-at "\\. "))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2614 (setq first nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2615 ;; 97/3/14 jhod: Kinsoku
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2616 ; (skip-chars-backward "^ \t\n"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2617 (fill-move-backward-to-break-point re-break-point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2618 ;; end patch
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2619 ;; If we find nowhere on the line to break it,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2620 ;; break after one word. Set bounce to t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2621 ;; so we will not keep going in this while loop.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2622 (if (bolp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2623 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2624 ;; 97/3/14 jhod: Kinsoku
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2625 ; (re-search-forward "[ \t]" opoint t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2626 (fill-move-forward-to-break-point re-break-point
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2627 opoint)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2628 ;; end patch
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2629 (setq bounce t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2630 (skip-chars-backward " \t"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2631 (if (and (featurep 'mule)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2632 (or bounce (bolp))) (kinsoku-process)) ;; 97/3/14 jhod: Kinsoku
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2633 ;; Let fill-point be set to the place where we end up.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2634 (point)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2635
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2636 ;; I'm not sure why Stig made this change but it breaks
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2637 ;; auto filling in at least C mode so I'm taking it back
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2638 ;; out. --cet
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2639 ;; XEmacs - adaptive fill.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2640 ;;(maybe-adapt-fill-prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2641 ;; (or from (setq from (save-excursion (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2642 ;; (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2643 ;; (or to (setq to (save-excursion (beginning-of-line 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2644 ;; (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2645 ;; t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2646
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2647 ;; If that place is not the beginning of the line,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2648 ;; break the line there.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2649 (if (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2650 (goto-char fill-point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2651 (not (or (bolp) (eolp)))) ; 97/3/14 jhod: during kinsoku processing it is possible to move beyond
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2652 (let ((prev-column (current-column)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2653 ;; If point is at the fill-point, do not `save-excursion'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2654 ;; Otherwise, if a comment prefix or fill-prefix is inserted,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2655 ;; point will end up before it rather than after it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2656 (if (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2657 (skip-chars-backward " \t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2658 (= (point) fill-point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2659 ;; 1999-09-17 hniksic: turn off Kinsoku until
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2660 ;; it's debugged.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2661 (indent-new-comment-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2662 ;; 97/3/14 jhod: Kinsoku processing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2663 ; ;(indent-new-comment-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2664 ; (let ((spacep (memq (char-before (point)) '(?\ ?\t))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2665 ; (funcall comment-line-break-function)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2666 ; ;; if user type space explicitly, leave SPC
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2667 ; ;; even if there is no WAN.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2668 ; (if spacep
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2669 ; (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2670 ; (goto-char fill-point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2671 ; ;; put SPC except that there is SPC
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2672 ; ;; already or there is sentence end.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2673 ; (or (memq (char-after (point)) '(?\ ?\t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2674 ; (fill-end-of-sentence-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2675 ; (insert ?\ )))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2676 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2677 (goto-char fill-point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2678 (funcall comment-line-break-function)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2679 ;; If making the new line didn't reduce the hpos of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2680 ;; the end of the line, then give up now;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2681 ;; trying again will not help.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2682 (if (>= (current-column) prev-column)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2683 (setq give-up t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2684 ;; No place to break => stop trying.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2685 (setq give-up t)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2686
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2687 ;; Put FSF one in until I can one or the other working properly, then the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2688 ;; other one is history.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2689 ;(defun fsf:do-auto-fill ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2690 ; (let (fc justify
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2691 ; ;; bol
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2692 ; give-up
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2693 ; (fill-prefix fill-prefix))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2694 ; (if (or (not (setq justify (current-justification)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2695 ; (null (setq fc (current-fill-column)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2696 ; (and (eq justify 'left)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2697 ; (<= (current-column) fc))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2698 ; (save-excursion (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2699 ; ;; (setq bol (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2700 ; (and auto-fill-inhibit-regexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2701 ; (looking-at auto-fill-inhibit-regexp))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2702 ; nil ;; Auto-filling not required
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2703 ; (if (memq justify '(full center right))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2704 ; (save-excursion (unjustify-current-line)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2705
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2706 ; ;; Choose a fill-prefix automatically.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2707 ; (if (and adaptive-fill-mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2708 ; (or (null fill-prefix) (string= fill-prefix "")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2709 ; (let ((prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2710 ; (fill-context-prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2711 ; (save-excursion (backward-paragraph 1) (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2712 ; (save-excursion (forward-paragraph 1) (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2713 ; ;; Don't accept a non-whitespace fill prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2714 ; ;; from the first line of a paragraph.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2715 ; "^[ \t]*$")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2716 ; (and prefix (not (equal prefix ""))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2717 ; (setq fill-prefix prefix))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2718
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2719 ; (while (and (not give-up) (> (current-column) fc))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2720 ; ;; Determine where to split the line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2721 ; (let ((fill-point
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2722 ; (let ((opoint (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2723 ; bounce
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2724 ; (first t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2725 ; (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2726 ; (move-to-column (1+ fc))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2727 ; ;; Move back to a word boundary.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2728 ; (while (or first
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2729 ; ;; If this is after period and a single space,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2730 ; ;; move back once more--we don't want to break
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2731 ; ;; the line there and make it look like a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2732 ; ;; sentence end.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2733 ; (and (not (bobp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2734 ; (not bounce)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2735 ; sentence-end-double-space
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2736 ; (save-excursion (forward-char -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2737 ; (and (looking-at "\\. ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2738 ; (not (looking-at "\\. "))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2739 ; (setq first nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2740 ; (skip-chars-backward "^ \t\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2741 ; ;; If we find nowhere on the line to break it,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2742 ; ;; break after one word. Set bounce to t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2743 ; ;; so we will not keep going in this while loop.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2744 ; (if (bolp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2745 ; (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2746 ; (re-search-forward "[ \t]" opoint t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2747 ; (setq bounce t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2748 ; (skip-chars-backward " \t"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2749 ; ;; Let fill-point be set to the place where we end up.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2750 ; (point)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2751 ; ;; If that place is not the beginning of the line,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2752 ; ;; break the line there.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2753 ; (if (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2754 ; (goto-char fill-point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2755 ; (not (bolp)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2756 ; (let ((prev-column (current-column)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2757 ; ;; If point is at the fill-point, do not `save-excursion'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2758 ; ;; Otherwise, if a comment prefix or fill-prefix is inserted,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2759 ; ;; point will end up before it rather than after it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2760 ; (if (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2761 ; (skip-chars-backward " \t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2762 ; (= (point) fill-point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2763 ; (funcall comment-line-break-function t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2764 ; (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2765 ; (goto-char fill-point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2766 ; (funcall comment-line-break-function t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2767 ; ;; Now do justification, if required
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2768 ; (if (not (eq justify 'left))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2769 ; (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2770 ; (end-of-line 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2771 ; (justify-current-line justify nil t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2772 ; ;; If making the new line didn't reduce the hpos of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2773 ; ;; the end of the line, then give up now;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2774 ; ;; trying again will not help.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2775 ; (if (>= (current-column) prev-column)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2776 ; (setq give-up t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2777 ; ;; No place to break => stop trying.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2778 ; (setq give-up t))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2779 ; ;; Justify last line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2780 ; (justify-current-line justify t t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2781 ; t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2782
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2783 (defvar normal-auto-fill-function 'do-auto-fill
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2784 "The function to use for `auto-fill-function' if Auto Fill mode is turned on.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2785 Some major modes set this.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2786
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2787 (defun auto-fill-mode (&optional arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2788 "Toggle auto-fill mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2789 With arg, turn auto-fill mode on if and only if arg is positive.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2790 In Auto-Fill mode, inserting a space at a column beyond `current-fill-column'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2791 automatically breaks the line at a previous space.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2792
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2793 The value of `normal-auto-fill-function' specifies the function to use
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2794 for `auto-fill-function' when turning Auto Fill mode on."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2795 (interactive "P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2796 (prog1 (setq auto-fill-function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2797 (if (if (null arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2798 (not auto-fill-function)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2799 (> (prefix-numeric-value arg) 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2800 normal-auto-fill-function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2801 nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2802 (redraw-modeline)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2803
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2804 ;; This holds a document string used to document auto-fill-mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2805 (defun auto-fill-function ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2806 "Automatically break line at a previous space, in insertion of text."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2807 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2808
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2809 (defun turn-on-auto-fill ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2810 "Unconditionally turn on Auto Fill mode."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2811 (auto-fill-mode 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2812
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2813 (defun set-fill-column (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2814 "Set `fill-column' to specified argument.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2815 Just \\[universal-argument] as argument means to use the current column
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2816 The variable `fill-column' has a separate value for each buffer."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2817 (interactive "_P") ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2818 (cond ((integerp arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2819 (setq fill-column arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2820 ((consp arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2821 (setq fill-column (current-column)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2822 ;; Disallow missing argument; it's probably a typo for C-x C-f.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2823 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2824 (error "set-fill-column requires an explicit argument")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2825 (lmessage 'command "fill-column set to %d" fill-column))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2826
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2827 (defcustom comment-multi-line t ; XEmacs - this works well with adaptive fill
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2828 "*Non-nil means \\[indent-new-comment-line] should continue same comment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2829 on new line, with no new terminator or starter.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2830 This is obsolete because you might as well use \\[newline-and-indent]."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2831 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2832 :group 'fill-comments)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2833
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2834 (defun indent-new-comment-line (&optional soft)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2835 "Break line at point and indent, continuing comment if within one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2836 This indents the body of the continued comment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2837 under the previous comment line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2838
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2839 This command is intended for styles where you write a comment per line,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2840 starting a new comment (and terminating it if necessary) on each line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2841 If you want to continue one comment across several lines, use \\[newline-and-indent].
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2842
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2843 If a fill column is specified, it overrides the use of the comment column
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2844 or comment indentation.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2845
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2846 The inserted newline is marked hard if `use-hard-newlines' is true,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2847 unless optional argument SOFT is non-nil."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2848 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2849 (let (comcol comstart)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2850 (skip-chars-backward " \t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2851 ;; 97/3/14 jhod: Kinsoku processing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2852 (if (featurep 'mule)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2853 (kinsoku-process))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2854 (delete-region (point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2855 (progn (skip-chars-forward " \t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2856 (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2857 (if soft (insert ?\n) (newline 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2858 (if fill-prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2859 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2860 (indent-to-left-margin)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2861 (insert fill-prefix))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2862 ;; #### - Eric Eide reverts to v18 semantics for this function in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2863 ;; fa-extras, which I'm not gonna do. His changes are to (1) execute
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2864 ;; the save-excursion below unconditionally, and (2) uncomment the check
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2865 ;; for (not comment-multi-line) further below. --Stig
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2866 ;;#### jhod: probably need to fix this for kinsoku processing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2867 (if (not comment-multi-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2868 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2869 (if (and comment-start-skip
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2870 (let ((opoint (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2871 (forward-line -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2872 (re-search-forward comment-start-skip opoint t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2873 ;; The old line is a comment.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2874 ;; Set WIN to the pos of the comment-start.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2875 ;; But if the comment is empty, look at preceding lines
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2876 ;; to find one that has a nonempty comment.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2877
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2878 ;; If comment-start-skip contains a \(...\) pair,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2879 ;; the real comment delimiter starts at the end of that pair.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2880 (let ((win (or (match-end 1) (match-beginning 0))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2881 (while (and (eolp) (not (bobp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2882 (let (opoint)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2883 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2884 (setq opoint (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2885 (forward-line -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2886 (re-search-forward comment-start-skip opoint t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2887 (setq win (or (match-end 1) (match-beginning 0))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2888 ;; Indent this line like what we found.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2889 (goto-char win)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2890 (setq comcol (current-column))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2891 (setq comstart
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2892 (buffer-substring (point) (match-end 0)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2893 (if (and comcol (not fill-prefix)) ; XEmacs - (ENE) from fa-extras.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2894 (let ((comment-column comcol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2895 (comment-start comstart)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2896 (block-comment-start comstart)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2897 (comment-end comment-end))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2898 (and comment-end (not (equal comment-end ""))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2899 ; (if (not comment-multi-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2900 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2901 (forward-char -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2902 (insert comment-end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2903 (forward-char 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2904 ; (setq comment-column (+ comment-column (length comment-start))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2905 ; comment-start "")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2906 ; )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2907 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2908 (if (not (eolp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2909 (setq comment-end ""))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2910 (insert ?\n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2911 (forward-char -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2912 (indent-for-comment)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2913 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2914 ;; Make sure we delete the newline inserted above.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2915 (end-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2916 (delete-char 1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2917 (indent-according-to-mode)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2918
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2919
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2920 (defun set-selective-display (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2921 "Set `selective-display' to ARG; clear it if no arg.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2922 When the value of `selective-display' is a number > 0,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2923 lines whose indentation is >= that value are not displayed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2924 The variable `selective-display' has a separate value for each buffer."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2925 (interactive "P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2926 (if (eq selective-display t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2927 (error "selective-display already in use for marked lines"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2928 (let ((current-vpos
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2929 (save-restriction
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2930 (narrow-to-region (point-min) (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2931 (goto-char (window-start))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2932 (vertical-motion (window-height)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2933 (setq selective-display
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2934 (and arg (prefix-numeric-value arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2935 (recenter current-vpos))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2936 (set-window-start (selected-window) (window-start (selected-window)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2937 ;; #### doesn't localize properly:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2938 (princ "selective-display set to " t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2939 (prin1 selective-display t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2940 (princ "." t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2941
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2942 ;; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2943 (defun nuke-selective-display ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2944 "Ensure that the buffer is not in selective-display mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2945 If `selective-display' is t, then restore the buffer text to its original
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2946 state before disabling selective display."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2947 ;; by Stig@hackvan.com
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2948 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2949 (and (eq t selective-display)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2950 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2951 (save-restriction
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2952 (widen)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2953 (goto-char (point-min))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2954 (let ((mod-p (buffer-modified-p))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2955 (buffer-read-only nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2956 (while (search-forward "\r" nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2957 (delete-char -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2958 (insert "\n"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2959 (set-buffer-modified-p mod-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2960 ))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2961 (setq selective-display nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2962
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2963 (add-hook 'change-major-mode-hook 'nuke-selective-display)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2964
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2965 (defconst overwrite-mode-textual (purecopy " Ovwrt")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2966 "The string displayed in the mode line when in overwrite mode.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2967 (defconst overwrite-mode-binary (purecopy " Bin Ovwrt")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2968 "The string displayed in the mode line when in binary overwrite mode.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2969
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2970 (defun overwrite-mode (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2971 "Toggle overwrite mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2972 With arg, turn overwrite mode on iff arg is positive.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2973 In overwrite mode, printing characters typed in replace existing text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2974 on a one-for-one basis, rather than pushing it to the right. At the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2975 end of a line, such characters extend the line. Before a tab,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2976 such characters insert until the tab is filled in.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2977 \\[quoted-insert] still inserts characters in overwrite mode; this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2978 is supposed to make it easier to insert characters when necessary."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2979 (interactive "P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2980 (setq overwrite-mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2981 (if (if (null arg) (not overwrite-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2982 (> (prefix-numeric-value arg) 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2983 'overwrite-mode-textual))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2984 (redraw-modeline))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2985
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2986 (defun binary-overwrite-mode (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2987 "Toggle binary overwrite mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2988 With arg, turn binary overwrite mode on iff arg is positive.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2989 In binary overwrite mode, printing characters typed in replace
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2990 existing text. Newlines are not treated specially, so typing at the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2991 end of a line joins the line to the next, with the typed character
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2992 between them. Typing before a tab character simply replaces the tab
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2993 with the character typed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2994 \\[quoted-insert] replaces the text at the cursor, just as ordinary
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2995 typing characters do.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2996
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2997 Note that binary overwrite mode is not its own minor mode; it is a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2998 specialization of overwrite-mode, entered by setting the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2999 `overwrite-mode' variable to `overwrite-mode-binary'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3000 (interactive "P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3001 (setq overwrite-mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3002 (if (if (null arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3003 (not (eq overwrite-mode 'overwrite-mode-binary))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3004 (> (prefix-numeric-value arg) 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3005 'overwrite-mode-binary))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3006 (redraw-modeline))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3007
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3008 (defcustom line-number-mode nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3009 "*Non-nil means display line number in modeline."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3010 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3011 :group 'editing-basics)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3012
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3013 (defun line-number-mode (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3014 "Toggle Line Number mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3015 With arg, turn Line Number mode on iff arg is positive.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3016 When Line Number mode is enabled, the line number appears
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3017 in the mode line."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3018 (interactive "P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3019 (setq line-number-mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3020 (if (null arg) (not line-number-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3021 (> (prefix-numeric-value arg) 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3022 (redraw-modeline))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3023
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3024 (defcustom column-number-mode nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3025 "*Non-nil means display column number in mode line."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3026 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3027 :group 'editing-basics)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3028
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3029 (defun column-number-mode (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3030 "Toggle Column Number mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3031 With arg, turn Column Number mode on iff arg is positive.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3032 When Column Number mode is enabled, the column number appears
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3033 in the mode line."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3034 (interactive "P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3035 (setq column-number-mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3036 (if (null arg) (not column-number-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3037 (> (prefix-numeric-value arg) 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3038 (redraw-modeline))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3039
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3040
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3041 (defcustom blink-matching-paren t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3042 "*Non-nil means show matching open-paren when close-paren is inserted."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3043 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3044 :group 'paren-blinking)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3045
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3046 (defcustom blink-matching-paren-on-screen t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3047 "*Non-nil means show matching open-paren when it is on screen.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3048 nil means don't show it (but the open-paren can still be shown
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3049 when it is off screen."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3050 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3051 :group 'paren-blinking)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3052
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3053 (defcustom blink-matching-paren-distance 12000
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3054 "*If non-nil, is maximum distance to search for matching open-paren."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3055 :type '(choice integer (const nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3056 :group 'paren-blinking)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3057
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3058 (defcustom blink-matching-delay 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3059 "*The number of seconds that `blink-matching-open' will delay at a match."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3060 :type 'number
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3061 :group 'paren-blinking)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3062
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3063 (defcustom blink-matching-paren-dont-ignore-comments nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3064 "*Non-nil means `blink-matching-paren' should not ignore comments."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3065 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3066 :group 'paren-blinking)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3067
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3068 (defun blink-matching-open ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3069 "Move cursor momentarily to the beginning of the sexp before point."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3070 (interactive "_") ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3071 (and (> (point) (1+ (point-min)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3072 blink-matching-paren
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3073 ;; Verify an even number of quoting characters precede the close.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3074 (= 1 (logand 1 (- (point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3075 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3076 (forward-char -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3077 (skip-syntax-backward "/\\")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3078 (point)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3079 (let* ((oldpos (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3080 (blinkpos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3081 (mismatch))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3082 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3083 (save-restriction
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3084 (if blink-matching-paren-distance
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3085 (narrow-to-region (max (point-min)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3086 (- (point) blink-matching-paren-distance))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3087 oldpos))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3088 (condition-case ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3089 (let ((parse-sexp-ignore-comments
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3090 (and parse-sexp-ignore-comments
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3091 (not blink-matching-paren-dont-ignore-comments))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3092 (setq blinkpos (scan-sexps oldpos -1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3093 (error nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3094 (and blinkpos
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3095 (/= (char-syntax (char-after blinkpos))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3096 ?\$)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3097 (setq mismatch
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3098 (or (null (matching-paren (char-after blinkpos)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3099 (/= (char-after (1- oldpos))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3100 (matching-paren (char-after blinkpos))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3101 (if mismatch (setq blinkpos nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3102 (if blinkpos
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3103 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3104 (goto-char blinkpos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3105 (if (pos-visible-in-window-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3106 (and blink-matching-paren-on-screen
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3107 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3108 (auto-show-make-point-visible)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3109 (sit-for blink-matching-delay)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3110 (goto-char blinkpos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3111 (lmessage 'command "Matches %s"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3112 ;; Show what precedes the open in its line, if anything.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3113 (if (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3114 (skip-chars-backward " \t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3115 (not (bolp)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3116 (buffer-substring (progn (beginning-of-line) (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3117 (1+ blinkpos))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3118 ;; Show what follows the open in its line, if anything.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3119 (if (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3120 (forward-char 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3121 (skip-chars-forward " \t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3122 (not (eolp)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3123 (buffer-substring blinkpos
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3124 (progn (end-of-line) (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3125 ;; Otherwise show the previous nonblank line,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3126 ;; if there is one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3127 (if (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3128 (skip-chars-backward "\n \t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3129 (not (bobp)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3130 (concat
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3131 (buffer-substring (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3132 (skip-chars-backward "\n \t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3133 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3134 (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3135 (progn (end-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3136 (skip-chars-backward " \t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3137 (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3138 ;; Replace the newline and other whitespace with `...'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3139 "..."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3140 (buffer-substring blinkpos (1+ blinkpos)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3141 ;; There is nothing to show except the char itself.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3142 (buffer-substring blinkpos (1+ blinkpos))))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3143 (cond (mismatch
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3144 (display-message 'no-log "Mismatched parentheses"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3145 ((not blink-matching-paren-distance)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3146 (display-message 'no-log "Unmatched parenthesis"))))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3147
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3148 ;Turned off because it makes dbx bomb out.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3149 (setq blink-paren-function 'blink-matching-open)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3150
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3151 (eval-when-compile (defvar myhelp)) ; suppress compiler warning
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3152
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3153 ;; XEmacs: Some functions moved to cmdloop.el:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3154 ;; keyboard-quit
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3155 ;; buffer-quit-function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3156 ;; keyboard-escape-quit
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3157
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3158 (defun assoc-ignore-case (key alist)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3159 "Like `assoc', but assumes KEY is a string and ignores case when comparing."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3160 (setq key (downcase key))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3161 (let (element)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3162 (while (and alist (not element))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3163 (if (equal key (downcase (car (car alist))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3164 (setq element (car alist)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3165 (setq alist (cdr alist)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3166 element))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3167
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3168
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3169 (defcustom mail-user-agent 'sendmail-user-agent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3170 "*Your preference for a mail composition package.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3171 Various Emacs Lisp packages (e.g. reporter) require you to compose an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3172 outgoing email message. This variable lets you specify which
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3173 mail-sending package you prefer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3174
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3175 Valid values include:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3176
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3177 sendmail-user-agent -- use the default Emacs Mail package
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3178 mh-e-user-agent -- use the Emacs interface to the MH mail system
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3179 message-user-agent -- use the GNUS mail sending package
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3180
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3181 Additional valid symbols may be available; check with the author of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3182 your package for details."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3183 :type '(radio (function-item :tag "Default Emacs mail"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3184 :format "%t\n"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3185 sendmail-user-agent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3186 (function-item :tag "Gnus mail sending package"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3187 :format "%t\n"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3188 message-user-agent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3189 (function :tag "Other"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3190 :group 'mail)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3191
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3192 (defun define-mail-user-agent (symbol composefunc sendfunc
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3193 &optional abortfunc hookvar)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3194 "Define a symbol to identify a mail-sending package for `mail-user-agent'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3195
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3196 SYMBOL can be any Lisp symbol. Its function definition and/or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3197 value as a variable do not matter for this usage; we use only certain
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3198 properties on its property list, to encode the rest of the arguments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3199
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3200 COMPOSEFUNC is program callable function that composes an outgoing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3201 mail message buffer. This function should set up the basics of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3202 buffer without requiring user interaction. It should populate the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3203 standard mail headers, leaving the `to:' and `subject:' headers blank
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3204 by default.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3205
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3206 COMPOSEFUNC should accept several optional arguments--the same
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3207 arguments that `compose-mail' takes. See that function's documentation.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3208
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3209 SENDFUNC is the command a user would run to send the message.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3210
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3211 Optional ABORTFUNC is the command a user would run to abort the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3212 message. For mail packages that don't have a separate abort function,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3213 this can be `kill-buffer' (the equivalent of omitting this argument).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3214
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3215 Optional HOOKVAR is a hook variable that gets run before the message
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3216 is actually sent. Callers that use the `mail-user-agent' may
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3217 install a hook function temporarily on this hook variable.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3218 If HOOKVAR is nil, `mail-send-hook' is used.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3219
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3220 The properties used on SYMBOL are `composefunc', `sendfunc',
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3221 `abortfunc', and `hookvar'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3222 (put symbol 'composefunc composefunc)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3223 (put symbol 'sendfunc sendfunc)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3224 (put symbol 'abortfunc (or abortfunc 'kill-buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3225 (put symbol 'hookvar (or hookvar 'mail-send-hook)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3226
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3227 (define-mail-user-agent 'sendmail-user-agent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3228 'sendmail-user-agent-compose 'mail-send-and-exit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3229
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3230 (define-mail-user-agent 'message-user-agent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3231 'message-mail 'message-send-and-exit
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3232 'message-kill-buffer 'message-send-hook)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3233
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3234 (defun sendmail-user-agent-compose (&optional to subject other-headers continue
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3235 switch-function yank-action
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3236 send-actions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3237 (if switch-function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3238 (let ((special-display-buffer-names nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3239 (special-display-regexps nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3240 (same-window-buffer-names nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3241 (same-window-regexps nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3242 (funcall switch-function "*mail*")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3243 (let ((cc (cdr (assoc-ignore-case "cc" other-headers)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3244 (in-reply-to (cdr (assoc-ignore-case "in-reply-to" other-headers))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3245 (or (mail continue to subject in-reply-to cc yank-action send-actions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3246 continue
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3247 (error "Message aborted"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3248 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3249 (goto-char (point-min))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3250 (search-forward mail-header-separator)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3251 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3252 (while other-headers
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3253 (if (not (member (car (car other-headers)) '("in-reply-to" "cc")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3254 (insert (car (car other-headers)) ": "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3255 (cdr (car other-headers)) "\n"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3256 (setq other-headers (cdr other-headers)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3257 t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3258
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3259 (define-mail-user-agent 'mh-e-user-agent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3260 'mh-user-agent-compose 'mh-send-letter 'mh-fully-kill-draft
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3261 'mh-before-send-letter-hook)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3262
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3263 (defun compose-mail (&optional to subject other-headers continue
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3264 switch-function yank-action send-actions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3265 "Start composing a mail message to send.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3266 This uses the user's chosen mail composition package
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3267 as selected with the variable `mail-user-agent'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3268 The optional arguments TO and SUBJECT specify recipients
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3269 and the initial Subject field, respectively.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3270
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3271 OTHER-HEADERS is an alist specifying additional
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3272 header fields. Elements look like (HEADER . VALUE) where both
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3273 HEADER and VALUE are strings.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3274
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3275 CONTINUE, if non-nil, says to continue editing a message already
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3276 being composed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3277
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3278 SWITCH-FUNCTION, if non-nil, is a function to use to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3279 switch to and display the buffer used for mail composition.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3280
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3281 YANK-ACTION, if non-nil, is an action to perform, if and when necessary,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3282 to insert the raw text of the message being replied to.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3283 It has the form (FUNCTION . ARGS). The user agent will apply
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3284 FUNCTION to ARGS, to insert the raw text of the original message.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3285 \(The user agent will also run `mail-citation-hook', *after* the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3286 original text has been inserted in this way.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3287
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3288 SEND-ACTIONS is a list of actions to call when the message is sent.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3289 Each action has the form (FUNCTION . ARGS)."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3290 (interactive
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3291 (list nil nil nil current-prefix-arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3292 (let ((function (get mail-user-agent 'composefunc)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3293 (funcall function to subject other-headers continue
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3294 switch-function yank-action send-actions)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3295
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3296 (defun compose-mail-other-window (&optional to subject other-headers continue
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3297 yank-action send-actions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3298 "Like \\[compose-mail], but edit the outgoing message in another window."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3299 (interactive
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3300 (list nil nil nil current-prefix-arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3301 (compose-mail to subject other-headers continue
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3302 'switch-to-buffer-other-window yank-action send-actions))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3303
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3304
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3305 (defun compose-mail-other-frame (&optional to subject other-headers continue
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3306 yank-action send-actions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3307 "Like \\[compose-mail], but edit the outgoing message in another frame."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3308 (interactive
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3309 (list nil nil nil current-prefix-arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3310 (compose-mail to subject other-headers continue
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3311 'switch-to-buffer-other-frame yank-action send-actions))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3312
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3313
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3314 (defun set-variable (var val)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3315 "Set VARIABLE to VALUE. VALUE is a Lisp object.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3316 When using this interactively, supply a Lisp expression for VALUE.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3317 If you want VALUE to be a string, you must surround it with doublequotes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3318 If VARIABLE is a specifier, VALUE is added to it as an instantiator in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3319 the 'global locale with nil tag set (see `set-specifier').
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3320
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3321 If VARIABLE has a `variable-interactive' property, that is used as if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3322 it were the arg to `interactive' (which see) to interactively read the value."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3323 (interactive
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3324 (let* ((var (read-variable "Set variable: "))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3325 ;; #### - yucky code replication here. This should use something
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3326 ;; from help.el or hyper-apropos.el
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3327 (minibuffer-help-form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3328 '(funcall myhelp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3329 (myhelp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3330 #'(lambda ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3331 (with-output-to-temp-buffer "*Help*"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3332 (prin1 var)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3333 (princ "\nDocumentation:\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3334 (princ (substring (documentation-property var 'variable-documentation)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3335 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3336 (if (boundp var)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3337 (let ((print-length 20))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3338 (princ "\n\nCurrent value: ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3339 (prin1 (symbol-value var))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3340 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3341 (set-buffer standard-output)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3342 (help-mode))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3343 nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3344 (list var
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3345 (let ((prop (get var 'variable-interactive)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3346 (if prop
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3347 ;; Use VAR's `variable-interactive' property
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3348 ;; as an interactive spec for prompting.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3349 (call-interactively (list 'lambda '(arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3350 (list 'interactive prop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3351 'arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3352 (eval-minibuffer (format "Set %s to value: " var)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3353 (if (and (boundp var) (specifierp (symbol-value var)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3354 (set-specifier (symbol-value var) val)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3355 (set var val)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3356
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3357 ;; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3358 (defun activate-region ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3359 "Activate the region, if `zmacs-regions' is true.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3360 Setting `zmacs-regions' to true causes LISPM-style active regions to be used.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3361 This function has no effect if `zmacs-regions' is false."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3362 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3363 (and zmacs-regions (zmacs-activate-region)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3364
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3365 ;; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3366 (defsubst region-exists-p ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3367 "Return t if the region exists.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3368 If active regions are in use (i.e. `zmacs-regions' is true), this means that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3369 the region is active. Otherwise, this means that the user has pushed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3370 a mark in this buffer at some point in the past.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3371 The functions `region-beginning' and `region-end' can be used to find the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3372 limits of the region."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3373 (not (null (mark))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3374
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3375 ;; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3376 (defun region-active-p ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3377 "Return non-nil if the region is active.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3378 If `zmacs-regions' is true, this is equivalent to `region-exists-p'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3379 Otherwise, this function always returns false."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3380 (and zmacs-regions zmacs-region-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3381
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3382 ;; A bunch of stuff was moved elsewhere:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3383 ;; completion-list-mode-map
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3384 ;; completion-reference-buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3385 ;; completion-base-size
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3386 ;; delete-completion-window
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3387 ;; previous-completion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3388 ;; next-completion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3389 ;; choose-completion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3390 ;; choose-completion-delete-max-match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3391 ;; choose-completion-string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3392 ;; completion-list-mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3393 ;; completion-fixup-function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3394 ;; completion-setup-function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3395 ;; switch-to-completions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3396 ;; event stuffs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3397 ;; keypad stuffs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3398
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3399 ;; The rest of this file is not in Lisp in FSF
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3400 (defun capitalize-region-or-word (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3401 "Capitalize the selected region or the following word (or ARG words)."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3402 (interactive "p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3403 (if (region-active-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3404 (capitalize-region (region-beginning) (region-end))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3405 (capitalize-word arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3406
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3407 (defun upcase-region-or-word (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3408 "Upcase the selected region or the following word (or ARG words)."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3409 (interactive "p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3410 (if (region-active-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3411 (upcase-region (region-beginning) (region-end))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3412 (upcase-word arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3413
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3414 (defun downcase-region-or-word (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3415 "Downcase the selected region or the following word (or ARG words)."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3416 (interactive "p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3417 (if (region-active-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3418 (downcase-region (region-beginning) (region-end))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3419 (downcase-word arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3420
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3421 ;; Most of the zmacs code is now in elisp. The only thing left in C
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3422 ;; are the variables zmacs-regions, zmacs-region-active-p and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3423 ;; zmacs-region-stays plus the function zmacs_update_region which
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3424 ;; simply calls the lisp level zmacs-update-region. It must remain
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3425 ;; for convenience, since it is called by core C code.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3426
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3427 (defvar zmacs-activate-region-hook nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3428 "Function or functions called when the region becomes active;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3429 see the variable `zmacs-regions'.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3430
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3431 (defvar zmacs-deactivate-region-hook nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3432 "Function or functions called when the region becomes inactive;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3433 see the variable `zmacs-regions'.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3434
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3435 (defvar zmacs-update-region-hook nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3436 "Function or functions called when the active region changes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3437 This is called after each command that sets `zmacs-region-stays' to t.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3438 See the variable `zmacs-regions'.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3439
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3440 (defvar zmacs-region-extent nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3441 "The extent of the zmacs region; don't use this.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3442
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3443 (defvar zmacs-region-rectangular-p nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3444 "Whether the zmacs region is a rectangle; don't use this.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3445
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3446 (defun zmacs-make-extent-for-region (region)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3447 ;; Given a region, this makes an extent in the buffer which holds that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3448 ;; region, for highlighting purposes. If the region isn't associated
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3449 ;; with a buffer, this does nothing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3450 (let ((buffer nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3451 (valid (and (extentp zmacs-region-extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3452 (extent-object zmacs-region-extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3453 (buffer-live-p (extent-object zmacs-region-extent))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3454 start end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3455 (cond ((consp region)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3456 (setq start (min (car region) (cdr region))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3457 end (max (car region) (cdr region))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3458 valid (and valid
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3459 (eq (marker-buffer (car region))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3460 (extent-object zmacs-region-extent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3461 buffer (marker-buffer (car region))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3462 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3463 (signal 'error (list "Invalid region" region))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3464
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3465 (if valid
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3466 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3467 ;; The condition case is in case any of the extents are dead or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3468 ;; otherwise incapacitated.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3469 (condition-case ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3470 (if (listp zmacs-region-extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3471 (mapc 'delete-extent zmacs-region-extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3472 (delete-extent zmacs-region-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3473 (error nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3474
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3475 (if valid
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3476 (set-extent-endpoints zmacs-region-extent start end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3477 (setq zmacs-region-extent (make-extent start end buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3478
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3479 ;; Make the extent be closed on the right, which means that if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3480 ;; characters are inserted exactly at the end of the extent, the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3481 ;; extent will grow to cover them. This is important for shell
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3482 ;; buffers - suppose one makes a region, and one end is at point-max.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3483 ;; If the shell produces output, that marker will remain at point-max
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3484 ;; (its position will increase). So it's important that the extent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3485 ;; exhibit the same behavior, lest the region covered by the extent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3486 ;; (the visual indication), and the region between point and mark
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3487 ;; (the actual region value) become different!
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3488 (set-extent-property zmacs-region-extent 'end-open nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3489
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3490 ;; use same priority as mouse-highlighting so that conflicts between
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3491 ;; the region extent and a mouse-highlighted extent are resolved by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3492 ;; the usual size-and-endpoint-comparison method.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3493 (set-extent-priority zmacs-region-extent mouse-highlight-priority)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3494 (set-extent-face zmacs-region-extent 'zmacs-region)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3495
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3496 ;; #### It might be better to actually break
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3497 ;; default-mouse-track-next-move-rect out of mouse.el so that we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3498 ;; can use its logic here.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3499 (cond
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3500 (zmacs-region-rectangular-p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3501 (setq zmacs-region-extent (list zmacs-region-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3502 (default-mouse-track-next-move-rect start end zmacs-region-extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3503 ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3504
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3505 zmacs-region-extent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3506
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3507 (defun zmacs-region-buffer ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3508 "Return the buffer containing the zmacs region, or nil."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3509 ;; #### this is horrible and kludgy! This stuff needs to be rethought.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3510 (and zmacs-regions zmacs-region-active-p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3511 (or (marker-buffer (mark-marker t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3512 (and (extent-live-p zmacs-region-extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3513 (buffer-live-p (extent-object zmacs-region-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3514 (extent-object zmacs-region-extent)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3515
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3516 (defun zmacs-activate-region ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3517 "Make the region between `point' and `mark' be active (highlighted),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3518 if `zmacs-regions' is true. Only a very small number of commands
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3519 should ever do this. Calling this function will call the hook
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3520 `zmacs-activate-region-hook', if the region was previously inactive.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3521 Calling this function ensures that the region stays active after the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3522 current command terminates, even if `zmacs-region-stays' is not set.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3523 Returns t if the region was activated (i.e. if `zmacs-regions' if t)."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3524 (if (not zmacs-regions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3525 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3526 (setq zmacs-region-active-p t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3527 zmacs-region-stays t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3528 zmacs-region-rectangular-p (and (boundp 'mouse-track-rectangle-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3529 mouse-track-rectangle-p))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3530 (if (marker-buffer (mark-marker t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3531 (zmacs-make-extent-for-region (cons (point-marker t) (mark-marker t))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3532 (run-hooks 'zmacs-activate-region-hook)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3533 t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3534
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3535 (defun zmacs-deactivate-region ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3536 "Make the region between `point' and `mark' no longer be active,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3537 if `zmacs-regions' is true. You shouldn't need to call this; the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3538 command loop calls it when appropriate. Calling this function will
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3539 call the hook `zmacs-deactivate-region-hook', if the region was
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3540 previously active. Returns t if the region had been active, nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3541 otherwise."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3542 (if (not zmacs-region-active-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3543 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3544 (setq zmacs-region-active-p nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3545 zmacs-region-stays nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3546 zmacs-region-rectangular-p nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3547 (if zmacs-region-extent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3548 (let ((inhibit-quit t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3549 (if (listp zmacs-region-extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3550 (mapc 'delete-extent zmacs-region-extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3551 (delete-extent zmacs-region-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3552 (setq zmacs-region-extent nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3553 (run-hooks 'zmacs-deactivate-region-hook)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3554 t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3555
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3556 (defun zmacs-update-region ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3557 "Update the highlighted region between `point' and `mark'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3558 You shouldn't need to call this; the command loop calls it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3559 when appropriate. Calling this function will call the hook
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3560 `zmacs-update-region-hook', if the region is active."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3561 (when zmacs-region-active-p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3562 (when (marker-buffer (mark-marker t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3563 (zmacs-make-extent-for-region (cons (point-marker t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3564 (mark-marker t))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3565 (run-hooks 'zmacs-update-region-hook)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3566
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3567 ;;;;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3568 ;;;;;; echo area stuff
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3569 ;;;;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3570
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3571 ;;; #### Should this be moved to a separate file, for clarity?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3572 ;;; -hniksic
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3573
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3574 ;;; The `message-stack' is an alist of labels with messages; the first
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3575 ;;; message in this list is always in the echo area. A call to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3576 ;;; `display-message' inserts a label/message pair at the head of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3577 ;;; list, and removes any other pairs with that label. Calling
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3578 ;;; `clear-message' causes any pair with matching label to be removed,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3579 ;;; and this may cause the displayed message to change or vanish. If
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3580 ;;; the label arg is nil, the entire message stack is cleared.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3581 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3582 ;;; Message/error filtering will be a little tricker to implement than
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3583 ;;; logging, since messages can be built up incrementally
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3584 ;;; using clear-message followed by repeated calls to append-message
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3585 ;;; (this happens with error messages). For messages which aren't
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3586 ;;; created this way, filtering could be implemented at display-message
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3587 ;;; very easily.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3588 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3589 ;;; Bits of the logging code are borrowed from log-messages.el by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3590 ;;; Robert Potter (rpotter@grip.cis.upenn.edu).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3591
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3592 ;; need this to terminate the currently-displayed message
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3593 ;; ("Loading simple ...")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3594 (when (and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3595 (not (fboundp 'display-message))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3596 (not (featurep 'debug)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3597 (send-string-to-terminal "\n"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3598
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3599 (defvar message-stack nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3600 "An alist of label/string pairs representing active echo-area messages.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3601 The first element in the list is currently displayed in the echo area.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3602 Do not modify this directly--use the `message' or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3603 `display-message'/`clear-message' functions.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3604
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3605 (defvar remove-message-hook 'log-message
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3606 "A function or list of functions to be called when a message is removed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3607 from the echo area at the bottom of the frame. The label of the removed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3608 message is passed as the first argument, and the text of the message
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3609 as the second argument.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3610
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3611 (defcustom log-message-max-size 50000
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3612 "Maximum size of the \" *Message-Log*\" buffer. See `log-message'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3613 :type 'integer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3614 :group 'log-message)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3615 (make-compatible-variable 'message-log-max 'log-message-max-size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3616
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3617 ;; We used to reject quite a lot of stuff here, but it was a bad idea,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3618 ;; for two reasons:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3619 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3620 ;; a) In most circumstances, you *want* to see the message in the log.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3621 ;; The explicitly non-loggable messages should be marked as such by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3622 ;; the issuer. Gratuitous non-displaying of random regexps made
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3623 ;; debugging harder, too (because various reasonable debugging
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3624 ;; messages would get eaten).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3625 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3626 ;; b) It slowed things down. Yes, visibly.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3627 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3628 ;; So, I left only a few of the really useless ones on this kill-list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3629 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3630 ;; --hniksic
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3631 (defcustom log-message-ignore-regexps
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3632 '(;; Note: adding entries to this list slows down messaging
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
3633 ;; significantly. Wherever possible, use message labels.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3634
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3635 ;; Often-seen messages
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3636 "\\`\\'" ; empty message
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3637 "\\`\\(Beginning\\|End\\) of buffer\\'"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3638 ;;"^Quit$"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3639 ;; completions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3640 ;; Many packages print this -- impossible to categorize
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3641 ;;"^Making completion list"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3642 ;; Gnus
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3643 ;; "^No news is no news$"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3644 ;; "^No more\\( unread\\)? newsgroups$"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3645 ;; "^Opening [^ ]+ server\\.\\.\\."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3646 ;; "^[^:]+: Reading incoming mail"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3647 ;; "^Getting mail from "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3648 ;; "^\\(Generating Summary\\|Sorting threads\\|Making sparse threads\\|Scoring\\|Checking new news\\|Expiring articles\\|Sending\\)\\.\\.\\."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3649 ;; "^\\(Fetching headers for\\|Retrieving newsgroup\\|Reading active file\\)"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3650 ;; "^No more\\( unread\\)? articles"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3651 ;; "^Deleting article "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3652 ;; W3
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3653 ;; "^Parsed [0-9]+ of [0-9]+ ([0-9]+%)"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3654 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3655 "List of regular expressions matching messages which shouldn't be logged.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3656 See `log-message'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3657
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3658 Ideally, packages which generate messages which might need to be ignored
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3659 should label them with 'progress, 'prompt, or 'no-log, so they can be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3660 filtered by the log-message-ignore-labels."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3661 :type '(repeat regexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3662 :group 'log-message)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3663
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3664 (defcustom log-message-ignore-labels
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3665 '(help-echo command progress prompt no-log garbage-collecting auto-saving)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3666 "List of symbols indicating labels of messages which shouldn't be logged.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3667 See `display-message' for some common labels. See also `log-message'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3668 :type '(repeat (symbol :tag "Label"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3669 :group 'log-message)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3670
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3671 ;;Subsumed by view-lossage
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3672 ;; Not really, I'm adding it back by popular demand. -slb
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3673 (defun show-message-log ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3674 "Show the \" *Message-Log*\" buffer, which contains old messages and errors."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3675 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3676 (pop-to-buffer (get-buffer-create " *Message-Log*")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3677
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3678 (defvar log-message-filter-function 'log-message-filter
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3679 "Value must be a function of two arguments: a symbol (label) and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3680 a string (message). It should return non-nil to indicate a message
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3681 should be logged. Possible values include 'log-message-filter and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3682 'log-message-filter-errors-only.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3683
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3684 (defun log-message-filter (label message)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3685 "Default value of `log-message-filter-function'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3686 Messages whose text matches one of the `log-message-ignore-regexps'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3687 or whose label appears in `log-message-ignore-labels' are not saved."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3688 (let ((r log-message-ignore-regexps)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3689 (ok (not (memq label log-message-ignore-labels))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3690 (save-match-data
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3691 (while (and r ok)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3692 (when (string-match (car r) message)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3693 (setq ok nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3694 (setq r (cdr r))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3695 ok))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3696
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3697 (defun log-message-filter-errors-only (label message)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3698 "For use as the `log-message-filter-function'. Only logs error messages."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3699 (eq label 'error))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3700
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3701 (defun log-message (label message)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3702 "Stuff a copy of the message into the \" *Message-Log*\" buffer,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3703 if it satisfies the `log-message-filter-function'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3704
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3705 For use on `remove-message-hook'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3706 (when (and (not noninteractive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3707 (funcall log-message-filter-function label message))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3708 ;; Use save-excursion rather than save-current-buffer because we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3709 ;; change the value of point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3710 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3711 (set-buffer (get-buffer-create " *Message-Log*"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3712 (goto-char (point-max))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3713 ;(insert (concat (upcase (symbol-name label)) ": " message "\n"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3714 (let (extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3715 ;; Mark multiline message with an extent, which `view-lossage'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3716 ;; will recognize.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3717 (when (string-match "\n" message)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3718 (setq extent (make-extent (point) (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3719 (set-extent-properties extent '(end-open nil message-multiline t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3720 (insert message "\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3721 (when extent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3722 (set-extent-property extent 'end-open t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3723 (when (> (point-max) (max log-message-max-size (point-min)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3724 ;; Trim log to ~90% of max size.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3725 (goto-char (max (- (point-max)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3726 (truncate (* 0.9 log-message-max-size)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3727 (point-min)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3728 (forward-line 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3729 (delete-region (point-min) (point))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3730
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3731 (defun message-displayed-p (&optional return-string frame)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3732 "Return a non-nil value if a message is presently displayed in the\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3733 minibuffer's echo area. If optional argument RETURN-STRING is non-nil,\n\
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3734 return a string containing the message, otherwise just return t."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3735 ;; by definition, a message is displayed if the echo area buffer is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3736 ;; non-empty (see also echo_area_active()). It had better also
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3737 ;; be the case that message-stack is nil exactly when the echo area
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3738 ;; is non-empty.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3739 (let ((buffer (get-buffer " *Echo Area*")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3740 (and (< (point-min buffer) (point-max buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3741 (if return-string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3742 (buffer-substring nil nil buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3743 t))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3744
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3745 ;;; Returns the string which remains in the echo area, or nil if none.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3746 ;;; If label is nil, the whole message stack is cleared.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3747 (defun clear-message (&optional label frame stdout-p no-restore)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3748 "Remove any message with the given LABEL from the message-stack,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3749 erasing it from the echo area if it's currently displayed there.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3750 If a message remains at the head of the message-stack and NO-RESTORE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3751 is nil, it will be displayed. The string which remains in the echo
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3752 area will be returned, or nil if the message-stack is now empty.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3753 If LABEL is nil, the entire message-stack is cleared.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3754
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3755 Unless you need the return value or you need to specify a label,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3756 you should just use (message nil)."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3757 (or frame (setq frame (selected-frame)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3758 (let ((clear-stream (and message-stack (eq 'stream (frame-type frame)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3759 (remove-message label frame)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3760 (let ((inhibit-read-only t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3761 (zmacs-region-stays zmacs-region-stays)) ; preserve from change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3762 (erase-buffer " *Echo Area*"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3763 (if clear-stream
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3764 (send-string-to-terminal ?\n stdout-p))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3765 (if no-restore
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3766 nil ; just preparing to put another msg up
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3767 (if message-stack
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3768 (let ((oldmsg (cdr (car message-stack))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3769 (raw-append-message oldmsg frame stdout-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3770 oldmsg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3771 ;; #### Should we (redisplay-echo-area) here? Messes some
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3772 ;; things up.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3773 nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3774
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3775 (defun remove-message (&optional label frame)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3776 ;; If label is nil, we want to remove all matching messages.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3777 ;; Must reverse the stack first to log them in the right order.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3778 (let ((log nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3779 (while (and message-stack
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3780 (or (null label) ; null label means clear whole stack
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3781 (eq label (car (car message-stack)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3782 (push (car message-stack) log)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3783 (setq message-stack (cdr message-stack)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3784 (let ((s message-stack))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3785 (while (cdr s)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3786 (let ((msg (car (cdr s))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3787 (if (eq label (car msg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3788 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3789 (push msg log)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3790 (setcdr s (cdr (cdr s))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3791 (setq s (cdr s))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3792 ;; (possibly) log each removed message
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3793 (while log
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3794 (condition-case e
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3795 (run-hook-with-args 'remove-message-hook
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3796 (car (car log)) (cdr (car log)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3797 (error (setq remove-message-hook nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3798 (lwarn 'message-log 'warning
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3799 "Error caught in `remove-message-hook': %s"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3800 (error-message-string e))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3801 (let ((inhibit-read-only t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3802 (erase-buffer " *Echo Area*"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3803 (signal (car e) (cdr e))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3804 (setq log (cdr log)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3805
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3806 (defun append-message (label message &optional frame stdout-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3807 (or frame (setq frame (selected-frame)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3808 ;; Add a new entry to the message-stack, or modify an existing one
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3809 (let ((top (car message-stack)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3810 (if (eq label (car top))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3811 (setcdr top (concat (cdr top) message))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3812 (push (cons label message) message-stack)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3813 (raw-append-message message frame stdout-p))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3814
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3815 ;; Really append the message to the echo area. no fiddling with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3816 ;; message-stack.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3817 (defun raw-append-message (message &optional frame stdout-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3818 (unless (equal message "")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3819 (let ((inhibit-read-only t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3820 (zmacs-region-stays zmacs-region-stays)) ; preserve from change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3821 (insert-string message " *Echo Area*")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3822 ;; Conditionalizing on the device type in this way is not that clean,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3823 ;; but neither is having a device method, as I originally implemented
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3824 ;; it: all non-stream devices behave in the same way. Perhaps
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3825 ;; the cleanest way is to make the concept of a "redisplayable"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3826 ;; device, which stream devices are not. Look into this more if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3827 ;; we ever create another non-redisplayable device type (e.g.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3828 ;; processes? printers?).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3829
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3830 ;; Don't redisplay the echo area if we are executing a macro.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3831 (if (not executing-kbd-macro)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3832 (if (eq 'stream (frame-type frame))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3833 (send-string-to-terminal message stdout-p (frame-device frame))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3834 (redisplay-echo-area))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3835
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3836 (defun display-message (label message &optional frame stdout-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3837 "Print a one-line message at the bottom of the frame. First argument
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3838 LABEL is an identifier for this message. MESSAGE is the string to display.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3839 Use `clear-message' to remove a labelled message.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3840
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3841 Here are some standard labels (those marked with `*' are not logged
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3842 by default--see the `log-message-ignore-labels' variable):
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3843 message default label used by the `message' function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3844 error default label used for reporting errors
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3845 * progress progress indicators like \"Converting... 45%\"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3846 * prompt prompt-like messages like \"I-search: foo\"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3847 * command helper command messages like \"Mark set\"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3848 * no-log messages that should never be logged"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3849 (clear-message label frame stdout-p t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3850 (append-message label message frame stdout-p))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3851
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3852 (defun current-message (&optional frame)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3853 "Return the current message in the echo area, or nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3854 The FRAME argument is currently unused."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3855 (cdr (car message-stack)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3856
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3857 ;;; may eventually be frame-dependent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3858 (defun current-message-label (&optional frame)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3859 (car (car message-stack)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3860
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3861 (defun message (fmt &rest args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3862 "Print a one-line message at the bottom of the frame.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3863 The arguments are the same as to `format'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3864
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3865 If the only argument is nil, clear any existing message; let the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3866 minibuffer contents show."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3867 ;; questionable junk in the C code
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3868 ;; (if (framep default-minibuffer-frame)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3869 ;; (make-frame-visible default-minibuffer-frame))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3870 (if (and (null fmt) (null args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3871 (prog1 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3872 (clear-message nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3873 (let ((str (apply 'format fmt args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3874 (display-message 'message str)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3875 str)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3876
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3877 (defun lmessage (label fmt &rest args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3878 "Print a one-line message at the bottom of the frame.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3879 First argument LABEL is an identifier for this message. The rest of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3880 arguments are the same as to `format'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3881
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3882 See `display-message' for a list of standard labels."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3883 (if (and (null fmt) (null args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3884 (prog1 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3885 (clear-message label nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3886 (let ((str (apply 'format fmt args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3887 (display-message label str)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3888 str)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3889
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3890
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3891 ;;;;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3892 ;;;;;; warning stuff
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3893 ;;;;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3894
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3895 (defcustom log-warning-minimum-level 'info
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3896 "Minimum level of warnings that should be logged.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3897 The warnings in levels below this are completely ignored, as if they never
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3898 happened.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3899
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3900 The recognized warning levels, in decreasing order of priority, are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3901 'emergency, 'alert, 'critical, 'error, 'warning, 'notice, 'info, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3902 'debug.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3903
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3904 See also `display-warning-minimum-level'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3905
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3906 You can also control which warnings are displayed on a class-by-class
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3907 basis. See `display-warning-suppressed-classes' and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3908 `log-warning-suppressed-classes'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3909 :type '(choice (const emergency) (const alert) (const critical)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3910 (const error) (const warning) (const notice)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3911 (const info) (const debug))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3912 :group 'warnings)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3913
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3914 (defcustom display-warning-minimum-level 'info
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3915 "Minimum level of warnings that should be displayed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3916 The warnings in levels below this will be generated, but not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3917 displayed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3918
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3919 The recognized warning levels, in decreasing order of priority, are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3920 'emergency, 'alert, 'critical, 'error, 'warning, 'notice, 'info, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3921 'debug.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3922
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3923 See also `log-warning-minimum-level'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3924
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3925 You can also control which warnings are displayed on a class-by-class
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3926 basis. See `display-warning-suppressed-classes' and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3927 `log-warning-suppressed-classes'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3928 :type '(choice (const emergency) (const alert) (const critical)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3929 (const error) (const warning) (const notice)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3930 (const info) (const debug))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3931 :group 'warnings)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3932
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3933 (defvar log-warning-suppressed-classes nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3934 "List of classes of warnings that shouldn't be logged or displayed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3935 If any of the CLASS symbols associated with a warning is the same as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3936 any of the symbols listed here, the warning will be completely ignored,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3937 as it they never happened.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3938
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3939 NOTE: In most circumstances, you should *not* set this variable.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3940 Set `display-warning-suppressed-classes' instead. That way the suppressed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3941 warnings are not displayed but are still unobtrusively logged.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3942
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3943 See also `log-warning-minimum-level' and `display-warning-minimum-level'.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3944
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3945 (defcustom display-warning-suppressed-classes nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3946 "List of classes of warnings that shouldn't be displayed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3947 If any of the CLASS symbols associated with a warning is the same as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3948 any of the symbols listed here, the warning will not be displayed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3949 The warning will still logged in the *Warnings* buffer (unless also
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3950 contained in `log-warning-suppressed-classes'), but the buffer will
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3951 not be automatically popped up.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3952
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3953 See also `log-warning-minimum-level' and `display-warning-minimum-level'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3954 :type '(repeat symbol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3955 :group 'warnings)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3956
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3957 (defvar warning-count 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3958 "Count of the number of warning messages displayed so far.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3959
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3960 (defconst warning-level-alist '((emergency . 8)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3961 (alert . 7)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3962 (critical . 6)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3963 (error . 5)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3964 (warning . 4)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3965 (notice . 3)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3966 (info . 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3967 (debug . 1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3968
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3969 (defun warning-level-p (level)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3970 "Non-nil if LEVEL specifies a warning level."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3971 (and (symbolp level) (assq level warning-level-alist)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3972
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3973 ;; If you're interested in rewriting this function, be aware that it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3974 ;; could be called at arbitrary points in a Lisp program (when a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3975 ;; built-in function wants to issue a warning, it will call out to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3976 ;; this function the next time some Lisp code is evaluated). Therefore,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3977 ;; this function *must* not permanently modify any global variables
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3978 ;; (e.g. the current buffer) except those that specifically apply
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3979 ;; to the warning system.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3980
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3981 (defvar before-init-deferred-warnings nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3982
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3983 (defun after-init-display-warnings ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3984 "Display warnings deferred till after the init file is run.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3985 Warnings that occur before then are deferred so that warning
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3986 suppression in the .emacs file will be honored."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3987 (while before-init-deferred-warnings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3988 (apply 'display-warning (car before-init-deferred-warnings))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3989 (setq before-init-deferred-warnings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3990 (cdr before-init-deferred-warnings))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3991
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3992 (add-hook 'after-init-hook 'after-init-display-warnings)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3993
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3994 (defun display-warning (class message &optional level)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3995 "Display a warning message.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3996 CLASS should be a symbol describing what sort of warning this is, such
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3997 as `resource' or `key-mapping'. A list of such symbols is also
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3998 accepted. (Individual classes can be suppressed; see
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3999 `display-warning-suppressed-classes'.) Optional argument LEVEL can
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4000 be used to specify a priority for the warning, other than default priority
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4001 `warning'. (See `display-warning-minimum-level'). The message is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4002 inserted into the *Warnings* buffer, which is made visible at appropriate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4003 times."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4004 (or level (setq level 'warning))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4005 (or (listp class) (setq class (list class)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4006 (check-argument-type 'warning-level-p level)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4007 (if (and (not (featurep 'infodock))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4008 (not init-file-loaded))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4009 (push (list class message level) before-init-deferred-warnings)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4010 (catch 'ignored
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4011 (let ((display-p t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4012 (level-num (cdr (assq level warning-level-alist))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4013 (if (< level-num (cdr (assq log-warning-minimum-level
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4014 warning-level-alist)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4015 (throw 'ignored nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4016 (if (intersection class log-warning-suppressed-classes)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4017 (throw 'ignored nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4018
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4019 (if (< level-num (cdr (assq display-warning-minimum-level
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4020 warning-level-alist)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4021 (setq display-p nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4022 (if (and display-p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4023 (intersection class display-warning-suppressed-classes))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4024 (setq display-p nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4025 (let ((buffer (get-buffer-create "*Warnings*")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4026 (when display-p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4027 ;; The C code looks at display-warning-tick to determine
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4028 ;; when it should call `display-warning-buffer'. Change it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4029 ;; to get the C code's attention.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4030 (incf display-warning-tick))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4031 (with-current-buffer buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4032 (goto-char (point-max))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4033 (incf warning-count)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4034 (princ (format "(%d) (%s/%s) "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4035 warning-count
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4036 (mapconcat 'symbol-name class ",")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4037 level)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4038 buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4039 (princ message buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4040 (terpri buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4041 (terpri buffer)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4042
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4043 (defun warn (&rest args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4044 "Display a warning message.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4045 The message is constructed by passing all args to `format'. The message
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4046 is placed in the *Warnings* buffer, which will be popped up at the next
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4047 redisplay. The class of the warning is `warning'. See also
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4048 `display-warning'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4049 (display-warning 'warning (apply 'format args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4050
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4051 (defun lwarn (class level &rest args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4052 "Display a labeled warning message.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4053 CLASS should be a symbol describing what sort of warning this is, such
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4054 as `resource' or `key-mapping'. A list of such symbols is also
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4055 accepted. (Individual classes can be suppressed; see
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4056 `display-warning-suppressed-classes'.) If non-nil, LEVEL can be used
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4057 to specify a priority for the warning, other than default priority
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4058 `warning'. (See `display-warning-minimum-level'). The message is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4059 inserted into the *Warnings* buffer, which is made visible at appropriate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4060 times.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4061
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4062 The rest of the arguments are passed to `format'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4063 (display-warning class (apply 'format args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4064 (or level 'warning)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4065
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4066 (defvar warning-marker nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4067
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4068 ;; When this function is called by the C code, all non-local exits are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4069 ;; trapped and C-g is inhibited; therefore, it would be a very, very
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4070 ;; bad idea for this function to get into an infinite loop.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4071
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4072 (defun display-warning-buffer ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4073 "Make the buffer that contains the warnings be visible.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4074 The C code calls this periodically, right before redisplay."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4075 (let ((buffer (get-buffer-create "*Warnings*")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4076 (when (or (not warning-marker)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4077 (not (eq (marker-buffer warning-marker) buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4078 (setq warning-marker (make-marker))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4079 (set-marker warning-marker 1 buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4080 (if temp-buffer-show-function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4081 (let ((show-buffer (get-buffer-create "*Warnings-Show*")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4082 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4083 (set-buffer show-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4084 (setq buffer-read-only nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4085 (erase-buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4086 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4087 (set-buffer buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4088 (copy-to-buffer show-buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4089 (marker-position warning-marker)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4090 (point-max)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4091 (funcall temp-buffer-show-function show-buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4092 (set-window-start (display-buffer buffer) warning-marker))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4093 (set-marker warning-marker (point-max buffer) buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4094
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4095 (defun emacs-name ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4096 "Return the printable name of this instance of Emacs."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4097 (cond ((featurep 'infodock) "InfoDock")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4098 ((featurep 'xemacs) "XEmacs")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4099 (t "Emacs")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4100
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4101 ;;; simple.el ends here