annotate lisp/simple.el @ 5584:d469c668462e

#'load-terminal-library; load term files correctly for gnuclient consoles. lisp/ChangeLog addition: 2011-10-17 Aidan Kehoe <kehoea@parhasard.net> * startup.el (load-terminal-library): Don't (getenv "TERM") here, call #'console-tty-terminal-type instead, different gnuclient consoles can and should have different terminal type function maps effective.
author Aidan Kehoe <kehoea@parhasard.net>
date Tue, 18 Oct 2011 12:03:36 +0100
parents 071b810ceb18
children cc6f0266bc36
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.
1261
465bd3c7d932 [xemacs-hg @ 2003-02-06 06:35:47 by ben]
ben
parents: 958
diff changeset
5 ;; Copyright (C) 2000, 2001, 2002, 2003 Ben Wing.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 ;; Maintainer: XEmacs Development Team
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 ;; Keywords: lisp, extensions, internal, dumped
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 ;; This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5228
diff changeset
12 ;; XEmacs is free software: you can redistribute it and/or modify it
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5228
diff changeset
13 ;; under the terms of the GNU General Public License as published by the
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5228
diff changeset
14 ;; Free Software Foundation, either version 3 of the License, or (at your
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5228
diff changeset
15 ;; option) any later version.
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5228
diff changeset
16
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5228
diff changeset
17 ;; XEmacs is distributed in the hope that it will be useful, but WITHOUT
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5228
diff changeset
18 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5228
diff changeset
19 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5228
diff changeset
20 ;; for more details.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5228
diff changeset
23 ;; along with XEmacs. If not, see <http://www.gnu.org/licenses/>.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 ;;; Synched up with: FSF 19.34 [But not very closely].
3000
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents: 2977
diff changeset
26 ;;; Occasional synching to FSF 21.2 and FSF 22.0, as marked. Comment stuff
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents: 2977
diff changeset
27 ;;; also synched, and in newcomment.el.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 ;;; Commentary:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 ;; This file is dumped with XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 ;; A grab-bag of basic XEmacs commands not specifically related to some
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 ;; major mode or to file-handling.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 ;; Changes for zmacs-style active-regions:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 ;; beginning-of-buffer, end-of-buffer, count-lines-region,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 ;; count-lines-buffer, what-line, what-cursor-position, set-goal-column,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 ;; 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
41 ;; 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
42 ;; don't affect the current region-hilighting state.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 ;; mark-whole-buffer, mark-word, exchange-point-and-mark, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 ;; set-mark-command (without an argument) call zmacs-activate-region.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 ;; mark takes an optional arg like the new Fmark_marker() does. When
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 ;; 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
49 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 ;; push-mark, pop-mark, exchange-point-and-mark, and set-marker, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 ;; 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
52 ;; the region is active or not.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 ;; shell-command, shell-command-on-region, yank, and yank-pop (which all
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 ;; 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
56 ;; argument, meaning "don't activate the region". These commands only use
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 ;; exchange-point-and-mark to position the newly-pushed mark correctly, so
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 ;; 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
59 ;; to use (mark t) for the same reason.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 487
diff changeset
61 ;; 97/3/14 Jareth Hein (jhod@po.iijnet.or.jp) added kinsoku processing
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 487
diff changeset
62 ;; (support for filling of Asian text) into the fill code. This was
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 487
diff changeset
63 ;; ripped bleeding from Mule-2.3, and could probably use some feature
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 487
diff changeset
64 ;; additions (like additional wrap styles, etc)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 ;; 97/06/11 Steve Baur (steve@xemacs.org) Convert use of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 ;; (preceding|following)-char to char-(after|before).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 ;;; Code:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 (defgroup editing-basics nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 "Most basic editing variables."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 :group 'editing)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 (defgroup killing nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 "Killing and yanking commands."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 :group 'editing)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 (defgroup fill-comments nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 "Indenting and filling of comments."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 :prefix "comment-"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 :group 'fill)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 (defgroup paren-matching nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 "Highlight (un)matching of parens and expressions."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 :prefix "paren-"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 :group 'matching)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 (defgroup log-message nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 "Messages logging and display customizations."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 :group 'minibuffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 (defgroup warnings nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 "Warnings customizations."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 :group 'minibuffer)
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 (defcustom search-caps-disable-folding t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 "*If non-nil, upper case chars disable case fold searching.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 This does not apply to \"yanked\" strings."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 :group 'editing-basics)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 ;; This is stolen (and slightly modified) from FSF emacs's
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 ;; `isearch-no-upper-case-p'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 (defun no-upper-case-p (string &optional regexp-flag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 "Return t if there are no upper case chars in STRING.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 If REGEXP-FLAG is non-nil, disregard letters preceded by `\\' (but not `\\\\')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 since they have special meaning in a regexp."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 (let ((case-fold-search nil))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
111 (not (string-match (if regexp-flag
428
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 "[A-Z]")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 string))
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 (defmacro with-search-caps-disable-folding (string regexp-flag &rest body) "\
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
118 Eval BODY with `case-fold-search' let to nil if `search-caps-disable-folding'
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 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
120 to REGEXP-FLAG) contains uppercase letters."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 `(let ((case-fold-search
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 (if (and case-fold-search search-caps-disable-folding)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 (no-upper-case-p ,string ,regexp-flag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 case-fold-search)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 ,@body))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 (put 'with-search-caps-disable-folding 'lisp-indent-function 2)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
127 (put 'with-search-caps-disable-folding 'edebug-form-spec
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 '(sexp sexp &rest form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
130 (defmacro with-interactive-search-caps-disable-folding (string regexp-flag
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 &rest body)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 "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
133 function called interactively."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 `(let ((case-fold-search
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
135 (if (and (interactive-p)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 case-fold-search search-caps-disable-folding)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 (no-upper-case-p ,string ,regexp-flag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 case-fold-search)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 ,@body))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 (put 'with-interactive-search-caps-disable-folding 'lisp-indent-function 2)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
141 (put 'with-interactive-search-caps-disable-folding 'edebug-form-spec
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 '(sexp sexp &rest form))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
144 (defun newline (&optional n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 "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
146 The newline is marked with the text-property `hard'.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
147 With optional arg N, insert that many newlines.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 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
149 (interactive "*P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 (barf-if-buffer-read-only nil (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 ;; 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
152 ;; 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
153 ;; 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
154 ;; the end of the previous line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 ;; #### Does this have any relevance in XEmacs?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 (let ((flag (and (not (bobp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 (bolp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 ;; Make sure the newline before point isn't intangible.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 (not (get-char-property (1- (point)) 'intangible))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 ;; Make sure the newline before point isn't read-only.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 (not (get-char-property (1- (point)) 'read-only))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 ;; Make sure the newline before point isn't invisible.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 (not (get-char-property (1- (point)) 'invisible))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 ;; This should probably also test for the previous char
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 ;; being the *last* character too.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 (not (get-char-property (1- (point)) 'end-open))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 ;; Make sure the newline before point has the same
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 ;; properties as the char before it (if any).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 (< (or (previous-extent-change (point)) -2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 (- (point) 2))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 (was-page-start (and (bolp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 (looking-at page-delimiter)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 (beforepos (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 (if flag (backward-char 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 ;; Call self-insert so that auto-fill, abbrev expansion etc. happens.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 ;; Set last-command-char to tell self-insert what to insert.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 (let ((last-command-char ?\n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 ;; Don't auto-fill if we have a numeric argument.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 ;; Also not if flag is true (it would fill wrong line);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 ;; there is no need to since we're at BOL.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
181 (auto-fill-function (if (or n flag) nil auto-fill-function)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 (unwind-protect
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
183 (self-insert-command (prefix-numeric-value n))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 ;; 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
185 (if flag (forward-char 1))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 ;; If we did *not* get an error, cancel that forward-char.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 (if flag (backward-char 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 ;; Mark the newline(s) `hard'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 (if use-hard-newlines
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
190 (let* ((from (- (point) (if n (prefix-numeric-value n) 1)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 (sticky (get-text-property from 'end-open))) ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 (put-text-property from (point) 'hard 't)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 ;; If end-open is not "t", add 'hard to end-open list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 (if (and (listp sticky) (not (memq 'hard sticky)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 (put-text-property from (point) 'end-open ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 (cons 'hard sticky)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 ;; If the newline leaves the previous line blank,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 ;; and we have a left margin, delete that from the blank line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 (or flag
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 (goto-char beforepos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 (and (looking-at "[ \t]$")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 (> (current-left-margin) 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 (delete-region (point) (progn (end-of-line) (point))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 (if flag (forward-char 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 ;; Indent the line after the newline, except in one case:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 ;; when we added the newline at the beginning of a line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 ;; which starts a page.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 (or was-page-start
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 (move-to-left-margin nil t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 (defun set-hard-newline-properties (from to)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 (let ((sticky (get-text-property from 'rear-nonsticky)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 (put-text-property from to 'hard 't)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 ;; If rear-nonsticky is not "t", add 'hard to rear-nonsticky list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 (if (and (listp sticky) (not (memq 'hard sticky)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 (put-text-property from (point) 'rear-nonsticky
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 (cons 'hard sticky)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
222 (defun open-line (n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 "Insert a newline and leave point before it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 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
225 if the line would have been blank.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 With arg N, insert N newlines."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 (interactive "*p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 (let* ((do-fill-prefix (and fill-prefix (bolp)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 (do-left-margin (and (bolp) (> (current-left-margin) 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 (loc (point)))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
231 (newline n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 (goto-char loc)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
233 (while (> n 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 (cond ((bolp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 (if do-left-margin (indent-to (current-left-margin)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 (if do-fill-prefix (insert fill-prefix))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 (forward-line 1)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
238 (setq n (1- n)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 (goto-char loc)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 (end-of-line)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 (defun split-line ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 "Split current line, moving portion beyond point vertically down."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 (interactive "*")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 (skip-chars-forward " \t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 (let ((col (current-column))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 (pos (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 (newline 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 (indent-to col 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 (goto-char pos)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 (defun quoted-insert (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 "Read next input character and insert it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 This is useful for inserting control characters.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 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
256
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 In overwrite mode, this function inserts the character anyway, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 does not handle octal digits specially. This means that if you use
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 overwrite as your normal editing mode, you can use this function to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 insert characters when necessary.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 In binary overwrite mode, this function does overwrite, and octal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 digits are interpreted as a character code. This is supposed to make
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 this function useful in editing binary files."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 (interactive "*p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 (let ((char (if (or (not overwrite-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 (eq overwrite-mode 'overwrite-mode-binary))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 (read-quoted-char)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 ;; read-char obeys C-g, so we should protect. FSF
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 ;; doesn't have the protection here, but it's a bug in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 ;; FSF.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 (let ((inhibit-quit t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 (read-char)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 (if (> arg 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 (if (eq overwrite-mode 'overwrite-mode-binary)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 (delete-char arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 (while (> arg 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 (insert char)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 (setq arg (1- arg)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 (defun delete-indentation (&optional arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 "Join this line to previous and fix up whitespace at join.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 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
284 With argument, join this line to following line."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 (interactive "*P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 (if arg (forward-line 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 (if (eq (char-before (point)) ?\n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 (delete-region (point) (1- (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 ;; If the second line started with the fill prefix,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 ;; delete the prefix.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 (if (and fill-prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 (<= (+ (point) (length fill-prefix)) (point-max))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 (string= fill-prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 (buffer-substring (point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 (+ (point) (length fill-prefix)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 (delete-region (point) (+ (point) (length fill-prefix))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 (fixup-whitespace))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300
958
4cbfb36b35e0 [xemacs-hg @ 2002-08-12 07:44:28 by youngs]
youngs
parents: 844
diff changeset
301 (defalias 'join-line 'delete-indentation)
4cbfb36b35e0 [xemacs-hg @ 2002-08-12 07:44:28 by youngs]
youngs
parents: 844
diff changeset
302
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 (defun fixup-whitespace ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 "Fixup white space between objects around point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 Leave one space or none, according to the context."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 (interactive "*")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 (delete-horizontal-space)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 (if (or (looking-at "^\\|\\s)")
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
310 (save-excursion (backward-char 1)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 (looking-at "$\\|\\s(\\|\\s'")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 (insert ?\ ))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 (defun delete-horizontal-space ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 "Delete all spaces and tabs around point."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 (interactive "*")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 (skip-chars-backward " \t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 (delete-region (point) (progn (skip-chars-forward " \t") (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 (defun just-one-space ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 "Delete all spaces and tabs around point, leaving one space."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 (interactive "*")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 (if abbrev-mode ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 (expand-abbrev))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 (skip-chars-backward " \t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 (if (eq (char-after (point)) ? ) ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 (forward-char 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 (insert ? ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 (delete-region (point) (progn (skip-chars-forward " \t") (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 (defun delete-blank-lines ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 "On blank line, delete all surrounding blank lines, leaving just one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 On isolated blank line, delete that one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 On nonblank line, delete any immediately following blank lines."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 (interactive "*")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 (let (thisblank singleblank)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 (setq thisblank (looking-at "[ \t]*$"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 ;; Set singleblank if there is just one blank line here.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 (setq singleblank
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 (and thisblank
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 (not (looking-at "[ \t]*\n[ \t]*$"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 (or (bobp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 (progn (forward-line -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 (not (looking-at "[ \t]*$")))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 ;; 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
349 (if thisblank
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 (if singleblank (forward-line 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 (delete-region (point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 (if (re-search-backward "[^ \t\n]" nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 (progn (forward-line 1) (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 (point-min)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 ;; Delete following blank lines, unless the current line is blank
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 ;; and there are no following blank lines.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 (if (not (and thisblank singleblank))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 (end-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 (forward-line 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 (delete-region (point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 (if (re-search-forward "[^ \t\n]" nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 (progn (beginning-of-line) (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 (point-max)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 ;; Handle the special case where point is followed by newline and eob.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 ;; Delete the line, leaving point at eob.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 (if (looking-at "^[ \t]*\n\\'")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 (delete-region (point) (point-max)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 (defun back-to-indentation ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 "Move point to the first non-whitespace character on this line."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 ;; XEmacs change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 (interactive "_")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 (beginning-of-line 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 (skip-chars-forward " \t"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 (defun newline-and-indent ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 "Insert a newline, then indent according to major mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 Indentation is done using the value of `indent-line-function'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 In programming language modes, this is the same as TAB.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 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
384 column specified by the function `current-left-margin'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 (interactive "*")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 (delete-region (point) (progn (skip-chars-backward " \t") (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 (newline)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 (indent-according-to-mode))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 (defun reindent-then-newline-and-indent ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 "Reindent current line, insert newline, then indent the new line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 Indentation of both lines is done according to the current major mode,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 which means calling the current value of `indent-line-function'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 In programming language modes, this is the same as TAB.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 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
396 column specified by the function `current-left-margin'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 (interactive "*")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399 (delete-region (point) (progn (skip-chars-backward " \t") (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 (indent-according-to-mode))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 (newline)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 (indent-according-to-mode))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 ;; Internal subroutine of delete-char
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 (defun kill-forward-chars (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 (if (listp arg) (setq arg (car arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 (if (eq arg '-) (setq arg -1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 (kill-region (point) (+ (point) arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 ;; Internal subroutine of backward-delete-char
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 (defun kill-backward-chars (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 (if (listp arg) (setq arg (car arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 (if (eq arg '-) (setq arg -1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 (kill-region (point) (- (point) arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 (defun backward-delete-char-untabify (arg &optional killp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 "Delete characters backward, changing tabs into spaces.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 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
419 Interactively, ARG is the prefix arg (default 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 and KILLP is t if a prefix arg was specified."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 (interactive "*p\nP")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 (let ((count arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 (while (and (> count 0) (not (bobp)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 (if (eq (char-before (point)) ?\t) ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 (let ((col (current-column)))
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
427 (backward-char 1)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 (setq col (- col (current-column)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 (insert-char ?\ col)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 (delete-char 1)))
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
431 (backward-char 1)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 (setq count (1- count)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 (delete-backward-char arg killp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 ;; XEmacs: In overwrite mode, back over columns while clearing them out,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 ;; unless at end of line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 (and overwrite-mode (not (eolp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 (save-excursion (insert-char ?\ arg))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 (defcustom delete-key-deletes-forward t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 "*If non-nil, the DEL key will erase one character forwards.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 If nil, the DEL key will erase one character backwards."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 :group 'editing-basics)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
445 (defcustom backward-delete-function 'delete-backward-char
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 "*Function called to delete backwards on a delete keypress.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 If `delete-key-deletes-forward' is nil, `backward-or-forward-delete-char'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448 calls this function to erase one character backwards. Default value
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
449 is `delete-backward-char', with `backward-delete-char-untabify' being a
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 popular alternate setting."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 :type 'function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 :group 'editing-basics)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 ;; Trash me, baby.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 (defsubst delete-forward-p ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 (and delete-key-deletes-forward
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 (or (not (eq (device-type) 'x))
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 487
diff changeset
458 (declare-fboundp
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 487
diff changeset
459 (x-keysym-on-keyboard-sans-modifiers-p 'backspace)))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 (defun backward-or-forward-delete-char (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 "Delete either one character backwards or one character forwards.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 Controlled by the state of `delete-key-deletes-forward' and whether the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 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
465 BackSpace keysym, the delete key should always delete one character
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 backwards."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 (interactive "*p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 (if (delete-forward-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 (delete-char arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 (funcall backward-delete-function arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 (defun backward-or-forward-kill-word (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 "Delete either one word backwards or one word forwards.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 Controlled by the state of `delete-key-deletes-forward' and whether the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 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
476 BackSpace keysym, the delete key should always delete one character
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 backwards."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 (interactive "*p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 (if (delete-forward-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 (kill-word arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 (backward-kill-word arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 (defun backward-or-forward-kill-sentence (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 "Delete either one sentence backwards or one sentence forwards.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 Controlled by the state of `delete-key-deletes-forward' and whether the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 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
487 BackSpace keysym, the delete key should always delete one character
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488 backwards."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 (interactive "*P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 (if (delete-forward-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 (kill-sentence arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 (backward-kill-sentence (prefix-numeric-value arg))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 (defun backward-or-forward-kill-sexp (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 "Delete either one sexpr backwards or one sexpr forwards.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 Controlled by the state of `delete-key-deletes-forward' and whether the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497 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
498 BackSpace keysym, the delete key should always delete one character
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 backwards."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500 (interactive "*p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 (if (delete-forward-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 (kill-sexp arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503 (backward-kill-sexp arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505 (defun zap-to-char (arg char)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 "Kill up to and including ARG'th occurrence of CHAR.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507 Goes backward if ARG is negative; error if CHAR not found."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 (interactive "*p\ncZap to char: ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 (kill-region (point) (with-interactive-search-caps-disable-folding
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 (char-to-string char) nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 (search-forward (char-to-string char) nil nil arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 (defun zap-up-to-char (arg char)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515 "Kill up to ARG'th occurrence of CHAR.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 Goes backward if ARG is negative; error if CHAR not found."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 (interactive "*p\ncZap up to char: ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 (kill-region (point) (with-interactive-search-caps-disable-folding
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 (char-to-string char) nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520 (search-forward (char-to-string char) nil nil arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 (goto-char (if (> arg 0) (1- (point)) (1+ (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 (point))))
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 (defun beginning-of-buffer (&optional arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 "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
526 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
527
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 If the buffer is narrowed, this command uses the beginning and size
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529 of the accessible part of the buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
531 The characters that are moved over may be added to the current selection
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
532 \(i.e. active region) if the Shift key is held down, a motion key is used
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
533 to invoke this command, and `shifted-motion-keys-select-region' is t; see
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
534 the documentation for this variable for more details.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
535
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 Don't use this command in Lisp programs!
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 \(goto-char (point-min)) is faster and avoids clobbering the mark."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 ;; XEmacs change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 (interactive "_P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 (push-mark)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541 (let ((size (- (point-max) (point-min))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 (goto-char (if arg
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 (+ (point-min)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 (if (> size 10000)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 ;; Avoid overflow for large buffer sizes!
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 (* (prefix-numeric-value arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 (/ size 10))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 (/ (+ 10 (* size (prefix-numeric-value arg))) 10)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 (point-min))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 (if arg (forward-line 1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552 (defun end-of-buffer (&optional arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 "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
554 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
555
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556 If the buffer is narrowed, this command uses the beginning and size
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557 of the accessible part of the buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
559 The characters that are moved over may be added to the current selection
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
560 \(i.e. active region) if the Shift key is held down, a motion key is used
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
561 to invoke this command, and `shifted-motion-keys-select-region' is t; see
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
562 the documentation for this variable for more details.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
563
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564 Don't use this command in Lisp programs!
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565 \(goto-char (point-max)) is faster and avoids clobbering the mark."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566 ;; XEmacs change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567 (interactive "_P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568 (push-mark)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569 ;; XEmacs changes here.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570 (let ((scroll-to-end (not (pos-visible-in-window-p (point-max))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571 (size (- (point-max) (point-min))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572 (goto-char (if arg
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573 (- (point-max)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 (if (> size 10000)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575 ;; Avoid overflow for large buffer sizes!
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 (* (prefix-numeric-value arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577 (/ size 10))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578 (/ (* size (prefix-numeric-value arg)) 10)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579 (point-max)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
580 (cond (arg
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581 ;; If we went to a place in the middle of the buffer,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
582 ;; adjust it to the beginning of a line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583 (forward-line 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584 ;; XEmacs change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 (scroll-to-end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586 ;; If the end of the buffer is not already on the screen,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 ;; then scroll specially to put it near, but not at, the bottom.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588 (recenter -3)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 ;; XEmacs (not in FSF)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591 (defun mark-beginning-of-buffer (&optional arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592 "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
593 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
594 (interactive "P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595 (push-mark (if arg
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
596 (if (> (buffer-size) 10000)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597 ;; Avoid overflow for large buffer sizes!
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 (* (prefix-numeric-value arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 (/ (buffer-size) 10))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 (/ (+ 10 (* (buffer-size) (prefix-numeric-value arg))) 10))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 (point-min))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 (define-function 'mark-bob 'mark-beginning-of-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606 ;; XEmacs (not in FSF)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 (defun mark-end-of-buffer (&optional arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 "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
609 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
610 (interactive "P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 (push-mark (if arg
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 (- (1+ (buffer-size))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613 (if (> (buffer-size) 10000)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614 ;; Avoid overflow for large buffer sizes!
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 (* (prefix-numeric-value arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616 (/ (buffer-size) 10))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617 (/ (* (buffer-size) (prefix-numeric-value arg)) 10)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618 (point-max))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620 t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621 (define-function 'mark-eob 'mark-end-of-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623 (defun mark-whole-buffer ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 "Put point at beginning and mark at end of buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625 You probably should not use this function in Lisp programs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626 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
627 that uses or sets the mark."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629 (push-mark (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630 (push-mark (point-max) nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631 (goto-char (point-min)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
633 ;; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634 (defun eval-current-buffer (&optional printflag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635 "Evaluate the current buffer as Lisp code.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636 Programs can pass argument PRINTFLAG which controls printing of output:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637 nil means discard it; anything else is stream for print."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
639 (eval-buffer (current-buffer) printflag))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
640
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641 ;; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642 (defun count-words-buffer (&optional buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 "Print the number of words in BUFFER.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 If called noninteractively, the value is returned rather than printed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645 BUFFER defaults to the current buffer."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647 (let ((words (count-words-region (point-min) (point-max) buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648 (when (interactive-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649 (message "Buffer has %d words" words))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650 words))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652 ;; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653 (defun count-words-region (start end &optional buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 "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
655 If called noninteractively, the value is returned rather than printed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656 BUFFER defaults to the current buffer."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657 (interactive "_r")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659 (set-buffer (or buffer (current-buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660 (let ((words 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661 (goto-char start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 (while (< (point) end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663 (when (forward-word 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664 (incf words)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
665 (when (interactive-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666 (message "Region has %d words" words))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
667 words)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669 (defun count-lines-region (start end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670 "Print number of lines and characters in the region."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671 ;; XEmacs change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672 (interactive "_r")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 (message "Region has %d lines, %d characters"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674 (count-lines start end) (- end start)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
675
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676 ;; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
677 (defun count-lines-buffer (&optional buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678 "Print number of lines and characters in BUFFER."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
679 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
680 (with-current-buffer (or buffer (current-buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
681 (let ((cnt (count-lines (point-min) (point-max))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682 (message "Buffer has %d lines, %d characters"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683 cnt (- (point-max) (point-min)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684 cnt)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686 ;;; 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
687 ;;; Expanded by Bob Weiner, BeOpen, on 02/12/1997
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688 (defun what-line ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
689 "Print the following variants of the line number of point:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690 Region line - displayed line within the active region
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691 Collapsed line - includes only selectively displayed lines;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692 Buffer line - physical line in the buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693 Narrowed line - line number from the start of the buffer narrowing."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694 ;; XEmacs change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695 (interactive "_")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
696 (let ((opoint (point)) start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698 (save-restriction
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699 (if (region-active-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700 (goto-char (region-beginning))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
701 (goto-char (point-min)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
702 (widen)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
703 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704 (setq start (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705 (goto-char opoint)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707 (let* ((buffer-line (1+ (count-lines 1 (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708 (narrowed-p (or (/= start 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
709 (/= (point-max) (1+ (buffer-size)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
710 (narrowed-line (if narrowed-p (1+ (count-lines start (point)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711 (selective-line (if selective-display
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712 (1+ (count-lines start (point) t))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713 (region-line (if (region-active-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
714 (1+ (count-lines start (point) selective-display)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715 (cond (region-line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716 (message "Region line %d; Buffer line %d"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
717 region-line buffer-line))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
718 ((and narrowed-p selective-line (/= selective-line narrowed-line))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
719 ;; buffer narrowed and some lines selectively displayed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
720 (message "Collapsed line %d; Buffer line %d; Narrowed line %d"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
721 selective-line buffer-line narrowed-line))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
722 (narrowed-p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
723 ;; buffer narrowed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724 (message "Buffer line %d; Narrowed line %d"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
725 buffer-line narrowed-line))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
726 ((and selective-line (/= selective-line buffer-line))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
727 ;; some lines selectively displayed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728 (message "Collapsed line %d; Buffer line %d"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
729 selective-line buffer-line))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731 ;; give a basic line count
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732 (message "Line %d" buffer-line)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733 (setq zmacs-region-stays t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
735 ;; new in XEmacs 21.2 (not in FSF).
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
736 (defun line-number (&optional pos respect-narrowing)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
737 "Return the line number of POS (defaults to point).
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
738 If RESPECT-NARROWING is non-nil, then the narrowed line number is returned;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
739 otherwise, the absolute line number is returned. The returned line can always
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
740 be given to `goto-line' to get back to the current line."
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
741 (if (and pos (/= pos (point)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
742 (save-excursion
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
743 (goto-char pos)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
744 (line-number nil respect-narrowing))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
745 (1+ (count-lines (if respect-narrowing (point-min) 1) (point-at-bol)))))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
746
3000
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents: 2977
diff changeset
747 ;; FSF 22.0.50.1 (CVS) version of above.
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents: 2977
diff changeset
748 (defun line-number-at-pos (&optional pos)
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents: 2977
diff changeset
749 (line-number pos t))
5df5ea55d3fc [xemacs-hg @ 2005-10-18 20:49:41 by malcolmp]
malcolmp
parents: 2977
diff changeset
750
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751 (defun count-lines (start end &optional ignore-invisible-lines-flag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
752 "Return number of lines between START and END.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753 This is usually the number of newlines between them,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754 but can be one more if START is not equal to END
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755 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
756
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757 With optional IGNORE-INVISIBLE-LINES-FLAG non-nil, lines collapsed with
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
758 selective-display are excluded from the line count.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
759
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
760 NOTE: The expression to return the current line number is not obvious:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
761
3767
6b2ef948e140 [xemacs-hg @ 2006-12-29 18:09:38 by aidan]
aidan
parents: 3724
diff changeset
762 \(1+ \(count-lines 1 \(point-at-bol)))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
763
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
764 See also `line-number'."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766 (save-restriction
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767 (narrow-to-region start end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768 (goto-char (point-min))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769 (if (and (not ignore-invisible-lines-flag) (eq selective-display t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
770 (save-match-data
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771 (let ((done 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772 (while (re-search-forward "[\n\C-m]" nil t 40)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773 (setq done (+ 40 done)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
774 (while (re-search-forward "[\n\C-m]" nil t 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775 (setq done (+ 1 done)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776 (goto-char (point-max))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777 (if (and (/= start end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778 (not (bolp)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
779 (1+ done)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780 done)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781 (- (buffer-size) (forward-line (buffer-size)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782
4468
a78d697ccd2c Import and extend GNU's descr-text.el, supporting prefix argument for C-x =
Aidan Kehoe <kehoea@parhasard.net>
parents: 4293
diff changeset
783 (defun what-cursor-position (&optional detail)
3724
1fe680cefdb7 [xemacs-hg @ 2006-12-06 21:28:47 by aidan]
aidan
parents: 3652
diff changeset
784 "Print info on cursor position (on screen and within buffer).
1fe680cefdb7 [xemacs-hg @ 2006-12-06 21:28:47 by aidan]
aidan
parents: 3652
diff changeset
785 Also describe the character after point, giving its UCS code point and Mule
1fe680cefdb7 [xemacs-hg @ 2006-12-06 21:28:47 by aidan]
aidan
parents: 3652
diff changeset
786 charset and codes; for ASCII characters, give its code in octal, decimal and
4468
a78d697ccd2c Import and extend GNU's descr-text.el, supporting prefix argument for C-x =
Aidan Kehoe <kehoea@parhasard.net>
parents: 4293
diff changeset
787 hex.
a78d697ccd2c Import and extend GNU's descr-text.el, supporting prefix argument for C-x =
Aidan Kehoe <kehoea@parhasard.net>
parents: 4293
diff changeset
788
a78d697ccd2c Import and extend GNU's descr-text.el, supporting prefix argument for C-x =
Aidan Kehoe <kehoea@parhasard.net>
parents: 4293
diff changeset
789 With prefix argument, show extended details about the character in a
a78d697ccd2c Import and extend GNU's descr-text.el, supporting prefix argument for C-x =
Aidan Kehoe <kehoea@parhasard.net>
parents: 4293
diff changeset
790 separate buffer. See also the command `describe-char'."
a78d697ccd2c Import and extend GNU's descr-text.el, supporting prefix argument for C-x =
Aidan Kehoe <kehoea@parhasard.net>
parents: 4293
diff changeset
791 ;; XEmacs change "_"
a78d697ccd2c Import and extend GNU's descr-text.el, supporting prefix argument for C-x =
Aidan Kehoe <kehoea@parhasard.net>
parents: 4293
diff changeset
792 (interactive "_P")
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793 (let* ((char (char-after (point))) ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
794 (beg (point-min))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
795 (end (point-max))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
796 (pos (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
797 (total (buffer-size))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
798 (percent (if (> total 50000)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
799 ;; Avoid overflow from multiplying by 100!
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800 (/ (+ (/ total 200) (1- pos)) (max (/ total 100) 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
801 (/ (+ (/ total 2) (* 100 (1- pos))) (max total 1))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
802 (hscroll (if (= (window-hscroll) 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803 ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804 (format " Hscroll=%d" (window-hscroll))))
3724
1fe680cefdb7 [xemacs-hg @ 2006-12-06 21:28:47 by aidan]
aidan
parents: 3652
diff changeset
805 (col (+ (current-column) (if column-number-start-at-one 1 0)))
1fe680cefdb7 [xemacs-hg @ 2006-12-06 21:28:47 by aidan]
aidan
parents: 3652
diff changeset
806 (unicode (and char (encode-char char 'ucs)))
1fe680cefdb7 [xemacs-hg @ 2006-12-06 21:28:47 by aidan]
aidan
parents: 3652
diff changeset
807 (unicode-string (and unicode (natnump unicode)
1fe680cefdb7 [xemacs-hg @ 2006-12-06 21:28:47 by aidan]
aidan
parents: 3652
diff changeset
808 (format (if (> unicode #xFFFF) "U+%06X" "U+%04X")
1fe680cefdb7 [xemacs-hg @ 2006-12-06 21:28:47 by aidan]
aidan
parents: 3652
diff changeset
809 unicode)))
1fe680cefdb7 [xemacs-hg @ 2006-12-06 21:28:47 by aidan]
aidan
parents: 3652
diff changeset
810 (narrowed-details (if (or (/= beg 1) (/= end (1+ total)))
1fe680cefdb7 [xemacs-hg @ 2006-12-06 21:28:47 by aidan]
aidan
parents: 3652
diff changeset
811 (format " <%d - %d>" beg end)
1fe680cefdb7 [xemacs-hg @ 2006-12-06 21:28:47 by aidan]
aidan
parents: 3652
diff changeset
812 "")))
1fe680cefdb7 [xemacs-hg @ 2006-12-06 21:28:47 by aidan]
aidan
parents: 3652
diff changeset
813
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
814 (if (= pos end)
3724
1fe680cefdb7 [xemacs-hg @ 2006-12-06 21:28:47 by aidan]
aidan
parents: 3652
diff changeset
815 (message "point=%d of %d(%d%%)%s column %d %s"
1fe680cefdb7 [xemacs-hg @ 2006-12-06 21:28:47 by aidan]
aidan
parents: 3652
diff changeset
816 pos total percent narrowed-details col hscroll)
4468
a78d697ccd2c Import and extend GNU's descr-text.el, supporting prefix argument for C-x =
Aidan Kehoe <kehoea@parhasard.net>
parents: 4293
diff changeset
817 (if detail
a78d697ccd2c Import and extend GNU's descr-text.el, supporting prefix argument for C-x =
Aidan Kehoe <kehoea@parhasard.net>
parents: 4293
diff changeset
818 (describe-char (point)))
3724
1fe680cefdb7 [xemacs-hg @ 2006-12-06 21:28:47 by aidan]
aidan
parents: 3652
diff changeset
819 ;; XEmacs: don't use single-key-description, treat non-ASCII
1fe680cefdb7 [xemacs-hg @ 2006-12-06 21:28:47 by aidan]
aidan
parents: 3652
diff changeset
820 ;; characters differently.
1fe680cefdb7 [xemacs-hg @ 2006-12-06 21:28:47 by aidan]
aidan
parents: 3652
diff changeset
821 (if (< char ?\x80)
1fe680cefdb7 [xemacs-hg @ 2006-12-06 21:28:47 by aidan]
aidan
parents: 3652
diff changeset
822 (message "Char: %s (0%o, %d, %x) point=%d of %d(%d%%)%s column %d %s"
1fe680cefdb7 [xemacs-hg @ 2006-12-06 21:28:47 by aidan]
aidan
parents: 3652
diff changeset
823 (text-char-description char) char char char pos total
1fe680cefdb7 [xemacs-hg @ 2006-12-06 21:28:47 by aidan]
aidan
parents: 3652
diff changeset
824 percent narrowed-details col hscroll)
1fe680cefdb7 [xemacs-hg @ 2006-12-06 21:28:47 by aidan]
aidan
parents: 3652
diff changeset
825 (message "Char: %s (%s %s) point=%d of %d(%d%%)%s column %d %s"
1fe680cefdb7 [xemacs-hg @ 2006-12-06 21:28:47 by aidan]
aidan
parents: 3652
diff changeset
826 (text-char-description char) unicode-string
3767
6b2ef948e140 [xemacs-hg @ 2006-12-29 18:09:38 by aidan]
aidan
parents: 3724
diff changeset
827 (mapconcat (lambda (arg) (format "%S" arg))
6b2ef948e140 [xemacs-hg @ 2006-12-29 18:09:38 by aidan]
aidan
parents: 3724
diff changeset
828 (split-char char) " ")
3724
1fe680cefdb7 [xemacs-hg @ 2006-12-06 21:28:47 by aidan]
aidan
parents: 3652
diff changeset
829 pos total
1fe680cefdb7 [xemacs-hg @ 2006-12-06 21:28:47 by aidan]
aidan
parents: 3652
diff changeset
830 percent narrowed-details col hscroll)))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832 (defun fundamental-mode ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
833 "Major mode not specialized for anything in particular.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834 Other major modes are defined by comparison with this one."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
835 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836 (kill-all-local-variables))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
837
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
838 ;; XEmacs the following are declared elsewhere
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
839 ;(defvar read-expression-map (cons 'keymap minibuffer-local-map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840 ; "Minibuffer keymap used for reading Lisp expressions.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841 ;(define-key read-expression-map "\M-\t" 'lisp-complete-symbol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
842
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
843 ;(put 'eval-expression 'disabled t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
845 ;(defvar read-expression-history nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
847 ;; We define this, rather than making `eval' interactive,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
848 ;; 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
849 (defun eval-expression (expression &optional eval-expression-insert-value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850 "Evaluate EXPRESSION and print value in minibuffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
851 Value is also consed on to front of the variable `values'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
852 With prefix argument, insert the result to the current buffer."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
853 ;(interactive "xEval: ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
854 (interactive
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
855 (list (read-from-minibuffer "Eval: "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
856 nil read-expression-map t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
857 'read-expression-history)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
858 current-prefix-arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
859 (setq values (cons (eval expression) values))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
860 (prin1 (car values)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
861 (if eval-expression-insert-value (current-buffer) t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
862
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
863 ;; XEmacs -- extra parameter (variant, but equivalent logic)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
864 (defun edit-and-eval-command (prompt form &optional history)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
865 "Prompting with PROMPT, let user edit FORM and eval result.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
866 FORM is a Lisp expression. Let user edit that expression in
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
867 the minibuffer, then read and evaluate the result."
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
868 (let ((form (read-expression prompt
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
869 ;; first try to format the thing readably;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
870 ;; and if that fails, print it normally.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
871 (condition-case ()
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
872 (let ((print-readably t))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
873 (prin1-to-string form))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
874 (error (prin1-to-string form)))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
875 (or history '(command-history . 1)))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
876 (or history (setq history 'command-history))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
877 (if (consp history)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
878 (setq history (car history)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
879 (if (eq history t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
880 nil
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
881 ;; If form was added to the history as a string,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
882 ;; get rid of that. We want only evallable expressions there.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
883 (if (stringp (car (symbol-value history)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
884 (set history (cdr (symbol-value history))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
885
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
886 ;; If form to be redone does not match front of history,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
887 ;; add it to the history.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
888 (or (equal form (car (symbol-value history)))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
889 (set history (cons form (symbol-value history)))))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
890 (eval form)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
891
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
892 (defun repeat-complex-command (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
893 "Edit and re-evaluate last complex command, or ARGth from last.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
894 A complex command is one which used the minibuffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
895 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
896 The result is executed, repeating the command as changed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
897 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
898 it is added to the front of the command history.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
899 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
900 to get different commands to edit and resubmit."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
901 (interactive "p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
902 ;; XEmacs: It looks like our version is better -sb
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
903 (let ((print-level nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
904 (edit-and-eval-command "Redo: "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
905 (or (nth (1- arg) command-history)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
906 (error ""))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
907 (cons 'command-history arg))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
908
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
909 ;; XEmacs: Functions moved to minibuf.el
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
910 ;; previous-matching-history-element
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
911 ;; next-matching-history-element
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
912 ;; next-history-element
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
913 ;; previous-history-element
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
914 ;; next-complete-history-element
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
915 ;; previous-complete-history-element
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
916
3361
9fddb79e8a88 [xemacs-hg @ 2006-04-25 19:46:23 by scop]
scop
parents: 3064
diff changeset
917 (defun goto-line (line &optional buffer)
9fddb79e8a88 [xemacs-hg @ 2006-04-25 19:46:23 by scop]
scop
parents: 3064
diff changeset
918 "Goto line LINE, counting from line 1 at beginning of BUFFER."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
919 (interactive "NGoto line: ")
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
920 (setq line (prefix-numeric-value line))
3361
9fddb79e8a88 [xemacs-hg @ 2006-04-25 19:46:23 by scop]
scop
parents: 3064
diff changeset
921 (if buffer
9fddb79e8a88 [xemacs-hg @ 2006-04-25 19:46:23 by scop]
scop
parents: 3064
diff changeset
922 (let ((window (get-buffer-window buffer)))
9fddb79e8a88 [xemacs-hg @ 2006-04-25 19:46:23 by scop]
scop
parents: 3064
diff changeset
923 (if window (select-window window)
9fddb79e8a88 [xemacs-hg @ 2006-04-25 19:46:23 by scop]
scop
parents: 3064
diff changeset
924 (switch-to-buffer-other-window buffer))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
925 (save-restriction
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
926 (widen)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
927 (goto-char 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
928 (if (eq selective-display t)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
929 (re-search-forward "[\n\C-m]" nil 'end (1- line))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
930 (forward-line (1- line)))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
931
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 613
diff changeset
932 ;[Put this on C-x u, so we can force that rather than C-_ into startup msg]
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 613
diff changeset
933 ;No more, stop pandering to TTY users.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
934 (define-function 'advertised-undo 'undo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
935
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
936 (defun undo (&optional count)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
937 "Undo some previous changes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
938 Repeat this command to undo more changes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
939 A numeric argument serves as a repeat count."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
940 (interactive "*p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
941 ;; 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
942 ;; for the following command.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
943 (setq this-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
944 (let ((modified (buffer-modified-p))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
945 (recent-save (recent-auto-save-p)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
946 (or (eq (selected-window) (minibuffer-window))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
947 (display-message 'command "Undo!"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
948 (or (and (eq last-command 'undo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
949 (eq (current-buffer) last-undo-buffer)) ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
950 (progn (undo-start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
951 (undo-more 1)))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
952 (undo-more (or count 1))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
953 ;; 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
954 ;; Instead, undoing this should move point to where the change is.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
955 (let ((tail buffer-undo-list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
956 done)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
957 (while (and tail (not done) (not (null (car tail))))
4885
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4869
diff changeset
958 (if (fixnump (car tail))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
959 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
960 (setq done t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
961 (setq buffer-undo-list (delq (car tail) buffer-undo-list))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
962 (setq tail (cdr tail))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
963 (and modified (not (buffer-modified-p))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
964 (delete-auto-save-file-if-necessary recent-save)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
965 ;; 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
966 (setq this-command 'undo))
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 (defvar pending-undo-list nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
969 "Within a run of consecutive undo commands, list remaining to be undone.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
970
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
971 (defvar last-undo-buffer nil) ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
972
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
973 (defun undo-start ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
974 "Set `pending-undo-list' to the front of the undo list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
975 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
976 (if (eq buffer-undo-list t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
977 (error "No undo information in this buffer"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
978 (setq pending-undo-list buffer-undo-list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
979
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
980 (defun undo-more (count)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
981 "Undo back N undo-boundaries beyond what was already undone recently.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
982 Call `undo-start' to get ready to undo recent changes,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
983 then call `undo-more' one or more times to undo them."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
984 (or pending-undo-list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
985 (error "No further undo information"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
986 (setq pending-undo-list (primitive-undo count pending-undo-list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
987 last-undo-buffer (current-buffer))) ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
988
844
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 843
diff changeset
989 (defun undo-all-changes ()
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 843
diff changeset
990 "Keep undoing till the start of the undo list is reached.
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 843
diff changeset
991 Undoes all changes, even past a file save. Especially useful when you've
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 843
diff changeset
992 saved the file at some point."
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 843
diff changeset
993 (interactive)
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 843
diff changeset
994 (undo-start)
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 843
diff changeset
995 (while pending-undo-list (undo-more 1)))
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 843
diff changeset
996
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
997 ;; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
998 (defun call-with-transparent-undo (fn &rest args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
999 "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
1000 buffer. The undo records are processed even if FN returns non-locally.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1001 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
1002
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1003 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
1004 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
1005 (let ((buffer-undo-list nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1006 ;; Kludge to prevent undo list truncation:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1007 (undo-high-threshold -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1008 (undo-threshold -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1009 (obuffer (current-buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1010 (unwind-protect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1011 (apply fn args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1012 ;; Go to the buffer we will restore and make it writable:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1013 (set-buffer obuffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1014 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1015 (let ((buffer-read-only nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1016 (save-restriction
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1017 (widen)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1018 ;; Perform all undos, with further undo logging disabled:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1019 (let ((tail buffer-undo-list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1020 (setq buffer-undo-list t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1021 (while tail
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1022 (setq tail (primitive-undo (length tail) tail))))))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1023
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1024 ;; XEmacs: The following are in other files
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1025 ;; shell-command-history
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1026 ;; shell-command-switch
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1027 ;; shell-command
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1028 ;; shell-command-sentinel
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1031 (defconst universal-argument-map
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1032 (let ((map (make-sparse-keymap)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1033 (set-keymap-default-binding map 'universal-argument-other-key)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1034 ;FSFmacs (define-key map [switch-frame] nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1035 (define-key map [(t)] 'universal-argument-other-key)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1036 (define-key map [(meta t)] 'universal-argument-other-key)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1037 (define-key map [(control u)] 'universal-argument-more)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1038 (define-key map [?-] 'universal-argument-minus)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1039 (define-key map [?0] 'digit-argument)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1040 (define-key map [?1] 'digit-argument)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1041 (define-key map [?2] 'digit-argument)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1042 (define-key map [?3] 'digit-argument)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1043 (define-key map [?4] 'digit-argument)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1044 (define-key map [?5] 'digit-argument)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1045 (define-key map [?6] 'digit-argument)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1046 (define-key map [?7] 'digit-argument)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1047 (define-key map [?8] 'digit-argument)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1048 (define-key map [?9] 'digit-argument)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1049 map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1050 "Keymap used while processing \\[universal-argument].")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1051
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1052 (defvar universal-argument-num-events nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1053 "Number of argument-specifying events read by `universal-argument'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1054 `universal-argument-other-key' uses this to discard those events
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1055 from (this-command-keys), and reread only the final command.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1056
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1057 (defun universal-argument ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1058 "Begin a numeric argument for the following command.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1059 Digits or minus sign following \\[universal-argument] make up the numeric argument.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1060 \\[universal-argument] following the digits or minus sign ends the argument.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1061 \\[universal-argument] without digits or minus sign provides 4 as argument.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1062 Repeating \\[universal-argument] without digits or minus sign
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1063 multiplies the argument by 4 each time."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1064 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1065 (setq prefix-arg (list 4))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1066 (setq zmacs-region-stays t) ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1067 (setq universal-argument-num-events (length (this-command-keys)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1068 (setq overriding-terminal-local-map universal-argument-map))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1069
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1070 ;; 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
1071 ;; 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
1072 (defun universal-argument-more (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1073 (interactive "_P") ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1074 (if (consp arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1075 (setq prefix-arg (list (* 4 (car arg))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1076 (setq prefix-arg arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1077 (setq overriding-terminal-local-map nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1078 (setq universal-argument-num-events (length (this-command-keys))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1079
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1080 (defun negative-argument (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1081 "Begin a negative numeric argument for the next command.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1082 \\[universal-argument] following digits or minus sign ends the argument."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1083 (interactive "_P") ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1084 (cond ((integerp arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1085 (setq prefix-arg (- arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1086 ((eq arg '-)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1087 (setq prefix-arg nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1088 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1089 (setq prefix-arg '-)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1090 (setq universal-argument-num-events (length (this-command-keys)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1091 (setq overriding-terminal-local-map universal-argument-map))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1092
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1093 ;; XEmacs: This function not synched with FSF
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1094 (defun digit-argument (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1095 "Part of the numeric argument for the next command.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1096 \\[universal-argument] following digits or minus sign ends the argument."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1097 (interactive "_P") ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1098 (let* ((event last-command-event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1099 (key (and (key-press-event-p event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1100 (event-key event)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1101 (digit (and key (characterp key) (>= key ?0) (<= key ?9)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1102 (- key ?0))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1103 (if (null digit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1104 (universal-argument-other-key arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1105 (cond ((integerp arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1106 (setq prefix-arg (+ (* arg 10)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1107 (if (< arg 0) (- digit) digit))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1108 ((eq arg '-)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1109 ;; Treat -0 as just -, so that -01 will work.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1110 (setq prefix-arg (if (zerop digit) '- (- digit))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1111 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1112 (setq prefix-arg digit)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1113 (setq universal-argument-num-events (length (this-command-keys)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1114 (setq overriding-terminal-local-map universal-argument-map))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1115
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1116 ;; For backward compatibility, minus with no modifiers is an ordinary
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1117 ;; command if digits have already been entered.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1118 (defun universal-argument-minus (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1119 (interactive "_P") ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1120 (if (integerp arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1121 (universal-argument-other-key arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1122 (negative-argument arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1123
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1124 ;; 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
1125 ;; executed as a command.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1126 (defun universal-argument-other-key (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1127 (interactive "_P") ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1128 (setq prefix-arg arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1129 (let* ((key (this-command-keys))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1130 ;; FSF calls silly function `listify-key-sequence' here.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1131 (keylist (append key nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1132 (setq unread-command-events
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1133 (append (nthcdr universal-argument-num-events keylist)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1134 unread-command-events)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1135 (reset-this-command-lengths)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1136 (setq overriding-terminal-local-map nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1137
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1138
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1139 ;; XEmacs -- keep zmacs-region active.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1140 (defun forward-to-indentation (count)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1141 "Move forward COUNT lines and position at first nonblank character."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1142 (interactive "_p")
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1143 (forward-line count)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1144 (skip-chars-forward " \t"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1145
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1146 (defun backward-to-indentation (count)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1147 "Move backward COUNT lines and position at first nonblank character."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1148 (interactive "_p")
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1149 (forward-line (- count))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1150 (skip-chars-forward " \t"))
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 (defcustom kill-whole-line nil
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1153 "*If non-nil, kill the whole line if point is at the beginning.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1154 Otherwise, `kill-line' kills only up to the end of the line, but not
503
98fb34b6fbe9 [xemacs-hg @ 2001-05-04 23:31:31 by ben]
ben
parents: 502
diff changeset
1155 the terminating newline.
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1156
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1157 WARNING: This is a misnamed variable! It should be called something
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1158 like `kill-whole-line-when-at-beginning'. If you simply want
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1159 \\[kill-line] to kill the entire current line, bind it to the function
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1160 `kill-entire-line'. "
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1161 :type 'boolean
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1162 :group 'killing)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1163
503
98fb34b6fbe9 [xemacs-hg @ 2001-05-04 23:31:31 by ben]
ben
parents: 502
diff changeset
1164 (defun kill-line-1 (arg entire-line)
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1165 (kill-region (if entire-line
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1166 (save-excursion
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1167 (beginning-of-line)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1168 (point))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1169 (point))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1170 ;; Don't shift point before doing the delete; that way,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1171 ;; undo will record the right position of point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1172 ;; FSF
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1173 ; ;; 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
1174 ; ;; before killing. That way, in a read-only buffer, point
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1175 ; ;; moves across the text that is copied to the kill ring.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1176 ; ;; The choice has no effect on undo now that undo records
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1177 ; ;; the value of point from before the command was run.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1178 ; (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1179 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1180 (if arg
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1181 (forward-line (prefix-numeric-value arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1182 (if (eobp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1183 (signal 'end-of-buffer nil))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1184 (if (or (looking-at "[ \t]*$")
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1185 (or entire-line
503
98fb34b6fbe9 [xemacs-hg @ 2001-05-04 23:31:31 by ben]
ben
parents: 502
diff changeset
1186 (and kill-whole-line (bolp))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1187 (forward-line 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1188 (end-of-line)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1189 (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1190
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1191 (defun kill-entire-line (&optional arg)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1192 "Kill the entire line.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1193 With prefix argument, kill that many lines from point. Negative
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1194 arguments kill lines backward.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1195
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1196 When calling from a program, nil means \"no arg\",
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1197 a number counts as a prefix arg."
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1198 (interactive "*P")
503
98fb34b6fbe9 [xemacs-hg @ 2001-05-04 23:31:31 by ben]
ben
parents: 502
diff changeset
1199 (kill-line-1 arg t))
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1200
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1201 (defun kill-line (&optional arg)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1202 "Kill the rest of the current line, or the entire line.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1203 If no nonblanks there, kill thru newline. If called interactively,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1204 may kill the entire line when given no argument at the beginning of a
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1205 line; see `kill-whole-line'. With prefix argument, kill that many
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1206 lines from point. Negative arguments kill lines backward.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1207
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1208 WARNING: This is a misnamed function! It should be called something
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1209 like `kill-to-end-of-line'. If you simply want to kill the entire
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1210 current line, use `kill-entire-line'.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1211
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1212 When calling from a program, nil means \"no arg\",
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1213 a number counts as a prefix arg."
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1214 (interactive "*P")
503
98fb34b6fbe9 [xemacs-hg @ 2001-05-04 23:31:31 by ben]
ben
parents: 502
diff changeset
1215 (kill-line-1 arg nil))
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1216
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1217 ;; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1218 (defun backward-kill-line nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1219 "Kill back to the beginning of the line."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1220 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1221 (let ((point (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1222 (beginning-of-line nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1223 (kill-region (point) point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1224
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1225
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1226 ;;;; Window system cut and paste hooks.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1227 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1228 ;;; 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
1229 ;;; than interprogram-cut-function (from FSFmacs). I don't like the behavior
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1230 ;;; of interprogram-paste-function: ^Y should always come from the kill ring,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1231 ;;; 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
1232 ;;; behave as) yank-hooks instead. -- jwz
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1233
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1234 ;; [... code snipped ...]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1235
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1236 (defcustom kill-hooks nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1237 "*Functions run when something is added to the XEmacs kill ring.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1238 These functions are called with one argument, the string most recently
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1239 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
1240 kill become the X Clipboard selection."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1241 :type 'hook
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1242 :group 'killing)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1243
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1244 ;;; `kill-hooks' seems not sufficient because
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1245 ;;; `interprogram-cut-function' requires more variable about to rotate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1246 ;;; the cut buffers. I'm afraid to change interface of `kill-hooks',
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1247 ;;; so I add it. (1997-11-03 by MORIOKA Tomohiko)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1248
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1249 (defcustom interprogram-cut-function 'own-clipboard
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1250 "Function to call to make a killed region available to other programs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1251
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1252 Most window systems provide some sort of facility for cutting and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1253 pasting text between the windows of different programs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1254 This variable holds a function that Emacs calls whenever text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1255 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
1256 programs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1257
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1258 The function takes one or two arguments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1259 The first argument, TEXT, is a string containing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1260 the text which should be made available.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1261 The second, PUSH, if non-nil means this is a \"new\" kill;
843
f46864126a0d [xemacs-hg @ 2002-05-15 15:27:40 by stephent]
stephent
parents: 829
diff changeset
1262 nil means appending to an \"old\" kill.
f46864126a0d [xemacs-hg @ 2002-05-15 15:27:40 by stephent]
stephent
parents: 829
diff changeset
1263
f46864126a0d [xemacs-hg @ 2002-05-15 15:27:40 by stephent]
stephent
parents: 829
diff changeset
1264 One reasonable choice is `own-clipboard' (the default)."
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1265 :type '(radio (function-item :tag "Send to Clipboard"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1266 :format "%t\n"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1267 own-clipboard)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1268 (const :tag "None" nil)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1269 (function :tag "Other"))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1270 :group 'killing)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1271
843
f46864126a0d [xemacs-hg @ 2002-05-15 15:27:40 by stephent]
stephent
parents: 829
diff changeset
1272 (defcustom interprogram-paste-function 'get-clipboard-foreign
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1273 "Function to call to get text cut from other programs.
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 Most window systems provide some sort of facility for cutting and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1276 pasting text between the windows of different programs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1277 This variable holds a function that Emacs calls to obtain
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1278 text that other programs have provided for pasting.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1279
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1280 The function should be called with no arguments. If the function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1281 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
1282 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
1283 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
1284
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1285 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
1286 than Emacs has provided a string for pasting; if Emacs provided the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1287 most recent string, the function should return nil. If it is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1288 difficult to tell whether Emacs or some other program provided the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1289 current string, it is probably good enough to return nil if the string
843
f46864126a0d [xemacs-hg @ 2002-05-15 15:27:40 by stephent]
stephent
parents: 829
diff changeset
1290 is equal (according to `string=') to the last text Emacs provided.
f46864126a0d [xemacs-hg @ 2002-05-15 15:27:40 by stephent]
stephent
parents: 829
diff changeset
1291
f46864126a0d [xemacs-hg @ 2002-05-15 15:27:40 by stephent]
stephent
parents: 829
diff changeset
1292 Reasonable choices include `get-clipboard-foreign' (the default), and
f46864126a0d [xemacs-hg @ 2002-05-15 15:27:40 by stephent]
stephent
parents: 829
diff changeset
1293 functions calling `get-selection-foreign' (q.v.)."
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1294 :type '(radio (function-item :tag "Get from Clipboard"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1295 :format "%t\n"
843
f46864126a0d [xemacs-hg @ 2002-05-15 15:27:40 by stephent]
stephent
parents: 829
diff changeset
1296 get-clipboard-foreign)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1297 (const :tag "None" nil)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1298 (function :tag "Other"))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1299 :group 'killing)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1300
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1301
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1302 ;;;; The kill ring data structure.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1303
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1304 (defvar kill-ring nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1305 "List of killed text sequences.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1306 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
1307 facilities offered by window systems, use of this variable should
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1308 interact nicely with `interprogram-cut-function' and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1309 `interprogram-paste-function'. The functions `kill-new',
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1310 `kill-append', and `current-kill' are supposed to implement this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1311 interaction; you may want to use them instead of manipulating the kill
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1312 ring directly.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1313
829
42a86787d173 [xemacs-hg @ 2002-05-07 15:58:46 by stephent]
stephent
parents: 801
diff changeset
1314 (defcustom kill-ring-max 60
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1315 "*Maximum length of kill ring before oldest elements are thrown away."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1316 :type 'integer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1317 :group 'killing)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1318
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1319 (defvar kill-ring-yank-pointer nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1320 "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
1321
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1322 (defun kill-new (string &optional replace)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1323 "Make STRING the latest kill in the kill ring.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1324 Set `kill-ring-yank-pointer' to point to it.
829
42a86787d173 [xemacs-hg @ 2002-05-07 15:58:46 by stephent]
stephent
parents: 801
diff changeset
1325 If `interprogram-cut-function' is non-nil, apply it to STRING.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1326 Run `kill-hooks'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1327 Optional second argument REPLACE non-nil means that STRING will replace
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1328 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
1329 ; (and (fboundp 'menu-bar-update-yank-menu)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1330 ; (menu-bar-update-yank-menu string (and replace (car kill-ring))))
829
42a86787d173 [xemacs-hg @ 2002-05-07 15:58:46 by stephent]
stephent
parents: 801
diff changeset
1331 (if (and replace kill-ring)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1332 (setcar kill-ring string)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1333 (setq kill-ring (cons string kill-ring))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1334 (if (> (length kill-ring) kill-ring-max)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1335 (setcdr (nthcdr (1- kill-ring-max) kill-ring) nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1336 (setq kill-ring-yank-pointer kill-ring)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1337 (if interprogram-cut-function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1338 (funcall interprogram-cut-function string (not replace)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1339 (run-hook-with-args 'kill-hooks string))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1340
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1341 (defun kill-append (string before-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1342 "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
1343 If BEFORE-P is non-nil, prepend STRING to the kill.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1344 Run `kill-hooks'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1345 (kill-new (if before-p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1346 (concat string (car kill-ring))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1347 (concat (car kill-ring) string)) t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1348
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1349 (defun current-kill (n &optional do-not-move)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1350 "Rotate the yanking point by N places, and then return that kill.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1351 If N is zero, `interprogram-paste-function' is set, and calling it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1352 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
1353 kill ring and returned as the latest kill.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1354 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
1355 yanking point\; just return the Nth kill forward."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1356 (let ((interprogram-paste (and (= n 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1357 interprogram-paste-function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1358 (funcall interprogram-paste-function))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1359 (if interprogram-paste
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1360 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1361 ;; Disable the interprogram cut function when we add the new
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1362 ;; 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
1363 ;; selection, with identical text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1364 (let ((interprogram-cut-function nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1365 (kill-new interprogram-paste))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1366 interprogram-paste)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1367 (or kill-ring (error "Kill ring is empty"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1368 (let* ((tem (nthcdr (mod (- n (length kill-ring-yank-pointer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1369 (length kill-ring))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1370 kill-ring)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1371 (or do-not-move
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1372 (setq kill-ring-yank-pointer tem))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1373 (car tem)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1374
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1375
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1376
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1377 ;;;; Commands for manipulating the kill ring.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1378
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1379 ;; 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
1380 ;; is a very bad idea -- see Jamie's comment below.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1381
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1382 ;(defvar kill-read-only-ok nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1383 ; "*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
1384
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1385 (defun kill-region (start end &optional verbose) ; verbose is XEmacs addition
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1386 "Kill between point and mark.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1387 The text is deleted but saved in the kill ring.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1388 The command \\[yank] can retrieve it from there.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1389 \(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
1390
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1391 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
1392 Supply two arguments, character numbers indicating the stretch of text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1393 to be killed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1394 Any command that calls this function is a \"kill command\".
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1395 If the previous command was also a kill command,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1396 the text killed this time appends to the text killed last time
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1397 to make one entry in the kill ring."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1398 (interactive "*r\np")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1399 ; (interactive
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1400 ; (let ((region-hack (and zmacs-regions (eq last-command 'yank))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1401 ; ;; 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
1402 ; (if region-hack (zmacs-activate-region))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1403 ; (prog1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1404 ; (list (point) (mark) current-prefix-arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1405 ; (if region-hack (zmacs-deactivate-region)))))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1406 ;; start and end can be markers but the rest of this function is
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1407 ;; written as if they are only integers
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1408 (if (markerp start) (setq start (marker-position start)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1409 (if (markerp end) (setq end (marker-position end)))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1410 (or (and start end) (if zmacs-regions ;; rewritten for I18N3 snarfing
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1411 (error "The region is not active now")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1412 (error "The mark is not set now")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1413 (if verbose (if buffer-read-only
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1414 (lmessage 'command "Copying %d characters"
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1415 (- (max start end) (min start end)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1416 (lmessage 'command "Killing %d characters"
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1417 (- (max start end) (min start end)))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1418 (cond
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 ;; I don't like this large change in behavior -- jwz
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1421 ;; 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
1422 ;; this code, but only for text-properties and not full extents. -sb
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1423 ;; 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
1424 ;; 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
1425 ;; the region's text in the kill ring, anyway.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1426 ((or (and buffer-read-only (not inhibit-read-only))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1427 (text-property-not-all (min start end) (max start end) 'read-only nil))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1428 ;; This is redundant.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1429 ;; (if verbose (message "Copying %d characters"
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1430 ;; (- (max start end) (min start end))))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1431 (copy-region-as-kill start end)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1432 ;; ;; This should always barf, and give us the correct error.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1433 ;; (if kill-read-only-ok
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1434 ;; (message "Read only text copied to kill ring")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1435 (setq this-command 'kill-region)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1436 (barf-if-buffer-read-only)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1437 (signal 'buffer-read-only (list (current-buffer))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1438
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1439 ;; 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
1440 ;; ring to share the same string object. This code does that.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1441 ((not (or (eq buffer-undo-list t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1442 (eq last-command 'kill-region)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1443 ;; Use = since positions may be numbers or markers.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1444 (= start end)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1445 ;; 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
1446 ;; FSF calls this `undo-strong-limit'
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1447 (let ((undo-high-threshold (+ (- end start) 100))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1448 ;(old-list buffer-undo-list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1449 tail)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1450 (delete-region start end)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1451 ;; Search back in buffer-undo-list for this string,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1452 ;; in case a change hook made property changes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1453 (setq tail buffer-undo-list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1454 (while (and tail
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1455 (not (stringp (car-safe (car-safe tail))))) ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1456 (pop tail))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1457 ;; Take the same string recorded for undo
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1458 ;; and put it in the kill-ring.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1459 (and tail
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1460 (kill-new (car (car tail))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1461
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1462 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1463 ;; 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
1464 ;; add another string to the undo list).
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1465 (copy-region-as-kill start end)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1466 (delete-region start end)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1467 (setq this-command 'kill-region))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1468
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1469 ;; 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
1470 ;; 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
1471 ;; then corrects it with the intended C-w.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1472 (defun copy-region-as-kill (start end)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1473 "Save the region as if killed, but don't kill it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1474 Run `kill-hooks'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1475 (interactive "r")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1476 (if (eq last-command 'kill-region)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1477 (kill-append (buffer-substring start end) (< end start))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1478 (kill-new (buffer-substring start end)))
428
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
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1481 (defun kill-ring-save (start end)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1482 "Save the region as if killed, but don't kill it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1483 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
1484 visual feedback indicating the extent of the region being copied."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1485 (interactive "r")
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1486 (copy-region-as-kill start end)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1487 ;; copy before delay, for xclipboard's benefit
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1488 (if (interactive-p)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1489 (let ((other-end (if (= (point) start) end start))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1490 (opoint (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1491 ;; Inhibit quitting so we can make a quit here
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1492 ;; look like a C-g typed as a command.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1493 (inhibit-quit t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1494 (if (pos-visible-in-window-p other-end (selected-window))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1495 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1496 ;; FSF (I'm not sure what this does -sb)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1497 ; ;; Swap point and mark.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1498 ; (set-marker (mark-marker) (point) (current-buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1499 (goto-char other-end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1500 (sit-for 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1501 ; ;; Swap back.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1502 ; (set-marker (mark-marker) other-end (current-buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1503 (goto-char opoint)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1504 ;; If user quit, deactivate the mark
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1505 ;; as C-g would as a command.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1506 (and quit-flag (mark)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1507 (zmacs-deactivate-region)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1508 ;; too noisy. -- jwz
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1509 ; (let* ((killed-text (current-kill 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1510 ; (message-len (min (length killed-text) 40)))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1511 ; (if (= (point) start)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1512 ; ;; Don't say "killed"; that is misleading.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1513 ; (message "Saved text until \"%s\""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1514 ; (substring killed-text (- message-len)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1515 ; (message "Saved text from \"%s\""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1516 ; (substring killed-text 0 message-len))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1517 ))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1518
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1519 (defun append-next-kill ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1520 "Cause following command, if it kills, to append to previous kill."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1521 ;; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1522 (interactive "_")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1523 (if (interactive-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1524 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1525 (setq this-command 'kill-region)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1526 (display-message 'command
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1527 "If the next command is a kill, it will append"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1528 (setq last-command 'kill-region)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1529
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1530 (defun yank-pop (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1531 "Replace just-yanked stretch of killed text with a different stretch.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1532 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
1533 At such a time, the region contains a stretch of reinserted
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1534 previously-killed text. `yank-pop' deletes that text and inserts in its
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1535 place a different stretch of killed text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1536
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1537 With no argument, the previous kill is inserted.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1538 With argument N, insert the Nth previous kill.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1539 If N is negative, this is a more recent kill.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1540
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1541 The sequence of kills wraps around, so that after the oldest one
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1542 comes the newest one."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1543 (interactive "*p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1544 (if (not (eq last-command 'yank))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1545 (error "Previous command was not a yank"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1546 (setq this-command 'yank)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1547 (let ((inhibit-read-only t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1548 (before (< (point) (mark t))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1549 (delete-region (point) (mark t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1550 ;;(set-marker (mark-marker) (point) (current-buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1551 (set-mark (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1552 (insert (current-kill arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1553 (if before
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1554 ;; 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
1555 ;; It is cleaner to avoid activation, even though the command
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1556 ;; loop would deactivate the mark because we inserted text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1557 (goto-char (prog1 (mark t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1558 (set-marker (mark-marker t) (point) (current-buffer))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1559 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1560
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 yank (&optional arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1563 "Reinsert the last stretch of killed text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1564 More precisely, reinsert the stretch of killed text most recently
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1565 killed OR yanked. Put point at end, and set mark at beginning.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1566 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
1567 With argument N, reinsert the Nth most recently killed stretch of killed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1568 text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1569 See also the command \\[yank-pop]."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1570 (interactive "*P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1571 ;; 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
1572 ;; for the following command.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1573 (setq this-command t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1574 (push-mark (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1575 (insert (current-kill (cond
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1576 ((listp arg) 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1577 ((eq arg '-) -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1578 (t (1- arg)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1579 (if (consp arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1580 ;; 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
1581 ;; It is cleaner to avoid activation, even though the command
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1582 ;; loop would deactivate the mark because we inserted text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1583 ;; (But it's an unnecessary kludge in XEmacs.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1584 ;(goto-char (prog1 (mark t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1585 ;(set-marker (mark-marker) (point) (current-buffer)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1586 (exchange-point-and-mark t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1587 ;; 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
1588 (setq this-command 'yank)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1589 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1590
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1591 (defun rotate-yank-pointer (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1592 "Rotate the yanking point in the kill ring.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1593 With argument, rotate that many kills forward (or backward, if negative)."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1594 (interactive "p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1595 (current-kill arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1596
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1597
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1598 (defun insert-buffer (buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1599 "Insert after point the contents of BUFFER.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1600 Puts mark after the inserted text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1601 BUFFER may be a buffer or a buffer name."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1602 (interactive
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1603 (list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1604 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1605 (barf-if-buffer-read-only)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1606 (read-buffer "Insert buffer: "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1607 ;; XEmacs: we have different args
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1608 (other-buffer (current-buffer) nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1609 t))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1610 (or (bufferp buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1611 (setq buffer (get-buffer buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1612 (let (start end newmark)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1613 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1614 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1615 (set-buffer buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1616 (setq start (point-min) end (point-max)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1617 (insert-buffer-substring buffer start end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1618 (setq newmark (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1619 (push-mark newmark))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1620 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1621
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1622 (defun append-to-buffer (buffer start end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1623 "Append to specified buffer the text of the region.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1624 It is inserted into that buffer before its point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1625
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1626 When calling from a program, give three arguments:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1627 BUFFER (or buffer name), START and END.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1628 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
1629 (interactive
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1630 ;; XEmacs: we have different args to other-buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1631 (list (read-buffer "Append to buffer: " (other-buffer (current-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1632 nil t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1633 (region-beginning) (region-end)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1634 (let ((oldbuf (current-buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1635 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1636 (set-buffer (get-buffer-create buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1637 (insert-buffer-substring oldbuf start end))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1638
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1639 (defun prepend-to-buffer (buffer start end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1640 "Prepend to specified buffer the text of the region.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1641 It is inserted into that buffer after its point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1642
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1643 When calling from a program, give three arguments:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1644 BUFFER (or buffer name), START and END.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1645 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
1646 (interactive "BPrepend to buffer: \nr")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1647 (let ((oldbuf (current-buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1648 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1649 (set-buffer (get-buffer-create buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1650 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1651 (insert-buffer-substring oldbuf start end)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1652
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1653 (defun copy-to-buffer (buffer start end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1654 "Copy to specified buffer the text of the region.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1655 It is inserted into that buffer, replacing existing text there.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1656
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1657 When calling from a program, give three arguments:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1658 BUFFER (or buffer name), START and END.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1659 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
1660 (interactive "BCopy to buffer: \nr")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1661 (let ((oldbuf (current-buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1662 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1663 (set-buffer (get-buffer-create buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1664 (erase-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1665 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1666 (insert-buffer-substring oldbuf start end)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1667
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1668 ;FSFmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1669 ;(put 'mark-inactive 'error-conditions '(mark-inactive error))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1670 ;(put 'mark-inactive 'error-message "The mark is not active now")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1671
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1672 (defun mark (&optional force buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1673 "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
1674
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1675 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
1676 currently in the active (highlighted) state. With an argument of t, this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1677 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
1678 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
1679 the user has expressed a preference for the active-region model.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1680
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1681 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
1682 a mistake; see the documentation of `set-mark'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1683 (setq buffer (decode-buffer buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1684 ;FSFmacs version:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1685 ; (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
1686 ; (marker-position (mark-marker))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1687 ; (signal 'mark-inactive nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1688 (let ((m (mark-marker force buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1689 (and m (marker-position m))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1690
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1691 ;;;#### FSFmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1692 ;;; 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
1693 ;;; run deactivate-mark-hook. This shorthand should simplify.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1694 ;(defsubst deactivate-mark ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1695 ; "Deactivate the mark by setting `mark-active' to nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1696 ;\(That makes a difference only in Transient Mark mode.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1697 ;Also runs the hook `deactivate-mark-hook'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1698 ; (if transient-mark-mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1699 ; (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1700 ; (setq mark-active nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1701 ; (run-hooks 'deactivate-mark-hook))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1702
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1703 (defun set-mark (pos &optional buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1704 "Set this buffer's mark to POS. Don't use this function!
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1705 That is to say, don't use this function unless you want
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1706 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
1707 mark position to be lost.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1708
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1709 Normally, when a new mark is set, the old one should go on the stack.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1710 This is why most applications should use `push-mark', not `set-mark'.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1711
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1712 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
1713 purposes. The mark saves a location for the user's convenience.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1714 Most editing commands should not alter the mark.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1715 To remember a location for internal use in the Lisp program,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1716 store it in a Lisp variable. Example:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1717
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1718 (let ((start (point))) (forward-line 1) (delete-region start (point)))."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1719
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1720 (setq buffer (decode-buffer buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1721 (set-marker (mark-marker t buffer) pos buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1722 ;; FSF
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1723 ; (if pos
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1724 ; (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1725 ; (setq mark-active t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1726 ; (run-hooks 'activate-mark-hook)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1727 ; (set-marker (mark-marker) pos (current-buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1728 ; ;; Normally we never clear mark-active except in Transient Mark mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1729 ; ;; But when we actually clear out the mark value too,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1730 ; ;; we must clear mark-active in any mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1731 ; (setq mark-active nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1732 ; (run-hooks 'deactivate-mark-hook)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1733 ; (set-marker (mark-marker) nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1734
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1735 (defvar mark-ring nil
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1736 "The list of former marks of the current buffer, most recent first.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1737 This variable is automatically buffer-local.")
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1738 (make-variable-buffer-local 'mark-ring)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1739 (put 'mark-ring 'permanent-local t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1740
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1741 (defvar dont-record-current-mark nil
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1742 "If set to t, the current mark value should not be recorded on the mark ring.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1743 This is set by commands that manipulate the mark incidentally, to avoid
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1744 cluttering the mark ring unnecessarily. Under most circumstances, you do
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1745 not need to set this directly; it is automatically reset each time
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1746 `push-mark' is called, according to `mark-ring-unrecorded-commands'. This
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1747 variable is automatically buffer-local.")
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1748 (make-variable-buffer-local 'dont-record-current-mark)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1749 (put 'dont-record-current-mark 'permanent-local t)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1750
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1751 ;; a conspiracy between push-mark and handle-pre-motion-command
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1752 (defvar in-shifted-motion-command nil)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1753
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1754 (defcustom mark-ring-unrecorded-commands '(shifted-motion-commands
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1755 yank
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1756 mark-beginning-of-buffer
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1757 mark-bob
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1758 mark-defun
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1759 mark-end-of-buffer
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1760 mark-end-of-line
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1761 mark-end-of-sentence
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1762 mark-eob
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1763 mark-marker
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1764 mark-page
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1765 mark-paragraph
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1766 mark-sexp
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1767 mark-whole-buffer
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1768 mark-word)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1769 "*List of commands whose marks should not be recorded on the mark stack.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1770 Many commands set the mark as part of their action. Normally, all such
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1771 marks get recorded onto the mark stack. However, this tends to clutter up
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1772 the mark stack unnecessarily. You can control this by putting a command
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1773 onto this list. Then, any marks set by the function will not be recorded.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1774
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1775 The special value `shifted-motion-commands' causes marks set as a result
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1776 of selection using any shifted motion commands to not be recorded.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1777
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1778 The value `yank' affects all yank-like commands, as well as just `yank'."
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1779 :type '(repeat (choice (const :tag "shifted motion commands"
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1780 shifted-motion-commands)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1781 (const :tag "functions that select text"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1782 :inline t
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1783 (mark-beginning-of-buffer
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1784 mark-bob
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1785 mark-defun
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1786 mark-end-of-buffer
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1787 mark-end-of-line
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1788 mark-end-of-sentence
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1789 mark-eob
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1790 mark-marker
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1791 mark-page
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1792 mark-paragraph
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1793 mark-sexp
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1794 mark-whole-buffer
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1795 mark-word))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1796 (const :tag "functions that paste text"
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1797 yank)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1798 function))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1799 :group 'killing)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1800
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1801 (defcustom mark-ring-max 16
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1802 "*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
1803 :type 'integer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1804 :group 'killing)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1805
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1806 (defvar global-mark-ring nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1807 "The list of saved global marks, most recent first.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1808
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1809 (defcustom global-mark-ring-max 16
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1810 "*Maximum size of global mark ring. \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1811 Start discarding off end if gets this big."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1812 :type 'integer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1813 :group 'killing)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1814
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1815 (defun set-mark-command (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1816 "Set mark at where point is, or jump to mark.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1817 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
1818 ring, and push mark on global mark ring.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1819 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
1820 \(does not affect global mark ring\).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1821
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1822 The mark ring is a per-buffer stack of marks, most recent first. Its
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1823 maximum length is controlled by `mark-ring-max'. Generally, when new
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1824 marks are set, the current mark is pushed onto the stack. You can pop
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1825 marks off the stack using \\[universal-argument] \\[set-mark-command]. The term \"ring\" is used because when
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1826 you pop a mark off the stack, the current mark value is pushed onto the
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1827 far end of the stack. If this is confusing, just think of the mark ring
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1828 as a stack.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1829
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1830 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
1831 purposes. See the documentation of `set-mark' for more information."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1832 (interactive "P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1833 (if (null arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1834 (push-mark nil nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1835 (if (null (mark t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1836 (error "No mark set in this buffer")
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1837 (if dont-record-current-mark (pop-mark))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1838 (goto-char (mark t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1839 (pop-mark))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1840
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1841 ;; XEmacs: Extra parameter
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1842 (defun push-mark (&optional location nomsg activate-region buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1843 "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
1844 If the last global mark pushed was not in the current buffer,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1845 also push LOCATION on the global mark ring.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1846 Display `Mark set' unless the optional second arg NOMSG is non-nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1847 Activate mark if optional third arg ACTIVATE-REGION non-nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1848
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1849 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
1850 purposes. See the documentation of `set-mark' for more information."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1851 (setq buffer (decode-buffer buffer)) ; XEmacs
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1852 (if (or dont-record-current-mark (null (mark t buffer))) ; XEmacs
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1853 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1854 ;; The save-excursion / set-buffer is necessary because mark-ring
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1855 ;; is a buffer local variable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1856 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1857 (set-buffer buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1858 (setq mark-ring (cons (copy-marker (mark-marker t buffer)) mark-ring))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1859 (if (> (length mark-ring) mark-ring-max)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1860 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1861 (move-marker (car (nthcdr mark-ring-max mark-ring)) nil buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1862 (setcdr (nthcdr (1- mark-ring-max) mark-ring) nil)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1863 (set-mark (or location (point buffer)) buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1864 ; (set-marker (mark-marker) (or location (point)) (current-buffer)) ; FSF
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1865 ;; Now push the mark on the global mark ring.
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1866 (if (and (not dont-record-current-mark)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1867 (or (null global-mark-ring)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1868 (not (eq (marker-buffer (car global-mark-ring)) buffer))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1869 ;; The last global mark pushed wasn't in this same buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1870 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1871 (setq global-mark-ring (cons (copy-marker (mark-marker t buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1872 global-mark-ring))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1873 (if (> (length global-mark-ring) global-mark-ring-max)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1874 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1875 (move-marker (car (nthcdr global-mark-ring-max global-mark-ring))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1876 nil buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1877 (setcdr (nthcdr (1- global-mark-ring-max) global-mark-ring) nil)))))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1878 (setq dont-record-current-mark
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1879 (not (not (or (and in-shifted-motion-command
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1880 (memq 'shifted-motion-commands
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1881 mark-ring-unrecorded-commands))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1882 (memq this-command mark-ring-unrecorded-commands)))))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1883 (or dont-record-current-mark nomsg executing-kbd-macro
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1884 (> (minibuffer-depth) 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1885 (display-message 'command "Mark set"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1886 (if activate-region
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1887 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1888 (setq zmacs-region-stays t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1889 (zmacs-activate-region)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1890 ; (if (or activate (not transient-mark-mode)) ; FSF
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1891 ; (set-mark (mark t))) ; FSF
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1892 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1893
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1894 (defun pop-mark ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1895 "Pop off mark ring into the buffer's actual mark.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1896 Does not set point. Does nothing if mark ring is empty."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1897 (if mark-ring
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1898 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1899 (setq mark-ring (nconc mark-ring (list (copy-marker (mark-marker t)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1900 (set-mark (car mark-ring))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1901 (move-marker (car mark-ring) nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1902 (if (null (mark t)) (ding))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1903 (setq mark-ring (cdr mark-ring)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1904
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1905 (define-function 'exchange-dot-and-mark 'exchange-point-and-mark)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1906 (defun exchange-point-and-mark (&optional dont-activate-region)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1907 "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
1908 The mark is activated unless DONT-ACTIVATE-REGION is non-nil."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1909 (interactive nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1910 (let ((omark (mark t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1911 (if (null omark)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1912 (error "No mark set in this buffer"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1913 (set-mark (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1914 (goto-char omark)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1915 (or dont-activate-region (zmacs-activate-region)) ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1916 nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1917
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1918 ;; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1919 (defun mark-something (mark-fn movement-fn arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1920 "internal function used by mark-sexp, mark-word, etc."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1921 (let (newmark (pushp t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1922 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1923 (if (and (eq last-command mark-fn) (mark))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1924 ;; Extend the previous state in the same direction:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1925 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1926 (if (< (mark) (point)) (setq arg (- arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1927 (goto-char (mark))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1928 (setq pushp nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1929 (funcall movement-fn arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1930 (setq newmark (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1931 (if pushp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1932 (push-mark newmark nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1933 ;; 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
1934 (set-mark newmark)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1935 (activate-region))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1936
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1937 ;(defun transient-mark-mode (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1938 ; "Toggle Transient Mark mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1939 ;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
1940 ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1941 ;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
1942 ;Changing the buffer \"deactivates\" the mark.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1943 ;So do certain other operations that set the mark
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1944 ;but whose main purpose is something else--for example,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1945 ;incremental search, \\[beginning-of-buffer], and \\[end-of-buffer]."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1946 ; (interactive "P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1947 ; (setq transient-mark-mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1948 ; (if (null arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1949 ; (not transient-mark-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1950 ; (> (prefix-numeric-value arg) 0))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1951
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1952 (defun pop-global-mark ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1953 "Pop off global mark ring and jump to the top location."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1954 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1955 ;; Pop entries which refer to non-existent buffers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1956 (while (and global-mark-ring (not (marker-buffer (car global-mark-ring))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1957 (setq global-mark-ring (cdr global-mark-ring)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1958 (or global-mark-ring
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1959 (error "No global mark set"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1960 (let* ((marker (car global-mark-ring))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1961 (buffer (marker-buffer marker))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1962 (position (marker-position marker)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1963 (setq global-mark-ring (nconc (cdr global-mark-ring)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1964 (list (car global-mark-ring))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1965 (set-buffer buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1966 (or (and (>= position (point-min))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1967 (<= position (point-max)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1968 (widen))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1969 (goto-char position)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1970 (switch-to-buffer buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1971
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1972
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1973 (defcustom signal-error-on-buffer-boundary t
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1974 "*If Non-nil, beep or signal an error when moving past buffer boundary.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1975 The commands that honor this variable are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1976
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1977 forward-char-command
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1978 backward-char-command
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1979 next-line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1980 previous-line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1981 scroll-up-command
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1982 scroll-down-command"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1983 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1984 :group 'editing-basics)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1985
3361
9fddb79e8a88 [xemacs-hg @ 2006-04-25 19:46:23 by scop]
scop
parents: 3064
diff changeset
1986 (defcustom next-line-add-newlines nil
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1987 "*If non-nil, `next-line' inserts newline when the point is at end of buffer.
3361
9fddb79e8a88 [xemacs-hg @ 2006-04-25 19:46:23 by scop]
scop
parents: 3064
diff changeset
1988 This behavior used to be the default, but is now considered an unnecessary and
9fddb79e8a88 [xemacs-hg @ 2006-04-25 19:46:23 by scop]
scop
parents: 3064
diff changeset
1989 unwanted side-effect."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1990 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1991 :group 'editing-basics)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1992
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1993 (defcustom shifted-motion-keys-select-region t
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1994 "*If non-nil, shifted motion keys select text, like in MS Windows.
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1995
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1996 More specifically, if a keystroke that matches one of the key
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1997 specifications in `motion-keys-for-shifted-motion' is pressed along
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1998 with the Shift key, and the command invoked moves the cursor and
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
1999 preserves the active region (see `zmacs-region-stays'), the
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2000 intervening text will be added to the active region.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2001
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2002 When the region has been enabled or augmented as a result of a shifted
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2003 motion key, an unshifted motion key will normally deselect the region.
2485
3e1c7efd5cde [xemacs-hg @ 2005-01-17 11:23:01 by adrian]
adrian
parents: 2439
diff changeset
2004 However, if `unshifted-motion-keys-deselect-region' is nil, the region
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2005 will remain active, augmented by the characters moved over by this
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2006 motion key.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2007
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2008 This functionality is specifically interpreted in terms of keys, and
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2009 *NOT* in terms of particular commands, because that produces the most
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2010 intuitive behavior: `forward-char' will work with shifted motion
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2011 when invoked by `right' but not `C-f', and user-written motion commands
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2012 bound to motion keys will automatically work with shifted motion."
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2013 :type 'boolean
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2014 :group 'editing-basics)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2015
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2016 (defcustom unshifted-motion-keys-deselect-region t
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2017 "*If non-nil, unshifted motion keys deselect a shifted-motion region.
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2018 This only occurs after a region has been selected or augmented using
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2019 shifted motion keys (not when using the traditional set-mark-then-move
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2020 method), and has no effect if `shifted-motion-keys-select-region' is
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2021 nil."
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2022 :type 'boolean
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2023 :group 'editing-basics)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2024
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2025 (defcustom motion-keys-for-shifted-motion
1261
465bd3c7d932 [xemacs-hg @ 2003-02-06 06:35:47 by ben]
ben
parents: 958
diff changeset
2026 ;; meta-shift-home/end are NOT shifted motion commands.
465bd3c7d932 [xemacs-hg @ 2003-02-06 06:35:47 by ben]
ben
parents: 958
diff changeset
2027 '(left right up down (home) (control home) (meta control home)
465bd3c7d932 [xemacs-hg @ 2003-02-06 06:35:47 by ben]
ben
parents: 958
diff changeset
2028 (end) (control end) (meta control end) prior next
465bd3c7d932 [xemacs-hg @ 2003-02-06 06:35:47 by ben]
ben
parents: 958
diff changeset
2029 kp-left kp-right kp-up kp-down (kp-home) (control kp-home)
465bd3c7d932 [xemacs-hg @ 2003-02-06 06:35:47 by ben]
ben
parents: 958
diff changeset
2030 (meta control kp-home) (kp-end) (control kp-end) (meta control kp-end)
465bd3c7d932 [xemacs-hg @ 2003-02-06 06:35:47 by ben]
ben
parents: 958
diff changeset
2031 kp-prior kp-next)
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2032 "*List of keys considered motion keys for the purpose of shifted selection.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2033 When one of these keys is pressed along with the Shift key, and the
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2034 command invoked moves the cursor and preserves the active region (see
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2035 `zmacs-region-stays'), the intervening text will be added to the active
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2036 region. See `shifted-motion-keys-select-region' for more details.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2037
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2038 Each entry should be a keysym or a list (MODIFIERS ... KEYSYM),
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2039 i.e. zero or more modifiers followed by a keysym. When a keysym alone
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2040 is given, a keystroke consisting of that keysym, with or without any
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2041 modifiers, is considered a motion key. When the list form is given,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2042 only a keystroke with exactly those modifiers and no others (with the
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2043 exception of the Shift key) is considered a motion key.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2044
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2045 NOTE: Currently, the keysym cannot be a non-alphabetic character key
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2046 such as the `=/+' key. In any case, the shifted-motion paradigm does
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2047 not make much sense with those keys. The keysym can, however, be an
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2048 alphabetic key without problem, and you can specify the key using
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2049 either a character or a symbol, uppercase or lowercase."
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2050 :type '(repeat (choice (const :tag "normal cursor-pad (\"gray\") keys"
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2051 :inline t
1261
465bd3c7d932 [xemacs-hg @ 2003-02-06 06:35:47 by ben]
ben
parents: 958
diff changeset
2052 (left
465bd3c7d932 [xemacs-hg @ 2003-02-06 06:35:47 by ben]
ben
parents: 958
diff changeset
2053 right up down
465bd3c7d932 [xemacs-hg @ 2003-02-06 06:35:47 by ben]
ben
parents: 958
diff changeset
2054 (home) (control home) (meta control home)
465bd3c7d932 [xemacs-hg @ 2003-02-06 06:35:47 by ben]
ben
parents: 958
diff changeset
2055 (end) (control end) (meta control end)
465bd3c7d932 [xemacs-hg @ 2003-02-06 06:35:47 by ben]
ben
parents: 958
diff changeset
2056 prior next))
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2057 (const :tag "keypad motion keys"
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2058 :inline t
1261
465bd3c7d932 [xemacs-hg @ 2003-02-06 06:35:47 by ben]
ben
parents: 958
diff changeset
2059 (kp-left
465bd3c7d932 [xemacs-hg @ 2003-02-06 06:35:47 by ben]
ben
parents: 958
diff changeset
2060 kp-right kp-up kp-down
465bd3c7d932 [xemacs-hg @ 2003-02-06 06:35:47 by ben]
ben
parents: 958
diff changeset
2061 (kp-home) (control kp-home)
465bd3c7d932 [xemacs-hg @ 2003-02-06 06:35:47 by ben]
ben
parents: 958
diff changeset
2062 (meta control kp-home)
465bd3c7d932 [xemacs-hg @ 2003-02-06 06:35:47 by ben]
ben
parents: 958
diff changeset
2063 (kp-end) (control kp-end)
465bd3c7d932 [xemacs-hg @ 2003-02-06 06:35:47 by ben]
ben
parents: 958
diff changeset
2064 (meta control kp-end)
465bd3c7d932 [xemacs-hg @ 2003-02-06 06:35:47 by ben]
ben
parents: 958
diff changeset
2065 kp-prior kp-next))
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2066 (const :tag "alphabetic motion keys"
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2067 :inline t
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2068 ((control b) (control f)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2069 (control p) (control n)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2070 (control a) (control e)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2071 (control v) (meta v)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2072 (meta b) (meta f)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2073 (meta a) (meta e)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2074 (meta m) ; back-to-indentation
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2075 (meta r) ; move-to-window-line
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2076 (meta control b) (meta control f)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2077 (meta control p) (meta control n)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2078 (meta control a) (meta control e)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2079 (meta control d) ;; down-list
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2080 (meta control u) ;; backward-up-list
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2081 ))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2082 symbol))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2083 :group 'editing-basics)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2084
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2085 (defun handle-pre-motion-command-current-command-is-motion ()
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2086 (and (key-press-event-p last-input-event)
5576
071b810ceb18 Declare labels as line where appropriate; use #'labels, not #'flet, tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5567
diff changeset
2087 (labels
071b810ceb18 Declare labels as line where appropriate; use #'labels, not #'flet, tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5567
diff changeset
2088 ((keysyms-equal (a b)
071b810ceb18 Declare labels as line where appropriate; use #'labels, not #'flet, tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5567
diff changeset
2089 (when (and
071b810ceb18 Declare labels as line where appropriate; use #'labels, not #'flet, tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5567
diff changeset
2090 ;; As of now, none of the elements of
071b810ceb18 Declare labels as line where appropriate; use #'labels, not #'flet, tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5567
diff changeset
2091 ;; motion-keys-for-shifted-motion are non-symbols;
071b810ceb18 Declare labels as line where appropriate; use #'labels, not #'flet, tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5567
diff changeset
2092 ;; this redundant check saves a few hundred
071b810ceb18 Declare labels as line where appropriate; use #'labels, not #'flet, tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5567
diff changeset
2093 ;; funcalls on startup.
071b810ceb18 Declare labels as line where appropriate; use #'labels, not #'flet, tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5567
diff changeset
2094 (not (symbolp b))
071b810ceb18 Declare labels as line where appropriate; use #'labels, not #'flet, tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5567
diff changeset
2095 (characterp b))
071b810ceb18 Declare labels as line where appropriate; use #'labels, not #'flet, tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5567
diff changeset
2096 (setf (car char-list) b
071b810ceb18 Declare labels as line where appropriate; use #'labels, not #'flet, tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5567
diff changeset
2097 b (intern (concat char-list nil))))
071b810ceb18 Declare labels as line where appropriate; use #'labels, not #'flet, tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5567
diff changeset
2098 (eq a b)))
071b810ceb18 Declare labels as line where appropriate; use #'labels, not #'flet, tests.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5567
diff changeset
2099 (declare (inline keysyms-equal) (special char-list))
4869
e533a9912ef1 Eliminate funcalls, #'handle-pre-motion-command-current-command-is-motion
Aidan Kehoe <kehoea@parhasard.net>
parents: 4783
diff changeset
2100 (loop
e533a9912ef1 Eliminate funcalls, #'handle-pre-motion-command-current-command-is-motion
Aidan Kehoe <kehoea@parhasard.net>
parents: 4783
diff changeset
2101 for keysym in motion-keys-for-shifted-motion
e533a9912ef1 Eliminate funcalls, #'handle-pre-motion-command-current-command-is-motion
Aidan Kehoe <kehoea@parhasard.net>
parents: 4783
diff changeset
2102 with key = (event-key last-input-event)
e533a9912ef1 Eliminate funcalls, #'handle-pre-motion-command-current-command-is-motion
Aidan Kehoe <kehoea@parhasard.net>
parents: 4783
diff changeset
2103 with mods = (delq 'shift (event-modifiers last-input-event))
e533a9912ef1 Eliminate funcalls, #'handle-pre-motion-command-current-command-is-motion
Aidan Kehoe <kehoea@parhasard.net>
parents: 4783
diff changeset
2104 with char-list = '(?a) ;; Some random character; the list will be
e533a9912ef1 Eliminate funcalls, #'handle-pre-motion-command-current-command-is-motion
Aidan Kehoe <kehoea@parhasard.net>
parents: 4783
diff changeset
2105 ;; modified in the constants vector over
e533a9912ef1 Eliminate funcalls, #'handle-pre-motion-command-current-command-is-motion
Aidan Kehoe <kehoea@parhasard.net>
parents: 4783
diff changeset
2106 ;; time.
e533a9912ef1 Eliminate funcalls, #'handle-pre-motion-command-current-command-is-motion
Aidan Kehoe <kehoea@parhasard.net>
parents: 4783
diff changeset
2107 initially (if (and (not (symbolp key)) (characterp key))
e533a9912ef1 Eliminate funcalls, #'handle-pre-motion-command-current-command-is-motion
Aidan Kehoe <kehoea@parhasard.net>
parents: 4783
diff changeset
2108 (setf (car char-list) key
e533a9912ef1 Eliminate funcalls, #'handle-pre-motion-command-current-command-is-motion
Aidan Kehoe <kehoea@parhasard.net>
parents: 4783
diff changeset
2109 key (intern (concat char-list nil))))
e533a9912ef1 Eliminate funcalls, #'handle-pre-motion-command-current-command-is-motion
Aidan Kehoe <kehoea@parhasard.net>
parents: 4783
diff changeset
2110 thereis (if (listp keysym)
e533a9912ef1 Eliminate funcalls, #'handle-pre-motion-command-current-command-is-motion
Aidan Kehoe <kehoea@parhasard.net>
parents: 4783
diff changeset
2111 (and (equal mods (butlast keysym))
e533a9912ef1 Eliminate funcalls, #'handle-pre-motion-command-current-command-is-motion
Aidan Kehoe <kehoea@parhasard.net>
parents: 4783
diff changeset
2112 (keysyms-equal
e533a9912ef1 Eliminate funcalls, #'handle-pre-motion-command-current-command-is-motion
Aidan Kehoe <kehoea@parhasard.net>
parents: 4783
diff changeset
2113 key (car (last keysym))))
e533a9912ef1 Eliminate funcalls, #'handle-pre-motion-command-current-command-is-motion
Aidan Kehoe <kehoea@parhasard.net>
parents: 4783
diff changeset
2114 (keysyms-equal key keysym))))))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2115
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2116 (defun handle-pre-motion-command ()
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2117 (if (and
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2118 (handle-pre-motion-command-current-command-is-motion)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2119 zmacs-regions
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2120 shifted-motion-keys-select-region
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2121 (not (region-active-p))
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2122 ;; Special-case alphabetic keysyms, because the `shift'
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2123 ;; modifier does not appear on them. (Unfortunately, we have no
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2124 ;; way of determining Shift-key status on non-alphabetic ASCII
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2125 ;; keysyms. However, in this case, using Shift will invoke a
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2126 ;; separate command from the non-shifted version, so the
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2127 ;; "shifted motion" paradigm makes no sense.)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2128 (or (memq 'shift (event-modifiers last-input-event))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2129 (let ((key (event-key last-input-event)))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2130 (and (characterp key)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2131 (not (eq key (downcase key)))))))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2132 (let ((in-shifted-motion-command t))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2133 (push-mark nil nil t))))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2134
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2135 (defun handle-post-motion-command ()
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2136 (if
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2137 (and
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2138 (handle-pre-motion-command-current-command-is-motion)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2139 zmacs-regions
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2140 (region-active-p))
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2141 ;; Special-case alphabetic keysyms, because the `shift'
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2142 ;; modifier does not appear on them. See above.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2143 (cond ((or (memq 'shift (event-modifiers last-input-event))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2144 (let ((key (event-key last-input-event)))
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2145 (and (characterp key)
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2146 (not (eq key (downcase key))))))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2147 (if shifted-motion-keys-select-region
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2148 (putf this-command-properties 'shifted-motion-command t))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2149 (setq zmacs-region-stays t))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2150 ((and (getf last-command-properties 'shifted-motion-command)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2151 unshifted-motion-keys-deselect-region)
487
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 462
diff changeset
2152 (setq zmacs-region-stays nil)))))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2153
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2154 (defun forward-char-command (&optional arg buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2155 "Move point right ARG characters (left if ARG negative) in BUFFER.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2156 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
2157 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
2158 Error signaling is suppressed if `signal-error-on-buffer-boundary'
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2159 is nil. If BUFFER is nil, the current buffer is assumed.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2160
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2161 The characters that are moved over may be added to the current selection
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2162 \(i.e. active region) if the Shift key is held down, a motion key is used
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2163 to invoke this command, and `shifted-motion-keys-select-region' is t; see
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2164 the documentation for this variable for more details."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2165 (interactive "_p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2166 (if signal-error-on-buffer-boundary
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2167 (forward-char arg buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2168 (condition-case nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2169 (forward-char arg buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2170 (beginning-of-buffer nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2171 (end-of-buffer nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2172
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2173 (defun backward-char-command (&optional arg buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2174 "Move point left ARG characters (right if ARG negative) in BUFFER.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2175 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
2176 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
2177 Error signaling is suppressed if `signal-error-on-buffer-boundary'
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2178 is nil. If BUFFER is nil, the current buffer is assumed.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2179
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2180 The characters that are moved over may be added to the current selection
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2181 \(i.e. active region) if the Shift key is held down, a motion key is used
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2182 to invoke this command, and `shifted-motion-keys-select-region' is t; see
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2183 the documentation for this variable for more details."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2184 (interactive "_p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2185 (if signal-error-on-buffer-boundary
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2186 (backward-char arg buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2187 (condition-case nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2188 (backward-char arg buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2189 (beginning-of-buffer nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2190 (end-of-buffer nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2191
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2192 (defun scroll-up-one ()
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2193 "Scroll text of current window upward one line.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2194 On attempt to scroll past end of buffer, `end-of-buffer' is signaled.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2195 On attempt to scroll past beginning of buffer, `beginning-of-buffer' is
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2196 signaled.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2197
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2198 If `signal-error-on-buffer-boundary' is nil, attempts to scroll past buffer
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2199 boundaries do not cause an error to be signaled."
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2200 (interactive "_")
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2201 (scroll-up-command 1))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2202
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2203 (defun scroll-up-command (&optional n)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2204 "Scroll current window upward N lines; or near full screen if N is nil.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2205 A near full screen is `next-screen-context-lines' less than a full screen.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2206 Negative N means scroll downward.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2207 When calling from a program, supply a number as argument or nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2208 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
2209 On attempt to scroll past beginning of buffer, `beginning-of-buffer' is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2210 signaled.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2211
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2212 The characters that are moved over may be added to the current selection
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2213 \(i.e. active region) if the Shift key is held down, a motion key is used
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2214 to invoke this command, and `shifted-motion-keys-select-region' is t; see
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2215 the documentation for this variable for more details.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2216
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2217 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
2218 boundaries do not cause an error to be signaled."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2219 (interactive "_P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2220 (if signal-error-on-buffer-boundary
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2221 (scroll-up n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2222 (condition-case nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2223 (scroll-up n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2224 (beginning-of-buffer nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2225 (end-of-buffer nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2226
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2227 (defun scroll-down-one ()
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2228 "Scroll text of current window downward one line.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2229 On attempt to scroll past end of buffer, `end-of-buffer' is signaled.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2230 On attempt to scroll past beginning of buffer, `beginning-of-buffer' is
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2231 signaled.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2232
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2233 If `signal-error-on-buffer-boundary' is nil, attempts to scroll past buffer
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2234 boundaries do not cause an error to be signaled."
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2235 (interactive "_")
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2236 (scroll-down-command 1))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2237
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2238 (defun scroll-down-command (&optional n)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2239 "Scroll current window downward N lines; or near full screen if N is nil.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2240 A near full screen is `next-screen-context-lines' less than a full screen.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2241 Negative N means scroll upward.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2242 When calling from a program, supply a number as argument or nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2243 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
2244 On attempt to scroll past beginning of buffer, `beginning-of-buffer' is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2245 signaled.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2246
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2247 If `signal-error-on-buffer-boundary' is nil, attempts to scroll past buffer
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2248 boundaries do not cause an error to be signaled.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2249
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2250 The characters that are moved over may be added to the current selection
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2251 \(i.e. active region) if the Shift key is held down, a motion key is used
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2252 to invoke this command, and `shifted-motion-keys-select-region' is t; see
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2253 the documentation for this variable for more details."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2254 (interactive "_P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2255 (if signal-error-on-buffer-boundary
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2256 (scroll-down n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2257 (condition-case nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2258 (scroll-down n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2259 (beginning-of-buffer nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2260 (end-of-buffer nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2261
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2262 (defun next-line (count)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2263 "Move cursor vertically down COUNT lines.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2264 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
2265 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
2266 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
2267
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2268 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
2269 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
2270 to create a line, and moves the cursor to that line. Otherwise it moves the
2439
292ead991a10 [xemacs-hg @ 2004-12-14 10:09:08 by stephent]
stephent
parents: 1703
diff changeset
2271 cursor to the end of the buffer. If `signal-error-on-buffer-boundary' is
292ead991a10 [xemacs-hg @ 2004-12-14 10:09:08 by stephent]
stephent
parents: 1703
diff changeset
2272 non-nil and you attempt to move past a buffer boundary, XEmacs will ring the
292ead991a10 [xemacs-hg @ 2004-12-14 10:09:08 by stephent]
stephent
parents: 1703
diff changeset
2273 bell using `ding'.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2274
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2275 The command \\[set-goal-column] can be used to create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2276 a semipermanent goal column to which this command always moves.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2277 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
2278 in `goal-column', which is nil when there is none.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2279
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2280 The characters that are moved over may be added to the current selection
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2281 \(i.e. active region) if the Shift key is held down, a motion key is used
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2282 to invoke this command, and `shifted-motion-keys-select-region' is t; see
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2283 the documentation for this variable for more details.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2284
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2285 If you are thinking of using this in a Lisp program, consider
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2286 using `forward-line' instead. It is usually easier to use
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2287 and more reliable (no dependence on goal column, etc.)."
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2288 (interactive "_p")
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2289 (if (and next-line-add-newlines (= count 1))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2290 (let ((opoint (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2291 (end-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2292 (if (eobp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2293 (newline 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2294 (goto-char opoint)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2295 (line-move count)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2296 (if (interactive-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2297 ;; XEmacs: Not sure what to do about this. It's inconsistent. -sb
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2298 (condition-case nil
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2299 (line-move count)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2300 ((beginning-of-buffer end-of-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2301 (when signal-error-on-buffer-boundary
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2302 (ding nil 'buffer-bound))))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2303 (line-move count)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2304 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2305
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2306 (defun previous-line (count)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2307 "Move cursor vertically up COUNT lines.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2308 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
2309 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
2310 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
2311
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2312 The command \\[set-goal-column] can be used to create
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2313 a semipermanent goal column to which this command always moves.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2314 Then it does not try to move vertically.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2315
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2316 The characters that are moved over may be added to the current selection
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2317 \(i.e. active region) if the Shift key is held down, a motion key is used
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2318 to invoke this command, and `shifted-motion-keys-select-region' is t; see
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2319 the documentation for this variable for more details.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2320
2439
292ead991a10 [xemacs-hg @ 2004-12-14 10:09:08 by stephent]
stephent
parents: 1703
diff changeset
2321 If `signal-error-on-buffer-boundary' is non-nil and you attempt to move past
292ead991a10 [xemacs-hg @ 2004-12-14 10:09:08 by stephent]
stephent
parents: 1703
diff changeset
2322 a buffer boundary, XEmacs will ring the bell using `ding'.
292ead991a10 [xemacs-hg @ 2004-12-14 10:09:08 by stephent]
stephent
parents: 1703
diff changeset
2323
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2324 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
2325 `forward-line' with a negative argument instead. It is usually easier
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2326 to use and more reliable (no dependence on goal column, etc.)."
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2327 (interactive "_p")
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2328 (if (interactive-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2329 (condition-case nil
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2330 (line-move (- count))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2331 ((beginning-of-buffer end-of-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2332 (when signal-error-on-buffer-boundary ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2333 (ding nil 'buffer-bound))))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2334 (line-move (- count)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2335 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2336
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2337 (defcustom block-movement-size 6
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2338 "*Number of lines that \"block movement\" commands (\\[forward-block-of-lines], \\[backward-block-of-lines]) move by."
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2339 :type 'integer
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2340 :group 'editing-basics)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2341
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2342 (defun backward-block-of-lines ()
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2343 "Move backward by one \"block\" of lines.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2344 The number of lines that make up a block is controlled by
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2345 `block-movement-size', which defaults to 6.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2346
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2347 The characters that are moved over may be added to the current selection
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2348 \(i.e. active region) if the Shift key is held down, a motion key is used
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2349 to invoke this command, and `shifted-motion-keys-select-region' is t; see
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2350 the documentation for this variable for more details."
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2351 (interactive "_")
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2352 (forward-line (- block-movement-size)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2353
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2354 (defun forward-block-of-lines ()
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2355 "Move forward by one \"block\" of lines.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2356 The number of lines that make up a block is controlled by
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2357 `block-movement-size', which defaults to 6.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2358
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2359 The characters that are moved over may be added to the current selection
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2360 \(i.e. active region) if the Shift key is held down, a motion key is used
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2361 to invoke this command, and `shifted-motion-keys-select-region' is t; see
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2362 the documentation for this variable for more details."
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2363 (interactive "_")
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2364 (forward-line block-movement-size))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2365
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2366 (defcustom track-eol nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2367 "*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
2368 This means moving to the end of each line moved onto.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2369 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
2370 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2371 :group 'editing-basics)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2372
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2373 (defcustom goal-column nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2374 "*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
2375 :type '(choice integer (const :tag "None" nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2376 :group 'editing-basics)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2377 (make-variable-buffer-local 'goal-column)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2378
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2379 (defvar temporary-goal-column 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2380 "Current goal column for vertical motion.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2381 It is the column where point was
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2382 at the start of current run of vertical motion commands.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2383 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
2384 (make-variable-buffer-local 'temporary-goal-column)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2385
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2386 ;XEmacs: not yet ported, so avoid compiler warnings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2387 (eval-when-compile
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2388 (defvar inhibit-point-motion-hooks))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2389
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2390 (defcustom line-move-ignore-invisible nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2391 "*Non-nil means \\[next-line] and \\[previous-line] ignore invisible lines.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2392 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
2393 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2394 :group 'editing-basics)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2395
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2396 ;; This is the guts of next-line and previous-line.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2397 ;; Count says how many lines to move.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2398 (defun line-move (count)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2399 ;; Don't run any point-motion hooks, and disregard intangibility,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2400 ;; for intermediate positions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2401 (let ((inhibit-point-motion-hooks t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2402 (opoint (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2403 new)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2404 (unwind-protect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2405 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2406 (if (not (or (eq last-command 'next-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2407 (eq last-command 'previous-line)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2408 (setq temporary-goal-column
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2409 (if (and track-eol (eolp)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2410 ;; Don't count start of empty line as end of line
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2411 ;; unless we just did explicit end-of-line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2412 (or (not (bolp)) (eq last-command 'end-of-line)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2413 9999
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2414 (current-column))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2415 (if (and (not (integerp selective-display))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2416 (not line-move-ignore-invisible))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2417 ;; Use just newline characters.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2418 (or (if (> count 0)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2419 (progn (if (> count 1) (forward-line (1- count)))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2420 ;; This way of moving forward COUNT lines
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2421 ;; verifies that we have a newline after the last one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2422 ;; It doesn't get confused by intangible text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2423 (end-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2424 (zerop (forward-line 1)))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2425 (and (zerop (forward-line count))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2426 (bolp)))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2427 (signal (if (< count 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2428 'beginning-of-buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2429 'end-of-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2430 nil))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2431 ;; Move by count lines, but ignore invisible ones.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2432 (while (> count 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2433 (end-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2434 (and (zerop (vertical-motion 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2435 (signal 'end-of-buffer nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2436 ;; If the following character is currently invisible,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2437 ;; skip all characters with that same `invisible' property value.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2438 (while (and (not (eobp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2439 (let ((prop
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2440 (get-char-property (point) 'invisible)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2441 (if (eq buffer-invisibility-spec t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2442 prop
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2443 (or (memq prop buffer-invisibility-spec)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2444 (assq prop buffer-invisibility-spec)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2445 (if (get-text-property (point) 'invisible)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2446 (goto-char (next-single-property-change (point) 'invisible))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2447 (goto-char (next-extent-change (point))))) ; XEmacs
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2448 (setq count (1- count)))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2449 (while (< count 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2450 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2451 (and (zerop (vertical-motion -1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2452 (signal 'beginning-of-buffer nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2453 (while (and (not (bobp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2454 (let ((prop
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2455 (get-char-property (1- (point)) 'invisible)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2456 (if (eq buffer-invisibility-spec t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2457 prop
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2458 (or (memq prop buffer-invisibility-spec)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2459 (assq prop buffer-invisibility-spec)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2460 (if (get-text-property (1- (point)) 'invisible)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2461 (goto-char (previous-single-property-change (point) 'invisible))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2462 (goto-char (previous-extent-change (point))))) ; XEmacs
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2463 (setq count (1+ count))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2464 (move-to-column (or goal-column temporary-goal-column)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2465 ;; Remember where we moved to, go back home,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2466 ;; then do the motion over again
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2467 ;; in just one step, with intangibility and point-motion hooks
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2468 ;; enabled this time.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2469 (setq new (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2470 (goto-char opoint)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2471 (setq inhibit-point-motion-hooks nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2472 (goto-char new)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2473 nil)
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 ;;; Many people have said they rarely use this feature, and often type
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2476 ;;; it by accident. Maybe it shouldn't even be on a key.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2477 ;; 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
2478 ;(put 'set-goal-column 'disabled t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2479
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2480 (defun set-goal-column (column)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2481 "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
2482 Those commands will move to this position in the line moved to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2483 rather than trying to keep the same horizontal position.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2484 With a non-nil argument, clears out the goal column
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2485 so that \\[next-line] and \\[previous-line] resume vertical motion.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2486 The goal column is stored in the variable `goal-column'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2487 (interactive "_P") ; XEmacs
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2488 (if column
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2489 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2490 (setq goal-column nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2491 (display-message 'command "No goal column"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2492 (setq goal-column (current-column))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2493 (lmessage 'command
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2494 "Goal column %d (use %s with a prefix arg to unset it)"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2495 goal-column
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2496 (substitute-command-keys "\\[set-goal-column]")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2497 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2498
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2499 ;; deleted FSFmacs terminal randomness hscroll-point-visible stuff.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2500 ;; hscroll-step
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2501 ;; hscroll-point-visible
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2502 ;; hscroll-window-column
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2503 ;; right-arrow
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2504 ;; left-arrow
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2505
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2506 (defun scroll-other-window-down (lines)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2507 "Scroll the \"other window\" down.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2508 For more details, see the documentation for `scroll-other-window'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2509 (interactive "P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2510 (scroll-other-window
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2511 ;; Just invert the argument's meaning.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2512 ;; We can do that without knowing which window it will be.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2513 (if (eq lines '-) nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2514 (if (null lines) '-
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2515 (- (prefix-numeric-value lines))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2516 ;(define-key esc-map [?\C-\S-v] 'scroll-other-window-down)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2517
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2518 (defun beginning-of-buffer-other-window (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2519 "Move point to the beginning of the buffer in the other window.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2520 Leave mark at previous position.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2521 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
2522 (interactive "P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2523 (let ((orig-window (selected-window))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2524 (window (other-window-for-scrolling)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2525 ;; We use unwind-protect rather than save-window-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2526 ;; because the latter would preserve the things we want to change.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2527 (unwind-protect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2528 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2529 (select-window window)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2530 ;; Set point and mark in that window's buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2531 (beginning-of-buffer arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2532 ;; Set point accordingly.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2533 (recenter '(t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2534 (select-window orig-window))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2535
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2536 (defun end-of-buffer-other-window (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2537 "Move point to the end of the buffer in the other window.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2538 Leave mark at previous position.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2539 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
2540 (interactive "P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2541 ;; See beginning-of-buffer-other-window for comments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2542 (let ((orig-window (selected-window))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2543 (window (other-window-for-scrolling)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2544 (unwind-protect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2545 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2546 (select-window window)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2547 (end-of-buffer arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2548 (recenter '(t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2549 (select-window orig-window))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2550
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2551 (defun transpose-chars (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2552 "Interchange characters around point, moving forward one character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2553 With prefix arg ARG, effect is to take character before point
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2554 and drag it forward past ARG other characters (backward if ARG negative).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2555 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
2556 (interactive "*P")
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2557 (and (null arg) (eolp) (backward-char 1))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2558 (transpose-subr 'forward-char (prefix-numeric-value arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2559
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2560 ;;; A very old implementation of transpose-chars from the old days ...
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2561 (defun transpose-preceding-chars (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2562 "Interchange characters before point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2563 With prefix arg ARG, effect is to take character before point
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2564 and drag it forward past ARG other characters (backward if ARG negative).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2565 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
2566 (interactive "*P")
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2567 (and (null arg) (not (bolp)) (backward-char 1))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2568 (transpose-subr 'forward-char (prefix-numeric-value arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2569
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 (defun transpose-words (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2572 "Interchange words around point, leaving point at end of them.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2573 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
2574 and drag it forward past ARG other words (backward if ARG negative).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2575 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
2576 are interchanged."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2577 (interactive "*p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2578 (transpose-subr 'forward-word arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2579
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2580 (defun transpose-sexps (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2581 "Like \\[transpose-words] but applies to sexps.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2582 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
2583 if it is a list or string."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2584 (interactive "*p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2585 (transpose-subr 'forward-sexp arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2586
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2587 (defun Simple-forward-line-creating-newline ()
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2588 ;; Move forward over a line,
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2589 ;; but create a newline if none exists yet.
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2590 (end-of-line)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2591 (if (eobp)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2592 (newline)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2593 (forward-char 1)))
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2594
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2595 (defun Simple-transpose-lines-mover (arg)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2596 (if (= arg 1)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2597 (Simple-forward-line-creating-newline)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2598 (forward-line arg)))
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2599
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2600 (defun transpose-lines (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2601 "Exchange current line and previous line, leaving point after both.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2602 With argument ARG, takes previous line and moves it past ARG lines.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2603 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
2604 (interactive "*p")
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2605 (transpose-subr 'Simple-transpose-lines-mover arg))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2606
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2607 (defun transpose-line-up (arg)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2608 "Move current line one line up, leaving point at beginning of that line.
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2609 With argument ARG, move it ARG lines up. This can be run repeatedly
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2610 to move the current line up a number of lines.
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2611
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2612 If the region is active, move the region up one line (or ARG lines,
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2613 if specified). The region will not be selected afterwards, but this
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2614 command can still be run repeatedly to move the region up a number
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2615 of lines."
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2616 (interactive "*p")
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2617 (transpose-line-down (- arg)))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2618
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2619 (defun transpose-line-down (arg)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2620 "Move current line one line down, leaving point at beginning of that line.
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2621 With argument ARG, move it ARG lines down. This can be run repeatedly
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2622 to move the current line down a number of lines.
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2623
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2624 If the region is active, move the region down one line (or ARG lines,
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2625 if specified). The region will not be selected afterwards, but this
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2626 command can still be run repeatedly to move the region down a number
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2627 of lines."
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2628 (interactive "*p")
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2629 (if (or (region-active-p)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2630 (getf last-command-properties 'transpose-region-by-line-command))
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2631 (progn
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2632 (transpose-subr 'Simple-transpose-lines-mover arg t)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2633 (putf this-command-properties 'transpose-region-by-line-command t))
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2634 (Simple-forward-line-creating-newline)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2635 (transpose-subr 'Simple-transpose-lines-mover arg)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2636 (forward-line -1)))
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2637
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2638 (defun transpose-subr (mover arg &optional move-region)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2639 (let (start1 end1 start2 end2)
5567
3bc58dc9d688 Replace #'flet by #'labels where appropriate, core code.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5473
diff changeset
2640 ;; XEmacs -- use labels instead of defining a separate function and
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2641 ;; relying on dynamic scope; use (mark t) etc; add code to support
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2642 ;; the new MOVE-REGION arg.
5567
3bc58dc9d688 Replace #'flet by #'labels where appropriate, core code.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5473
diff changeset
2643 (labels ((transpose-subr-1 ()
3bc58dc9d688 Replace #'flet by #'labels where appropriate, core code.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5473
diff changeset
2644 (if (> (min end1 end2) (max start1 start2))
3bc58dc9d688 Replace #'flet by #'labels where appropriate, core code.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5473
diff changeset
2645 (error "Don't have two things to transpose"))
3bc58dc9d688 Replace #'flet by #'labels where appropriate, core code.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5473
diff changeset
2646 (let ((word1 (buffer-substring start1 end1))
3bc58dc9d688 Replace #'flet by #'labels where appropriate, core code.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5473
diff changeset
2647 (word2 (buffer-substring start2 end2)))
3bc58dc9d688 Replace #'flet by #'labels where appropriate, core code.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5473
diff changeset
2648 (delete-region start2 end2)
3bc58dc9d688 Replace #'flet by #'labels where appropriate, core code.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5473
diff changeset
2649 (goto-char start2)
3bc58dc9d688 Replace #'flet by #'labels where appropriate, core code.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5473
diff changeset
2650 (insert word1)
3bc58dc9d688 Replace #'flet by #'labels where appropriate, core code.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5473
diff changeset
2651 (goto-char (if (< start1 start2) start1
3bc58dc9d688 Replace #'flet by #'labels where appropriate, core code.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5473
diff changeset
2652 (+ start1 (- (length word1) (length word2)))))
3bc58dc9d688 Replace #'flet by #'labels where appropriate, core code.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5473
diff changeset
2653 (delete-char (length word1))
3bc58dc9d688 Replace #'flet by #'labels where appropriate, core code.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5473
diff changeset
2654 (insert word2))))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2655 (if (= arg 0)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2656 (progn
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2657 (save-excursion
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2658 (funcall mover 1)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2659 (setq end2 (point))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2660 (funcall mover -1)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2661 (setq start2 (point))
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2662 (goto-char (mark t))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2663 (funcall mover 1)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2664 (setq end1 (point))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2665 (funcall mover -1)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2666 (setq start1 (point))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2667 (transpose-subr-1))
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2668 (exchange-point-and-mark t)))
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2669 (if move-region
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2670 (let ((rbeg (region-beginning))
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2671 (rend (region-end)))
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2672 (while (> arg 0)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2673 (goto-char rend)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2674 (funcall mover 1)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2675 (setq end2 (point))
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2676 (funcall mover -1)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2677 (setq start2 (point))
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2678 (setq start1 rbeg end1 rend)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2679 (transpose-subr-1)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2680 (incf rbeg (- end2 start2))
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2681 (incf rend (- end2 start2))
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2682 (setq arg (1- arg)))
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2683 (while (< arg 0)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2684 (goto-char rbeg)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2685 (funcall mover -1)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2686 (setq start1 (point))
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2687 (funcall mover 1)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2688 (setq end1 (point))
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2689 (setq start2 rbeg end2 rend)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2690 (transpose-subr-1)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2691 (decf rbeg (- end1 start1))
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2692 (decf rend (- end1 start1))
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2693 (setq arg (1+ arg)))
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2694 (set-mark rbeg)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2695 (goto-char rend))
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2696 (while (> arg 0)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2697 (funcall mover -1)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2698 (setq start1 (point))
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2699 (funcall mover 1)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2700 (setq end1 (point))
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2701 (funcall mover 1)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2702 (setq end2 (point))
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2703 (funcall mover -1)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2704 (setq start2 (point))
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2705 (transpose-subr-1)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2706 (goto-char end2)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2707 (setq arg (1- arg)))
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2708 (while (< arg 0)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2709 (funcall mover -1)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2710 (setq start2 (point))
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2711 (funcall mover -1)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2712 (setq start1 (point))
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2713 (funcall mover 1)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2714 (setq end1 (point))
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2715 (funcall mover 1)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2716 (setq end2 (point))
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2717 (transpose-subr-1)
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 503
diff changeset
2718 (setq arg (1+ arg)))))))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2719
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2720
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2721 ;; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2722 (defun prefix-region (prefix)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2723 "Add a prefix string to each line between mark and point."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2724 (interactive "sPrefix string: ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2725 (if prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2726 (let ((count (count-lines (mark) (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2727 (goto-char (min (mark) (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2728 (while (> count 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2729 (setq count (1- count))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2730 (beginning-of-line 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2731 (insert prefix)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2732 (end-of-line 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2733 (forward-char 1)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2734
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2735
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2736 (defun backward-word (&optional count buffer)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2737 "Move point backward COUNT words (forward if COUNT is negative).
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2738 Normally t is returned, but if an edge of the buffer is reached,
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2739 point is left there and nil is returned.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2740
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2741 COUNT defaults to 1, and BUFFER defaults to the current buffer.
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2742
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2743 The characters that are moved over may be added to the current selection
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2744 \(i.e. active region) if the Shift key is held down, a motion key is used
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2745 to invoke this command, and `shifted-motion-keys-select-region' is t; see
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 448
diff changeset
2746 the documentation for this variable for more details."
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2747 (interactive "_p")
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2748 (forward-word (- (or count 1)) buffer))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2749
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2750 (defun mark-word (&optional count)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2751 "Mark the text from point until encountering the end of a word.
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2752 With optional argument COUNT, mark COUNT words."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2753 (interactive "p")
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2754 (mark-something 'mark-word 'forward-word count))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2755
844
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 843
diff changeset
2756 (defcustom kill-word-into-kill-ring t
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 843
diff changeset
2757 "*Non-nil means `kill-word' saves word killed into kill ring.
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 843
diff changeset
2758 \(Normally, this also affects the clipboard.)
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 843
diff changeset
2759 Nil means word is just deleted, without being remembered.
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 843
diff changeset
2760 This also applies to `backward-kill-word' and `backward-or-forward-kill-word'."
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 843
diff changeset
2761 :type 'boolean
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 843
diff changeset
2762 :group 'editing-basics)
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 843
diff changeset
2763
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2764 (defun kill-word (&optional count)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2765 "Kill characters forward until encountering the end of a word.
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2766 With optional argument COUNT, do this that many times."
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2767 (interactive "*p")
844
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 843
diff changeset
2768 (if kill-word-into-kill-ring
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 843
diff changeset
2769 (kill-region (point) (save-excursion (forward-word count) (point)))
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 843
diff changeset
2770 (delete-region (point) (save-excursion (forward-word count) (point)))))
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2771
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2772 (defun backward-kill-word (&optional count)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2773 "Kill characters backward until encountering the end of a word.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2774 With argument, do this that many times."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2775 (interactive "*p")
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2776 (kill-word (- (or count 1))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2777
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2778 (defun current-word (&optional strict)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2779 "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
2780 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
2781 or adjacent to a word.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2782 If point is not between two word-constituent characters, but immediately
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2783 follows one, move back first.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2784 Otherwise, if point precedes a word constituent, move forward first.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2785 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
2786 if you a newlines is reached first, move forward instead."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2787 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2788 (let ((oldpoint (point)) (start (point)) (end (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2789 (skip-syntax-backward "w_") (setq start (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2790 (goto-char oldpoint)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2791 (skip-syntax-forward "w_") (setq end (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2792 (if (and (eq start oldpoint) (eq end oldpoint))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2793 ;; Point is neither within nor adjacent to a word.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2794 (and (not strict)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2795 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2796 ;; Look for preceding word in same line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2797 (skip-syntax-backward "^w_"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2798 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2799 (beginning-of-line) (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2800 (if (bolp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2801 ;; No preceding word in same line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2802 ;; Look for following word in same line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2803 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2804 (skip-syntax-forward "^w_"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2805 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2806 (end-of-line) (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2807 (setq start (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2808 (skip-syntax-forward "w_")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2809 (setq end (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2810 (setq end (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2811 (skip-syntax-backward "w_")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2812 (setq start (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2813 (buffer-substring start end)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2814 (buffer-substring start end)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2815
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2816 (defcustom fill-prefix nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2817 "*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
2818 Setting this variable automatically makes it local to the current buffer."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2819 :type '(choice (const :tag "None" nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2820 string)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2821 :group 'fill)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2822 (make-variable-buffer-local 'fill-prefix)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2823
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2824 (defcustom auto-fill-inhibit-regexp nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2825 "*Regexp to match lines which should not be auto-filled."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2826 :type '(choice (const :tag "None" nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2827 regexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2828 :group 'fill)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2829
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2830 (defvar comment-line-break-function 'indent-new-comment-line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2831 "*Mode-specific function which line breaks and continues a comment.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2832
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2833 This function is only called during auto-filling of a comment section.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2834 The function should take a single optional argument which is a flag
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2835 indicating whether soft newlines should be inserted.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2836
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2837 ;; This function is the auto-fill-function of a buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2838 ;; when Auto-Fill mode is enabled.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2839 ;; It returns t if it really did any work.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2840 ;; XEmacs: This function is totally different.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2841 (defun do-auto-fill ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2842 (let (give-up)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2843 (or (and auto-fill-inhibit-regexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2844 (save-excursion (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2845 (looking-at auto-fill-inhibit-regexp)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2846 (while (and (not give-up) (> (current-column) fill-column))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2847 ;; Determine where to split the line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2848 (let ((fill-prefix fill-prefix)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2849 (fill-point
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2850 (let ((opoint (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2851 bounce
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 487
diff changeset
2852 (re-break-point ;; Kinsoku processing
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 487
diff changeset
2853 (if (featurep 'mule)
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 613
diff changeset
2854 (with-boundp 'word-across-newline
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 613
diff changeset
2855 (concat "[ \t\n]\\|" word-across-newline
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 613
diff changeset
2856 ".\\|." word-across-newline))
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 487
diff changeset
2857 "[ \t\n]"))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2858 (first t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2859 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2860 (move-to-column (1+ fill-column))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2861 ;; Move back to a word boundary.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2862 (while (or first
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2863 ;; If this is after period and a single space,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2864 ;; move back once more--we don't want to break
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2865 ;; the line there and make it look like a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2866 ;; sentence end.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2867 (and (not (bobp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2868 (not bounce)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2869 sentence-end-double-space
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2870 (save-excursion (backward-char 1)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2871 (and (looking-at "\\. ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2872 (not (looking-at "\\. "))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2873 (setq first nil)
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 487
diff changeset
2874 ;; XEmacs: change for Kinsoku processing
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2875 (fill-move-backward-to-break-point re-break-point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2876 ;; If we find nowhere on the line to break it,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2877 ;; break after one word. Set bounce to t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2878 ;; so we will not keep going in this while loop.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2879 (if (bolp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2880 (progn
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 487
diff changeset
2881 ;; XEmacs: change for Kinsoku processing
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2882 (fill-move-forward-to-break-point re-break-point
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2883 opoint)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2884 (setq bounce t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2885 (skip-chars-backward " \t"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2886 (if (and (featurep 'mule)
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 487
diff changeset
2887 (or bounce (bolp)))
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 487
diff changeset
2888 (declare-fboundp (kinsoku-process)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2889 ;; Let fill-point be set to the place where we end up.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2890 (point)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2891
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2892 ;; I'm not sure why Stig made this change but it breaks
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2893 ;; 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
2894 ;; out. --cet
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2895 ;; XEmacs - adaptive fill.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2896 ;;(maybe-adapt-fill-prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2897 ;; (or from (setq from (save-excursion (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2898 ;; (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2899 ;; (or to (setq to (save-excursion (beginning-of-line 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2900 ;; (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2901 ;; t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2902
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2903 ;; If that place is not the beginning of the line,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2904 ;; break the line there.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2905 (if (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2906 (goto-char fill-point)
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 487
diff changeset
2907 ;; during kinsoku processing it is possible to move beyond
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 487
diff changeset
2908 (not (or (bolp) (eolp))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2909 (let ((prev-column (current-column)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2910 ;; If point is at the fill-point, do not `save-excursion'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2911 ;; Otherwise, if a comment prefix or fill-prefix is inserted,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2912 ;; point will end up before it rather than after it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2913 (if (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2914 (skip-chars-backward " \t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2915 (= (point) fill-point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2916 ;; 1999-09-17 hniksic: turn off Kinsoku until
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2917 ;; it's debugged.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2918 (funcall comment-line-break-function)
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 487
diff changeset
2919 ;; XEmacs: Kinsoku processing
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2920 ; ;(indent-new-comment-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2921 ; (let ((spacep (memq (char-before (point)) '(?\ ?\t))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2922 ; (funcall comment-line-break-function)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2923 ; ;; if user type space explicitly, leave SPC
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2924 ; ;; even if there is no WAN.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2925 ; (if spacep
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2926 ; (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2927 ; (goto-char fill-point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2928 ; ;; put SPC except that there is SPC
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2929 ; ;; already or there is sentence end.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2930 ; (or (memq (char-after (point)) '(?\ ?\t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2931 ; (fill-end-of-sentence-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2932 ; (insert ?\ )))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2933 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2934 (goto-char fill-point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2935 (funcall comment-line-break-function)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2936 ;; If making the new line didn't reduce the hpos of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2937 ;; the end of the line, then give up now;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2938 ;; trying again will not help.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2939 (if (>= (current-column) prev-column)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2940 (setq give-up t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2941 ;; No place to break => stop trying.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2942 (setq give-up t)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2943
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2944 ;; 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
2945 ;; other one is history.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2946 ;(defun fsf:do-auto-fill ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2947 ; (let (fc justify
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2948 ; ;; bol
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2949 ; give-up
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2950 ; (fill-prefix fill-prefix))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2951 ; (if (or (not (setq justify (current-justification)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2952 ; (null (setq fc (current-fill-column)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2953 ; (and (eq justify 'left)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2954 ; (<= (current-column) fc))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2955 ; (save-excursion (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2956 ; ;; (setq bol (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2957 ; (and auto-fill-inhibit-regexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2958 ; (looking-at auto-fill-inhibit-regexp))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2959 ; nil ;; Auto-filling not required
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2960 ; (if (memq justify '(full center right))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2961 ; (save-excursion (unjustify-current-line)))
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 ; ;; Choose a fill-prefix automatically.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2964 ; (if (and adaptive-fill-mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2965 ; (or (null fill-prefix) (string= fill-prefix "")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2966 ; (let ((prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2967 ; (fill-context-prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2968 ; (save-excursion (backward-paragraph 1) (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2969 ; (save-excursion (forward-paragraph 1) (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2970 ; ;; Don't accept a non-whitespace fill prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2971 ; ;; from the first line of a paragraph.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2972 ; "^[ \t]*$")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2973 ; (and prefix (not (equal prefix ""))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2974 ; (setq fill-prefix prefix))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2975
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2976 ; (while (and (not give-up) (> (current-column) fc))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2977 ; ;; Determine where to split the line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2978 ; (let ((fill-point
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2979 ; (let ((opoint (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2980 ; bounce
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2981 ; (first t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2982 ; (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2983 ; (move-to-column (1+ fc))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2984 ; ;; Move back to a word boundary.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2985 ; (while (or first
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2986 ; ;; If this is after period and a single space,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2987 ; ;; move back once more--we don't want to break
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2988 ; ;; the line there and make it look like a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2989 ; ;; sentence end.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2990 ; (and (not (bobp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2991 ; (not bounce)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2992 ; sentence-end-double-space
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
2993 ; (save-excursion (backward-char 1)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2994 ; (and (looking-at "\\. ")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2995 ; (not (looking-at "\\. "))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2996 ; (setq first nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2997 ; (skip-chars-backward "^ \t\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2998 ; ;; If we find nowhere on the line to break it,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2999 ; ;; break after one word. Set bounce to t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3000 ; ;; so we will not keep going in this while loop.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3001 ; (if (bolp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3002 ; (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3003 ; (re-search-forward "[ \t]" opoint t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3004 ; (setq bounce t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3005 ; (skip-chars-backward " \t"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3006 ; ;; Let fill-point be set to the place where we end up.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3007 ; (point)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3008 ; ;; If that place is not the beginning of the line,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3009 ; ;; break the line there.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3010 ; (if (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3011 ; (goto-char fill-point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3012 ; (not (bolp)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3013 ; (let ((prev-column (current-column)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3014 ; ;; If point is at the fill-point, do not `save-excursion'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3015 ; ;; Otherwise, if a comment prefix or fill-prefix is inserted,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3016 ; ;; point will end up before it rather than after it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3017 ; (if (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3018 ; (skip-chars-backward " \t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3019 ; (= (point) fill-point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3020 ; (funcall comment-line-break-function t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3021 ; (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3022 ; (goto-char fill-point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3023 ; (funcall comment-line-break-function t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3024 ; ;; Now do justification, if required
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3025 ; (if (not (eq justify 'left))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3026 ; (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3027 ; (end-of-line 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3028 ; (justify-current-line justify nil t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3029 ; ;; If making the new line didn't reduce the hpos of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3030 ; ;; the end of the line, then give up now;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3031 ; ;; trying again will not help.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3032 ; (if (>= (current-column) prev-column)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3033 ; (setq give-up t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3034 ; ;; No place to break => stop trying.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3035 ; (setq give-up t))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3036 ; ;; Justify last line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3037 ; (justify-current-line justify t t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3038 ; t)))
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 (defvar normal-auto-fill-function 'do-auto-fill
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3041 "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
3042 Some major modes set this.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3043
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3044 (defun auto-fill-mode (&optional arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3045 "Toggle auto-fill mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3046 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
3047 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
3048 automatically breaks the line at a previous space.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3049
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3050 The value of `normal-auto-fill-function' specifies the function to use
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3051 for `auto-fill-function' when turning Auto Fill mode on."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3052 (interactive "P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3053 (prog1 (setq auto-fill-function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3054 (if (if (null arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3055 (not auto-fill-function)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3056 (> (prefix-numeric-value arg) 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3057 normal-auto-fill-function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3058 nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3059 (redraw-modeline)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3060
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3061 ;; This holds a document string used to document auto-fill-mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3062 (defun auto-fill-function ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3063 "Automatically break line at a previous space, in insertion of text."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3064 nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3065
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3066 (defun turn-on-auto-fill ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3067 "Unconditionally turn on Auto Fill mode."
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3068 (interactive)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3069 (auto-fill-mode 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3070
4681
64ac4337298b Implement turn-off-auto-fill.
Malcolm Purvis <malcolmp@xemacs.org>
parents: 4680
diff changeset
3071 (defun turn-off-auto-fill ()
64ac4337298b Implement turn-off-auto-fill.
Malcolm Purvis <malcolmp@xemacs.org>
parents: 4680
diff changeset
3072 "Unconditionally turn off Auto Fill mode."
64ac4337298b Implement turn-off-auto-fill.
Malcolm Purvis <malcolmp@xemacs.org>
parents: 4680
diff changeset
3073 (interactive)
64ac4337298b Implement turn-off-auto-fill.
Malcolm Purvis <malcolmp@xemacs.org>
parents: 4680
diff changeset
3074 (auto-fill-mode -1))
64ac4337298b Implement turn-off-auto-fill.
Malcolm Purvis <malcolmp@xemacs.org>
parents: 4680
diff changeset
3075
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3076 (defun set-fill-column (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3077 "Set `fill-column' to specified argument.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3078 Just \\[universal-argument] as argument means to use the current column
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3079 The variable `fill-column' has a separate value for each buffer."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3080 (interactive "_P") ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3081 (cond ((integerp arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3082 (setq fill-column arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3083 ((consp arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3084 (setq fill-column (current-column)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3085 ;; 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
3086 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3087 (error "set-fill-column requires an explicit argument")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3088 (lmessage 'command "fill-column set to %d" fill-column))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3089
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3090
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3091 ;; BEGIN SYNCHED WITH FSF 21.2.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3092
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3093 (defun set-selective-display (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3094 "Set `selective-display' to ARG; clear it if no arg.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3095 When the value of `selective-display' is a number > 0,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3096 lines whose indentation is >= that value are not displayed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3097 The variable `selective-display' has a separate value for each buffer."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3098 (interactive "P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3099 (if (eq selective-display t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3100 (error "selective-display already in use for marked lines"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3101 (let ((current-vpos
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3102 (save-restriction
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3103 (narrow-to-region (point-min) (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3104 (goto-char (window-start))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3105 (vertical-motion (window-height)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3106 (setq selective-display
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3107 (and arg (prefix-numeric-value arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3108 (recenter current-vpos))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3109 (set-window-start (selected-window) (window-start (selected-window)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3110 ;; #### doesn't localize properly:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3111 (princ "selective-display set to " t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3112 (prin1 selective-display t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3113 (princ "." t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3114
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3115 ;; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3116 (defun nuke-selective-display ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3117 "Ensure that the buffer is not in selective-display mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3118 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
3119 state before disabling selective display."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3120 ;; by Stig@hackvan.com
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3121 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3122 (and (eq t selective-display)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3123 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3124 (save-restriction
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3125 (widen)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3126 (goto-char (point-min))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3127 (let ((mod-p (buffer-modified-p))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3128 (buffer-read-only nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3129 (while (search-forward "\r" nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3130 (delete-char -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3131 (insert "\n"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3132 (set-buffer-modified-p mod-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3133 ))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3134 (setq selective-display nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3135
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3136 (add-hook 'change-major-mode-hook 'nuke-selective-display)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3137
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3138 (defvar overwrite-mode-textual " Ovwrt"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3139 "The string displayed in the mode line when in overwrite mode.")
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3140 (defvar overwrite-mode-binary " Bin Ovwrt"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3141 "The string displayed in the mode line when in binary overwrite mode.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3142
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3143 (defun overwrite-mode (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3144 "Toggle overwrite mode.
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3145 With arg, turn overwrite mode on iff arg is positive.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3146 In overwrite mode, printing characters typed in replace existing text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3147 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
3148 end of a line, such characters extend the line. Before a tab,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3149 such characters insert until the tab is filled in.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3150 \\[quoted-insert] still inserts characters in overwrite mode; this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3151 is supposed to make it easier to insert characters when necessary."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3152 (interactive "P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3153 (setq overwrite-mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3154 (if (if (null arg) (not overwrite-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3155 (> (prefix-numeric-value arg) 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3156 'overwrite-mode-textual))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3157 (redraw-modeline))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3158
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3159 (defun binary-overwrite-mode (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3160 "Toggle binary overwrite mode.
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3161 With arg, turn binary overwrite mode on iff arg is positive.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3162 In binary overwrite mode, printing characters typed in replace
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3163 existing text. Newlines are not treated specially, so typing at the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3164 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
3165 between them. Typing before a tab character simply replaces the tab
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3166 with the character typed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3167 \\[quoted-insert] replaces the text at the cursor, just as ordinary
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3168 typing characters do.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3169
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3170 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
3171 specialization of overwrite-mode, entered by setting the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3172 `overwrite-mode' variable to `overwrite-mode-binary'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3173 (interactive "P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3174 (setq overwrite-mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3175 (if (if (null arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3176 (not (eq overwrite-mode 'overwrite-mode-binary))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3177 (> (prefix-numeric-value arg) 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3178 'overwrite-mode-binary))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3179 (redraw-modeline))
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3180
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3181 ;; END SYNCHED WITH FSF 21.2.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3182
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3183
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 613
diff changeset
3184 (defcustom line-number-mode t
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3185 "*Non-nil means display line number in modeline."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3186 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3187 :group 'editing-basics)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3188
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3189 (defun line-number-mode (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3190 "Toggle Line Number mode.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3191 With arg, enable Line Number mode if arg is positive, else disable.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3192 When Line Number mode is enabled, the line number appears
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3193 in the mode line."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3194 (interactive "P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3195 (setq line-number-mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3196 (if (null arg) (not line-number-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3197 (> (prefix-numeric-value arg) 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3198 (redraw-modeline))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3199
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 613
diff changeset
3200 (defcustom column-number-mode t
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3201 "*Non-nil means display column number in mode line."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3202 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3203 :group 'editing-basics)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3204
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3205 (defun column-number-mode (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3206 "Toggle Column Number mode.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3207 With arg, enable Column Number mode if arg is positive, else disable.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3208 When Column Number mode is enabled, the column number appears
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3209 in the mode line."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3210 (interactive "P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3211 (setq column-number-mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3212 (if (null arg) (not column-number-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3213 (> (prefix-numeric-value arg) 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3214 (redraw-modeline))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3215
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3216
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3217 (defcustom blink-matching-paren t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3218 "*Non-nil means show matching open-paren when close-paren is inserted."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3219 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3220 :group 'paren-blinking)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3221
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3222 (defcustom blink-matching-paren-on-screen t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3223 "*Non-nil means show matching open-paren when it is on screen.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3224 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
3225 when it is off screen."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3226 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3227 :group 'paren-blinking)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3228
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3229 (defcustom blink-matching-paren-distance 12000
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3230 "*If non-nil, is maximum distance to search for matching open-paren."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3231 :type '(choice integer (const nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3232 :group 'paren-blinking)
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 (defcustom blink-matching-delay 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3235 "*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
3236 :type 'number
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3237 :group 'paren-blinking)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3238
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3239 (defcustom blink-matching-paren-dont-ignore-comments nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3240 "*Non-nil means `blink-matching-paren' should not ignore comments."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3241 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3242 :group 'paren-blinking)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3243
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3244 (defun blink-matching-open ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3245 "Move cursor momentarily to the beginning of the sexp before point."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3246 (interactive "_") ; XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3247 (and (> (point) (1+ (point-min)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3248 blink-matching-paren
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3249 ;; Verify an even number of quoting characters precede the close.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3250 (= 1 (logand 1 (- (point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3251 (save-excursion
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
3252 (backward-char 1)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3253 (skip-syntax-backward "/\\")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3254 (point)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3255 (let* ((oldpos (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3256 (blinkpos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3257 (mismatch))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3258 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3259 (save-restriction
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3260 (if blink-matching-paren-distance
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3261 (narrow-to-region (max (point-min)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3262 (- (point) blink-matching-paren-distance))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3263 oldpos))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3264 (condition-case ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3265 (let ((parse-sexp-ignore-comments
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3266 (and parse-sexp-ignore-comments
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3267 (not blink-matching-paren-dont-ignore-comments))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3268 (setq blinkpos (scan-sexps oldpos -1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3269 (error nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3270 (and blinkpos
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3271 (/= (char-syntax (char-after blinkpos))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3272 ?\$)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3273 (setq mismatch
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3274 (or (null (matching-paren (char-after blinkpos)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3275 (/= (char-after (1- oldpos))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3276 (matching-paren (char-after blinkpos))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3277 (if mismatch (setq blinkpos nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3278 (if blinkpos
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3279 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3280 (goto-char blinkpos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3281 (if (pos-visible-in-window-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3282 (and blink-matching-paren-on-screen
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3283 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3284 (auto-show-make-point-visible)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3285 (sit-for blink-matching-delay)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3286 (goto-char blinkpos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3287 (lmessage 'command "Matches %s"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3288 ;; Show what precedes the open in its line, if anything.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3289 (if (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3290 (skip-chars-backward " \t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3291 (not (bolp)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3292 (buffer-substring (progn (beginning-of-line) (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3293 (1+ blinkpos))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3294 ;; Show what follows the open in its line, if anything.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3295 (if (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3296 (forward-char 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3297 (skip-chars-forward " \t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3298 (not (eolp)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3299 (buffer-substring blinkpos
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3300 (progn (end-of-line) (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3301 ;; Otherwise show the previous nonblank line,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3302 ;; if there is one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3303 (if (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3304 (skip-chars-backward "\n \t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3305 (not (bobp)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3306 (concat
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3307 (buffer-substring (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3308 (skip-chars-backward "\n \t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3309 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3310 (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3311 (progn (end-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3312 (skip-chars-backward " \t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3313 (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3314 ;; Replace the newline and other whitespace with `...'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3315 "..."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3316 (buffer-substring blinkpos (1+ blinkpos)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3317 ;; There is nothing to show except the char itself.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3318 (buffer-substring blinkpos (1+ blinkpos))))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3319 (cond (mismatch
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3320 (display-message 'no-log "Mismatched parentheses"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3321 ((not blink-matching-paren-distance)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3322 (display-message 'no-log "Unmatched parenthesis"))))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3323
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3324 ;Turned off because it makes dbx bomb out.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3325 (setq blink-paren-function 'blink-matching-open)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3326
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3327
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3328 ;; XEmacs: Some functions moved to cmdloop.el:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3329 ;; keyboard-quit
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3330 ;; buffer-quit-function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3331 ;; keyboard-escape-quit
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3332
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3333 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3334 ;; mail composition code ;;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3335 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3336
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3337 ;; BEGIN SYNCHED WITH FSF 21.2.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3338
2768
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3339 (defcustom mail-user-agent 'xemacs-default-mail-user-agent
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3340 "*Your preference for a mail composition package.
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3341 Various Emacs Lisp packages (e.g. Reporter) require you to compose an
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3342 outgoing email message. This variable lets you specify which
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3343 mail-sending package you prefer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3344
2768
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3345 Valid values may include:
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3346
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3347 `vm-user-agent' -- use Kyle Jones' VM, as documented in the `(vm)'
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3348 Info node. Compatible with `sendmail-user-agent'
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3349 and can handle attachments and non-ASCII content,
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3350 which the former can't.
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3351 `sendmail-user-agent' -- use the default, bare-bones, Emacs Mail
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3352 package. See Info node `(xemacs)Sending Mail'.
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3353 `mh-e-user-agent' -- use the Emacs interface to the MH mail system.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3354 See Info node `(mh-e)'.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3355 `message-user-agent' -- use the Gnus Message package.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3356 See Info node `(message)'.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3357 `gnus-user-agent' -- like `message-user-agent', but with Gnus
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3358 paraphernalia, particularly the Gcc: header for
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3359 archiving.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3360
2768
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3361 If you examine the value of this variable before setting it or composing a
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3362 mail, it will have another value, `xemacs-default-mail-user-agent'--this is to
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3363 allow XEmacs to suggest that you use another email client instead of
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3364 `sendmail-user-agent'. The latter, while part of the base XEmacs Lisp code,
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3365 and very lightweight, doesn't support MIME, a considerable disadvantage
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3366 today.
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3367
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3368 Additional valid symbols may be available; check with the author of
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3369 your package for details. The function should return non-nil if it
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3370 succeeds.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3371
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3372 See also `read-mail-command' concerning reading mail."
2768
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3373 :type '(radio (function-item :tag "VM mail package"
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3374 :format "%t\n"
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3375 vm-user-agent)
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3376 (function-item :tag "Bare-bones Emacs mail"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3377 :format "%t\n"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3378 sendmail-user-agent)
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3379 (function-item :tag "Emacs interface to MH"
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3380 :format "%t\n"
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3381 mh-e-user-agent)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3382 (function-item :tag "Gnus Message package"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3383 :format "%t\n"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3384 message-user-agent)
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3385 (function-item :tag "Gnus Message with full Gnus features"
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3386 :format "%t\n"
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3387 gnus-user-agent)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3388 (function :tag "Other"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3389 :group 'mail)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3390
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3391 (defun define-mail-user-agent (symbol composefunc sendfunc
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3392 &optional abortfunc hookvar)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3393 "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
3394
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3395 SYMBOL can be any Lisp symbol. Its function definition and/or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3396 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
3397 properties on its property list, to encode the rest of the arguments.
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 COMPOSEFUNC is program callable function that composes an outgoing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3400 mail message buffer. This function should set up the basics of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3401 buffer without requiring user interaction. It should populate the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3402 standard mail headers, leaving the `to:' and `subject:' headers blank
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3403 by default.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3404
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3405 COMPOSEFUNC should accept several optional arguments--the same
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3406 arguments that `compose-mail' takes. See that function's documentation.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3407
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3408 SENDFUNC is the command a user would run to send the message.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3409
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3410 Optional ABORTFUNC is the command a user would run to abort the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3411 message. For mail packages that don't have a separate abort function,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3412 this can be `kill-buffer' (the equivalent of omitting this argument).
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 Optional HOOKVAR is a hook variable that gets run before the message
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3415 is actually sent. Callers that use the `mail-user-agent' may
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3416 install a hook function temporarily on this hook variable.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3417 If HOOKVAR is nil, `mail-send-hook' is used.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3418
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3419 The properties used on SYMBOL are `composefunc', `sendfunc',
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3420 `abortfunc', and `hookvar'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3421 (put symbol 'composefunc composefunc)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3422 (put symbol 'sendfunc sendfunc)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3423 (put symbol 'abortfunc (or abortfunc 'kill-buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3424 (put symbol 'hookvar (or hookvar 'mail-send-hook)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3425
2768
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3426 (define-mail-user-agent 'vm-user-agent
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3427 'vm-compose-mail
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3428 'vm-mail-send-and-exit)
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3429
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3430 (define-mail-user-agent 'sendmail-user-agent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3431 'sendmail-user-agent-compose 'mail-send-and-exit)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3432
2768
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3433 ;; Recent GNU sendmail.el does have MIME support, but it's buggy (as of
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3434 ;; 2005-05-01.) For example, if you FCC to a file more than once with
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3435 ;; different coding systems, your non-ASCII data will get
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3436 ;; trashed. quoted-printable encoding isn't done by default, attachments
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3437 ;; just add a line:
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3438 ;;
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3439 ;; ===File /path/to/file/here=================
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3440 ;;
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3441 ;; the file's contents,
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3442 ;;
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3443 ;; ===========================================
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3444 ;;
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3445 ;; and hope for the best. Not code we want to use, IMO.
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3446
4293
bea04dade8af [xemacs-hg @ 2007-11-28 21:23:55 by aidan]
aidan
parents: 4222
diff changeset
3447 (defvar xemacs-default-composefunc-dont-nag nil
bea04dade8af [xemacs-hg @ 2007-11-28 21:23:55 by aidan]
aidan
parents: 4222
diff changeset
3448 "Disable the `xemacs-default-composefunc' nagging; for bug reports.")
bea04dade8af [xemacs-hg @ 2007-11-28 21:23:55 by aidan]
aidan
parents: 4222
diff changeset
3449
2768
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3450 (defun xemacs-default-composefunc (&rest args)
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3451 "Warn that the default mail-reading package is heinously underfeatured;
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3452 compose a mail using it, all the same. "
4293
bea04dade8af [xemacs-hg @ 2007-11-28 21:23:55 by aidan]
aidan
parents: 4222
diff changeset
3453 (unless (or noninteractive xemacs-default-composefunc-dont-nag)
2977
0a759f4c4225 [xemacs-hg @ 2005-10-05 04:32:44 by stephent]
stephent
parents: 2768
diff changeset
3454 (warn "
2768
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3455
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3456 Defaulting to the GNU Emacs-derived `sendmail.el' mail client. This facility,
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3457 while part of base XEmacs, is heinously underfeatured, and not going to get
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3458 better in the medium term. We include it so that bug reports work without
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3459 packages; we suggest that you choose and/or install one of the other mail
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3460 clients from packages if you're doing something other than M-x
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3461 report-xemacs-bug , or even if you are reporting bugs regularly.
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3462
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3463 To choose a package from those installed, click on \"Options\" ->
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3464 \"Internet\" -> \"Compose Mail With ...\" and decide on one from the
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3465 list. Gnus and VM are full-featured and have active user communities.
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3466
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3467 To disable this warning and stick with the old behavior, you can explicitly
2977
0a759f4c4225 [xemacs-hg @ 2005-10-05 04:32:44 by stephent]
stephent
parents: 2768
diff changeset
3468 initialize `mail-user-agent' to 'sendmail-user-agent . "))
2768
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3469 (setq mail-user-agent 'sendmail-user-agent)
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3470 (apply (get 'sendmail-user-agent 'composefunc) args))
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3471
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3472 (defun xemacs-default-sendfunc (&rest args)
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3473 "Set `mail-user-agent' to `sendmail-user-agent'; call the send function
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3474 associated with that package, passing it the supplied arguments. "
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3475 (setq mail-user-agent 'sendmail-user-agent)
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3476 (apply (get 'sendmail-user-agent 'sendfunc) args))
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3477
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3478 (define-mail-user-agent 'xemacs-default-mail-user-agent
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3479 'xemacs-default-composefunc 'xemacs-default-sendfunc)
feeb145e30f4 [xemacs-hg @ 2005-05-10 17:35:57 by aidan]
aidan
parents: 2611
diff changeset
3480
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3481 (define-mail-user-agent 'message-user-agent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3482 'message-mail 'message-send-and-exit
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3483 'message-kill-buffer 'message-send-hook)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3484
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3485 (defun rfc822-goto-eoh ()
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3486 ;; Go to header delimiter line in a mail message, following RFC822 rules
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3487 (goto-char (point-min))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3488 (while (looking-at "^[^: \n]+:\\|^[ \t]")
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3489 (forward-line 1))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3490 (point))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3491
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3492 (defun sendmail-user-agent-compose (&optional to subject other-headers continue
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3493 switch-function yank-action
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3494 send-actions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3495 (if switch-function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3496 (let ((special-display-buffer-names nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3497 (special-display-regexps nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3498 (same-window-buffer-names nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3499 (same-window-regexps nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3500 (funcall switch-function "*mail*")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3501 (let ((cc (cdr (assoc-ignore-case "cc" other-headers)))
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3502 (in-reply-to (cdr (assoc-ignore-case "in-reply-to" other-headers)))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3503 (body (cdr (assoc-ignore-case "body" other-headers))))
776
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
3504 (or (declare-fboundp
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
3505 (mail continue to subject in-reply-to cc yank-action send-actions))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3506 continue
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3507 (error "Message aborted"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3508 (save-excursion
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3509 (rfc822-goto-eoh)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3510 (while other-headers
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3511 (unless (member* (car (car other-headers))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3512 '("in-reply-to" "cc" "body")
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3513 :test 'equalp)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3514 (insert (car (car other-headers)) ": "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3515 (cdr (car other-headers)) "\n"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3516 (setq other-headers (cdr other-headers)))
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3517 (when body
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3518 (forward-line 1)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3519 (insert body))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3520 t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3521
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3522 (define-mail-user-agent 'mh-e-user-agent
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3523 'mh-smail-batch 'mh-send-letter 'mh-fully-kill-draft
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3524 'mh-before-send-letter-hook)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3525
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3526 (defun compose-mail (&optional to subject other-headers continue
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3527 switch-function yank-action send-actions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3528 "Start composing a mail message to send.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3529 This uses the user's chosen mail composition package
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3530 as selected with the variable `mail-user-agent'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3531 The optional arguments TO and SUBJECT specify recipients
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3532 and the initial Subject field, respectively.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3533
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3534 OTHER-HEADERS is an alist specifying additional
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3535 header fields. Elements look like (HEADER . VALUE) where both
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3536 HEADER and VALUE are strings.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3537
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3538 CONTINUE, if non-nil, says to continue editing a message already
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3539 being composed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3540
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3541 SWITCH-FUNCTION, if non-nil, is a function to use to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3542 switch to and display the buffer used for mail composition.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3543
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3544 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
3545 to insert the raw text of the message being replied to.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3546 It has the form (FUNCTION . ARGS). The user agent will apply
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3547 FUNCTION to ARGS, to insert the raw text of the original message.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3548 \(The user agent will also run `mail-citation-hook', *after* the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3549 original text has been inserted in this way.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3550
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3551 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
3552 Each action has the form (FUNCTION . ARGS)."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3553 (interactive
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3554 (list nil nil nil current-prefix-arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3555 (let ((function (get mail-user-agent 'composefunc)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3556 (funcall function to subject other-headers continue
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3557 switch-function yank-action send-actions)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3558
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3559 (defun compose-mail-other-window (&optional to subject other-headers continue
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3560 yank-action send-actions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3561 "Like \\[compose-mail], but edit the outgoing message in another window."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3562 (interactive
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3563 (list nil nil nil current-prefix-arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3564 (compose-mail to subject other-headers continue
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3565 'switch-to-buffer-other-window yank-action send-actions))
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 (defun compose-mail-other-frame (&optional to subject other-headers continue
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3569 yank-action send-actions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3570 "Like \\[compose-mail], but edit the outgoing message in another frame."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3571 (interactive
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3572 (list nil nil nil current-prefix-arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3573 (compose-mail to subject other-headers continue
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3574 'switch-to-buffer-other-frame yank-action send-actions))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3575
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3576
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3577 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3578 ;; set variable ;;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3579 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3580
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3581 (defvar set-variable-value-history nil
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3582 "History of values entered with `set-variable'.")
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3583
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3584 (defun set-variable (var val)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3585 "Set VARIABLE to VALUE. VALUE is a Lisp object.
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3586 When using this interactively, enter a Lisp object for VALUE.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3587 If you want VALUE to be a string, you must surround it with doublequotes.
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3588 VALUE is used literally, not evaluated.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3589
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3590 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
3591 the 'global locale with nil tag set (see `set-specifier').
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3592
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3593 If VARIABLE has a `variable-interactive' property, that is used as if
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3594 it were the arg to `interactive' (which see) to interactively read VALUE.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3595
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3596 If VARIABLE has been defined with `defcustom', then the type information
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3597 in the definition is used to check that VALUE is valid."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3598 (interactive
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3599 (let* ((default-var (variable-at-point))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3600 (var (if (symbolp default-var)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3601 (read-variable (format "Set variable (default %s): " default-var)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3602 default-var)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3603 (read-variable "Set variable: ")))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3604 (minibuffer-help-form '(describe-variable var))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3605 (prop (get var 'variable-interactive))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3606 (prompt (format "Set %s to value: " var))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3607 (val (if prop
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3608 ;; Use VAR's `variable-interactive' property
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3609 ;; as an interactive spec for prompting.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3610 (call-interactively `(lambda (arg)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3611 (interactive ,prop)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3612 arg))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3613 (read
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3614 (read-string prompt nil
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3615 'set-variable-value-history)))))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3616 (list var val)))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3617
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3618 (let ((type (get var 'custom-type)))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3619 (when type
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3620 ;; Match with custom type.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3621 (require 'cus-edit)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3622 (setq type (widget-convert type))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3623 (unless (widget-apply type :match val)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3624 (error "Value `%S' does not match type %S of %S"
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3625 val (car type) var))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3626 (if (and (boundp var) (specifierp (symbol-value var)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3627 (set-specifier (symbol-value var) val)
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3628 (set var val))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3629
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3630 ;; Force a thorough redisplay for the case that the variable
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3631 ;; has an effect on the display, like `tab-width' has.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3632 (force-mode-line-update))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3633
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3634
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3635
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3636 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3637 ;; forking a twin copy of a buffer ;;
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3638 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3639
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3640 (defvar clone-buffer-hook nil
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3641 "Normal hook to run in the new buffer at the end of `clone-buffer'.")
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3642
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3643 (defun clone-process (process &optional newname)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3644 "Create a twin copy of PROCESS.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3645 If NEWNAME is nil, it defaults to PROCESS' name;
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3646 NEWNAME is modified by adding or incrementing <N> at the end as necessary.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3647 If PROCESS is associated with a buffer, the new process will be associated
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3648 with the current buffer instead.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3649 Returns nil if PROCESS has already terminated."
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3650 (setq newname (or newname (process-name process)))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3651 (if (string-match "<[0-9]+>\\'" newname)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3652 (setq newname (substring newname 0 (match-beginning 0))))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3653 (when (memq (process-status process) '(run stop open))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3654 (let* ((process-connection-type (process-tty-name process))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3655 (old-kwoq (process-kill-without-query process nil))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3656 (new-process
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3657 (if (memq (process-status process) '(open))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3658 (apply 'open-network-stream newname
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3659 (if (process-buffer process) (current-buffer))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3660 ;; FSF: (process-contact process)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3661 (process-command process))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3662 (apply 'start-process newname
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3663 (if (process-buffer process) (current-buffer))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3664 (process-command process)))))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3665 (process-kill-without-query new-process old-kwoq)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3666 (process-kill-without-query process old-kwoq)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3667 ;; FSF 21.2:
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3668 ; (set-process-inherit-coding-system-flag
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3669 ; new-process (process-inherit-coding-system-flag process))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3670 (set-process-filter new-process (process-filter process))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3671 (set-process-sentinel new-process (process-sentinel process))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3672 new-process)))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3673
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3674 ;; things to maybe add (currently partly covered by `funcall mode':
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3675 ;; - syntax-table
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3676 ;; - overlays
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3677 (defun clone-buffer (&optional newname display-flag)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3678 "Create a twin copy of the current buffer.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3679 If NEWNAME is nil, it defaults to the current buffer's name;
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3680 NEWNAME is modified by adding or incrementing <N> at the end as necessary.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3681
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3682 If DISPLAY-FLAG is non-nil, the new buffer is shown with `pop-to-buffer'.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3683 This runs the normal hook `clone-buffer-hook' in the new buffer
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3684 after it has been set up properly in other respects."
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3685 (interactive (list (if current-prefix-arg (read-string "Name: "))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3686 t))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3687 (if buffer-file-name
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3688 (error "Cannot clone a file-visiting buffer"))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3689 (if (get major-mode 'no-clone)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3690 (error "Cannot clone a buffer in %s mode" mode-name))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3691 (setq newname (or newname (buffer-name)))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3692 (if (string-match "<[0-9]+>\\'" newname)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3693 (setq newname (substring newname 0 (match-beginning 0))))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3694 (let ((buf (current-buffer))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3695 (ptmin (point-min))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3696 (ptmax (point-max))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3697 (pt (point))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3698 (mk (mark t)) ;(if mark-active (mark t)))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3699 (modified (buffer-modified-p))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3700 (mode major-mode)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3701 (lvars (buffer-local-variables))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3702 (process (get-buffer-process (current-buffer)))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3703 (new (generate-new-buffer (or newname (buffer-name)))))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3704 (save-restriction
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3705 (widen)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3706 (with-current-buffer new
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3707 (insert-buffer-substring buf)))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3708 (with-current-buffer new
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3709 (narrow-to-region ptmin ptmax)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3710 (goto-char pt)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3711 (if mk (set-mark mk))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3712 (set-buffer-modified-p modified)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3713
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3714 ;; Clone the old buffer's process, if any.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3715 (when process (clone-process process))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3716
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3717 ;; Now set up the major mode.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3718 (funcall mode)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3719
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3720 ;; Set up other local variables.
4783
e29fcfd8df5f Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4687
diff changeset
3721 (mapc (lambda (v)
e29fcfd8df5f Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4687
diff changeset
3722 (condition-case () ;in case var is read-only
e29fcfd8df5f Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4687
diff changeset
3723 (if (symbolp v)
e29fcfd8df5f Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4687
diff changeset
3724 (makunbound v)
e29fcfd8df5f Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4687
diff changeset
3725 (set (make-local-variable (car v)) (cdr v)))
e29fcfd8df5f Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4687
diff changeset
3726 (error nil)))
e29fcfd8df5f Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4687
diff changeset
3727 lvars)
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3728
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3729 ;; Run any hooks (typically set up by the major mode
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3730 ;; for cloning to work properly).
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3731 (run-hooks 'clone-buffer-hook))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3732 (if display-flag (pop-to-buffer new))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3733 new))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3734
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3735
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3736 (defun clone-indirect-buffer (newname display-flag &optional norecord)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3737 "Create an indirect buffer that is a twin copy of the current buffer.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3738
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3739 Give the indirect buffer name NEWNAME. Interactively, read NEW-NAME
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3740 from the minibuffer when invoked with a prefix arg. If NEWNAME is nil
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3741 or if not called with a prefix arg, NEWNAME defaults to the current
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3742 buffer's name. The name is modified by adding a `<N>' suffix to it
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3743 or by incrementing the N in an existing suffix.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3744
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3745 DISPLAY-FLAG non-nil means show the new buffer with `pop-to-buffer'.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3746 This is always done when called interactively.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3747
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3748 Optional last arg NORECORD non-nil means do not put this buffer at the
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3749 front of the list of recently selected ones."
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3750 (interactive (list (if current-prefix-arg
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3751 (read-string "BName of indirect buffer: "))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3752 t))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3753 (setq newname (or newname (buffer-name)))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3754 (if (string-match "<[0-9]+>\\'" newname)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3755 (setq newname (substring newname 0 (match-beginning 0))))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3756 (let* ((name (generate-new-buffer-name newname))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3757 (buffer (make-indirect-buffer (current-buffer) name t)))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3758 (when display-flag
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3759 (pop-to-buffer buffer norecord))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3760 buffer))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3761
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3762
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3763 (defun clone-indirect-buffer-other-window (buffer &optional norecord)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3764 "Create an indirect buffer that is a twin copy of BUFFER.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3765 Select the new buffer in another window.
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3766 Optional second arg NORECORD non-nil means do not put this buffer at
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3767 the front of the list of recently selected ones."
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3768 (interactive "bClone buffer in other window: ")
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3769 (let ((pop-up-windows t))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3770 (set-buffer buffer)
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3771 (clone-indirect-buffer nil t norecord)))
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3772
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 1261
diff changeset
3773 ;; END SYNCHED WITH FSF 21.2.
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3774
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3775
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3776 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3777 ;; case changing code ;;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3778 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3779
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3780 ;; A bunch of stuff was moved elsewhere:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3781 ;; completion-list-mode-map
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3782 ;; completion-reference-buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3783 ;; completion-base-size
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3784 ;; delete-completion-window
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3785 ;; previous-completion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3786 ;; next-completion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3787 ;; choose-completion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3788 ;; choose-completion-delete-max-match
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3789 ;; choose-completion-string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3790 ;; completion-list-mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3791 ;; completion-fixup-function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3792 ;; completion-setup-function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3793 ;; switch-to-completions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3794 ;; event stuffs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3795 ;; keypad stuffs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3796
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3797 ;; The rest of this file is not in Lisp in FSF
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3798 (defun capitalize-region-or-word (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3799 "Capitalize the selected region or the following word (or ARG words)."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3800 (interactive "p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3801 (if (region-active-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3802 (capitalize-region (region-beginning) (region-end))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3803 (capitalize-word arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3804
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3805 (defun upcase-region-or-word (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3806 "Upcase the selected region or the following word (or ARG words)."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3807 (interactive "p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3808 (if (region-active-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3809 (upcase-region (region-beginning) (region-end))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3810 (upcase-word arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3811
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3812 (defun downcase-region-or-word (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3813 "Downcase the selected region or the following word (or ARG words)."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3814 (interactive "p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3815 (if (region-active-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3816 (downcase-region (region-beginning) (region-end))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3817 (downcase-word arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3818
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3819 ;; #### not localized
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3820 (defvar uncapitalized-title-words
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3821 '("the" "a" "an" "in" "of" "for" "to" "and" "but" "at" "on" "as" "by"))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3822
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3823 (defvar uncapitalized-title-word-regexp
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3824 (concat "[ \t]*\\(" (mapconcat #'identity uncapitalized-title-words "\\|")
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3825 "\\)\\>"))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3826
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3827 (defun capitalize-string-as-title (string)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3828 "Capitalize the words in the string, except for small words (as in titles).
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3829 The words not capitalized are specified in `uncapitalized-title-words'."
4946
9b5d4b35f8d7 (main branch) redo capitalize-string-as-title
Ben Wing <ben@xemacs.org>
parents: 4869
diff changeset
3830 (with-string-as-buffer-contents string
9b5d4b35f8d7 (main branch) redo capitalize-string-as-title
Ben Wing <ben@xemacs.org>
parents: 4869
diff changeset
3831 (capitalize-region-as-title (point-min) (point-max))))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3832
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3833 (defun capitalize-region-as-title (b e &optional buffer)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3834 "Capitalize the words in the region, except for small words (as in titles).
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3835 The words not capitalized are specified in `uncapitalized-title-words'."
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3836 (interactive "r")
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3837 (save-excursion
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3838 (and buffer
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3839 (set-buffer buffer))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3840 (save-restriction
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3841 (narrow-to-region b e)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3842 (goto-char (point-min))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3843 (let ((first t))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3844 (while (< (point) (point-max))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3845 (if (or first
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3846 (not (looking-at uncapitalized-title-word-regexp)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3847 (capitalize-word 1)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3848 (forward-word 1))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3849 (setq first nil))))))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3850
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3851
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3852 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3853 ;; zmacs active region code ;;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3854 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3855
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3856 ;; 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
3857 ;; are the variables zmacs-regions, zmacs-region-active-p and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3858 ;; zmacs-region-stays plus the function zmacs_update_region which
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3859 ;; simply calls the lisp level zmacs-update-region. It must remain
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3860 ;; for convenience, since it is called by core C code.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3861
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3862 ;; XEmacs
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3863 (defun activate-region ()
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3864 "Activate the region, if `zmacs-regions' is true.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3865 Setting `zmacs-regions' to true causes LISPM-style active regions to be used.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3866 This function has no effect if `zmacs-regions' is false."
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3867 (interactive)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3868 (and zmacs-regions (zmacs-activate-region)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3869
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3870 ;; XEmacs
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3871 (defsubst region-exists-p ()
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3872 "Return t if the region exists.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3873 If active regions are in use (i.e. `zmacs-regions' is true), this means that
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3874 the region is active. Otherwise, this means that the user has pushed
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3875 a mark in this buffer at some point in the past.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3876 The functions `region-beginning' and `region-end' can be used to find the
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 487
diff changeset
3877 limits of the region.
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 487
diff changeset
3878
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 487
diff changeset
3879 You should use this, *NOT* `region-active-p', in a menu item
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 487
diff changeset
3880 specification that you want grayed out when the region is not active:
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 487
diff changeset
3881
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 487
diff changeset
3882 [ ... ... :active (region-exists-p)]
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 487
diff changeset
3883
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 487
diff changeset
3884 This correctly caters to the user's setting of `zmacs-regions'."
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3885 (not (null (mark))))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3886
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3887 ;; XEmacs
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3888 (defun region-active-p ()
2611
139afe9fb2ee [xemacs-hg @ 2005-02-23 22:25:15 by adrian]
adrian
parents: 2485
diff changeset
3889 "Return non-nil if the region is active in the current buffer.
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3890 If `zmacs-regions' is true, this is equivalent to `region-exists-p'.
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 487
diff changeset
3891 Otherwise, this function always returns false.
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 487
diff changeset
3892
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 487
diff changeset
3893 You should generally *NOT* use this in a menu item specification that you
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 487
diff changeset
3894 want grayed out when the region is not active. Instead, use this:
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 487
diff changeset
3895
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 487
diff changeset
3896 [ ... ... :active (region-exists-p)]
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 487
diff changeset
3897
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 487
diff changeset
3898 Which correctly caters to the user's setting of `zmacs-regions'."
2611
139afe9fb2ee [xemacs-hg @ 2005-02-23 22:25:15 by adrian]
adrian
parents: 2485
diff changeset
3899 (and zmacs-regions zmacs-region-extent
139afe9fb2ee [xemacs-hg @ 2005-02-23 22:25:15 by adrian]
adrian
parents: 2485
diff changeset
3900 (eq (current-buffer) (zmacs-region-buffer))))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3901
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3902 (defvar zmacs-activate-region-hook nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3903 "Function or functions called when the region becomes active;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3904 see the variable `zmacs-regions'.")
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 (defvar zmacs-deactivate-region-hook nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3907 "Function or functions called when the region becomes inactive;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3908 see the variable `zmacs-regions'.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3909
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3910 (defvar zmacs-update-region-hook nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3911 "Function or functions called when the active region changes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3912 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
3913 See the variable `zmacs-regions'.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3914
487
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 462
diff changeset
3915 (add-hook 'zmacs-deactivate-region-hook 'disown-selection)
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 462
diff changeset
3916 (add-hook 'zmacs-activate-region-hook 'activate-region-as-selection)
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 462
diff changeset
3917 (add-hook 'zmacs-update-region-hook 'activate-region-as-selection)
54fa1a5c2d12 [xemacs-hg @ 2001-04-28 07:48:36 by ben]
ben
parents: 462
diff changeset
3918
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3919 (defvar zmacs-region-extent nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3920 "The extent of the zmacs region; don't use this.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3921
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3922 (defvar zmacs-region-rectangular-p nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3923 "Whether the zmacs region is a rectangle; don't use this.")
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 (defun zmacs-make-extent-for-region (region)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3926 ;; 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
3927 ;; region, for highlighting purposes. If the region isn't associated
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3928 ;; with a buffer, this does nothing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3929 (let ((buffer nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3930 (valid (and (extentp zmacs-region-extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3931 (extent-object zmacs-region-extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3932 (buffer-live-p (extent-object zmacs-region-extent))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3933 start end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3934 (cond ((consp region)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3935 (setq start (min (car region) (cdr region))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3936 end (max (car region) (cdr region))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3937 valid (and valid
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3938 (eq (marker-buffer (car region))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3939 (extent-object zmacs-region-extent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3940 buffer (marker-buffer (car region))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3941 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3942 (signal 'error (list "Invalid region" region))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3943
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3944 (if valid
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3945 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3946 ;; 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
3947 ;; otherwise incapacitated.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3948 (condition-case ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3949 (if (listp zmacs-region-extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3950 (mapc 'delete-extent zmacs-region-extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3951 (delete-extent zmacs-region-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3952 (error nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3953
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3954 (if valid
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3955 (set-extent-endpoints zmacs-region-extent start end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3956 (setq zmacs-region-extent (make-extent start end buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3957
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3958 ;; Make the extent be closed on the right, which means that if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3959 ;; characters are inserted exactly at the end of the extent, the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3960 ;; extent will grow to cover them. This is important for shell
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3961 ;; 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
3962 ;; If the shell produces output, that marker will remain at point-max
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3963 ;; (its position will increase). So it's important that the extent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3964 ;; exhibit the same behavior, lest the region covered by the extent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3965 ;; (the visual indication), and the region between point and mark
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3966 ;; (the actual region value) become different!
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3967 (set-extent-property zmacs-region-extent 'end-open nil)
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 ;; use same priority as mouse-highlighting so that conflicts between
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3970 ;; the region extent and a mouse-highlighted extent are resolved by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3971 ;; the usual size-and-endpoint-comparison method.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3972 (set-extent-priority zmacs-region-extent mouse-highlight-priority)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3973 (set-extent-face zmacs-region-extent 'zmacs-region)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3974
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3975 ;; #### It might be better to actually break
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3976 ;; 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
3977 ;; can use its logic here.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3978 (cond
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3979 (zmacs-region-rectangular-p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3980 (setq zmacs-region-extent (list zmacs-region-extent))
5368
ed74d2ca7082 Use ', not #', when a given symbol may not have a function binding at read time
Aidan Kehoe <kehoea@parhasard.net>
parents: 5321
diff changeset
3981 (when-fboundp 'default-mouse-track-next-move-rect
4222
38ef5a6da799 [xemacs-hg @ 2007-10-13 14:08:26 by aidan]
aidan
parents: 3929
diff changeset
3982 (default-mouse-track-next-move-rect start end zmacs-region-extent))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3983 ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3984
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3985 zmacs-region-extent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3986
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3987 (defun zmacs-region-buffer ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3988 "Return the buffer containing the zmacs region, or nil."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3989 ;; #### this is horrible and kludgy! This stuff needs to be rethought.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3990 (and zmacs-regions zmacs-region-active-p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3991 (or (marker-buffer (mark-marker t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3992 (and (extent-live-p zmacs-region-extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3993 (buffer-live-p (extent-object zmacs-region-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3994 (extent-object zmacs-region-extent)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3995
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3996 (defun zmacs-activate-region ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3997 "Make the region between `point' and `mark' be active (highlighted),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3998 if `zmacs-regions' is true. Only a very small number of commands
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3999 should ever do this. Calling this function will call the hook
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4000 `zmacs-activate-region-hook', if the region was previously inactive.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4001 Calling this function ensures that the region stays active after the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4002 current command terminates, even if `zmacs-region-stays' is not set.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4003 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
4004 (if (not zmacs-regions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4005 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4006 (setq zmacs-region-active-p t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4007 zmacs-region-stays t
4222
38ef5a6da799 [xemacs-hg @ 2007-10-13 14:08:26 by aidan]
aidan
parents: 3929
diff changeset
4008 zmacs-region-rectangular-p (and-boundp 'mouse-track-rectangle-p
38ef5a6da799 [xemacs-hg @ 2007-10-13 14:08:26 by aidan]
aidan
parents: 3929
diff changeset
4009 mouse-track-rectangle-p))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4010 (if (marker-buffer (mark-marker t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4011 (zmacs-make-extent-for-region (cons (point-marker t) (mark-marker t))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4012 (run-hooks 'zmacs-activate-region-hook)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4013 t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4014
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4015 (defun zmacs-deactivate-region ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4016 "Make the region between `point' and `mark' no longer be active,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4017 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
4018 command loop calls it when appropriate. Calling this function will
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4019 call the hook `zmacs-deactivate-region-hook', if the region was
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4020 previously active. Returns t if the region had been active, nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4021 otherwise."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4022 (if (not zmacs-region-active-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4023 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4024 (setq zmacs-region-active-p nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4025 zmacs-region-stays nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4026 zmacs-region-rectangular-p nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4027 (if zmacs-region-extent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4028 (let ((inhibit-quit t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4029 (if (listp zmacs-region-extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4030 (mapc 'delete-extent zmacs-region-extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4031 (delete-extent zmacs-region-extent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4032 (setq zmacs-region-extent nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4033 (run-hooks 'zmacs-deactivate-region-hook)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4034 t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4035
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4036 (defun zmacs-update-region ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4037 "Update the highlighted region between `point' and `mark'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4038 You shouldn't need to call this; the command loop calls it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4039 when appropriate. Calling this function will call the hook
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4040 `zmacs-update-region-hook', if the region is active."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4041 (when zmacs-region-active-p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4042 (when (marker-buffer (mark-marker t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4043 (zmacs-make-extent-for-region (cons (point-marker t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4044 (mark-marker t))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4045 (run-hooks 'zmacs-update-region-hook)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4046
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4047
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4048 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4049 ;; message logging code ;;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4050 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4051
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4052 ;;; #### Should this be moved to a separate file, for clarity?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4053 ;;; -hniksic
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4054
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4055 ;;; The `message-stack' is an alist of labels with messages; the first
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4056 ;;; 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
4057 ;;; `display-message' inserts a label/message pair at the head of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4058 ;;; list, and removes any other pairs with that label. Calling
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4059 ;;; `clear-message' causes any pair with matching label to be removed,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4060 ;;; and this may cause the displayed message to change or vanish. If
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4061 ;;; the label arg is nil, the entire message stack is cleared.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4062 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4063 ;;; Message/error filtering will be a little tricker to implement than
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4064 ;;; logging, since messages can be built up incrementally
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4065 ;;; using clear-message followed by repeated calls to append-message
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4066 ;;; (this happens with error messages). For messages which aren't
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4067 ;;; created this way, filtering could be implemented at display-message
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4068 ;;; very easily.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4069 ;;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4070 ;;; Bits of the logging code are borrowed from log-messages.el by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4071 ;;; Robert Potter (rpotter@grip.cis.upenn.edu).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4072
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4073 ;; need this to terminate the currently-displayed message
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4074 ;; ("Loading simple ...")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4075 (when (and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4076 (not (fboundp 'display-message))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4077 (not (featurep 'debug)))
1346
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
4078 (set-device-clear-left-side nil nil)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4079 (send-string-to-terminal "\n"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4080
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4081 (defvar message-stack nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4082 "An alist of label/string pairs representing active echo-area messages.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4083 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
4084 Do not modify this directly--use the `message' or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4085 `display-message'/`clear-message' functions.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4086
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4087 (defvar remove-message-hook 'log-message
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4088 "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
4089 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
4090 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
4091 as the second argument.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4092
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4093 (defcustom log-message-max-size 50000
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4094 "Maximum size of the \" *Message-Log*\" buffer. See `log-message'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4095 :type 'integer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4096 :group 'log-message)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4097 (make-compatible-variable 'message-log-max 'log-message-max-size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4098
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4099 ;; 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
4100 ;; for two reasons:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4101 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4102 ;; 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
4103 ;; The explicitly non-loggable messages should be marked as such by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4104 ;; the issuer. Gratuitous non-displaying of random regexps made
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4105 ;; debugging harder, too (because various reasonable debugging
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4106 ;; messages would get eaten).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4107 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4108 ;; b) It slowed things down. Yes, visibly.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4109 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4110 ;; 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
4111 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4112 ;; --hniksic
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4113 (defcustom log-message-ignore-regexps
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4114 '(;; Note: adding entries to this list slows down messaging
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
4115 ;; significantly. Wherever possible, use message labels.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4116
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4117 ;; Often-seen messages
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4118 "\\`\\'" ; empty message
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4119 "\\`\\(Beginning\\|End\\) of buffer\\'"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4120 ;;"^Quit$"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4121 ;; completions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4122 ;; Many packages print this -- impossible to categorize
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4123 ;;"^Making completion list"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4124 ;; Gnus
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4125 ;; "^No news is no news$"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4126 ;; "^No more\\( unread\\)? newsgroups$"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4127 ;; "^Opening [^ ]+ server\\.\\.\\."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4128 ;; "^[^:]+: Reading incoming mail"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4129 ;; "^Getting mail from "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4130 ;; "^\\(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
4131 ;; "^\\(Fetching headers for\\|Retrieving newsgroup\\|Reading active file\\)"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4132 ;; "^No more\\( unread\\)? articles"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4133 ;; "^Deleting article "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4134 ;; W3
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4135 ;; "^Parsed [0-9]+ of [0-9]+ ([0-9]+%)"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4136 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4137 "List of regular expressions matching messages which shouldn't be logged.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4138 See `log-message'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4139
3929
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4140 Adding entries to this list slows down messaging significantly. Wherever
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4141 possible, messages which might need to be ignored should be labeled with
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4142 'progress, 'prompt, or 'no-log, so they can be filtered by
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4143 log-message-ignore-labels."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4144 :type '(repeat regexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4145 :group 'log-message)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4146
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4147 (defcustom log-message-ignore-labels
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4148 '(help-echo command progress prompt no-log garbage-collecting auto-saving)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4149 "List of symbols indicating labels of messages which shouldn't be logged.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4150 See `display-message' for some common labels. See also `log-message'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4151 :type '(repeat (symbol :tag "Label"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4152 :group 'log-message)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4153
1703
f561c3904bb3 [xemacs-hg @ 2003-09-20 01:46:53 by youngs]
youngs
parents: 1346
diff changeset
4154 (defcustom redisplay-echo-area-function 'redisplay-echo-area
f561c3904bb3 [xemacs-hg @ 2003-09-20 01:46:53 by youngs]
youngs
parents: 1346
diff changeset
4155 "The function to call to display echo area buffer."
f561c3904bb3 [xemacs-hg @ 2003-09-20 01:46:53 by youngs]
youngs
parents: 1346
diff changeset
4156 :type 'function
f561c3904bb3 [xemacs-hg @ 2003-09-20 01:46:53 by youngs]
youngs
parents: 1346
diff changeset
4157 :group 'log-message)
f561c3904bb3 [xemacs-hg @ 2003-09-20 01:46:53 by youngs]
youngs
parents: 1346
diff changeset
4158
f561c3904bb3 [xemacs-hg @ 2003-09-20 01:46:53 by youngs]
youngs
parents: 1346
diff changeset
4159 (defcustom undisplay-echo-area-function nil
3929
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4160 "The function to call to undisplay echo area buffer.
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4161 WARNING: any problem with your function is likely to result in an
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4162 uninterruptible infinite loop. Use of custom functions is therefore not
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4163 recommended."
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4164 :type '(choice (const nil)
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4165 function)
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4166 :group 'log-message)
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4167
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4168 (defvar undisplay-echo-area-resize-window-allowed t
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4169 "INTERNAL USE ONLY.
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4170 Guards against `undisplay-echo-area-resize-window' infloops.
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4171 Touch this at your own risk.")
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4172
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4173 (defun undisplay-echo-area-resize-window ()
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4174 "Resize idle echo area window to `resize-minibuffer-idle-height'.
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4175 If either `resize-minibuffer-idle-height' or `resize-minibuffer-mode' is nil,
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4176 does nothing. If `resize-minibuffer-window-exactly' is non-nil, always resize
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4177 to this height exactly, otherwise if current height is no larger than this,
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4178 leave it as is."
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4179 (when (default-value undisplay-echo-area-resize-window-allowed)
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4180 (setq-default undisplay-echo-area-resize-window-allowed nil)
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4181 (let* ((mbw (minibuffer-window))
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4182 (height (window-height mbw)))
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4183 (with-boundp '(resize-minibuffer-idle-height)
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4184 (and resize-minibuffer-mode
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4185 (numberp resize-minibuffer-idle-height)
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4186 (> resize-minibuffer-idle-height 0)
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4187 (unless (if resize-minibuffer-window-exactly
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4188 (= resize-minibuffer-idle-height height)
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4189 (<= resize-minibuffer-idle-height height))
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4190 (enlarge-window (- resize-minibuffer-idle-height height)
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4191 nil mbw))))
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4192 (setq-default undisplay-echo-area-resize-window-allowed t))))
1703
f561c3904bb3 [xemacs-hg @ 2003-09-20 01:46:53 by youngs]
youngs
parents: 1346
diff changeset
4193
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4194 ;;Subsumed by view-lossage
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4195 ;; Not really, I'm adding it back by popular demand. -slb
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4196 (defun show-message-log ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4197 "Show the \" *Message-Log*\" buffer, which contains old messages and errors."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4198 (interactive)
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4199 (view-lossage t))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4200
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4201 (defvar log-message-filter-function 'log-message-filter
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4202 "Value must be a function of two arguments: a symbol (label) and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4203 a string (message). It should return non-nil to indicate a message
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4204 should be logged. Possible values include 'log-message-filter and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4205 'log-message-filter-errors-only.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4206
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4207 (defun log-message-filter (label message)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4208 "Default value of `log-message-filter-function'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4209 Messages whose text matches one of the `log-message-ignore-regexps'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4210 or whose label appears in `log-message-ignore-labels' are not saved."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4211 (let ((r log-message-ignore-regexps)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4212 (ok (not (memq label log-message-ignore-labels))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4213 (save-match-data
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4214 (while (and r ok)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4215 (when (string-match (car r) message)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4216 (setq ok nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4217 (setq r (cdr r))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4218 ok))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4219
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4220 (defun log-message-filter-errors-only (label message)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4221 "For use as the `log-message-filter-function'. Only logs error messages."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4222 (eq label 'error))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4223
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4224 (defun log-message (label message)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4225 "Stuff a copy of the message into the \" *Message-Log*\" buffer,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4226 if it satisfies the `log-message-filter-function'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4227
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4228 For use on `remove-message-hook'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4229 (when (and (not noninteractive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4230 (funcall log-message-filter-function label message))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4231 ;; Use save-excursion rather than save-current-buffer because we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4232 ;; change the value of point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4233 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4234 (set-buffer (get-buffer-create " *Message-Log*"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4235 (goto-char (point-max))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4236 ;(insert (concat (upcase (symbol-name label)) ": " message "\n"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4237 (let (extent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4238 ;; Mark multiline message with an extent, which `view-lossage'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4239 ;; will recognize.
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4240 (save-match-data
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4241 (when (string-match "\n" message)
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4242 (setq extent (make-extent (point) (point)))
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4243 (set-extent-properties extent '(end-open nil message-multiline t)))
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4244 )
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4245 (insert message "\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4246 (when extent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4247 (set-extent-property extent 'end-open t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4248 (when (> (point-max) (max log-message-max-size (point-min)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4249 ;; Trim log to ~90% of max size.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4250 (goto-char (max (- (point-max)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4251 (truncate (* 0.9 log-message-max-size)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4252 (point-min)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4253 (forward-line 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4254 (delete-region (point-min) (point))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4255
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4256 (defun message-displayed-p (&optional return-string frame)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4257 "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
4258 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
4259 return a string containing the message, otherwise just return t."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4260 ;; by definition, a message is displayed if the echo area buffer is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4261 ;; non-empty (see also echo_area_active()). It had better also
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4262 ;; 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
4263 ;; is non-empty.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4264 (let ((buffer (get-buffer " *Echo Area*")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4265 (and (< (point-min buffer) (point-max buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4266 (if return-string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4267 (buffer-substring nil nil buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4268 t))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4269
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4270 ;;; 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
4271 ;;; If label is nil, the whole message stack is cleared.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4272 (defun clear-message (&optional label frame stdout-p no-restore)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4273 "Remove any message with the given LABEL from the message-stack,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4274 erasing it from the echo area if it's currently displayed there.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4275 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
4276 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
4277 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
4278 If LABEL is nil, the entire message-stack is cleared.
3929
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4279 STDOUT-P is ignored, except for output to stream devices. For streams,
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4280 STDOUT-P non-nil directs output to stdout, otherwise to stderr. \(This is
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4281 used only in case of restoring an earlier message from the stack.)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4282
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4283 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
4284 you should just use (message nil)."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4285 (or frame (setq frame (selected-frame)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4286 (let ((clear-stream (and message-stack (eq 'stream (frame-type frame)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4287 (remove-message label frame)
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 487
diff changeset
4288 (let ((inhibit-read-only t))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4289 (erase-buffer " *Echo Area*"))
1703
f561c3904bb3 [xemacs-hg @ 2003-09-20 01:46:53 by youngs]
youngs
parents: 1346
diff changeset
4290 (if undisplay-echo-area-function
f561c3904bb3 [xemacs-hg @ 2003-09-20 01:46:53 by youngs]
youngs
parents: 1346
diff changeset
4291 (funcall undisplay-echo-area-function))
1346
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
4292 ;; If outputting to the terminal, make sure we clear the left side.
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
4293 (when (or clear-stream
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
4294 (and (eq 'stream (frame-type frame))
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
4295 (not (device-left-side-clear-p (frame-device frame)))))
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
4296 (set-device-clear-left-side (frame-device frame) nil)
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
4297 (send-string-to-terminal ?\n stdout-p))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4298 (if no-restore
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4299 nil ; just preparing to put another msg up
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4300 (if message-stack
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4301 (let ((oldmsg (cdr (car message-stack))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4302 (raw-append-message oldmsg frame stdout-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4303 oldmsg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4304 ;; #### Should we (redisplay-echo-area) here? Messes some
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4305 ;; things up.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4306 nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4307
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4308 (defun remove-message (&optional label frame)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4309 ;; If label is nil, we want to remove all matching messages.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4310 ;; Must reverse the stack first to log them in the right order.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4311 (let ((log nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4312 (while (and message-stack
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4313 (or (null label) ; null label means clear whole stack
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4314 (eq label (car (car message-stack)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4315 (push (car message-stack) log)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4316 (setq message-stack (cdr message-stack)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4317 (let ((s message-stack))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4318 (while (cdr s)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4319 (let ((msg (car (cdr s))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4320 (if (eq label (car msg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4321 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4322 (push msg log)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4323 (setcdr s (cdr (cdr s))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4324 (setq s (cdr s))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4325 ;; (possibly) log each removed message
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4326 (while log
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4327 (with-trapping-errors
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4328 :operation 'remove-message-hook
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4329 :class 'message-log
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4330 :error-form (progn
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4331 (setq remove-message-hook nil)
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4332 (let ((inhibit-read-only t))
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4333 (erase-buffer " *Echo Area*")))
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4334 :resignal t
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4335 (run-hook-with-args 'remove-message-hook
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4336 (car (car log)) (cdr (car log))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4337 (setq log (cdr log)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4338
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4339 (defun append-message (label message &optional frame stdout-p)
3929
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4340 "Add MESSAGE to the message-stack, or append it to the existing text.
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4341 LABEL is the class of the message. If it is the same as that of the top of
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4342 the message stack, MESSAGE is appended to the existing message, otherwise
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4343 it is pushed on the stack.
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4344 FRAME determines the minibuffer window to send the message to.
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4345 STDOUT-P is ignored, except for output to stream devices. For streams,
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4346 STDOUT-P non-nil directs output to stdout, otherwise to stderr."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4347 (or frame (setq frame (selected-frame)))
1346
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
4348 ;; If outputting to the terminal, make sure output from anyone else clears
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
4349 ;; the left side first, but don't do it ourselves, otherwise we won't be
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
4350 ;; able to append to an existing message.
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
4351 (if (eq 'stream (frame-type frame))
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
4352 (set-device-clear-left-side (frame-device frame) nil))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4353 (let ((top (car message-stack)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4354 (if (eq label (car top))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4355 (setcdr top (concat (cdr top) message))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4356 (push (cons label message) message-stack)))
1346
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
4357 (raw-append-message message frame stdout-p)
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
4358 (if (eq 'stream (frame-type frame))
01c57eb70ae9 [xemacs-hg @ 2003-03-09 02:27:27 by ben]
ben
parents: 1333
diff changeset
4359 (set-device-clear-left-side (frame-device frame) t)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4360
3929
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4361 ;; Really append the message to the echo area. No fiddling with
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4362 ;; message-stack.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4363 (defun raw-append-message (message &optional frame stdout-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4364 (unless (equal message "")
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 487
diff changeset
4365 (let ((inhibit-read-only t))
3652
bd7189f2e967 [xemacs-hg @ 2006-11-01 21:35:35 by adrian]
adrian
parents: 3361
diff changeset
4366 (with-current-buffer " *Echo Area*"
bd7189f2e967 [xemacs-hg @ 2006-11-01 21:35:35 by adrian]
adrian
parents: 3361
diff changeset
4367 (insert-string message)
3929
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4368 ;; #### This needs to be conditional; cf discussion by Stefan Monnier
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4369 ;; et al on emacs-devel in mid-to-late April 2007. One problem is
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4370 ;; there is no known good way to guess whether the user wants to have
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4371 ;; the echo area height changed on him asynchronously, especially
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4372 ;; after message display.
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4373 ;; There is also a problem where Lisp backtraces get sent to the echo
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4374 ;; area, thus maxing out the window height. Unfortunately, it doesn't
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4375 ;; return to a reasonable size very quickly.
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4376 ;; It is not clear that echo area and minibuffer behavior should be
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4377 ;; linked as we do here. It's OK for now; at least this obeys the
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4378 ;; minibuffer resizing conventions which seem a pretty good guess
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4379 ;; at user preference.
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4380 (when resize-minibuffer-mode
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4381 ;; #### interesting idea, unbearable implementation
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4382 ;; (fill-region (point-min) (point-max))
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4383 ;;
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4384 ;; #### We'd like to be able to do something like
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4385 ;;
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4386 ;; (save-window-excursion
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4387 ;; (select-window (minibuffer-window frame))
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4388 ;; (resize-minibuffer-window))))
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4389 ;;
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4390 ;; but that can't work, because the echo area isn't a real window!
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4391 ;; We should fix that, but this is an approximation, duplicating the
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4392 ;; resize-minibuffer code.
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4393 (let* ((mbw (minibuffer-window frame))
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4394 (height (window-height mbw))
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4395 (lines (ceiling (/ (- (point-max) (point-min))
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4396 (- (window-width mbw) 1.0)))))
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4397 (and (numberp resize-minibuffer-window-max-height)
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4398 (> resize-minibuffer-window-max-height 0)
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4399 (setq lines (min lines
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4400 resize-minibuffer-window-max-height)))
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4401 (or (if resize-minibuffer-window-exactly
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4402 (= lines height)
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4403 (<= lines height))
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4404 (enlarge-window (- lines height) nil mbw)))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4405
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4406 ;; Don't redisplay the echo area if we are executing a macro.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4407 (if (not executing-kbd-macro)
3929
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4408 ;; Conditionalizing on the device type in this way isn't clean, but
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4409 ;; neither is having a device method, as I originally implemented
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4410 ;; it: all non-stream devices behave in the same way. Perhaps
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4411 ;; the cleanest way is to make the concept of a "redisplayable"
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4412 ;; device, which stream devices are not. Look into this more if
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4413 ;; we ever create another non-redisplayable device type (e.g.
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4414 ;; processes? printers?).
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4415 (if (eq 'stream (frame-type frame))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4416 (send-string-to-terminal message stdout-p (frame-device frame))
1703
f561c3904bb3 [xemacs-hg @ 2003-09-20 01:46:53 by youngs]
youngs
parents: 1346
diff changeset
4417 (funcall redisplay-echo-area-function))))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4418
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4419 (defun display-message (label message &optional frame stdout-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4420 "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
4421 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
4422 Use `clear-message' to remove a labelled message.
3929
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4423 STDOUT-P is ignored, except for output to stream devices. For streams,
94ecba3ecd77 [xemacs-hg @ 2007-04-30 16:16:48 by stephent]
stephent
parents: 3767
diff changeset
4424 STDOUT-P non-nil directs output to stdout, otherwise to stderr.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4425
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4426 Here are some standard labels (those marked with `*' are not logged
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4427 by default--see the `log-message-ignore-labels' variable):
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4428 message default label used by the `message' function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4429 error default label used for reporting errors
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4430 * progress progress indicators like \"Converting... 45%\"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4431 * prompt prompt-like messages like \"I-search: foo\"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4432 * command helper command messages like \"Mark set\"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4433 * no-log messages that should never be logged"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4434 (clear-message label frame stdout-p t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4435 (append-message label message frame stdout-p))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4436
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4437 (defun current-message (&optional frame)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4438 "Return the current message in the echo area, or nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4439 The FRAME argument is currently unused."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4440 (cdr (car message-stack)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4441
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4442 ;;; may eventually be frame-dependent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4443 (defun current-message-label (&optional frame)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4444 (car (car message-stack)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4445
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4446 (defun message (fmt &rest args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4447 "Print a one-line message at the bottom of the frame.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4448 The arguments are the same as to `format'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4449
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4450 If the only argument is nil, clear any existing message; let the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4451 minibuffer contents show."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4452 ;; questionable junk in the C code
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4453 ;; (if (framep default-minibuffer-frame)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4454 ;; (make-frame-visible default-minibuffer-frame))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4455 (if (and (null fmt) (null args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4456 (prog1 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4457 (clear-message nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4458 (let ((str (apply 'format fmt args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4459 (display-message 'message str)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4460 str)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4461
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4462 (defun lmessage (label fmt &rest args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4463 "Print a one-line message at the bottom of the frame.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4464 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
4465 arguments are the same as to `format'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4466
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4467 See `display-message' for a list of standard labels."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4468 (if (and (null fmt) (null args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4469 (prog1 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4470 (clear-message label nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4471 (let ((str (apply 'format fmt args)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4472 (display-message label str)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4473 str)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4474
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4475
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4476 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4477 ;; warning code ;;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4478 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4479
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4480 (defcustom log-warning-minimum-level 'info
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4481 "Minimum level of warnings that should be logged.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4482 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
4483 happened.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4484
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4485 The recognized warning levels, in decreasing order of priority, are
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4486 'emergency, 'critical, 'error, 'warning, 'alert, 'notice, 'info, and
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4487 'debug.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4488
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4489 See also `display-warning-minimum-level'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4490
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4491 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
4492 basis. See `display-warning-suppressed-classes' and
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4493 `log-warning-suppressed-classes'.
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4494
3064
b350e85a2a5e [xemacs-hg @ 2005-11-13 10:51:17 by ben]
ben
parents: 3000
diff changeset
4495 For a description of the meaning of the levels, see `display-warning'."
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4496 :type '(choice (const emergency) (const critical)
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4497 (const error) (const warning) (const alert) (const notice)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4498 (const info) (const debug))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4499 :group 'warnings)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4500
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4501 (defcustom display-warning-minimum-level 'warning
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4502 "Minimum level of warnings that cause the warnings buffer to be displayed.
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4503 Warnings at this level or higher will force the *Warnings* buffer, in which
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4504 the warnings are logged, to be displayed. The warnings in levels below
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4505 this, but at least as high as `log-warning-suppressed-classes', will be
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4506 shown in the minibuffer.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4507
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4508 The recognized warning levels, in decreasing order of priority, are
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4509 'emergency, 'critical, 'error, 'warning, 'alert, 'notice, 'info, and
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4510 'debug.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4511
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4512 See also `log-warning-minimum-level'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4513
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4514 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
4515 basis. See `display-warning-suppressed-classes' and
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4516 `log-warning-suppressed-classes'.
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4517
3064
b350e85a2a5e [xemacs-hg @ 2005-11-13 10:51:17 by ben]
ben
parents: 3000
diff changeset
4518 For a description of the meaning of the levels, see `display-warning'."
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4519 :type '(choice (const emergency) (const critical)
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4520 (const error) (const warning) (const alert) (const notice)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4521 (const info) (const debug))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4522 :group 'warnings)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4523
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4524 (defvar log-warning-suppressed-classes nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4525 "List of classes of warnings that shouldn't be logged or displayed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4526 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
4527 any of the symbols listed here, the warning will be completely ignored,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4528 as it they never happened.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4529
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4530 NOTE: In most circumstances, you should *not* set this variable.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4531 Set `display-warning-suppressed-classes' instead. That way the suppressed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4532 warnings are not displayed but are still unobtrusively logged.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4533
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4534 See also `log-warning-minimum-level' and `display-warning-minimum-level'.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4535
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4536 (defcustom display-warning-suppressed-classes nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4537 "List of classes of warnings that shouldn't be displayed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4538 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
4539 any of the symbols listed here, the warning will not be displayed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4540 The warning will still logged in the *Warnings* buffer (unless also
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4541 contained in `log-warning-suppressed-classes'), but the buffer will
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4542 not be automatically popped up.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4543
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4544 See also `log-warning-minimum-level' and `display-warning-minimum-level'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4545 :type '(repeat symbol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4546 :group 'warnings)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4547
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4548 (defvar warning-count 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4549 "Count of the number of warning messages displayed so far.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4550
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4551 (defconst warning-level-alist '((emergency . 8)
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4552 (critical . 7)
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4553 (error . 6)
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4554 (warning . 5)
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4555 (alert . 4)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4556 (notice . 3)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4557 (info . 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4558 (debug . 1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4559
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4560 (defun warning-level-p (level)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4561 "Non-nil if LEVEL specifies a warning level."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4562 (and (symbolp level) (assq level warning-level-alist)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4563
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4564 (defun warning-level-< (level1 level2)
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4565 "Non-nil if warning level LEVEL1 is lower than LEVEL2."
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4566 (check-argument-type 'warning-level-p level1)
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4567 (check-argument-type 'warning-level-p level2)
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4568 (< (cdr (assq level1 warning-level-alist))
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4569 (cdr (assq level2 warning-level-alist))))
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4570
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4571 ;; If you're interested in rewriting this function, be aware that it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4572 ;; could be called at arbitrary points in a Lisp program (when a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4573 ;; 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
4574 ;; this function the next time some Lisp code is evaluated). Therefore,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4575 ;; this function *must* not permanently modify any global variables
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4576 ;; (e.g. the current buffer) except those that specifically apply
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4577 ;; to the warning system.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4578
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4579 (defvar before-init-deferred-warnings nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4580
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4581 (defun after-init-display-warnings ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4582 "Display warnings deferred till after the init file is run.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4583 Warnings that occur before then are deferred so that warning
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4584 suppression in the .emacs file will be honored."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4585 (while before-init-deferred-warnings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4586 (apply 'display-warning (car before-init-deferred-warnings))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4587 (setq before-init-deferred-warnings
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4588 (cdr before-init-deferred-warnings))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4589
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4590 (add-hook 'after-init-hook 'after-init-display-warnings)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4591
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4592 (defun display-warning (class message &optional level)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4593 "Display a warning message.
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4594
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4595 \[This is the most basic entry point for displaying a warning. In practice,
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4596 `lwarn' or `warn' are probably more convenient for most usages.]
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4597
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4598 CLASS should be a symbol describing what sort of warning this is, such as
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4599 `resource' or `key-mapping' -- this refers, more or less, to the module in
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4600 which the warning is generated and serves to group warnings together with
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4601 similar semantics. A list of such symbols is also accepted.
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4602
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4603 Optional argument LEVEL can be used to specify a priority for the warning,
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4604 other than default priority `warning'. The currently defined levels are,
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4605 from highest to lowest:
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4606
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4607 Level Meaning
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4608 -----------------------------------------------------------------------------
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4609 emergency A fatal or near-fatal error. XEmacs is likely to crash.
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4610
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4611 critical A serious, nonrecoverable problem has occurred -- e.g., the
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4612 loss of a major subsystem, such as the crash of the X server
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4613 when XEmacs is connected to the server.
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4614
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4615 error A warning about a problematic condition that should be fixed,
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4616 and XEmacs cannot work around it -- it causes a failure of an
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4617 operation. (In most circumstances, consider just signalling
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4618 an error). However, there is no permanent damage and the
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4619 situation is ultimately recoverable.
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4620
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4621 warning A warning about a problematic condition that should be fixed,
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4622 but XEmacs can work around it.
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4623
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4624 \[By default, warnings above here, as well as being logged, cause the
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4625 *Warnings* buffer to be forcibly displayed, so that the warning (and
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4626 previous warnings, since often a whole series of warnings are issued at
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4627 once) can be examined in detail. Also, the annoying presence of the
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4628 *Warnings* buffer will encourage people to go out and fix the
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4629 problem. Warnings below here are displayed in the minibuffer as well as
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4630 logged in the *Warnings* buffer. but the *Warnings* buffer will not be
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4631 forcibly shown, as these represent conditions the user is not expected to
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4632 fix.]
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4633
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4634 alert A warning about a problematic condition that can't easily be
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4635 fixed (often having to do with the external environment), and
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4636 causes a failure. We don't force the *Warnings* buffer to be
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4637 displayed because the purpose of doing that is to force the
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4638 user to fix the problem so that the buffer no longer appears.
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4639 When the problem is outside the user's control, forcing the
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4640 buffer is pointless and annoying.
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4641
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4642 notice A warning about a problematic condition that can't easily be
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4643 fixed (often having to do with the external environment),
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4644 but XEmacs can work around it.
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4645
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4646 info Random info about something new or unexpected that was noticed;
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4647 does not generally indicate a problem.
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4648
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4649 \[By default, warnings below here are ignored entirely. All warnings above
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4650 here are logged in the *Warnings* buffer.]
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4651
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4652 debug A debugging notice; normally, not seen at all.
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4653
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4654 NOTE: `specifier-instance' outputs warnings at level `debug' when errors occur
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4655 in the process of trying to instantiate a particular instantiator. If you
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4656 want to see these, change `log-warning-minimum-level'.
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4657
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4658 There are two sets of variables. One controls the lower level (see the
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4659 above diagram) -- i.e. ignored entirely. One controls the upper level --
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4660 whether the *Warnings* buffer is forcibly displayed. In particular:
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4661
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4662 `display-warning-minimum-level' sets the upper level (see above), and
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4663 `log-warning-minimum-level' the lower level.
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4664
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4665 Individual classes can be suppressed. `log-warning-suppressed-classes'
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4666 specifies a list of classes where warnings on those classes will be treated
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4667 as if their level is below `log-warning-minimum-level' (i.e. they will be
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4668 ignored completely), regardless of their actual level. Similarly,
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4669 `display-warning-suppressed-classes' specifies a list of classes where
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4670 warnings on those classes will be treated as if their level is below
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4671 `display-warning-minimum-level', but above `log-warning-minimum-level' so
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4672 long as they're not listed in that variable as well."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4673 (or level (setq level 'warning))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4674 (or (listp class) (setq class (list class)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4675 (check-argument-type 'warning-level-p level)
5228
5efbd1253905 Remove all support for InfoDock.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4957
diff changeset
4676 (if (not init-file-loaded)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4677 (push (list class message level) before-init-deferred-warnings)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4678 (catch 'ignored
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4679 (let ((display-p t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4680 (level-num (cdr (assq level warning-level-alist))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4681 (if (< level-num (cdr (assq log-warning-minimum-level
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4682 warning-level-alist)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4683 (throw 'ignored nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4684 (if (intersection class log-warning-suppressed-classes)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4685 (throw 'ignored nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4686
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4687 (if (< level-num (cdr (assq display-warning-minimum-level
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4688 warning-level-alist)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4689 (setq display-p nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4690 (if (and display-p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4691 (intersection class display-warning-suppressed-classes))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4692 (setq display-p nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4693 (let ((buffer (get-buffer-create "*Warnings*")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4694 (when display-p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4695 ;; The C code looks at display-warning-tick to determine
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4696 ;; when it should call `display-warning-buffer'. Change it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4697 ;; to get the C code's attention.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4698 (incf display-warning-tick))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4699 (with-current-buffer buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4700 (goto-char (point-max))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4701 (incf warning-count)
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4702 (let ((start (point)))
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4703 (princ (format "(%d) (%s/%s) "
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4704 warning-count
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4705 (mapconcat 'symbol-name class ",")
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4706 level)
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4707 buffer)
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4708 (princ message buffer)
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4709 (terpri buffer)
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4710 (terpri buffer)
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4711 (let ((ex (make-extent start (point))))
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4712 (set-extent-properties ex
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4713 `(warning t warning-count ,warning-count
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4714 warning-class ,class
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4715 warning-level ,level)))))
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4716 (message "%s: %s" (capitalize (symbol-name level)) message))))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4717
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4718 (defun warn (&rest args)
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4719 "Display a formatted warning message at default class and level.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4720 The message is constructed by passing all args to `format'. The message
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4721 is placed in the *Warnings* buffer, which will be popped up at the next
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4722 redisplay. The class of the warning is `general'; the level is `warning'.
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4723
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4724 See `display-warning' for more info."
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4725 (display-warning 'default (apply 'format args)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4726
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4727 (defun lwarn (class level &rest args)
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4728 "Display a formatted warning message at specified class and level.
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4729 The message is constructed by passing all args to `format'. The message
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4730 is placed in the *Warnings* buffer, which will be popped up at the next
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4731 redisplay.
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4732
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4733 See `display-warning' for more info."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4734 (display-warning class (apply 'format args)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4735 (or level 'warning)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4736
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4737 (defvar warning-marker nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4738
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4739 ;; 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
4740 ;; 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
4741 ;; bad idea for this function to get into an infinite loop.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4742
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4743 (defun display-warning-buffer ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4744 "Make the buffer that contains the warnings be visible.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4745 The C code calls this periodically, right before redisplay."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4746 (let ((buffer (get-buffer-create "*Warnings*")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4747 (when (or (not warning-marker)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4748 (not (eq (marker-buffer warning-marker) buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4749 (setq warning-marker (make-marker))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4750 (set-marker warning-marker 1 buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4751 (if temp-buffer-show-function
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4752 (progn
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4753 (funcall temp-buffer-show-function buffer)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4754 (mapc #'(lambda (win) (set-window-start win warning-marker))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4755 (windows-of-buffer buffer nil t)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4756 (set-window-start (display-buffer buffer) warning-marker))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4757 (set-marker warning-marker (point-max buffer) buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4758
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4759
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4760 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4761 ;; misc junk ;;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4762 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4763
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4764 (defun emacs-name ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4765 "Return the printable name of this instance of Emacs."
5228
5efbd1253905 Remove all support for InfoDock.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4957
diff changeset
4766 (cond ((featurep 'xemacs) "XEmacs")
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4767 (t "Emacs")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4768
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4769 (defun debug-print-1 (&rest args)
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4770 "Send a debugging-type string to standard output.
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4771 If the first argument is a string, it is considered to be a format
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4772 specifier if there are sufficient numbers of other args, and the string is
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4773 formatted using (apply #'format args). Otherwise, each argument is printed
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4774 individually in a numbered list."
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4775 (let ((standard-output 'external-debugging-output)
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4776 (fmt (condition-case nil
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4777 (and (stringp (first args))
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4778 (apply #'format args))
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4779 (error nil))))
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4780 (if fmt
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4781 (progn
3064
b350e85a2a5e [xemacs-hg @ 2005-11-13 10:51:17 by ben]
ben
parents: 3000
diff changeset
4782 (princ (apply #'format args))
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4783 (terpri))
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4784 (princ "--> ")
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4785 (let ((i 1))
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4786 (dolist (sgra args)
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4787 (if (> i 1) (princ " "))
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4788 (princ (format "%d. " i))
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4789 (prin1 sgra)
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4790 (incf i))
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4791 (terpri)))))
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4792
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4793 (defun debug-print (&rest args)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4794 "Send a string to the debugging output.
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4795 If the first argument is a string, it is considered to be a format
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4796 specifier if there are sufficient numbers of other args, and the string is
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4797 formatted using (apply #'format args). Otherwise, each argument is printed
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4798 individually in a numbered list."
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4799 (let ((standard-output 'external-debugging-output))
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4800 (apply #'debug-print-1 args)))
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4801
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4802 (defun debug-backtrace ()
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4803 "Send a backtrace to the debugging output."
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4804 (let ((standard-output 'external-debugging-output))
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4805 (backtrace nil t)
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 776
diff changeset
4806 (terpri)))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
4807
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4808 ;;; simple.el ends here