Mercurial > hg > xemacs-beta
annotate lisp/simple.el @ 5565:48a3d3281b48
Pass eighth bit on TTY consoles to coding system if needed.
src/ChangeLog addition:
2011-09-06 Aidan Kehoe <kehoea@parhasard.net>
* redisplay-tty.c (init_tty_for_redisplay):
Only set the console meta key flag to treat the eight bit as meta
if the native coding system doesn't need that.
* general-slots.h:
* mule-coding.c:
* mule-coding.c (syms_of_mule_coding):
Move Qiso2022, Qseven to general-slots.h, they're now used in
redisplay-tty.c.
lisp/ChangeLog addition:
2011-09-06 Aidan Kehoe <kehoea@parhasard.net>
* mule/mule-cmds.el (set-language-environment-coding-systems):
Set the input mode for TTY consoles to use the eighth bit for
character information if the native coding system for the language
environment needs that.
| author | Aidan Kehoe <kehoea@parhasard.net> |
|---|---|
| date | Tue, 06 Sep 2011 11:44:50 +0100 |
| parents | ac37a5f7e5be |
| children | 3bc58dc9d688 |
| rev | line source |
|---|---|
| 428 | 1 ;;; simple.el --- basic editing commands for XEmacs |
| 2 | |
| 3 ;; Copyright (C) 1985-7, 1993-5, 1997 Free Software Foundation, Inc. | |
| 4 ;; Copyright (C) 1995 Tinker Systems and INS Engineering Corp. | |
| 1261 | 5 ;; Copyright (C) 2000, 2001, 2002, 2003 Ben Wing. |
| 428 | 6 |
| 7 ;; Maintainer: XEmacs Development Team | |
| 8 ;; Keywords: lisp, extensions, internal, dumped | |
| 9 | |
| 10 ;; This file is part of XEmacs. | |
| 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 | 21 |
| 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 | 24 |
| 25 ;;; Synched up with: FSF 19.34 [But not very closely]. | |
| 3000 | 26 ;;; Occasional synching to FSF 21.2 and FSF 22.0, as marked. Comment stuff |
| 27 ;;; also synched, and in newcomment.el. | |
| 428 | 28 |
| 29 ;;; Commentary: | |
| 30 | |
| 31 ;; This file is dumped with XEmacs. | |
| 32 | |
| 33 ;; A grab-bag of basic XEmacs commands not specifically related to some | |
| 34 ;; major mode or to file-handling. | |
| 35 | |
| 36 ;; Changes for zmacs-style active-regions: | |
| 37 ;; | |
| 38 ;; beginning-of-buffer, end-of-buffer, count-lines-region, | |
| 39 ;; count-lines-buffer, what-line, what-cursor-position, set-goal-column, | |
| 40 ;; set-fill-column, prefix-arg-internal, and line-move (which is used by | |
| 41 ;; next-line and previous-line) set zmacs-region-stays to t, so that they | |
| 42 ;; don't affect the current region-hilighting state. | |
| 43 ;; | |
| 44 ;; mark-whole-buffer, mark-word, exchange-point-and-mark, and | |
| 45 ;; set-mark-command (without an argument) call zmacs-activate-region. | |
| 46 ;; | |
| 47 ;; mark takes an optional arg like the new Fmark_marker() does. When | |
| 48 ;; the region is not active, mark returns nil unless the optional arg is true. | |
| 49 ;; | |
| 50 ;; push-mark, pop-mark, exchange-point-and-mark, and set-marker, and | |
| 51 ;; set-mark-command use (mark t) so that they can access the mark whether | |
| 52 ;; the region is active or not. | |
| 53 ;; | |
| 54 ;; shell-command, shell-command-on-region, yank, and yank-pop (which all | |
| 55 ;; push a mark) have been altered to call exchange-point-and-mark with an | |
| 56 ;; argument, meaning "don't activate the region". These commands only use | |
| 57 ;; exchange-point-and-mark to position the newly-pushed mark correctly, so | |
| 58 ;; this isn't a user-visible change. These functions have also been altered | |
| 59 ;; to use (mark t) for the same reason. | |
| 60 | |
| 502 | 61 ;; 97/3/14 Jareth Hein (jhod@po.iijnet.or.jp) added kinsoku processing |
| 62 ;; (support for filling of Asian text) into the fill code. This was | |
| 63 ;; ripped bleeding from Mule-2.3, and could probably use some feature | |
| 64 ;; additions (like additional wrap styles, etc) | |
| 428 | 65 |
| 66 ;; 97/06/11 Steve Baur (steve@xemacs.org) Convert use of | |
| 67 ;; (preceding|following)-char to char-(after|before). | |
| 68 | |
| 69 ;;; Code: | |
| 70 | |
| 71 (defgroup editing-basics nil | |
| 72 "Most basic editing variables." | |
| 73 :group 'editing) | |
| 74 | |
| 75 (defgroup killing nil | |
| 76 "Killing and yanking commands." | |
| 77 :group 'editing) | |
| 78 | |
| 79 (defgroup fill-comments nil | |
| 80 "Indenting and filling of comments." | |
| 81 :prefix "comment-" | |
| 82 :group 'fill) | |
| 83 | |
| 84 (defgroup paren-matching nil | |
| 85 "Highlight (un)matching of parens and expressions." | |
| 86 :prefix "paren-" | |
| 87 :group 'matching) | |
| 88 | |
| 89 (defgroup log-message nil | |
| 90 "Messages logging and display customizations." | |
| 91 :group 'minibuffer) | |
| 92 | |
| 93 (defgroup warnings nil | |
| 94 "Warnings customizations." | |
| 95 :group 'minibuffer) | |
| 96 | |
| 97 | |
| 98 (defcustom search-caps-disable-folding t | |
| 99 "*If non-nil, upper case chars disable case fold searching. | |
| 100 This does not apply to \"yanked\" strings." | |
| 101 :type 'boolean | |
| 102 :group 'editing-basics) | |
| 103 | |
| 104 ;; This is stolen (and slightly modified) from FSF emacs's | |
| 105 ;; `isearch-no-upper-case-p'. | |
| 106 (defun no-upper-case-p (string &optional regexp-flag) | |
| 107 "Return t if there are no upper case chars in STRING. | |
| 108 If REGEXP-FLAG is non-nil, disregard letters preceded by `\\' (but not `\\\\') | |
| 109 since they have special meaning in a regexp." | |
| 110 (let ((case-fold-search nil)) | |
| 444 | 111 (not (string-match (if regexp-flag |
| 428 | 112 "\\(^\\|\\\\\\\\\\|[^\\]\\)[A-Z]" |
| 113 "[A-Z]") | |
| 114 string)) | |
| 115 )) | |
| 116 | |
| 117 (defmacro with-search-caps-disable-folding (string regexp-flag &rest body) "\ | |
| 444 | 118 Eval BODY with `case-fold-search' let to nil if `search-caps-disable-folding' |
| 428 | 119 is non-nil, and if STRING (either a string or a regular expression according |
| 120 to REGEXP-FLAG) contains uppercase letters." | |
| 121 `(let ((case-fold-search | |
| 122 (if (and case-fold-search search-caps-disable-folding) | |
| 123 (no-upper-case-p ,string ,regexp-flag) | |
| 124 case-fold-search))) | |
| 125 ,@body)) | |
| 126 (put 'with-search-caps-disable-folding 'lisp-indent-function 2) | |
| 444 | 127 (put 'with-search-caps-disable-folding 'edebug-form-spec |
| 428 | 128 '(sexp sexp &rest form)) |
| 129 | |
| 444 | 130 (defmacro with-interactive-search-caps-disable-folding (string regexp-flag |
| 428 | 131 &rest body) |
| 132 "Same as `with-search-caps-disable-folding', but only in the case of a | |
| 133 function called interactively." | |
| 134 `(let ((case-fold-search | |
| 444 | 135 (if (and (interactive-p) |
| 428 | 136 case-fold-search search-caps-disable-folding) |
| 137 (no-upper-case-p ,string ,regexp-flag) | |
| 138 case-fold-search))) | |
| 139 ,@body)) | |
| 140 (put 'with-interactive-search-caps-disable-folding 'lisp-indent-function 2) | |
| 444 | 141 (put 'with-interactive-search-caps-disable-folding 'edebug-form-spec |
| 428 | 142 '(sexp sexp &rest form)) |
| 143 | |
| 444 | 144 (defun newline (&optional n) |
| 428 | 145 "Insert a newline, and move to left margin of the new line if it's blank. |
| 146 The newline is marked with the text-property `hard'. | |
| 444 | 147 With optional arg N, insert that many newlines. |
| 428 | 148 In Auto Fill mode, if no numeric arg, break the preceding line if it's long." |
| 149 (interactive "*P") | |
| 150 (barf-if-buffer-read-only nil (point)) | |
| 151 ;; Inserting a newline at the end of a line produces better redisplay in | |
| 152 ;; try_window_id than inserting at the beginning of a line, and the textual | |
| 153 ;; result is the same. So, if we're at beginning of line, pretend to be at | |
| 154 ;; the end of the previous line. | |
| 155 ;; #### Does this have any relevance in XEmacs? | |
| 156 (let ((flag (and (not (bobp)) | |
| 157 (bolp) | |
| 158 ;; Make sure the newline before point isn't intangible. | |
| 159 (not (get-char-property (1- (point)) 'intangible)) | |
| 160 ;; Make sure the newline before point isn't read-only. | |
| 161 (not (get-char-property (1- (point)) 'read-only)) | |
| 162 ;; Make sure the newline before point isn't invisible. | |
| 163 (not (get-char-property (1- (point)) 'invisible)) | |
| 164 ;; This should probably also test for the previous char | |
| 165 ;; being the *last* character too. | |
| 166 (not (get-char-property (1- (point)) 'end-open)) | |
| 167 ;; Make sure the newline before point has the same | |
| 168 ;; properties as the char before it (if any). | |
| 169 (< (or (previous-extent-change (point)) -2) | |
| 170 (- (point) 2)))) | |
| 171 (was-page-start (and (bolp) | |
| 172 (looking-at page-delimiter))) | |
| 173 (beforepos (point))) | |
| 174 (if flag (backward-char 1)) | |
| 175 ;; Call self-insert so that auto-fill, abbrev expansion etc. happens. | |
| 176 ;; Set last-command-char to tell self-insert what to insert. | |
| 177 (let ((last-command-char ?\n) | |
| 178 ;; Don't auto-fill if we have a numeric argument. | |
| 179 ;; Also not if flag is true (it would fill wrong line); | |
| 180 ;; there is no need to since we're at BOL. | |
| 444 | 181 (auto-fill-function (if (or n flag) nil auto-fill-function))) |
| 428 | 182 (unwind-protect |
| 444 | 183 (self-insert-command (prefix-numeric-value n)) |
| 428 | 184 ;; If we get an error in self-insert-command, put point at right place. |
| 185 (if flag (forward-char 1)))) | |
| 186 ;; If we did *not* get an error, cancel that forward-char. | |
| 187 (if flag (backward-char 1)) | |
| 188 ;; Mark the newline(s) `hard'. | |
| 189 (if use-hard-newlines | |
| 444 | 190 (let* ((from (- (point) (if n (prefix-numeric-value n) 1))) |
| 428 | 191 (sticky (get-text-property from 'end-open))) ; XEmacs |
| 192 (put-text-property from (point) 'hard 't) | |
| 193 ;; If end-open is not "t", add 'hard to end-open list | |
| 194 (if (and (listp sticky) (not (memq 'hard sticky))) | |
| 195 (put-text-property from (point) 'end-open ; XEmacs | |
| 196 (cons 'hard sticky))))) | |
| 197 ;; If the newline leaves the previous line blank, | |
| 198 ;; and we have a left margin, delete that from the blank line. | |
| 199 (or flag | |
| 200 (save-excursion | |
| 201 (goto-char beforepos) | |
| 202 (beginning-of-line) | |
| 203 (and (looking-at "[ \t]$") | |
| 204 (> (current-left-margin) 0) | |
| 205 (delete-region (point) (progn (end-of-line) (point)))))) | |
| 206 (if flag (forward-char 1)) | |
| 207 ;; Indent the line after the newline, except in one case: | |
| 208 ;; when we added the newline at the beginning of a line | |
| 209 ;; which starts a page. | |
| 210 (or was-page-start | |
| 211 (move-to-left-margin nil t))) | |
| 212 nil) | |
| 213 | |
| 214 (defun set-hard-newline-properties (from to) | |
| 215 (let ((sticky (get-text-property from 'rear-nonsticky))) | |
| 216 (put-text-property from to 'hard 't) | |
| 217 ;; If rear-nonsticky is not "t", add 'hard to rear-nonsticky list | |
| 218 (if (and (listp sticky) (not (memq 'hard sticky))) | |
| 219 (put-text-property from (point) 'rear-nonsticky | |
| 220 (cons 'hard sticky))))) | |
| 221 | |
| 444 | 222 (defun open-line (n) |
| 428 | 223 "Insert a newline and leave point before it. |
| 224 If there is a fill prefix and/or a left-margin, insert them on the new line | |
| 225 if the line would have been blank. | |
| 226 With arg N, insert N newlines." | |
| 227 (interactive "*p") | |
| 228 (let* ((do-fill-prefix (and fill-prefix (bolp))) | |
| 229 (do-left-margin (and (bolp) (> (current-left-margin) 0))) | |
| 230 (loc (point))) | |
| 444 | 231 (newline n) |
| 428 | 232 (goto-char loc) |
| 444 | 233 (while (> n 0) |
| 428 | 234 (cond ((bolp) |
| 235 (if do-left-margin (indent-to (current-left-margin))) | |
| 236 (if do-fill-prefix (insert fill-prefix)))) | |
| 237 (forward-line 1) | |
| 444 | 238 (setq n (1- n))) |
| 428 | 239 (goto-char loc) |
| 240 (end-of-line))) | |
| 241 | |
| 242 (defun split-line () | |
| 243 "Split current line, moving portion beyond point vertically down." | |
| 244 (interactive "*") | |
| 245 (skip-chars-forward " \t") | |
| 246 (let ((col (current-column)) | |
| 247 (pos (point))) | |
| 248 (newline 1) | |
| 249 (indent-to col 0) | |
| 250 (goto-char pos))) | |
| 251 | |
| 252 (defun quoted-insert (arg) | |
| 253 "Read next input character and insert it. | |
| 254 This is useful for inserting control characters. | |
| 255 You may also type up to 3 octal digits, to insert a character with that code. | |
| 256 | |
| 257 In overwrite mode, this function inserts the character anyway, and | |
| 258 does not handle octal digits specially. This means that if you use | |
| 259 overwrite as your normal editing mode, you can use this function to | |
| 260 insert characters when necessary. | |
| 261 | |
| 262 In binary overwrite mode, this function does overwrite, and octal | |
| 263 digits are interpreted as a character code. This is supposed to make | |
| 264 this function useful in editing binary files." | |
| 265 (interactive "*p") | |
| 266 (let ((char (if (or (not overwrite-mode) | |
| 267 (eq overwrite-mode 'overwrite-mode-binary)) | |
| 268 (read-quoted-char) | |
| 269 ;; read-char obeys C-g, so we should protect. FSF | |
| 270 ;; doesn't have the protection here, but it's a bug in | |
| 271 ;; FSF. | |
| 272 (let ((inhibit-quit t)) | |
| 273 (read-char))))) | |
| 274 (if (> arg 0) | |
| 275 (if (eq overwrite-mode 'overwrite-mode-binary) | |
| 276 (delete-char arg))) | |
| 277 (while (> arg 0) | |
| 278 (insert char) | |
| 279 (setq arg (1- arg))))) | |
| 280 | |
| 281 (defun delete-indentation (&optional arg) | |
| 282 "Join this line to previous and fix up whitespace at join. | |
| 283 If there is a fill prefix, delete it from the beginning of this line. | |
| 284 With argument, join this line to following line." | |
| 285 (interactive "*P") | |
| 286 (beginning-of-line) | |
| 287 (if arg (forward-line 1)) | |
| 288 (if (eq (char-before (point)) ?\n) | |
| 289 (progn | |
| 290 (delete-region (point) (1- (point))) | |
| 291 ;; If the second line started with the fill prefix, | |
| 292 ;; delete the prefix. | |
| 293 (if (and fill-prefix | |
| 294 (<= (+ (point) (length fill-prefix)) (point-max)) | |
| 295 (string= fill-prefix | |
| 296 (buffer-substring (point) | |
| 297 (+ (point) (length fill-prefix))))) | |
| 298 (delete-region (point) (+ (point) (length fill-prefix)))) | |
| 299 (fixup-whitespace)))) | |
| 300 | |
| 958 | 301 (defalias 'join-line 'delete-indentation) |
| 302 | |
| 428 | 303 (defun fixup-whitespace () |
| 304 "Fixup white space between objects around point. | |
| 305 Leave one space or none, according to the context." | |
| 306 (interactive "*") | |
| 307 (save-excursion | |
| 308 (delete-horizontal-space) | |
| 309 (if (or (looking-at "^\\|\\s)") | |
| 446 | 310 (save-excursion (backward-char 1) |
| 428 | 311 (looking-at "$\\|\\s(\\|\\s'"))) |
| 312 nil | |
| 313 (insert ?\ )))) | |
| 314 | |
| 315 (defun delete-horizontal-space () | |
| 316 "Delete all spaces and tabs around point." | |
| 317 (interactive "*") | |
| 318 (skip-chars-backward " \t") | |
| 319 (delete-region (point) (progn (skip-chars-forward " \t") (point)))) | |
| 320 | |
| 321 (defun just-one-space () | |
| 322 "Delete all spaces and tabs around point, leaving one space." | |
| 323 (interactive "*") | |
| 324 (if abbrev-mode ; XEmacs | |
| 325 (expand-abbrev)) | |
| 326 (skip-chars-backward " \t") | |
| 327 (if (eq (char-after (point)) ? ) ; XEmacs | |
| 328 (forward-char 1) | |
| 329 (insert ? )) | |
| 330 (delete-region (point) (progn (skip-chars-forward " \t") (point)))) | |
| 331 | |
| 332 (defun delete-blank-lines () | |
| 333 "On blank line, delete all surrounding blank lines, leaving just one. | |
| 334 On isolated blank line, delete that one. | |
| 335 On nonblank line, delete any immediately following blank lines." | |
| 336 (interactive "*") | |
| 337 (let (thisblank singleblank) | |
| 338 (save-excursion | |
| 339 (beginning-of-line) | |
| 340 (setq thisblank (looking-at "[ \t]*$")) | |
| 341 ;; Set singleblank if there is just one blank line here. | |
| 342 (setq singleblank | |
| 343 (and thisblank | |
| 344 (not (looking-at "[ \t]*\n[ \t]*$")) | |
| 345 (or (bobp) | |
| 346 (progn (forward-line -1) | |
| 347 (not (looking-at "[ \t]*$"))))))) | |
| 348 ;; Delete preceding blank lines, and this one too if it's the only one. | |
| 349 (if thisblank | |
| 350 (progn | |
| 351 (beginning-of-line) | |
| 352 (if singleblank (forward-line 1)) | |
| 353 (delete-region (point) | |
| 354 (if (re-search-backward "[^ \t\n]" nil t) | |
| 355 (progn (forward-line 1) (point)) | |
| 356 (point-min))))) | |
| 357 ;; Delete following blank lines, unless the current line is blank | |
| 358 ;; and there are no following blank lines. | |
| 359 (if (not (and thisblank singleblank)) | |
| 360 (save-excursion | |
| 361 (end-of-line) | |
| 362 (forward-line 1) | |
| 363 (delete-region (point) | |
| 364 (if (re-search-forward "[^ \t\n]" nil t) | |
| 365 (progn (beginning-of-line) (point)) | |
| 366 (point-max))))) | |
| 367 ;; Handle the special case where point is followed by newline and eob. | |
| 368 ;; Delete the line, leaving point at eob. | |
| 369 (if (looking-at "^[ \t]*\n\\'") | |
| 370 (delete-region (point) (point-max))))) | |
| 371 | |
| 372 (defun back-to-indentation () | |
| 373 "Move point to the first non-whitespace character on this line." | |
| 374 ;; XEmacs change | |
| 375 (interactive "_") | |
| 376 (beginning-of-line 1) | |
| 377 (skip-chars-forward " \t")) | |
| 378 | |
| 379 (defun newline-and-indent () | |
| 380 "Insert a newline, then indent according to major mode. | |
| 381 Indentation is done using the value of `indent-line-function'. | |
| 382 In programming language modes, this is the same as TAB. | |
| 383 In some text modes, where TAB inserts a tab, this command indents to the | |
| 384 column specified by the function `current-left-margin'." | |
| 385 (interactive "*") | |
| 386 (delete-region (point) (progn (skip-chars-backward " \t") (point))) | |
| 387 (newline) | |
| 388 (indent-according-to-mode)) | |
| 389 | |
| 390 (defun reindent-then-newline-and-indent () | |
| 391 "Reindent current line, insert newline, then indent the new line. | |
| 392 Indentation of both lines is done according to the current major mode, | |
| 393 which means calling the current value of `indent-line-function'. | |
| 394 In programming language modes, this is the same as TAB. | |
| 395 In some text modes, where TAB inserts a tab, this indents to the | |
| 396 column specified by the function `current-left-margin'." | |
| 397 (interactive "*") | |
| 398 (save-excursion | |
| 399 (delete-region (point) (progn (skip-chars-backward " \t") (point))) | |
| 400 (indent-according-to-mode)) | |
| 401 (newline) | |
| 402 (indent-according-to-mode)) | |
| 403 | |
| 404 ;; Internal subroutine of delete-char | |
| 405 (defun kill-forward-chars (arg) | |
| 406 (if (listp arg) (setq arg (car arg))) | |
| 407 (if (eq arg '-) (setq arg -1)) | |
| 408 (kill-region (point) (+ (point) arg))) | |
| 409 | |
| 410 ;; Internal subroutine of backward-delete-char | |
| 411 (defun kill-backward-chars (arg) | |
| 412 (if (listp arg) (setq arg (car arg))) | |
| 413 (if (eq arg '-) (setq arg -1)) | |
| 414 (kill-region (point) (- (point) arg))) | |
| 415 | |
| 416 (defun backward-delete-char-untabify (arg &optional killp) | |
| 417 "Delete characters backward, changing tabs into spaces. | |
| 418 Delete ARG chars, and kill (save in kill ring) if KILLP is non-nil. | |
| 419 Interactively, ARG is the prefix arg (default 1) | |
| 420 and KILLP is t if a prefix arg was specified." | |
| 421 (interactive "*p\nP") | |
| 422 (let ((count arg)) | |
| 423 (save-excursion | |
| 424 (while (and (> count 0) (not (bobp))) | |
| 425 (if (eq (char-before (point)) ?\t) ; XEmacs | |
| 426 (let ((col (current-column))) | |
| 446 | 427 (backward-char 1) |
| 428 | 428 (setq col (- col (current-column))) |
| 429 (insert-char ?\ col) | |
| 430 (delete-char 1))) | |
| 446 | 431 (backward-char 1) |
| 428 | 432 (setq count (1- count))))) |
| 433 (delete-backward-char arg killp) | |
| 434 ;; XEmacs: In overwrite mode, back over columns while clearing them out, | |
| 435 ;; unless at end of line. | |
| 436 (and overwrite-mode (not (eolp)) | |
| 437 (save-excursion (insert-char ?\ arg)))) | |
| 438 | |
| 439 (defcustom delete-key-deletes-forward t | |
| 440 "*If non-nil, the DEL key will erase one character forwards. | |
| 441 If nil, the DEL key will erase one character backwards." | |
| 442 :type 'boolean | |
| 443 :group 'editing-basics) | |
| 444 | |
| 446 | 445 (defcustom backward-delete-function 'delete-backward-char |
| 428 | 446 "*Function called to delete backwards on a delete keypress. |
| 447 If `delete-key-deletes-forward' is nil, `backward-or-forward-delete-char' | |
| 448 calls this function to erase one character backwards. Default value | |
| 446 | 449 is `delete-backward-char', with `backward-delete-char-untabify' being a |
| 428 | 450 popular alternate setting." |
| 451 :type 'function | |
| 452 :group 'editing-basics) | |
| 453 | |
| 454 ;; Trash me, baby. | |
| 455 (defsubst delete-forward-p () | |
| 456 (and delete-key-deletes-forward | |
| 457 (or (not (eq (device-type) 'x)) | |
| 502 | 458 (declare-fboundp |
| 459 (x-keysym-on-keyboard-sans-modifiers-p 'backspace))))) | |
| 428 | 460 |
| 461 (defun backward-or-forward-delete-char (arg) | |
| 462 "Delete either one character backwards or one character forwards. | |
| 463 Controlled by the state of `delete-key-deletes-forward' and whether the | |
| 464 BackSpace keysym even exists on your keyboard. If you don't have a | |
| 465 BackSpace keysym, the delete key should always delete one character | |
| 466 backwards." | |
| 467 (interactive "*p") | |
| 468 (if (delete-forward-p) | |
| 469 (delete-char arg) | |
| 470 (funcall backward-delete-function arg))) | |
| 471 | |
| 472 (defun backward-or-forward-kill-word (arg) | |
| 473 "Delete either one word backwards or one word forwards. | |
| 474 Controlled by the state of `delete-key-deletes-forward' and whether the | |
| 475 BackSpace keysym even exists on your keyboard. If you don't have a | |
| 476 BackSpace keysym, the delete key should always delete one character | |
| 477 backwards." | |
| 478 (interactive "*p") | |
| 479 (if (delete-forward-p) | |
| 480 (kill-word arg) | |
| 481 (backward-kill-word arg))) | |
| 482 | |
| 483 (defun backward-or-forward-kill-sentence (arg) | |
| 484 "Delete either one sentence backwards or one sentence forwards. | |
| 485 Controlled by the state of `delete-key-deletes-forward' and whether the | |
| 486 BackSpace keysym even exists on your keyboard. If you don't have a | |
| 487 BackSpace keysym, the delete key should always delete one character | |
| 488 backwards." | |
| 489 (interactive "*P") | |
| 490 (if (delete-forward-p) | |
| 491 (kill-sentence arg) | |
| 492 (backward-kill-sentence (prefix-numeric-value arg)))) | |
| 493 | |
| 494 (defun backward-or-forward-kill-sexp (arg) | |
| 495 "Delete either one sexpr backwards or one sexpr forwards. | |
| 496 Controlled by the state of `delete-key-deletes-forward' and whether the | |
| 497 BackSpace keysym even exists on your keyboard. If you don't have a | |
| 498 BackSpace keysym, the delete key should always delete one character | |
| 499 backwards." | |
| 500 (interactive "*p") | |
| 501 (if (delete-forward-p) | |
| 502 (kill-sexp arg) | |
| 503 (backward-kill-sexp arg))) | |
| 504 | |
| 505 (defun zap-to-char (arg char) | |
| 506 "Kill up to and including ARG'th occurrence of CHAR. | |
| 507 Goes backward if ARG is negative; error if CHAR not found." | |
| 508 (interactive "*p\ncZap to char: ") | |
| 509 (kill-region (point) (with-interactive-search-caps-disable-folding | |
| 510 (char-to-string char) nil | |
| 511 (search-forward (char-to-string char) nil nil arg) | |
| 512 (point)))) | |
| 513 | |
| 514 (defun zap-up-to-char (arg char) | |
| 515 "Kill up to ARG'th occurrence of CHAR. | |
| 516 Goes backward if ARG is negative; error if CHAR not found." | |
| 517 (interactive "*p\ncZap up to char: ") | |
| 518 (kill-region (point) (with-interactive-search-caps-disable-folding | |
| 519 (char-to-string char) nil | |
| 520 (search-forward (char-to-string char) nil nil arg) | |
| 521 (goto-char (if (> arg 0) (1- (point)) (1+ (point)))) | |
| 522 (point)))) | |
| 523 | |
| 524 (defun beginning-of-buffer (&optional arg) | |
| 525 "Move point to the beginning of the buffer; leave mark at previous position. | |
| 526 With arg N, put point N/10 of the way from the beginning. | |
| 527 | |
| 528 If the buffer is narrowed, this command uses the beginning and size | |
| 529 of the accessible part of the buffer. | |
| 530 | |
| 462 | 531 The characters that are moved over may be added to the current selection |
| 532 \(i.e. active region) if the Shift key is held down, a motion key is used | |
| 533 to invoke this command, and `shifted-motion-keys-select-region' is t; see | |
| 534 the documentation for this variable for more details. | |
| 535 | |
| 428 | 536 Don't use this command in Lisp programs! |
| 537 \(goto-char (point-min)) is faster and avoids clobbering the mark." | |
| 538 ;; XEmacs change | |
| 539 (interactive "_P") | |
| 540 (push-mark) | |
| 541 (let ((size (- (point-max) (point-min)))) | |
| 542 (goto-char (if arg | |
| 543 (+ (point-min) | |
| 544 (if (> size 10000) | |
| 545 ;; Avoid overflow for large buffer sizes! | |
| 546 (* (prefix-numeric-value arg) | |
| 547 (/ size 10)) | |
| 548 (/ (+ 10 (* size (prefix-numeric-value arg))) 10))) | |
| 549 (point-min)))) | |
| 550 (if arg (forward-line 1))) | |
| 551 | |
| 552 (defun end-of-buffer (&optional arg) | |
| 553 "Move point to the end of the buffer; leave mark at previous position. | |
| 554 With arg N, put point N/10 of the way from the end. | |
| 555 | |
| 556 If the buffer is narrowed, this command uses the beginning and size | |
| 557 of the accessible part of the buffer. | |
| 558 | |
| 462 | 559 The characters that are moved over may be added to the current selection |
| 560 \(i.e. active region) if the Shift key is held down, a motion key is used | |
| 561 to invoke this command, and `shifted-motion-keys-select-region' is t; see | |
| 562 the documentation for this variable for more details. | |
| 563 | |
| 428 | 564 Don't use this command in Lisp programs! |
| 565 \(goto-char (point-max)) is faster and avoids clobbering the mark." | |
| 566 ;; XEmacs change | |
| 567 (interactive "_P") | |
| 568 (push-mark) | |
| 569 ;; XEmacs changes here. | |
| 570 (let ((scroll-to-end (not (pos-visible-in-window-p (point-max)))) | |
| 571 (size (- (point-max) (point-min)))) | |
| 572 (goto-char (if arg | |
| 573 (- (point-max) | |
| 574 (if (> size 10000) | |
| 575 ;; Avoid overflow for large buffer sizes! | |
| 576 (* (prefix-numeric-value arg) | |
| 577 (/ size 10)) | |
| 578 (/ (* size (prefix-numeric-value arg)) 10))) | |
| 579 (point-max))) | |
| 580 (cond (arg | |
| 581 ;; If we went to a place in the middle of the buffer, | |
| 582 ;; adjust it to the beginning of a line. | |
| 583 (forward-line 1)) | |
| 584 ;; XEmacs change | |
| 585 (scroll-to-end | |
| 586 ;; If the end of the buffer is not already on the screen, | |
| 587 ;; then scroll specially to put it near, but not at, the bottom. | |
| 588 (recenter -3))))) | |
| 589 | |
| 590 ;; XEmacs (not in FSF) | |
| 591 (defun mark-beginning-of-buffer (&optional arg) | |
| 592 "Push a mark at the beginning of the buffer; leave point where it is. | |
| 593 With arg N, push mark N/10 of the way from the true beginning." | |
| 594 (interactive "P") | |
| 595 (push-mark (if arg | |
| 596 (if (> (buffer-size) 10000) | |
| 597 ;; Avoid overflow for large buffer sizes! | |
| 598 (* (prefix-numeric-value arg) | |
| 599 (/ (buffer-size) 10)) | |
| 600 (/ (+ 10 (* (buffer-size) (prefix-numeric-value arg))) 10)) | |
| 601 (point-min)) | |
| 602 nil | |
| 603 t)) | |
| 604 (define-function 'mark-bob 'mark-beginning-of-buffer) | |
| 605 | |
| 606 ;; XEmacs (not in FSF) | |
| 607 (defun mark-end-of-buffer (&optional arg) | |
| 608 "Push a mark at the end of the buffer; leave point where it is. | |
| 609 With arg N, push mark N/10 of the way from the true end." | |
| 610 (interactive "P") | |
| 611 (push-mark (if arg | |
| 612 (- (1+ (buffer-size)) | |
| 613 (if (> (buffer-size) 10000) | |
| 614 ;; Avoid overflow for large buffer sizes! | |
| 615 (* (prefix-numeric-value arg) | |
| 616 (/ (buffer-size) 10)) | |
| 617 (/ (* (buffer-size) (prefix-numeric-value arg)) 10))) | |
| 618 (point-max)) | |
| 619 nil | |
| 620 t)) | |
| 621 (define-function 'mark-eob 'mark-end-of-buffer) | |
| 622 | |
| 623 (defun mark-whole-buffer () | |
| 624 "Put point at beginning and mark at end of buffer. | |
| 625 You probably should not use this function in Lisp programs; | |
| 626 it is usually a mistake for a Lisp function to use any subroutine | |
| 627 that uses or sets the mark." | |
| 628 (interactive) | |
| 629 (push-mark (point)) | |
| 630 (push-mark (point-max) nil t) | |
| 631 (goto-char (point-min))) | |
| 632 | |
| 633 ;; XEmacs | |
| 634 (defun eval-current-buffer (&optional printflag) | |
| 635 "Evaluate the current buffer as Lisp code. | |
| 636 Programs can pass argument PRINTFLAG which controls printing of output: | |
| 637 nil means discard it; anything else is stream for print." | |
| 638 (interactive) | |
| 639 (eval-buffer (current-buffer) printflag)) | |
| 640 | |
| 641 ;; XEmacs | |
| 642 (defun count-words-buffer (&optional buffer) | |
| 643 "Print the number of words in BUFFER. | |
| 644 If called noninteractively, the value is returned rather than printed. | |
| 645 BUFFER defaults to the current buffer." | |
| 646 (interactive) | |
| 647 (let ((words (count-words-region (point-min) (point-max) buffer))) | |
| 648 (when (interactive-p) | |
| 649 (message "Buffer has %d words" words)) | |
| 650 words)) | |
| 651 | |
| 652 ;; XEmacs | |
| 653 (defun count-words-region (start end &optional buffer) | |
| 654 "Print the number of words in region between START and END in BUFFER. | |
| 655 If called noninteractively, the value is returned rather than printed. | |
| 656 BUFFER defaults to the current buffer." | |
| 657 (interactive "_r") | |
| 658 (save-excursion | |
| 659 (set-buffer (or buffer (current-buffer))) | |
| 660 (let ((words 0)) | |
| 661 (goto-char start) | |
| 662 (while (< (point) end) | |
| 663 (when (forward-word 1) | |
| 664 (incf words))) | |
| 665 (when (interactive-p) | |
| 666 (message "Region has %d words" words)) | |
| 667 words))) | |
| 668 | |
| 669 (defun count-lines-region (start end) | |
| 670 "Print number of lines and characters in the region." | |
| 671 ;; XEmacs change | |
| 672 (interactive "_r") | |
| 673 (message "Region has %d lines, %d characters" | |
| 674 (count-lines start end) (- end start))) | |
| 675 | |
| 676 ;; XEmacs | |
| 677 (defun count-lines-buffer (&optional buffer) | |
| 678 "Print number of lines and characters in BUFFER." | |
| 679 (interactive) | |
| 680 (with-current-buffer (or buffer (current-buffer)) | |
| 681 (let ((cnt (count-lines (point-min) (point-max)))) | |
| 682 (message "Buffer has %d lines, %d characters" | |
| 683 cnt (- (point-max) (point-min))) | |
| 684 cnt))) | |
| 685 | |
| 686 ;;; Modified by Bob Weiner, 8/24/95, to print narrowed line number also. | |
| 687 ;;; Expanded by Bob Weiner, BeOpen, on 02/12/1997 | |
| 688 (defun what-line () | |
| 689 "Print the following variants of the line number of point: | |
| 690 Region line - displayed line within the active region | |
| 691 Collapsed line - includes only selectively displayed lines; | |
| 692 Buffer line - physical line in the buffer; | |
| 693 Narrowed line - line number from the start of the buffer narrowing." | |
| 694 ;; XEmacs change | |
| 695 (interactive "_") | |
| 696 (let ((opoint (point)) start) | |
| 697 (save-excursion | |
| 698 (save-restriction | |
| 699 (if (region-active-p) | |
| 700 (goto-char (region-beginning)) | |
| 701 (goto-char (point-min))) | |
| 702 (widen) | |
| 703 (beginning-of-line) | |
| 704 (setq start (point)) | |
| 705 (goto-char opoint) | |
| 706 (beginning-of-line) | |
| 707 (let* ((buffer-line (1+ (count-lines 1 (point)))) | |
| 708 (narrowed-p (or (/= start 1) | |
| 709 (/= (point-max) (1+ (buffer-size))))) | |
| 710 (narrowed-line (if narrowed-p (1+ (count-lines start (point))))) | |
| 711 (selective-line (if selective-display | |
| 712 (1+ (count-lines start (point) t)))) | |
| 713 (region-line (if (region-active-p) | |
| 714 (1+ (count-lines start (point) selective-display))))) | |
| 715 (cond (region-line | |
| 716 (message "Region line %d; Buffer line %d" | |
| 717 region-line buffer-line)) | |
| 718 ((and narrowed-p selective-line (/= selective-line narrowed-line)) | |
| 719 ;; buffer narrowed and some lines selectively displayed | |
| 720 (message "Collapsed line %d; Buffer line %d; Narrowed line %d" | |
| 721 selective-line buffer-line narrowed-line)) | |
| 722 (narrowed-p | |
| 723 ;; buffer narrowed | |
| 724 (message "Buffer line %d; Narrowed line %d" | |
| 725 buffer-line narrowed-line)) | |
| 726 ((and selective-line (/= selective-line buffer-line)) | |
| 727 ;; some lines selectively displayed | |
| 728 (message "Collapsed line %d; Buffer line %d" | |
| 729 selective-line buffer-line)) | |
| 730 (t | |
| 731 ;; give a basic line count | |
| 732 (message "Line %d" buffer-line))))))) | |
| 733 (setq zmacs-region-stays t)) | |
| 734 | |
| 442 | 735 ;; new in XEmacs 21.2 (not in FSF). |
| 736 (defun line-number (&optional pos respect-narrowing) | |
| 737 "Return the line number of POS (defaults to point). | |
| 738 If RESPECT-NARROWING is non-nil, then the narrowed line number is returned; | |
| 739 otherwise, the absolute line number is returned. The returned line can always | |
| 740 be given to `goto-line' to get back to the current line." | |
| 741 (if (and pos (/= pos (point))) | |
| 742 (save-excursion | |
| 743 (goto-char pos) | |
| 744 (line-number nil respect-narrowing)) | |
| 745 (1+ (count-lines (if respect-narrowing (point-min) 1) (point-at-bol))))) | |
| 746 | |
| 3000 | 747 ;; FSF 22.0.50.1 (CVS) version of above. |
| 748 (defun line-number-at-pos (&optional pos) | |
| 749 (line-number pos t)) | |
| 750 | |
| 428 | 751 (defun count-lines (start end &optional ignore-invisible-lines-flag) |
| 752 "Return number of lines between START and END. | |
| 753 This is usually the number of newlines between them, | |
| 754 but can be one more if START is not equal to END | |
| 755 and the greater of them is not at the start of a line. | |
| 756 | |
| 757 With optional IGNORE-INVISIBLE-LINES-FLAG non-nil, lines collapsed with | |
| 442 | 758 selective-display are excluded from the line count. |
| 759 | |
| 760 NOTE: The expression to return the current line number is not obvious: | |
| 761 | |
| 3767 | 762 \(1+ \(count-lines 1 \(point-at-bol))) |
| 442 | 763 |
| 764 See also `line-number'." | |
| 428 | 765 (save-excursion |
| 766 (save-restriction | |
| 767 (narrow-to-region start end) | |
| 768 (goto-char (point-min)) | |
| 769 (if (and (not ignore-invisible-lines-flag) (eq selective-display t)) | |
| 770 (save-match-data | |
| 771 (let ((done 0)) | |
| 772 (while (re-search-forward "[\n\C-m]" nil t 40) | |
| 773 (setq done (+ 40 done))) | |
| 774 (while (re-search-forward "[\n\C-m]" nil t 1) | |
| 775 (setq done (+ 1 done))) | |
| 776 (goto-char (point-max)) | |
| 777 (if (and (/= start end) | |
| 778 (not (bolp))) | |
| 779 (1+ done) | |
| 780 done))) | |
| 781 (- (buffer-size) (forward-line (buffer-size))))))) | |
| 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 | 784 "Print info on cursor position (on screen and within buffer). |
| 785 Also describe the character after point, giving its UCS code point and Mule | |
| 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 | 793 (let* ((char (char-after (point))) ; XEmacs |
| 794 (beg (point-min)) | |
| 795 (end (point-max)) | |
| 796 (pos (point)) | |
| 797 (total (buffer-size)) | |
| 798 (percent (if (> total 50000) | |
| 799 ;; Avoid overflow from multiplying by 100! | |
| 800 (/ (+ (/ total 200) (1- pos)) (max (/ total 100) 1)) | |
| 801 (/ (+ (/ total 2) (* 100 (1- pos))) (max total 1)))) | |
| 802 (hscroll (if (= (window-hscroll) 0) | |
| 803 "" | |
| 804 (format " Hscroll=%d" (window-hscroll)))) | |
| 3724 | 805 (col (+ (current-column) (if column-number-start-at-one 1 0))) |
| 806 (unicode (and char (encode-char char 'ucs))) | |
| 807 (unicode-string (and unicode (natnump unicode) | |
| 808 (format (if (> unicode #xFFFF) "U+%06X" "U+%04X") | |
| 809 unicode))) | |
| 810 (narrowed-details (if (or (/= beg 1) (/= end (1+ total))) | |
| 811 (format " <%d - %d>" beg end) | |
| 812 ""))) | |
| 813 | |
| 428 | 814 (if (= pos end) |
| 3724 | 815 (message "point=%d of %d(%d%%)%s column %d %s" |
| 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 | 819 ;; XEmacs: don't use single-key-description, treat non-ASCII |
| 820 ;; characters differently. | |
| 821 (if (< char ?\x80) | |
| 822 (message "Char: %s (0%o, %d, %x) point=%d of %d(%d%%)%s column %d %s" | |
| 823 (text-char-description char) char char char pos total | |
| 824 percent narrowed-details col hscroll) | |
| 825 (message "Char: %s (%s %s) point=%d of %d(%d%%)%s column %d %s" | |
| 826 (text-char-description char) unicode-string | |
| 3767 | 827 (mapconcat (lambda (arg) (format "%S" arg)) |
| 828 (split-char char) " ") | |
| 3724 | 829 pos total |
| 830 percent narrowed-details col hscroll))))) | |
| 428 | 831 |
| 832 (defun fundamental-mode () | |
| 833 "Major mode not specialized for anything in particular. | |
| 834 Other major modes are defined by comparison with this one." | |
| 835 (interactive) | |
| 836 (kill-all-local-variables)) | |
| 837 | |
| 838 ;; XEmacs the following are declared elsewhere | |
| 839 ;(defvar read-expression-map (cons 'keymap minibuffer-local-map) | |
| 840 ; "Minibuffer keymap used for reading Lisp expressions.") | |
| 841 ;(define-key read-expression-map "\M-\t" 'lisp-complete-symbol) | |
| 842 | |
| 843 ;(put 'eval-expression 'disabled t) | |
| 844 | |
| 845 ;(defvar read-expression-history nil) | |
| 846 | |
| 847 ;; We define this, rather than making `eval' interactive, | |
| 848 ;; for the sake of completion of names like eval-region, eval-current-buffer. | |
| 849 (defun eval-expression (expression &optional eval-expression-insert-value) | |
| 850 "Evaluate EXPRESSION and print value in minibuffer. | |
| 851 Value is also consed on to front of the variable `values'. | |
| 852 With prefix argument, insert the result to the current buffer." | |
| 853 ;(interactive "xEval: ") | |
| 854 (interactive | |
| 855 (list (read-from-minibuffer "Eval: " | |
| 856 nil read-expression-map t | |
| 857 'read-expression-history) | |
| 858 current-prefix-arg)) | |
| 859 (setq values (cons (eval expression) values)) | |
| 860 (prin1 (car values) | |
| 861 (if eval-expression-insert-value (current-buffer) t))) | |
| 862 | |
| 863 ;; XEmacs -- extra parameter (variant, but equivalent logic) | |
| 444 | 864 (defun edit-and-eval-command (prompt form &optional history) |
| 865 "Prompting with PROMPT, let user edit FORM and eval result. | |
| 866 FORM is a Lisp expression. Let user edit that expression in | |
| 428 | 867 the minibuffer, then read and evaluate the result." |
| 444 | 868 (let ((form (read-expression prompt |
| 869 ;; first try to format the thing readably; | |
| 870 ;; and if that fails, print it normally. | |
| 871 (condition-case () | |
| 872 (let ((print-readably t)) | |
| 873 (prin1-to-string form)) | |
| 874 (error (prin1-to-string form))) | |
| 875 (or history '(command-history . 1))))) | |
| 428 | 876 (or history (setq history 'command-history)) |
| 877 (if (consp history) | |
| 878 (setq history (car history))) | |
| 879 (if (eq history t) | |
| 880 nil | |
| 444 | 881 ;; If form was added to the history as a string, |
| 428 | 882 ;; get rid of that. We want only evallable expressions there. |
| 883 (if (stringp (car (symbol-value history))) | |
| 884 (set history (cdr (symbol-value history)))) | |
| 885 | |
| 444 | 886 ;; If form to be redone does not match front of history, |
| 428 | 887 ;; add it to the history. |
| 444 | 888 (or (equal form (car (symbol-value history))) |
| 889 (set history (cons form (symbol-value history))))) | |
| 890 (eval form))) | |
| 428 | 891 |
| 892 (defun repeat-complex-command (arg) | |
| 893 "Edit and re-evaluate last complex command, or ARGth from last. | |
| 894 A complex command is one which used the minibuffer. | |
| 895 The command is placed in the minibuffer as a Lisp form for editing. | |
| 896 The result is executed, repeating the command as changed. | |
| 897 If the command has been changed or is not the most recent previous command | |
| 898 it is added to the front of the command history. | |
| 899 You can use the minibuffer history commands \\<minibuffer-local-map>\\[next-history-element] and \\[previous-history-element] | |
| 900 to get different commands to edit and resubmit." | |
| 901 (interactive "p") | |
| 902 ;; XEmacs: It looks like our version is better -sb | |
| 903 (let ((print-level nil)) | |
| 904 (edit-and-eval-command "Redo: " | |
| 905 (or (nth (1- arg) command-history) | |
| 906 (error "")) | |
| 907 (cons 'command-history arg)))) | |
| 908 | |
| 909 ;; XEmacs: Functions moved to minibuf.el | |
| 910 ;; previous-matching-history-element | |
| 911 ;; next-matching-history-element | |
| 912 ;; next-history-element | |
| 913 ;; previous-history-element | |
| 914 ;; next-complete-history-element | |
| 915 ;; previous-complete-history-element | |
| 916 | |
| 3361 | 917 (defun goto-line (line &optional buffer) |
| 918 "Goto line LINE, counting from line 1 at beginning of BUFFER." | |
| 428 | 919 (interactive "NGoto line: ") |
| 444 | 920 (setq line (prefix-numeric-value line)) |
| 3361 | 921 (if buffer |
| 922 (let ((window (get-buffer-window buffer))) | |
| 923 (if window (select-window window) | |
| 924 (switch-to-buffer-other-window buffer)))) | |
| 428 | 925 (save-restriction |
| 926 (widen) | |
| 927 (goto-char 1) | |
| 928 (if (eq selective-display t) | |
| 444 | 929 (re-search-forward "[\n\C-m]" nil 'end (1- line)) |
| 930 (forward-line (1- line))))) | |
| 428 | 931 |
| 771 | 932 ;[Put this on C-x u, so we can force that rather than C-_ into startup msg] |
| 933 ;No more, stop pandering to TTY users. | |
| 428 | 934 (define-function 'advertised-undo 'undo) |
| 935 | |
| 444 | 936 (defun undo (&optional count) |
| 428 | 937 "Undo some previous changes. |
| 938 Repeat this command to undo more changes. | |
| 939 A numeric argument serves as a repeat count." | |
| 940 (interactive "*p") | |
| 941 ;; If we don't get all the way through, make last-command indicate that | |
| 942 ;; for the following command. | |
| 943 (setq this-command t) | |
| 944 (let ((modified (buffer-modified-p)) | |
| 945 (recent-save (recent-auto-save-p))) | |
| 946 (or (eq (selected-window) (minibuffer-window)) | |
| 947 (display-message 'command "Undo!")) | |
| 948 (or (and (eq last-command 'undo) | |
| 949 (eq (current-buffer) last-undo-buffer)) ; XEmacs | |
| 950 (progn (undo-start) | |
| 951 (undo-more 1))) | |
| 444 | 952 (undo-more (or count 1)) |
| 428 | 953 ;; Don't specify a position in the undo record for the undo command. |
| 954 ;; Instead, undoing this should move point to where the change is. | |
| 955 (let ((tail buffer-undo-list) | |
| 956 done) | |
| 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 | 959 (progn |
| 960 (setq done t) | |
| 961 (setq buffer-undo-list (delq (car tail) buffer-undo-list)))) | |
| 962 (setq tail (cdr tail)))) | |
| 963 (and modified (not (buffer-modified-p)) | |
| 964 (delete-auto-save-file-if-necessary recent-save))) | |
| 965 ;; If we do get all the way through, make this-command indicate that. | |
| 966 (setq this-command 'undo)) | |
| 967 | |
| 968 (defvar pending-undo-list nil | |
| 969 "Within a run of consecutive undo commands, list remaining to be undone.") | |
| 970 | |
| 971 (defvar last-undo-buffer nil) ; XEmacs | |
| 972 | |
| 973 (defun undo-start () | |
| 974 "Set `pending-undo-list' to the front of the undo list. | |
| 975 The next call to `undo-more' will undo the most recently made change." | |
| 976 (if (eq buffer-undo-list t) | |
| 977 (error "No undo information in this buffer")) | |
| 978 (setq pending-undo-list buffer-undo-list)) | |
| 979 | |
| 980 (defun undo-more (count) | |
| 981 "Undo back N undo-boundaries beyond what was already undone recently. | |
| 982 Call `undo-start' to get ready to undo recent changes, | |
| 983 then call `undo-more' one or more times to undo them." | |
| 984 (or pending-undo-list | |
| 985 (error "No further undo information")) | |
| 986 (setq pending-undo-list (primitive-undo count pending-undo-list) | |
| 987 last-undo-buffer (current-buffer))) ; XEmacs | |
| 988 | |
| 844 | 989 (defun undo-all-changes () |
| 990 "Keep undoing till the start of the undo list is reached. | |
| 991 Undoes all changes, even past a file save. Especially useful when you've | |
| 992 saved the file at some point." | |
| 993 (interactive) | |
| 994 (undo-start) | |
| 995 (while pending-undo-list (undo-more 1))) | |
| 996 | |
| 428 | 997 ;; XEmacs |
| 998 (defun call-with-transparent-undo (fn &rest args) | |
| 999 "Apply FN to ARGS, and then undo all changes made by FN to the current | |
| 1000 buffer. The undo records are processed even if FN returns non-locally. | |
| 1001 There is no trace of the changes made by FN in the buffer's undo history. | |
| 1002 | |
| 1003 You can use this in a write-file-hooks function with continue-save-buffer | |
| 1004 to make the contents of a disk file differ from its in-memory buffer." | |
| 1005 (let ((buffer-undo-list nil) | |
| 1006 ;; Kludge to prevent undo list truncation: | |
| 1007 (undo-high-threshold -1) | |
| 1008 (undo-threshold -1) | |
| 1009 (obuffer (current-buffer))) | |
| 1010 (unwind-protect | |
| 1011 (apply fn args) | |
| 1012 ;; Go to the buffer we will restore and make it writable: | |
| 1013 (set-buffer obuffer) | |
| 1014 (save-excursion | |
| 1015 (let ((buffer-read-only nil)) | |
| 1016 (save-restriction | |
| 1017 (widen) | |
| 1018 ;; Perform all undos, with further undo logging disabled: | |
| 1019 (let ((tail buffer-undo-list)) | |
| 1020 (setq buffer-undo-list t) | |
| 1021 (while tail | |
| 1022 (setq tail (primitive-undo (length tail) tail)))))))))) | |
| 1023 | |
| 1024 ;; XEmacs: The following are in other files | |
| 1025 ;; shell-command-history | |
| 1026 ;; shell-command-switch | |
| 1027 ;; shell-command | |
| 1028 ;; shell-command-sentinel | |
| 1029 | |
| 1030 | |
| 1031 (defconst universal-argument-map | |
| 1032 (let ((map (make-sparse-keymap))) | |
| 1033 (set-keymap-default-binding map 'universal-argument-other-key) | |
| 1034 ;FSFmacs (define-key map [switch-frame] nil) | |
| 1035 (define-key map [(t)] 'universal-argument-other-key) | |
| 1036 (define-key map [(meta t)] 'universal-argument-other-key) | |
| 1037 (define-key map [(control u)] 'universal-argument-more) | |
| 1038 (define-key map [?-] 'universal-argument-minus) | |
| 1039 (define-key map [?0] 'digit-argument) | |
| 1040 (define-key map [?1] 'digit-argument) | |
| 1041 (define-key map [?2] 'digit-argument) | |
| 1042 (define-key map [?3] 'digit-argument) | |
| 1043 (define-key map [?4] 'digit-argument) | |
| 1044 (define-key map [?5] 'digit-argument) | |
| 1045 (define-key map [?6] 'digit-argument) | |
| 1046 (define-key map [?7] 'digit-argument) | |
| 1047 (define-key map [?8] 'digit-argument) | |
| 1048 (define-key map [?9] 'digit-argument) | |
| 1049 map) | |
| 1050 "Keymap used while processing \\[universal-argument].") | |
| 1051 | |
| 1052 (defvar universal-argument-num-events nil | |
| 1053 "Number of argument-specifying events read by `universal-argument'. | |
| 1054 `universal-argument-other-key' uses this to discard those events | |
| 1055 from (this-command-keys), and reread only the final command.") | |
| 1056 | |
| 1057 (defun universal-argument () | |
| 1058 "Begin a numeric argument for the following command. | |
| 1059 Digits or minus sign following \\[universal-argument] make up the numeric argument. | |
| 1060 \\[universal-argument] following the digits or minus sign ends the argument. | |
| 1061 \\[universal-argument] without digits or minus sign provides 4 as argument. | |
| 1062 Repeating \\[universal-argument] without digits or minus sign | |
| 1063 multiplies the argument by 4 each time." | |
| 1064 (interactive) | |
| 1065 (setq prefix-arg (list 4)) | |
| 1066 (setq zmacs-region-stays t) ; XEmacs | |
| 1067 (setq universal-argument-num-events (length (this-command-keys))) | |
| 1068 (setq overriding-terminal-local-map universal-argument-map)) | |
| 1069 | |
| 1070 ;; A subsequent C-u means to multiply the factor by 4 if we've typed | |
| 1071 ;; nothing but C-u's; otherwise it means to terminate the prefix arg. | |
| 1072 (defun universal-argument-more (arg) | |
| 1073 (interactive "_P") ; XEmacs | |
| 1074 (if (consp arg) | |
| 1075 (setq prefix-arg (list (* 4 (car arg)))) | |
| 1076 (setq prefix-arg arg) | |
| 1077 (setq overriding-terminal-local-map nil)) | |
| 1078 (setq universal-argument-num-events (length (this-command-keys)))) | |
| 1079 | |
| 1080 (defun negative-argument (arg) | |
| 1081 "Begin a negative numeric argument for the next command. | |
| 1082 \\[universal-argument] following digits or minus sign ends the argument." | |
| 1083 (interactive "_P") ; XEmacs | |
| 1084 (cond ((integerp arg) | |
| 1085 (setq prefix-arg (- arg))) | |
| 1086 ((eq arg '-) | |
| 1087 (setq prefix-arg nil)) | |
| 1088 (t | |
| 1089 (setq prefix-arg '-))) | |
| 1090 (setq universal-argument-num-events (length (this-command-keys))) | |
| 1091 (setq overriding-terminal-local-map universal-argument-map)) | |
| 1092 | |
| 1093 ;; XEmacs: This function not synched with FSF | |
| 1094 (defun digit-argument (arg) | |
| 1095 "Part of the numeric argument for the next command. | |
| 1096 \\[universal-argument] following digits or minus sign ends the argument." | |
| 1097 (interactive "_P") ; XEmacs | |
| 1098 (let* ((event last-command-event) | |
| 1099 (key (and (key-press-event-p event) | |
| 1100 (event-key event))) | |
| 1101 (digit (and key (characterp key) (>= key ?0) (<= key ?9) | |
| 1102 (- key ?0)))) | |
| 1103 (if (null digit) | |
| 1104 (universal-argument-other-key arg) | |
| 1105 (cond ((integerp arg) | |
| 1106 (setq prefix-arg (+ (* arg 10) | |
| 1107 (if (< arg 0) (- digit) digit)))) | |
| 1108 ((eq arg '-) | |
| 1109 ;; Treat -0 as just -, so that -01 will work. | |
| 1110 (setq prefix-arg (if (zerop digit) '- (- digit)))) | |
| 1111 (t | |
| 1112 (setq prefix-arg digit))) | |
| 1113 (setq universal-argument-num-events (length (this-command-keys))) | |
| 1114 (setq overriding-terminal-local-map universal-argument-map)))) | |
| 1115 | |
| 1116 ;; For backward compatibility, minus with no modifiers is an ordinary | |
| 1117 ;; command if digits have already been entered. | |
| 1118 (defun universal-argument-minus (arg) | |
| 1119 (interactive "_P") ; XEmacs | |
| 1120 (if (integerp arg) | |
| 1121 (universal-argument-other-key arg) | |
| 1122 (negative-argument arg))) | |
| 1123 | |
| 1124 ;; Anything else terminates the argument and is left in the queue to be | |
| 1125 ;; executed as a command. | |
| 1126 (defun universal-argument-other-key (arg) | |
| 1127 (interactive "_P") ; XEmacs | |
| 1128 (setq prefix-arg arg) | |
| 1129 (let* ((key (this-command-keys)) | |
| 1130 ;; FSF calls silly function `listify-key-sequence' here. | |
| 1131 (keylist (append key nil))) | |
| 1132 (setq unread-command-events | |
| 1133 (append (nthcdr universal-argument-num-events keylist) | |
| 1134 unread-command-events))) | |
| 1135 (reset-this-command-lengths) | |
| 1136 (setq overriding-terminal-local-map nil)) | |
| 1137 | |
| 1138 | |
| 1139 ;; XEmacs -- keep zmacs-region active. | |
| 444 | 1140 (defun forward-to-indentation (count) |
| 1141 "Move forward COUNT lines and position at first nonblank character." | |
| 428 | 1142 (interactive "_p") |
| 444 | 1143 (forward-line count) |
| 428 | 1144 (skip-chars-forward " \t")) |
| 1145 | |
| 444 | 1146 (defun backward-to-indentation (count) |
| 1147 "Move backward COUNT lines and position at first nonblank character." | |
| 428 | 1148 (interactive "_p") |
| 444 | 1149 (forward-line (- count)) |
| 428 | 1150 (skip-chars-forward " \t")) |
| 1151 | |
| 1152 (defcustom kill-whole-line nil | |
| 462 | 1153 "*If non-nil, kill the whole line if point is at the beginning. |
| 1154 Otherwise, `kill-line' kills only up to the end of the line, but not | |
| 503 | 1155 the terminating newline. |
| 462 | 1156 |
| 1157 WARNING: This is a misnamed variable! It should be called something | |
| 1158 like `kill-whole-line-when-at-beginning'. If you simply want | |
| 1159 \\[kill-line] to kill the entire current line, bind it to the function | |
| 1160 `kill-entire-line'. " | |
| 1161 :type 'boolean | |
| 428 | 1162 :group 'killing) |
| 1163 | |
| 503 | 1164 (defun kill-line-1 (arg entire-line) |
| 462 | 1165 (kill-region (if entire-line |
| 442 | 1166 (save-excursion |
| 1167 (beginning-of-line) | |
| 1168 (point)) | |
| 1169 (point)) | |
| 428 | 1170 ;; Don't shift point before doing the delete; that way, |
| 1171 ;; undo will record the right position of point. | |
| 1172 ;; FSF | |
| 1173 ; ;; It is better to move point to the other end of the kill | |
| 1174 ; ;; before killing. That way, in a read-only buffer, point | |
| 1175 ; ;; moves across the text that is copied to the kill ring. | |
| 1176 ; ;; The choice has no effect on undo now that undo records | |
| 1177 ; ;; the value of point from before the command was run. | |
| 1178 ; (progn | |
| 1179 (save-excursion | |
| 1180 (if arg | |
| 1181 (forward-line (prefix-numeric-value arg)) | |
| 1182 (if (eobp) | |
| 1183 (signal 'end-of-buffer nil)) | |
| 442 | 1184 (if (or (looking-at "[ \t]*$") |
| 462 | 1185 (or entire-line |
| 503 | 1186 (and kill-whole-line (bolp)))) |
| 428 | 1187 (forward-line 1) |
| 1188 (end-of-line))) | |
| 1189 (point)))) | |
| 1190 | |
| 462 | 1191 (defun kill-entire-line (&optional arg) |
| 1192 "Kill the entire line. | |
| 1193 With prefix argument, kill that many lines from point. Negative | |
| 1194 arguments kill lines backward. | |
| 1195 | |
| 1196 When calling from a program, nil means \"no arg\", | |
| 1197 a number counts as a prefix arg." | |
| 1198 (interactive "*P") | |
| 503 | 1199 (kill-line-1 arg t)) |
| 462 | 1200 |
| 1201 (defun kill-line (&optional arg) | |
| 1202 "Kill the rest of the current line, or the entire line. | |
| 1203 If no nonblanks there, kill thru newline. If called interactively, | |
| 1204 may kill the entire line when given no argument at the beginning of a | |
| 1205 line; see `kill-whole-line'. With prefix argument, kill that many | |
| 1206 lines from point. Negative arguments kill lines backward. | |
| 1207 | |
| 1208 WARNING: This is a misnamed function! It should be called something | |
| 1209 like `kill-to-end-of-line'. If you simply want to kill the entire | |
| 1210 current line, use `kill-entire-line'. | |
| 1211 | |
| 1212 When calling from a program, nil means \"no arg\", | |
| 1213 a number counts as a prefix arg." | |
| 1214 (interactive "*P") | |
| 503 | 1215 (kill-line-1 arg nil)) |
| 462 | 1216 |
| 428 | 1217 ;; XEmacs |
| 1218 (defun backward-kill-line nil | |
| 1219 "Kill back to the beginning of the line." | |
| 1220 (interactive) | |
| 1221 (let ((point (point))) | |
| 1222 (beginning-of-line nil) | |
| 1223 (kill-region (point) point))) | |
| 1224 | |
| 1225 | |
| 1226 ;;;; Window system cut and paste hooks. | |
| 1227 ;;; | |
| 1228 ;;; I think that kill-hooks is a better name and more general mechanism | |
| 1229 ;;; than interprogram-cut-function (from FSFmacs). I don't like the behavior | |
| 1230 ;;; of interprogram-paste-function: ^Y should always come from the kill ring, | |
| 1231 ;;; not the X selection. But if that were provided, it should be called (and | |
| 1232 ;;; behave as) yank-hooks instead. -- jwz | |
| 1233 | |
| 1234 ;; [... code snipped ...] | |
| 1235 | |
| 1236 (defcustom kill-hooks nil | |
| 1237 "*Functions run when something is added to the XEmacs kill ring. | |
| 1238 These functions are called with one argument, the string most recently | |
| 1239 cut or copied. You can use this to, for example, make the most recent | |
| 1240 kill become the X Clipboard selection." | |
| 1241 :type 'hook | |
| 1242 :group 'killing) | |
| 1243 | |
| 1244 ;;; `kill-hooks' seems not sufficient because | |
| 1245 ;;; `interprogram-cut-function' requires more variable about to rotate | |
| 1246 ;;; the cut buffers. I'm afraid to change interface of `kill-hooks', | |
| 1247 ;;; so I add it. (1997-11-03 by MORIOKA Tomohiko) | |
| 1248 | |
| 442 | 1249 (defcustom interprogram-cut-function 'own-clipboard |
| 428 | 1250 "Function to call to make a killed region available to other programs. |
| 1251 | |
| 1252 Most window systems provide some sort of facility for cutting and | |
| 1253 pasting text between the windows of different programs. | |
| 1254 This variable holds a function that Emacs calls whenever text | |
| 1255 is put in the kill ring, to make the new kill available to other | |
| 1256 programs. | |
| 1257 | |
| 1258 The function takes one or two arguments. | |
| 1259 The first argument, TEXT, is a string containing | |
| 1260 the text which should be made available. | |
| 1261 The second, PUSH, if non-nil means this is a \"new\" kill; | |
| 843 | 1262 nil means appending to an \"old\" kill. |
| 1263 | |
| 1264 One reasonable choice is `own-clipboard' (the default)." | |
| 442 | 1265 :type '(radio (function-item :tag "Send to Clipboard" |
| 1266 :format "%t\n" | |
| 1267 own-clipboard) | |
| 1268 (const :tag "None" nil) | |
| 1269 (function :tag "Other")) | |
| 1270 :group 'killing) | |
| 1271 | |
| 843 | 1272 (defcustom interprogram-paste-function 'get-clipboard-foreign |
| 428 | 1273 "Function to call to get text cut from other programs. |
| 1274 | |
| 1275 Most window systems provide some sort of facility for cutting and | |
| 1276 pasting text between the windows of different programs. | |
| 1277 This variable holds a function that Emacs calls to obtain | |
| 1278 text that other programs have provided for pasting. | |
| 1279 | |
| 1280 The function should be called with no arguments. If the function | |
| 1281 returns nil, then no other program has provided such text, and the top | |
| 1282 of the Emacs kill ring should be used. If the function returns a | |
| 1283 string, that string should be put in the kill ring as the latest kill. | |
| 1284 | |
| 1285 Note that the function should return a string only if a program other | |
| 1286 than Emacs has provided a string for pasting; if Emacs provided the | |
| 1287 most recent string, the function should return nil. If it is | |
| 1288 difficult to tell whether Emacs or some other program provided the | |
| 1289 current string, it is probably good enough to return nil if the string | |
| 843 | 1290 is equal (according to `string=') to the last text Emacs provided. |
| 1291 | |
| 1292 Reasonable choices include `get-clipboard-foreign' (the default), and | |
| 1293 functions calling `get-selection-foreign' (q.v.)." | |
| 442 | 1294 :type '(radio (function-item :tag "Get from Clipboard" |
| 1295 :format "%t\n" | |
| 843 | 1296 get-clipboard-foreign) |
| 442 | 1297 (const :tag "None" nil) |
| 1298 (function :tag "Other")) | |
| 1299 :group 'killing) | |
| 428 | 1300 |
| 1301 | |
| 1302 ;;;; The kill ring data structure. | |
| 1303 | |
| 1304 (defvar kill-ring nil | |
| 1305 "List of killed text sequences. | |
| 1306 Since the kill ring is supposed to interact nicely with cut-and-paste | |
| 1307 facilities offered by window systems, use of this variable should | |
| 1308 interact nicely with `interprogram-cut-function' and | |
| 1309 `interprogram-paste-function'. The functions `kill-new', | |
| 1310 `kill-append', and `current-kill' are supposed to implement this | |
| 1311 interaction; you may want to use them instead of manipulating the kill | |
| 1312 ring directly.") | |
| 1313 | |
| 829 | 1314 (defcustom kill-ring-max 60 |
| 428 | 1315 "*Maximum length of kill ring before oldest elements are thrown away." |
| 1316 :type 'integer | |
| 1317 :group 'killing) | |
| 1318 | |
| 1319 (defvar kill-ring-yank-pointer nil | |
| 1320 "The tail of the kill ring whose car is the last thing yanked.") | |
| 1321 | |
| 1322 (defun kill-new (string &optional replace) | |
| 1323 "Make STRING the latest kill in the kill ring. | |
| 444 | 1324 Set `kill-ring-yank-pointer' to point to it. |
| 829 | 1325 If `interprogram-cut-function' is non-nil, apply it to STRING. |
| 428 | 1326 Run `kill-hooks'. |
| 1327 Optional second argument REPLACE non-nil means that STRING will replace | |
| 1328 the front of the kill ring, rather than being added to the list." | |
| 1329 ; (and (fboundp 'menu-bar-update-yank-menu) | |
| 1330 ; (menu-bar-update-yank-menu string (and replace (car kill-ring)))) | |
| 829 | 1331 (if (and replace kill-ring) |
| 428 | 1332 (setcar kill-ring string) |
| 1333 (setq kill-ring (cons string kill-ring)) | |
| 1334 (if (> (length kill-ring) kill-ring-max) | |
| 1335 (setcdr (nthcdr (1- kill-ring-max) kill-ring) nil))) | |
| 1336 (setq kill-ring-yank-pointer kill-ring) | |
| 1337 (if interprogram-cut-function | |
| 1338 (funcall interprogram-cut-function string (not replace))) | |
| 1339 (run-hook-with-args 'kill-hooks string)) | |
| 1340 | |
| 1341 (defun kill-append (string before-p) | |
| 1342 "Append STRING to the end of the latest kill in the kill ring. | |
| 1343 If BEFORE-P is non-nil, prepend STRING to the kill. | |
| 1344 Run `kill-hooks'." | |
| 1345 (kill-new (if before-p | |
| 1346 (concat string (car kill-ring)) | |
| 1347 (concat (car kill-ring) string)) t)) | |
| 1348 | |
| 1349 (defun current-kill (n &optional do-not-move) | |
| 1350 "Rotate the yanking point by N places, and then return that kill. | |
| 1351 If N is zero, `interprogram-paste-function' is set, and calling it | |
| 1352 returns a string, then that string is added to the front of the | |
| 1353 kill ring and returned as the latest kill. | |
| 1354 If optional arg DO-NOT-MOVE is non-nil, then don't actually move the | |
| 1355 yanking point\; just return the Nth kill forward." | |
| 1356 (let ((interprogram-paste (and (= n 0) | |
| 1357 interprogram-paste-function | |
| 1358 (funcall interprogram-paste-function)))) | |
| 1359 (if interprogram-paste | |
| 1360 (progn | |
| 1361 ;; Disable the interprogram cut function when we add the new | |
| 1362 ;; text to the kill ring, so Emacs doesn't try to own the | |
| 1363 ;; selection, with identical text. | |
| 1364 (let ((interprogram-cut-function nil)) | |
| 1365 (kill-new interprogram-paste)) | |
| 1366 interprogram-paste) | |
| 1367 (or kill-ring (error "Kill ring is empty")) | |
| 1368 (let* ((tem (nthcdr (mod (- n (length kill-ring-yank-pointer)) | |
| 1369 (length kill-ring)) | |
| 1370 kill-ring))) | |
| 1371 (or do-not-move | |
| 1372 (setq kill-ring-yank-pointer tem)) | |
| 1373 (car tem))))) | |
| 1374 | |
| 1375 | |
| 1376 | |
| 1377 ;;;; Commands for manipulating the kill ring. | |
| 1378 | |
| 1379 ;; In FSF killing read-only text just pastes it into kill-ring. Which | |
| 1380 ;; is a very bad idea -- see Jamie's comment below. | |
| 1381 | |
| 1382 ;(defvar kill-read-only-ok nil | |
| 1383 ; "*Non-nil means don't signal an error for killing read-only text.") | |
| 1384 | |
| 444 | 1385 (defun kill-region (start end &optional verbose) ; verbose is XEmacs addition |
| 428 | 1386 "Kill between point and mark. |
| 1387 The text is deleted but saved in the kill ring. | |
| 1388 The command \\[yank] can retrieve it from there. | |
| 1389 \(If you want to kill and then yank immediately, use \\[copy-region-as-kill].) | |
| 1390 | |
| 1391 This is the primitive for programs to kill text (as opposed to deleting it). | |
| 1392 Supply two arguments, character numbers indicating the stretch of text | |
| 1393 to be killed. | |
| 1394 Any command that calls this function is a \"kill command\". | |
| 1395 If the previous command was also a kill command, | |
| 1396 the text killed this time appends to the text killed last time | |
| 1397 to make one entry in the kill ring." | |
| 1398 (interactive "*r\np") | |
| 1399 ; (interactive | |
| 1400 ; (let ((region-hack (and zmacs-regions (eq last-command 'yank)))) | |
| 1401 ; ;; This lets "^Y^W" work. I think this is dumb, but zwei did it. | |
| 1402 ; (if region-hack (zmacs-activate-region)) | |
| 1403 ; (prog1 | |
| 1404 ; (list (point) (mark) current-prefix-arg) | |
| 1405 ; (if region-hack (zmacs-deactivate-region))))) | |
| 444 | 1406 ;; start and end can be markers but the rest of this function is |
| 428 | 1407 ;; written as if they are only integers |
| 444 | 1408 (if (markerp start) (setq start (marker-position start))) |
| 428 | 1409 (if (markerp end) (setq end (marker-position end))) |
| 444 | 1410 (or (and start end) (if zmacs-regions ;; rewritten for I18N3 snarfing |
| 428 | 1411 (error "The region is not active now") |
| 1412 (error "The mark is not set now"))) | |
| 1413 (if verbose (if buffer-read-only | |
| 1414 (lmessage 'command "Copying %d characters" | |
| 444 | 1415 (- (max start end) (min start end))) |
| 428 | 1416 (lmessage 'command "Killing %d characters" |
| 444 | 1417 (- (max start end) (min start end))))) |
| 428 | 1418 (cond |
| 1419 | |
| 1420 ;; I don't like this large change in behavior -- jwz | |
| 1421 ;; Read-Only text means it shouldn't be deleted, so I'm restoring | |
| 1422 ;; this code, but only for text-properties and not full extents. -sb | |
| 1423 ;; If the buffer is read-only, we should beep, in case the person | |
| 1424 ;; just isn't aware of this. However, there's no harm in putting | |
| 1425 ;; the region's text in the kill ring, anyway. | |
| 1426 ((or (and buffer-read-only (not inhibit-read-only)) | |
| 444 | 1427 (text-property-not-all (min start end) (max start end) 'read-only nil)) |
| 428 | 1428 ;; This is redundant. |
| 1429 ;; (if verbose (message "Copying %d characters" | |
| 444 | 1430 ;; (- (max start end) (min start end)))) |
| 1431 (copy-region-as-kill start end) | |
| 428 | 1432 ;; ;; This should always barf, and give us the correct error. |
| 1433 ;; (if kill-read-only-ok | |
| 1434 ;; (message "Read only text copied to kill ring") | |
| 1435 (setq this-command 'kill-region) | |
| 1436 (barf-if-buffer-read-only) | |
| 1437 (signal 'buffer-read-only (list (current-buffer)))) | |
| 1438 | |
| 1439 ;; In certain cases, we can arrange for the undo list and the kill | |
| 1440 ;; ring to share the same string object. This code does that. | |
| 1441 ((not (or (eq buffer-undo-list t) | |
| 1442 (eq last-command 'kill-region) | |
| 1443 ;; Use = since positions may be numbers or markers. | |
| 444 | 1444 (= start end))) |
| 428 | 1445 ;; Don't let the undo list be truncated before we can even access it. |
| 1446 ;; FSF calls this `undo-strong-limit' | |
| 444 | 1447 (let ((undo-high-threshold (+ (- end start) 100)) |
| 428 | 1448 ;(old-list buffer-undo-list) |
| 1449 tail) | |
| 444 | 1450 (delete-region start end) |
| 428 | 1451 ;; Search back in buffer-undo-list for this string, |
| 1452 ;; in case a change hook made property changes. | |
| 1453 (setq tail buffer-undo-list) | |
| 1454 (while (and tail | |
| 1455 (not (stringp (car-safe (car-safe tail))))) ; XEmacs | |
| 1456 (pop tail)) | |
| 1457 ;; Take the same string recorded for undo | |
| 1458 ;; and put it in the kill-ring. | |
| 1459 (and tail | |
| 1460 (kill-new (car (car tail)))))) | |
| 1461 | |
| 1462 (t | |
| 1463 ;; if undo is not kept, grab the string then delete it (which won't | |
| 1464 ;; add another string to the undo list). | |
| 444 | 1465 (copy-region-as-kill start end) |
| 1466 (delete-region start end))) | |
| 428 | 1467 (setq this-command 'kill-region)) |
| 1468 | |
| 1469 ;; copy-region-as-kill no longer sets this-command, because it's confusing | |
| 1470 ;; to get two copies of the text when the user accidentally types M-w and | |
| 1471 ;; then corrects it with the intended C-w. | |
| 444 | 1472 (defun copy-region-as-kill (start end) |
| 428 | 1473 "Save the region as if killed, but don't kill it. |
| 1474 Run `kill-hooks'." | |
| 1475 (interactive "r") | |
| 1476 (if (eq last-command 'kill-region) | |
| 444 | 1477 (kill-append (buffer-substring start end) (< end start)) |
| 1478 (kill-new (buffer-substring start end))) | |
| 428 | 1479 nil) |
| 1480 | |
| 444 | 1481 (defun kill-ring-save (start end) |
| 428 | 1482 "Save the region as if killed, but don't kill it. |
| 1483 This command is similar to `copy-region-as-kill', except that it gives | |
| 1484 visual feedback indicating the extent of the region being copied." | |
| 1485 (interactive "r") | |
| 444 | 1486 (copy-region-as-kill start end) |
| 428 | 1487 ;; copy before delay, for xclipboard's benefit |
| 1488 (if (interactive-p) | |
| 444 | 1489 (let ((other-end (if (= (point) start) end start)) |
| 428 | 1490 (opoint (point)) |
| 1491 ;; Inhibit quitting so we can make a quit here | |
| 1492 ;; look like a C-g typed as a command. | |
| 1493 (inhibit-quit t)) | |
| 1494 (if (pos-visible-in-window-p other-end (selected-window)) | |
| 1495 (progn | |
| 1496 ;; FSF (I'm not sure what this does -sb) | |
| 1497 ; ;; Swap point and mark. | |
| 1498 ; (set-marker (mark-marker) (point) (current-buffer)) | |
| 1499 (goto-char other-end) | |
| 1500 (sit-for 1) | |
| 1501 ; ;; Swap back. | |
| 1502 ; (set-marker (mark-marker) other-end (current-buffer)) | |
| 1503 (goto-char opoint) | |
| 1504 ;; If user quit, deactivate the mark | |
| 1505 ;; as C-g would as a command. | |
| 1506 (and quit-flag (mark) | |
| 1507 (zmacs-deactivate-region))) | |
| 1508 ;; too noisy. -- jwz | |
| 1509 ; (let* ((killed-text (current-kill 0)) | |
| 1510 ; (message-len (min (length killed-text) 40))) | |
| 444 | 1511 ; (if (= (point) start) |
| 428 | 1512 ; ;; Don't say "killed"; that is misleading. |
| 1513 ; (message "Saved text until \"%s\"" | |
| 1514 ; (substring killed-text (- message-len))) | |
| 1515 ; (message "Saved text from \"%s\"" | |
| 1516 ; (substring killed-text 0 message-len)))) | |
| 1517 )))) | |
| 1518 | |
| 1519 (defun append-next-kill () | |
| 1520 "Cause following command, if it kills, to append to previous kill." | |
| 1521 ;; XEmacs | |
| 1522 (interactive "_") | |
| 1523 (if (interactive-p) | |
| 1524 (progn | |
| 1525 (setq this-command 'kill-region) | |
| 1526 (display-message 'command | |
| 1527 "If the next command is a kill, it will append")) | |
| 1528 (setq last-command 'kill-region))) | |
| 1529 | |
| 1530 (defun yank-pop (arg) | |
| 1531 "Replace just-yanked stretch of killed text with a different stretch. | |
| 1532 This command is allowed only immediately after a `yank' or a `yank-pop'. | |
| 1533 At such a time, the region contains a stretch of reinserted | |
| 1534 previously-killed text. `yank-pop' deletes that text and inserts in its | |
| 1535 place a different stretch of killed text. | |
| 1536 | |
| 1537 With no argument, the previous kill is inserted. | |
| 1538 With argument N, insert the Nth previous kill. | |
| 1539 If N is negative, this is a more recent kill. | |
| 1540 | |
| 1541 The sequence of kills wraps around, so that after the oldest one | |
| 1542 comes the newest one." | |
| 1543 (interactive "*p") | |
| 1544 (if (not (eq last-command 'yank)) | |
| 1545 (error "Previous command was not a yank")) | |
| 1546 (setq this-command 'yank) | |
| 1547 (let ((inhibit-read-only t) | |
| 1548 (before (< (point) (mark t)))) | |
| 1549 (delete-region (point) (mark t)) | |
| 1550 ;;(set-marker (mark-marker) (point) (current-buffer)) | |
| 1551 (set-mark (point)) | |
| 1552 (insert (current-kill arg)) | |
| 1553 (if before | |
| 1554 ;; This is like exchange-point-and-mark, but doesn't activate the mark. | |
| 1555 ;; It is cleaner to avoid activation, even though the command | |
| 1556 ;; loop would deactivate the mark because we inserted text. | |
| 1557 (goto-char (prog1 (mark t) | |
| 1558 (set-marker (mark-marker t) (point) (current-buffer)))))) | |
| 1559 nil) | |
| 1560 | |
| 1561 | |
| 1562 (defun yank (&optional arg) | |
| 1563 "Reinsert the last stretch of killed text. | |
| 1564 More precisely, reinsert the stretch of killed text most recently | |
| 1565 killed OR yanked. Put point at end, and set mark at beginning. | |
| 1566 With just C-u as argument, same but put point at beginning (and mark at end). | |
| 1567 With argument N, reinsert the Nth most recently killed stretch of killed | |
| 1568 text. | |
| 1569 See also the command \\[yank-pop]." | |
| 1570 (interactive "*P") | |
| 1571 ;; If we don't get all the way through, make last-command indicate that | |
| 1572 ;; for the following command. | |
| 1573 (setq this-command t) | |
| 1574 (push-mark (point)) | |
| 1575 (insert (current-kill (cond | |
| 1576 ((listp arg) 0) | |
| 1577 ((eq arg '-) -1) | |
| 1578 (t (1- arg))))) | |
| 1579 (if (consp arg) | |
| 1580 ;; This is like exchange-point-and-mark, but doesn't activate the mark. | |
| 1581 ;; It is cleaner to avoid activation, even though the command | |
| 1582 ;; loop would deactivate the mark because we inserted text. | |
| 1583 ;; (But it's an unnecessary kludge in XEmacs.) | |
| 1584 ;(goto-char (prog1 (mark t) | |
| 1585 ;(set-marker (mark-marker) (point) (current-buffer))))) | |
| 1586 (exchange-point-and-mark t)) | |
| 1587 ;; If we do get all the way thru, make this-command indicate that. | |
| 1588 (setq this-command 'yank) | |
| 1589 nil) | |
| 1590 | |
| 1591 (defun rotate-yank-pointer (arg) | |
| 1592 "Rotate the yanking point in the kill ring. | |
| 1593 With argument, rotate that many kills forward (or backward, if negative)." | |
| 1594 (interactive "p") | |
| 1595 (current-kill arg)) | |
| 1596 | |
| 1597 | |
| 1598 (defun insert-buffer (buffer) | |
| 1599 "Insert after point the contents of BUFFER. | |
| 1600 Puts mark after the inserted text. | |
| 1601 BUFFER may be a buffer or a buffer name." | |
| 1602 (interactive | |
| 1603 (list | |
| 1604 (progn | |
| 1605 (barf-if-buffer-read-only) | |
| 1606 (read-buffer "Insert buffer: " | |
| 1607 ;; XEmacs: we have different args | |
| 1608 (other-buffer (current-buffer) nil t) | |
| 1609 t)))) | |
| 1610 (or (bufferp buffer) | |
| 1611 (setq buffer (get-buffer buffer))) | |
| 1612 (let (start end newmark) | |
| 1613 (save-excursion | |
| 1614 (save-excursion | |
| 1615 (set-buffer buffer) | |
| 1616 (setq start (point-min) end (point-max))) | |
| 1617 (insert-buffer-substring buffer start end) | |
| 1618 (setq newmark (point))) | |
| 1619 (push-mark newmark)) | |
| 1620 nil) | |
| 1621 | |
| 1622 (defun append-to-buffer (buffer start end) | |
| 1623 "Append to specified buffer the text of the region. | |
| 1624 It is inserted into that buffer before its point. | |
| 1625 | |
| 1626 When calling from a program, give three arguments: | |
| 1627 BUFFER (or buffer name), START and END. | |
| 1628 START and END specify the portion of the current buffer to be copied." | |
| 1629 (interactive | |
| 1630 ;; XEmacs: we have different args to other-buffer | |
| 1631 (list (read-buffer "Append to buffer: " (other-buffer (current-buffer) | |
| 1632 nil t)) | |
| 1633 (region-beginning) (region-end))) | |
| 1634 (let ((oldbuf (current-buffer))) | |
| 1635 (save-excursion | |
| 1636 (set-buffer (get-buffer-create buffer)) | |
| 1637 (insert-buffer-substring oldbuf start end)))) | |
| 1638 | |
| 1639 (defun prepend-to-buffer (buffer start end) | |
| 1640 "Prepend to specified buffer the text of the region. | |
| 1641 It is inserted into that buffer after its point. | |
| 1642 | |
| 1643 When calling from a program, give three arguments: | |
| 1644 BUFFER (or buffer name), START and END. | |
| 1645 START and END specify the portion of the current buffer to be copied." | |
| 1646 (interactive "BPrepend to buffer: \nr") | |
| 1647 (let ((oldbuf (current-buffer))) | |
| 1648 (save-excursion | |
| 1649 (set-buffer (get-buffer-create buffer)) | |
| 1650 (save-excursion | |
| 1651 (insert-buffer-substring oldbuf start end))))) | |
| 1652 | |
| 1653 (defun copy-to-buffer (buffer start end) | |
| 1654 "Copy to specified buffer the text of the region. | |
| 1655 It is inserted into that buffer, replacing existing text there. | |
| 1656 | |
| 1657 When calling from a program, give three arguments: | |
| 1658 BUFFER (or buffer name), START and END. | |
| 1659 START and END specify the portion of the current buffer to be copied." | |
| 1660 (interactive "BCopy to buffer: \nr") | |
| 1661 (let ((oldbuf (current-buffer))) | |
| 1662 (save-excursion | |
| 1663 (set-buffer (get-buffer-create buffer)) | |
| 1664 (erase-buffer) | |
| 1665 (save-excursion | |
| 1666 (insert-buffer-substring oldbuf start end))))) | |
| 1667 | |
| 1668 ;FSFmacs | |
| 1669 ;(put 'mark-inactive 'error-conditions '(mark-inactive error)) | |
| 1670 ;(put 'mark-inactive 'error-message "The mark is not active now") | |
| 1671 | |
| 1672 (defun mark (&optional force buffer) | |
| 1673 "Return this buffer's mark value as integer, or nil if no mark. | |
| 1674 | |
| 1675 If `zmacs-regions' is true, then this returns nil unless the region is | |
| 1676 currently in the active (highlighted) state. With an argument of t, this | |
| 1677 returns the mark (if there is one) regardless of the active-region state. | |
| 1678 You should *generally* not use the mark unless the region is active, if | |
| 1679 the user has expressed a preference for the active-region model. | |
| 1680 | |
| 1681 If you are using this in an editing command, you are most likely making | |
| 1682 a mistake; see the documentation of `set-mark'." | |
| 1683 (setq buffer (decode-buffer buffer)) | |
| 1684 ;FSFmacs version: | |
| 1685 ; (if (or force (not transient-mark-mode) mark-active mark-even-if-inactive) | |
| 1686 ; (marker-position (mark-marker)) | |
| 1687 ; (signal 'mark-inactive nil))) | |
| 1688 (let ((m (mark-marker force buffer))) | |
| 1689 (and m (marker-position m)))) | |
| 1690 | |
| 1691 ;;;#### FSFmacs | |
| 1692 ;;; Many places set mark-active directly, and several of them failed to also | |
| 1693 ;;; run deactivate-mark-hook. This shorthand should simplify. | |
| 1694 ;(defsubst deactivate-mark () | |
| 1695 ; "Deactivate the mark by setting `mark-active' to nil. | |
| 1696 ;\(That makes a difference only in Transient Mark mode.) | |
| 1697 ;Also runs the hook `deactivate-mark-hook'." | |
| 1698 ; (if transient-mark-mode | |
| 1699 ; (progn | |
| 1700 ; (setq mark-active nil) | |
| 1701 ; (run-hooks 'deactivate-mark-hook)))) | |
| 1702 | |
| 1703 (defun set-mark (pos &optional buffer) | |
| 1704 "Set this buffer's mark to POS. Don't use this function! | |
| 1705 That is to say, don't use this function unless you want | |
| 1706 the user to see that the mark has moved, and you want the previous | |
| 1707 mark position to be lost. | |
| 1708 | |
| 1709 Normally, when a new mark is set, the old one should go on the stack. | |
| 444 | 1710 This is why most applications should use `push-mark', not `set-mark'. |
| 428 | 1711 |
| 1712 Novice Emacs Lisp programmers often try to use the mark for the wrong | |
| 1713 purposes. The mark saves a location for the user's convenience. | |
| 1714 Most editing commands should not alter the mark. | |
| 1715 To remember a location for internal use in the Lisp program, | |
| 1716 store it in a Lisp variable. Example: | |
| 1717 | |
| 444 | 1718 (let ((start (point))) (forward-line 1) (delete-region start (point)))." |
| 428 | 1719 |
| 1720 (setq buffer (decode-buffer buffer)) | |
| 1721 (set-marker (mark-marker t buffer) pos buffer)) | |
| 1722 ;; FSF | |
| 1723 ; (if pos | |
| 1724 ; (progn | |
| 1725 ; (setq mark-active t) | |
| 1726 ; (run-hooks 'activate-mark-hook) | |
| 1727 ; (set-marker (mark-marker) pos (current-buffer))) | |
| 1728 ; ;; Normally we never clear mark-active except in Transient Mark mode. | |
| 1729 ; ;; But when we actually clear out the mark value too, | |
| 1730 ; ;; we must clear mark-active in any mode. | |
| 1731 ; (setq mark-active nil) | |
| 1732 ; (run-hooks 'deactivate-mark-hook) | |
| 1733 ; (set-marker (mark-marker) nil))) | |
| 1734 | |
| 1735 (defvar mark-ring nil | |
| 442 | 1736 "The list of former marks of the current buffer, most recent first. |
| 1737 This variable is automatically buffer-local.") | |
| 428 | 1738 (make-variable-buffer-local 'mark-ring) |
| 1739 (put 'mark-ring 'permanent-local t) | |
| 1740 | |
| 442 | 1741 (defvar dont-record-current-mark nil |
| 1742 "If set to t, the current mark value should not be recorded on the mark ring. | |
| 1743 This is set by commands that manipulate the mark incidentally, to avoid | |
| 1744 cluttering the mark ring unnecessarily. Under most circumstances, you do | |
| 1745 not need to set this directly; it is automatically reset each time | |
| 1746 `push-mark' is called, according to `mark-ring-unrecorded-commands'. This | |
| 1747 variable is automatically buffer-local.") | |
| 1748 (make-variable-buffer-local 'dont-record-current-mark) | |
| 1749 (put 'dont-record-current-mark 'permanent-local t) | |
| 1750 | |
| 1751 ;; a conspiracy between push-mark and handle-pre-motion-command | |
| 1752 (defvar in-shifted-motion-command nil) | |
| 1753 | |
| 1754 (defcustom mark-ring-unrecorded-commands '(shifted-motion-commands | |
| 1755 yank | |
| 1756 mark-beginning-of-buffer | |
| 1757 mark-bob | |
| 1758 mark-defun | |
| 1759 mark-end-of-buffer | |
| 1760 mark-end-of-line | |
| 1761 mark-end-of-sentence | |
| 1762 mark-eob | |
| 1763 mark-marker | |
| 1764 mark-page | |
| 1765 mark-paragraph | |
| 1766 mark-sexp | |
| 1767 mark-whole-buffer | |
| 1768 mark-word) | |
| 1769 "*List of commands whose marks should not be recorded on the mark stack. | |
| 1770 Many commands set the mark as part of their action. Normally, all such | |
| 1771 marks get recorded onto the mark stack. However, this tends to clutter up | |
| 1772 the mark stack unnecessarily. You can control this by putting a command | |
| 1773 onto this list. Then, any marks set by the function will not be recorded. | |
| 1774 | |
| 1775 The special value `shifted-motion-commands' causes marks set as a result | |
| 1776 of selection using any shifted motion commands to not be recorded. | |
| 1777 | |
| 1778 The value `yank' affects all yank-like commands, as well as just `yank'." | |
| 1779 :type '(repeat (choice (const :tag "shifted motion commands" | |
| 462 | 1780 shifted-motion-commands) |
| 442 | 1781 (const :tag "functions that select text" |
| 1782 :inline t | |
| 462 | 1783 (mark-beginning-of-buffer |
| 1784 mark-bob | |
| 1785 mark-defun | |
| 1786 mark-end-of-buffer | |
| 1787 mark-end-of-line | |
| 1788 mark-end-of-sentence | |
| 1789 mark-eob | |
| 1790 mark-marker | |
| 1791 mark-page | |
| 1792 mark-paragraph | |
| 1793 mark-sexp | |
| 1794 mark-whole-buffer | |
| 1795 mark-word)) | |
| 442 | 1796 (const :tag "functions that paste text" |
| 462 | 1797 yank) |
| 442 | 1798 function)) |
| 1799 :group 'killing) | |
| 1800 | |
| 428 | 1801 (defcustom mark-ring-max 16 |
| 1802 "*Maximum size of mark ring. Start discarding off end if gets this big." | |
| 1803 :type 'integer | |
| 1804 :group 'killing) | |
| 1805 | |
| 1806 (defvar global-mark-ring nil | |
| 1807 "The list of saved global marks, most recent first.") | |
| 1808 | |
| 1809 (defcustom global-mark-ring-max 16 | |
| 1810 "*Maximum size of global mark ring. \ | |
| 1811 Start discarding off end if gets this big." | |
| 1812 :type 'integer | |
| 1813 :group 'killing) | |
| 1814 | |
| 1815 (defun set-mark-command (arg) | |
| 1816 "Set mark at where point is, or jump to mark. | |
| 1817 With no prefix argument, set mark, push old mark position on local mark | |
| 1818 ring, and push mark on global mark ring. | |
| 1819 With argument, jump to mark, and pop a new position for mark off the ring | |
| 1820 \(does not affect global mark ring\). | |
| 1821 | |
| 442 | 1822 The mark ring is a per-buffer stack of marks, most recent first. Its |
| 1823 maximum length is controlled by `mark-ring-max'. Generally, when new | |
| 1824 marks are set, the current mark is pushed onto the stack. You can pop | |
| 1825 marks off the stack using \\[universal-argument] \\[set-mark-command]. The term \"ring\" is used because when | |
| 1826 you pop a mark off the stack, the current mark value is pushed onto the | |
| 1827 far end of the stack. If this is confusing, just think of the mark ring | |
| 1828 as a stack. | |
| 1829 | |
| 428 | 1830 Novice Emacs Lisp programmers often try to use the mark for the wrong |
| 1831 purposes. See the documentation of `set-mark' for more information." | |
| 1832 (interactive "P") | |
| 1833 (if (null arg) | |
| 1834 (push-mark nil nil t) | |
| 1835 (if (null (mark t)) | |
| 1836 (error "No mark set in this buffer") | |
| 442 | 1837 (if dont-record-current-mark (pop-mark)) |
| 428 | 1838 (goto-char (mark t)) |
| 1839 (pop-mark)))) | |
| 1840 | |
| 1841 ;; XEmacs: Extra parameter | |
| 1842 (defun push-mark (&optional location nomsg activate-region buffer) | |
| 1843 "Set mark at LOCATION (point, by default) and push old mark on mark ring. | |
| 1844 If the last global mark pushed was not in the current buffer, | |
| 1845 also push LOCATION on the global mark ring. | |
| 1846 Display `Mark set' unless the optional second arg NOMSG is non-nil. | |
| 1847 Activate mark if optional third arg ACTIVATE-REGION non-nil. | |
| 1848 | |
| 1849 Novice Emacs Lisp programmers often try to use the mark for the wrong | |
| 1850 purposes. See the documentation of `set-mark' for more information." | |
| 1851 (setq buffer (decode-buffer buffer)) ; XEmacs | |
| 442 | 1852 (if (or dont-record-current-mark (null (mark t buffer))) ; XEmacs |
| 428 | 1853 nil |
| 1854 ;; The save-excursion / set-buffer is necessary because mark-ring | |
| 1855 ;; is a buffer local variable | |
| 1856 (save-excursion | |
| 1857 (set-buffer buffer) | |
| 1858 (setq mark-ring (cons (copy-marker (mark-marker t buffer)) mark-ring)) | |
| 1859 (if (> (length mark-ring) mark-ring-max) | |
| 1860 (progn | |
| 1861 (move-marker (car (nthcdr mark-ring-max mark-ring)) nil buffer) | |
| 1862 (setcdr (nthcdr (1- mark-ring-max) mark-ring) nil))))) | |
| 1863 (set-mark (or location (point buffer)) buffer) | |
| 1864 ; (set-marker (mark-marker) (or location (point)) (current-buffer)) ; FSF | |
| 1865 ;; Now push the mark on the global mark ring. | |
| 442 | 1866 (if (and (not dont-record-current-mark) |
| 1867 (or (null global-mark-ring) | |
| 1868 (not (eq (marker-buffer (car global-mark-ring)) buffer)))) | |
| 428 | 1869 ;; The last global mark pushed wasn't in this same buffer. |
| 1870 (progn | |
| 1871 (setq global-mark-ring (cons (copy-marker (mark-marker t buffer)) | |
| 1872 global-mark-ring)) | |
| 1873 (if (> (length global-mark-ring) global-mark-ring-max) | |
| 1874 (progn | |
| 1875 (move-marker (car (nthcdr global-mark-ring-max global-mark-ring)) | |
| 1876 nil buffer) | |
| 1877 (setcdr (nthcdr (1- global-mark-ring-max) global-mark-ring) nil))))) | |
| 442 | 1878 (setq dont-record-current-mark |
| 1879 (not (not (or (and in-shifted-motion-command | |
| 1880 (memq 'shifted-motion-commands | |
| 1881 mark-ring-unrecorded-commands)) | |
| 1882 (memq this-command mark-ring-unrecorded-commands))))) | |
| 1883 (or dont-record-current-mark nomsg executing-kbd-macro | |
| 1884 (> (minibuffer-depth) 0) | |
| 428 | 1885 (display-message 'command "Mark set")) |
| 1886 (if activate-region | |
| 1887 (progn | |
| 1888 (setq zmacs-region-stays t) | |
| 1889 (zmacs-activate-region))) | |
| 1890 ; (if (or activate (not transient-mark-mode)) ; FSF | |
| 1891 ; (set-mark (mark t))) ; FSF | |
| 1892 nil) | |
| 1893 | |
| 1894 (defun pop-mark () | |
| 1895 "Pop off mark ring into the buffer's actual mark. | |
| 1896 Does not set point. Does nothing if mark ring is empty." | |
| 1897 (if mark-ring | |
| 1898 (progn | |
| 1899 (setq mark-ring (nconc mark-ring (list (copy-marker (mark-marker t))))) | |
| 1900 (set-mark (car mark-ring)) | |
| 1901 (move-marker (car mark-ring) nil) | |
| 1902 (if (null (mark t)) (ding)) | |
| 1903 (setq mark-ring (cdr mark-ring))))) | |
| 1904 | |
| 1905 (define-function 'exchange-dot-and-mark 'exchange-point-and-mark) | |
| 1906 (defun exchange-point-and-mark (&optional dont-activate-region) | |
| 1907 "Put the mark where point is now, and point where the mark is now. | |
| 1908 The mark is activated unless DONT-ACTIVATE-REGION is non-nil." | |
| 1909 (interactive nil) | |
| 1910 (let ((omark (mark t))) | |
| 1911 (if (null omark) | |
| 1912 (error "No mark set in this buffer")) | |
| 1913 (set-mark (point)) | |
| 1914 (goto-char omark) | |
| 1915 (or dont-activate-region (zmacs-activate-region)) ; XEmacs | |
| 1916 nil)) | |
| 1917 | |
| 1918 ;; XEmacs | |
| 1919 (defun mark-something (mark-fn movement-fn arg) | |
| 1920 "internal function used by mark-sexp, mark-word, etc." | |
| 1921 (let (newmark (pushp t)) | |
| 1922 (save-excursion | |
| 1923 (if (and (eq last-command mark-fn) (mark)) | |
| 1924 ;; Extend the previous state in the same direction: | |
| 1925 (progn | |
| 1926 (if (< (mark) (point)) (setq arg (- arg))) | |
| 1927 (goto-char (mark)) | |
| 1928 (setq pushp nil))) | |
| 1929 (funcall movement-fn arg) | |
| 1930 (setq newmark (point))) | |
| 1931 (if pushp | |
| 1932 (push-mark newmark nil t) | |
| 1933 ;; Do not mess with the mark stack, but merely adjust the previous state: | |
| 1934 (set-mark newmark) | |
| 1935 (activate-region)))) | |
| 1936 | |
| 1937 ;(defun transient-mark-mode (arg) | |
| 1938 ; "Toggle Transient Mark mode. | |
| 1939 ;With arg, turn Transient Mark mode on if arg is positive, off otherwise. | |
| 1940 ; | |
| 1941 ;In Transient Mark mode, when the mark is active, the region is highlighted. | |
| 1942 ;Changing the buffer \"deactivates\" the mark. | |
| 1943 ;So do certain other operations that set the mark | |
| 1944 ;but whose main purpose is something else--for example, | |
| 1945 ;incremental search, \\[beginning-of-buffer], and \\[end-of-buffer]." | |
| 1946 ; (interactive "P") | |
| 1947 ; (setq transient-mark-mode | |
| 1948 ; (if (null arg) | |
| 1949 ; (not transient-mark-mode) | |
| 1950 ; (> (prefix-numeric-value arg) 0)))) | |
| 1951 | |
| 1952 (defun pop-global-mark () | |
| 1953 "Pop off global mark ring and jump to the top location." | |
| 1954 (interactive) | |
| 1955 ;; Pop entries which refer to non-existent buffers. | |
| 1956 (while (and global-mark-ring (not (marker-buffer (car global-mark-ring)))) | |
| 1957 (setq global-mark-ring (cdr global-mark-ring))) | |
| 1958 (or global-mark-ring | |
| 1959 (error "No global mark set")) | |
| 1960 (let* ((marker (car global-mark-ring)) | |
| 1961 (buffer (marker-buffer marker)) | |
| 1962 (position (marker-position marker))) | |
| 1963 (setq global-mark-ring (nconc (cdr global-mark-ring) | |
| 1964 (list (car global-mark-ring)))) | |
| 1965 (set-buffer buffer) | |
| 1966 (or (and (>= position (point-min)) | |
| 1967 (<= position (point-max))) | |
| 1968 (widen)) | |
| 1969 (goto-char position) | |
| 1970 (switch-to-buffer buffer))) | |
| 1971 | |
| 1972 | |
| 1973 (defcustom signal-error-on-buffer-boundary t | |
| 462 | 1974 "*If Non-nil, beep or signal an error when moving past buffer boundary. |
| 428 | 1975 The commands that honor this variable are |
| 1976 | |
| 1977 forward-char-command | |
| 1978 backward-char-command | |
| 1979 next-line | |
| 1980 previous-line | |
| 1981 scroll-up-command | |
| 1982 scroll-down-command" | |
| 1983 :type 'boolean | |
| 1984 :group 'editing-basics) | |
| 1985 | |
| 3361 | 1986 (defcustom next-line-add-newlines nil |
| 428 | 1987 "*If non-nil, `next-line' inserts newline when the point is at end of buffer. |
| 3361 | 1988 This behavior used to be the default, but is now considered an unnecessary and |
| 1989 unwanted side-effect." | |
| 428 | 1990 :type 'boolean |
| 1991 :group 'editing-basics) | |
| 1992 | |
| 442 | 1993 (defcustom shifted-motion-keys-select-region t |
| 1994 "*If non-nil, shifted motion keys select text, like in MS Windows. | |
| 462 | 1995 |
| 1996 More specifically, if a keystroke that matches one of the key | |
| 1997 specifications in `motion-keys-for-shifted-motion' is pressed along | |
| 1998 with the Shift key, and the command invoked moves the cursor and | |
| 1999 preserves the active region (see `zmacs-region-stays'), the | |
| 2000 intervening text will be added to the active region. | |
| 2001 | |
| 2002 When the region has been enabled or augmented as a result of a shifted | |
| 2003 motion key, an unshifted motion key will normally deselect the region. | |
| 2485 | 2004 However, if `unshifted-motion-keys-deselect-region' is nil, the region |
| 462 | 2005 will remain active, augmented by the characters moved over by this |
| 2006 motion key. | |
| 2007 | |
| 2008 This functionality is specifically interpreted in terms of keys, and | |
| 2009 *NOT* in terms of particular commands, because that produces the most | |
| 2010 intuitive behavior: `forward-char' will work with shifted motion | |
| 2011 when invoked by `right' but not `C-f', and user-written motion commands | |
| 2012 bound to motion keys will automatically work with shifted motion." | |
| 442 | 2013 :type 'boolean |
| 2014 :group 'editing-basics) | |
| 2015 | |
| 2016 (defcustom unshifted-motion-keys-deselect-region t | |
| 2017 "*If non-nil, unshifted motion keys deselect a shifted-motion region. | |
| 462 | 2018 This only occurs after a region has been selected or augmented using |
| 2019 shifted motion keys (not when using the traditional set-mark-then-move | |
| 2020 method), and has no effect if `shifted-motion-keys-select-region' is | |
| 2021 nil." | |
| 442 | 2022 :type 'boolean |
| 2023 :group 'editing-basics) | |
| 2024 | |
| 462 | 2025 (defcustom motion-keys-for-shifted-motion |
| 1261 | 2026 ;; meta-shift-home/end are NOT shifted motion commands. |
| 2027 '(left right up down (home) (control home) (meta control home) | |
| 2028 (end) (control end) (meta control end) prior next | |
| 2029 kp-left kp-right kp-up kp-down (kp-home) (control kp-home) | |
| 2030 (meta control kp-home) (kp-end) (control kp-end) (meta control kp-end) | |
| 2031 kp-prior kp-next) | |
| 462 | 2032 "*List of keys considered motion keys for the purpose of shifted selection. |
| 2033 When one of these keys is pressed along with the Shift key, and the | |
| 2034 command invoked moves the cursor and preserves the active region (see | |
| 2035 `zmacs-region-stays'), the intervening text will be added to the active | |
| 2036 region. See `shifted-motion-keys-select-region' for more details. | |
| 2037 | |
| 2038 Each entry should be a keysym or a list (MODIFIERS ... KEYSYM), | |
| 2039 i.e. zero or more modifiers followed by a keysym. When a keysym alone | |
| 2040 is given, a keystroke consisting of that keysym, with or without any | |
| 2041 modifiers, is considered a motion key. When the list form is given, | |
| 2042 only a keystroke with exactly those modifiers and no others (with the | |
| 2043 exception of the Shift key) is considered a motion key. | |
| 2044 | |
| 2045 NOTE: Currently, the keysym cannot be a non-alphabetic character key | |
| 2046 such as the `=/+' key. In any case, the shifted-motion paradigm does | |
| 2047 not make much sense with those keys. The keysym can, however, be an | |
| 2048 alphabetic key without problem, and you can specify the key using | |
| 2049 either a character or a symbol, uppercase or lowercase." | |
| 2050 :type '(repeat (choice (const :tag "normal cursor-pad (\"gray\") keys" | |
| 2051 :inline t | |
| 1261 | 2052 (left |
| 2053 right up down | |
| 2054 (home) (control home) (meta control home) | |
| 2055 (end) (control end) (meta control end) | |
| 2056 prior next)) | |
| 462 | 2057 (const :tag "keypad motion keys" |
| 2058 :inline t | |
| 1261 | 2059 (kp-left |
| 2060 kp-right kp-up kp-down | |
| 2061 (kp-home) (control kp-home) | |
| 2062 (meta control kp-home) | |
| 2063 (kp-end) (control kp-end) | |
| 2064 (meta control kp-end) | |
| 2065 kp-prior kp-next)) | |
| 462 | 2066 (const :tag "alphabetic motion keys" |
| 2067 :inline t | |
| 2068 ((control b) (control f) | |
| 2069 (control p) (control n) | |
| 2070 (control a) (control e) | |
| 2071 (control v) (meta v) | |
| 2072 (meta b) (meta f) | |
| 2073 (meta a) (meta e) | |
| 2074 (meta m) ; back-to-indentation | |
| 2075 (meta r) ; move-to-window-line | |
| 2076 (meta control b) (meta control f) | |
| 2077 (meta control p) (meta control n) | |
| 2078 (meta control a) (meta control e) | |
| 2079 (meta control d) ;; down-list | |
| 2080 (meta control u) ;; backward-up-list | |
| 2081 )) | |
| 2082 symbol)) | |
| 2083 :group 'editing-basics) | |
| 2084 | |
| 442 | 2085 (defun handle-pre-motion-command-current-command-is-motion () |
| 2086 (and (key-press-event-p last-input-event) | |
|
4869
e533a9912ef1
Eliminate funcalls, #'handle-pre-motion-command-current-command-is-motion
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
2087 (macrolet |
|
e533a9912ef1
Eliminate funcalls, #'handle-pre-motion-command-current-command-is-motion
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
2088 ((keysyms-equal (&rest args) |
|
e533a9912ef1
Eliminate funcalls, #'handle-pre-motion-command-current-command-is-motion
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
2089 `((lambda (a b) |
|
e533a9912ef1
Eliminate funcalls, #'handle-pre-motion-command-current-command-is-motion
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
2090 (when (and |
|
e533a9912ef1
Eliminate funcalls, #'handle-pre-motion-command-current-command-is-motion
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
2091 ;; As of now, none of the elements of |
|
e533a9912ef1
Eliminate funcalls, #'handle-pre-motion-command-current-command-is-motion
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
2092 ;; motion-keys-for-shifted-motion are non-symbols; |
|
e533a9912ef1
Eliminate funcalls, #'handle-pre-motion-command-current-command-is-motion
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
2093 ;; this redundant check saves a few hundred |
|
e533a9912ef1
Eliminate funcalls, #'handle-pre-motion-command-current-command-is-motion
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
2094 ;; funcalls on startup. |
|
e533a9912ef1
Eliminate funcalls, #'handle-pre-motion-command-current-command-is-motion
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
2095 (not (symbolp b)) |
|
e533a9912ef1
Eliminate funcalls, #'handle-pre-motion-command-current-command-is-motion
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
2096 (characterp b)) |
|
e533a9912ef1
Eliminate funcalls, #'handle-pre-motion-command-current-command-is-motion
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
2097 (setf (car char-list) b |
|
e533a9912ef1
Eliminate funcalls, #'handle-pre-motion-command-current-command-is-motion
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
2098 b (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
|
2099 (eq a b)) |
|
e533a9912ef1
Eliminate funcalls, #'handle-pre-motion-command-current-command-is-motion
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
2100 ,@args))) |
|
e533a9912ef1
Eliminate funcalls, #'handle-pre-motion-command-current-command-is-motion
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
2101 (loop |
|
e533a9912ef1
Eliminate funcalls, #'handle-pre-motion-command-current-command-is-motion
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
2102 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
|
2103 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
|
2104 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
|
2105 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
|
2106 ;; 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
|
2107 ;; time. |
|
e533a9912ef1
Eliminate funcalls, #'handle-pre-motion-command-current-command-is-motion
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
2108 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
|
2109 (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
|
2110 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
|
2111 thereis (if (listp keysym) |
|
e533a9912ef1
Eliminate funcalls, #'handle-pre-motion-command-current-command-is-motion
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
2112 (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
|
2113 (keysyms-equal |
|
e533a9912ef1
Eliminate funcalls, #'handle-pre-motion-command-current-command-is-motion
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
2114 key (car (last keysym)))) |
|
e533a9912ef1
Eliminate funcalls, #'handle-pre-motion-command-current-command-is-motion
Aidan Kehoe <kehoea@parhasard.net>
parents:
4783
diff
changeset
|
2115 (keysyms-equal key keysym)))))) |
| 444 | 2116 |
| 442 | 2117 (defun handle-pre-motion-command () |
| 462 | 2118 (if (and |
| 442 | 2119 (handle-pre-motion-command-current-command-is-motion) |
| 2120 zmacs-regions | |
| 2121 shifted-motion-keys-select-region | |
| 2122 (not (region-active-p)) | |
| 462 | 2123 ;; Special-case alphabetic keysyms, because the `shift' |
| 2124 ;; modifier does not appear on them. (Unfortunately, we have no | |
| 2125 ;; way of determining Shift-key status on non-alphabetic ASCII | |
| 2126 ;; keysyms. However, in this case, using Shift will invoke a | |
| 2127 ;; separate command from the non-shifted version, so the | |
| 2128 ;; "shifted motion" paradigm makes no sense.) | |
| 2129 (or (memq 'shift (event-modifiers last-input-event)) | |
| 2130 (let ((key (event-key last-input-event))) | |
| 2131 (and (characterp key) | |
| 2132 (not (eq key (downcase key))))))) | |
| 442 | 2133 (let ((in-shifted-motion-command t)) |
| 2134 (push-mark nil nil t)))) | |
| 2135 | |
| 2136 (defun handle-post-motion-command () | |
| 2137 (if | |
| 2138 (and | |
| 2139 (handle-pre-motion-command-current-command-is-motion) | |
| 2140 zmacs-regions | |
| 2141 (region-active-p)) | |
| 462 | 2142 ;; Special-case alphabetic keysyms, because the `shift' |
| 2143 ;; modifier does not appear on them. See above. | |
| 2144 (cond ((or (memq 'shift (event-modifiers last-input-event)) | |
| 2145 (let ((key (event-key last-input-event))) | |
| 2146 (and (characterp key) | |
| 2147 (not (eq key (downcase key)))))) | |
| 442 | 2148 (if shifted-motion-keys-select-region |
| 2149 (putf this-command-properties 'shifted-motion-command t)) | |
| 2150 (setq zmacs-region-stays t)) | |
| 2151 ((and (getf last-command-properties 'shifted-motion-command) | |
| 2152 unshifted-motion-keys-deselect-region) | |
| 487 | 2153 (setq zmacs-region-stays nil))))) |
| 442 | 2154 |
| 428 | 2155 (defun forward-char-command (&optional arg buffer) |
| 2156 "Move point right ARG characters (left if ARG negative) in BUFFER. | |
| 2157 On attempt to pass end of buffer, stop and signal `end-of-buffer'. | |
| 2158 On attempt to pass beginning of buffer, stop and signal `beginning-of-buffer'. | |
| 2159 Error signaling is suppressed if `signal-error-on-buffer-boundary' | |
| 462 | 2160 is nil. If BUFFER is nil, the current buffer is assumed. |
| 2161 | |
| 2162 The characters that are moved over may be added to the current selection | |
| 2163 \(i.e. active region) if the Shift key is held down, a motion key is used | |
| 2164 to invoke this command, and `shifted-motion-keys-select-region' is t; see | |
| 2165 the documentation for this variable for more details." | |
| 428 | 2166 (interactive "_p") |
| 2167 (if signal-error-on-buffer-boundary | |
| 2168 (forward-char arg buffer) | |
| 2169 (condition-case nil | |
| 2170 (forward-char arg buffer) | |
| 2171 (beginning-of-buffer nil) | |
| 2172 (end-of-buffer nil)))) | |
| 2173 | |
| 2174 (defun backward-char-command (&optional arg buffer) | |
| 2175 "Move point left ARG characters (right if ARG negative) in BUFFER. | |
| 2176 On attempt to pass end of buffer, stop and signal `end-of-buffer'. | |
| 2177 On attempt to pass beginning of buffer, stop and signal `beginning-of-buffer'. | |
| 2178 Error signaling is suppressed if `signal-error-on-buffer-boundary' | |
| 462 | 2179 is nil. If BUFFER is nil, the current buffer is assumed. |
| 2180 | |
| 2181 The characters that are moved over may be added to the current selection | |
| 2182 \(i.e. active region) if the Shift key is held down, a motion key is used | |
| 2183 to invoke this command, and `shifted-motion-keys-select-region' is t; see | |
| 2184 the documentation for this variable for more details." | |
| 428 | 2185 (interactive "_p") |
| 2186 (if signal-error-on-buffer-boundary | |
| 2187 (backward-char arg buffer) | |
| 2188 (condition-case nil | |
| 2189 (backward-char arg buffer) | |
| 2190 (beginning-of-buffer nil) | |
| 2191 (end-of-buffer nil)))) | |
| 2192 | |
| 442 | 2193 (defun scroll-up-one () |
| 2194 "Scroll text of current window upward one line. | |
| 2195 On attempt to scroll past end of buffer, `end-of-buffer' is signaled. | |
| 2196 On attempt to scroll past beginning of buffer, `beginning-of-buffer' is | |
| 2197 signaled. | |
| 2198 | |
| 2199 If `signal-error-on-buffer-boundary' is nil, attempts to scroll past buffer | |
| 2200 boundaries do not cause an error to be signaled." | |
| 2201 (interactive "_") | |
| 2202 (scroll-up-command 1)) | |
| 2203 | |
| 428 | 2204 (defun scroll-up-command (&optional n) |
| 444 | 2205 "Scroll current window upward N lines; or near full screen if N is nil. |
| 428 | 2206 A near full screen is `next-screen-context-lines' less than a full screen. |
| 444 | 2207 Negative N means scroll downward. |
| 428 | 2208 When calling from a program, supply a number as argument or nil. |
| 2209 On attempt to scroll past end of buffer, `end-of-buffer' is signaled. | |
| 2210 On attempt to scroll past beginning of buffer, `beginning-of-buffer' is | |
| 2211 signaled. | |
| 2212 | |
| 462 | 2213 The characters that are moved over may be added to the current selection |
| 2214 \(i.e. active region) if the Shift key is held down, a motion key is used | |
| 2215 to invoke this command, and `shifted-motion-keys-select-region' is t; see | |
| 2216 the documentation for this variable for more details. | |
| 2217 | |
| 428 | 2218 If `signal-error-on-buffer-boundary' is nil, attempts to scroll past buffer |
| 2219 boundaries do not cause an error to be signaled." | |
| 2220 (interactive "_P") | |
| 2221 (if signal-error-on-buffer-boundary | |
| 2222 (scroll-up n) | |
| 2223 (condition-case nil | |
| 2224 (scroll-up n) | |
| 2225 (beginning-of-buffer nil) | |
| 2226 (end-of-buffer nil)))) | |
| 2227 | |
| 442 | 2228 (defun scroll-down-one () |
| 2229 "Scroll text of current window downward one line. | |
| 2230 On attempt to scroll past end of buffer, `end-of-buffer' is signaled. | |
| 2231 On attempt to scroll past beginning of buffer, `beginning-of-buffer' is | |
| 2232 signaled. | |
| 2233 | |
| 2234 If `signal-error-on-buffer-boundary' is nil, attempts to scroll past buffer | |
| 2235 boundaries do not cause an error to be signaled." | |
| 2236 (interactive "_") | |
| 2237 (scroll-down-command 1)) | |
| 2238 | |
| 428 | 2239 (defun scroll-down-command (&optional n) |
| 444 | 2240 "Scroll current window downward N lines; or near full screen if N is nil. |
| 428 | 2241 A near full screen is `next-screen-context-lines' less than a full screen. |
| 444 | 2242 Negative N means scroll upward. |
| 428 | 2243 When calling from a program, supply a number as argument or nil. |
| 2244 On attempt to scroll past end of buffer, `end-of-buffer' is signaled. | |
| 2245 On attempt to scroll past beginning of buffer, `beginning-of-buffer' is | |
| 2246 signaled. | |
| 2247 | |
| 2248 If `signal-error-on-buffer-boundary' is nil, attempts to scroll past buffer | |
| 462 | 2249 boundaries do not cause an error to be signaled. |
| 2250 | |
| 2251 The characters that are moved over may be added to the current selection | |
| 2252 \(i.e. active region) if the Shift key is held down, a motion key is used | |
| 2253 to invoke this command, and `shifted-motion-keys-select-region' is t; see | |
| 2254 the documentation for this variable for more details." | |
| 428 | 2255 (interactive "_P") |
| 2256 (if signal-error-on-buffer-boundary | |
| 2257 (scroll-down n) | |
| 2258 (condition-case nil | |
| 2259 (scroll-down n) | |
| 2260 (beginning-of-buffer nil) | |
| 2261 (end-of-buffer nil)))) | |
| 2262 | |
| 444 | 2263 (defun next-line (count) |
| 2264 "Move cursor vertically down COUNT lines. | |
| 428 | 2265 If there is no character in the target line exactly under the current column, |
| 2266 the cursor is positioned after the character in that line which spans this | |
| 2267 column, or at the end of the line if it is not long enough. | |
| 2268 | |
| 2269 If there is no line in the buffer after this one, behavior depends on the | |
| 2270 value of `next-line-add-newlines'. If non-nil, it inserts a newline character | |
| 2271 to create a line, and moves the cursor to that line. Otherwise it moves the | |
| 2439 | 2272 cursor to the end of the buffer. If `signal-error-on-buffer-boundary' is |
| 2273 non-nil and you attempt to move past a buffer boundary, XEmacs will ring the | |
| 2274 bell using `ding'. | |
| 428 | 2275 |
| 2276 The command \\[set-goal-column] can be used to create | |
| 2277 a semipermanent goal column to which this command always moves. | |
| 2278 Then it does not try to move vertically. This goal column is stored | |
| 2279 in `goal-column', which is nil when there is none. | |
| 2280 | |
| 462 | 2281 The characters that are moved over may be added to the current selection |
| 2282 \(i.e. active region) if the Shift key is held down, a motion key is used | |
| 2283 to invoke this command, and `shifted-motion-keys-select-region' is t; see | |
| 2284 the documentation for this variable for more details. | |
| 2285 | |
| 428 | 2286 If you are thinking of using this in a Lisp program, consider |
| 2287 using `forward-line' instead. It is usually easier to use | |
| 2288 and more reliable (no dependence on goal column, etc.)." | |
| 442 | 2289 (interactive "_p") |
| 444 | 2290 (if (and next-line-add-newlines (= count 1)) |
| 428 | 2291 (let ((opoint (point))) |
| 2292 (end-of-line) | |
| 2293 (if (eobp) | |
| 2294 (newline 1) | |
| 2295 (goto-char opoint) | |
| 444 | 2296 (line-move count))) |
| 428 | 2297 (if (interactive-p) |
| 2298 ;; XEmacs: Not sure what to do about this. It's inconsistent. -sb | |
| 2299 (condition-case nil | |
| 444 | 2300 (line-move count) |
| 428 | 2301 ((beginning-of-buffer end-of-buffer) |
| 2302 (when signal-error-on-buffer-boundary | |
| 2303 (ding nil 'buffer-bound)))) | |
| 444 | 2304 (line-move count))) |
| 428 | 2305 nil) |
| 2306 | |
| 444 | 2307 (defun previous-line (count) |
| 2308 "Move cursor vertically up COUNT lines. | |
| 428 | 2309 If there is no character in the target line exactly over the current column, |
| 2310 the cursor is positioned after the character in that line which spans this | |
| 2311 column, or at the end of the line if it is not long enough. | |
| 2312 | |
| 2313 The command \\[set-goal-column] can be used to create | |
| 2314 a semipermanent goal column to which this command always moves. | |
| 2315 Then it does not try to move vertically. | |
| 2316 | |
| 462 | 2317 The characters that are moved over may be added to the current selection |
| 2318 \(i.e. active region) if the Shift key is held down, a motion key is used | |
| 2319 to invoke this command, and `shifted-motion-keys-select-region' is t; see | |
| 2320 the documentation for this variable for more details. | |
| 2321 | |
| 2439 | 2322 If `signal-error-on-buffer-boundary' is non-nil and you attempt to move past |
| 2323 a buffer boundary, XEmacs will ring the bell using `ding'. | |
| 2324 | |
| 428 | 2325 If you are thinking of using this in a Lisp program, consider using |
| 2326 `forward-line' with a negative argument instead. It is usually easier | |
| 2327 to use and more reliable (no dependence on goal column, etc.)." | |
| 442 | 2328 (interactive "_p") |
| 428 | 2329 (if (interactive-p) |
| 2330 (condition-case nil | |
| 444 | 2331 (line-move (- count)) |
| 428 | 2332 ((beginning-of-buffer end-of-buffer) |
| 2333 (when signal-error-on-buffer-boundary ; XEmacs | |
| 2334 (ding nil 'buffer-bound)))) | |
| 444 | 2335 (line-move (- count))) |
| 428 | 2336 nil) |
| 2337 | |
| 442 | 2338 (defcustom block-movement-size 6 |
| 2339 "*Number of lines that \"block movement\" commands (\\[forward-block-of-lines], \\[backward-block-of-lines]) move by." | |
| 2340 :type 'integer | |
| 2341 :group 'editing-basics) | |
| 2342 | |
| 2343 (defun backward-block-of-lines () | |
| 2344 "Move backward by one \"block\" of lines. | |
| 2345 The number of lines that make up a block is controlled by | |
| 462 | 2346 `block-movement-size', which defaults to 6. |
| 2347 | |
| 2348 The characters that are moved over may be added to the current selection | |
| 2349 \(i.e. active region) if the Shift key is held down, a motion key is used | |
| 2350 to invoke this command, and `shifted-motion-keys-select-region' is t; see | |
| 2351 the documentation for this variable for more details." | |
| 442 | 2352 (interactive "_") |
| 2353 (forward-line (- block-movement-size))) | |
| 2354 | |
| 2355 (defun forward-block-of-lines () | |
| 2356 "Move forward by one \"block\" of lines. | |
| 2357 The number of lines that make up a block is controlled by | |
| 462 | 2358 `block-movement-size', which defaults to 6. |
| 2359 | |
| 2360 The characters that are moved over may be added to the current selection | |
| 2361 \(i.e. active region) if the Shift key is held down, a motion key is used | |
| 2362 to invoke this command, and `shifted-motion-keys-select-region' is t; see | |
| 2363 the documentation for this variable for more details." | |
| 442 | 2364 (interactive "_") |
| 2365 (forward-line block-movement-size)) | |
| 2366 | |
| 428 | 2367 (defcustom track-eol nil |
| 2368 "*Non-nil means vertical motion starting at end of line keeps to ends of lines. | |
| 2369 This means moving to the end of each line moved onto. | |
| 2370 The beginning of a blank line does not count as the end of a line." | |
| 2371 :type 'boolean | |
| 2372 :group 'editing-basics) | |
| 2373 | |
| 2374 (defcustom goal-column nil | |
| 2375 "*Semipermanent goal column for vertical motion, as set by \\[set-goal-column], or nil." | |
| 2376 :type '(choice integer (const :tag "None" nil)) | |
| 2377 :group 'editing-basics) | |
| 2378 (make-variable-buffer-local 'goal-column) | |
| 2379 | |
| 2380 (defvar temporary-goal-column 0 | |
| 2381 "Current goal column for vertical motion. | |
| 2382 It is the column where point was | |
| 2383 at the start of current run of vertical motion commands. | |
| 2384 When the `track-eol' feature is doing its job, the value is 9999.") | |
| 2385 (make-variable-buffer-local 'temporary-goal-column) | |
| 2386 | |
| 2387 ;XEmacs: not yet ported, so avoid compiler warnings | |
| 2388 (eval-when-compile | |
| 2389 (defvar inhibit-point-motion-hooks)) | |
| 2390 | |
| 2391 (defcustom line-move-ignore-invisible nil | |
| 2392 "*Non-nil means \\[next-line] and \\[previous-line] ignore invisible lines. | |
| 2393 Use with care, as it slows down movement significantly. Outline mode sets this." | |
| 2394 :type 'boolean | |
| 2395 :group 'editing-basics) | |
| 2396 | |
| 2397 ;; This is the guts of next-line and previous-line. | |
| 444 | 2398 ;; Count says how many lines to move. |
| 2399 (defun line-move (count) | |
| 428 | 2400 ;; Don't run any point-motion hooks, and disregard intangibility, |
| 2401 ;; for intermediate positions. | |
| 2402 (let ((inhibit-point-motion-hooks t) | |
| 2403 (opoint (point)) | |
| 2404 new) | |
| 2405 (unwind-protect | |
| 2406 (progn | |
| 2407 (if (not (or (eq last-command 'next-line) | |
| 2408 (eq last-command 'previous-line))) | |
| 2409 (setq temporary-goal-column | |
| 2410 (if (and track-eol (eolp) | |
| 444 | 2411 ;; Don't count start of empty line as end of line |
| 428 | 2412 ;; unless we just did explicit end-of-line. |
| 2413 (or (not (bolp)) (eq last-command 'end-of-line))) | |
| 2414 9999 | |
| 2415 (current-column)))) | |
| 2416 (if (and (not (integerp selective-display)) | |
| 2417 (not line-move-ignore-invisible)) | |
| 2418 ;; Use just newline characters. | |
| 444 | 2419 (or (if (> count 0) |
| 2420 (progn (if (> count 1) (forward-line (1- count))) | |
| 2421 ;; This way of moving forward COUNT lines | |
| 428 | 2422 ;; verifies that we have a newline after the last one. |
| 2423 ;; It doesn't get confused by intangible text. | |
| 2424 (end-of-line) | |
| 2425 (zerop (forward-line 1))) | |
| 444 | 2426 (and (zerop (forward-line count)) |
| 428 | 2427 (bolp))) |
| 444 | 2428 (signal (if (< count 0) |
| 428 | 2429 'beginning-of-buffer |
| 2430 'end-of-buffer) | |
| 2431 nil)) | |
| 444 | 2432 ;; Move by count lines, but ignore invisible ones. |
| 2433 (while (> count 0) | |
| 428 | 2434 (end-of-line) |
| 2435 (and (zerop (vertical-motion 1)) | |
| 2436 (signal 'end-of-buffer nil)) | |
| 2437 ;; If the following character is currently invisible, | |
| 2438 ;; skip all characters with that same `invisible' property value. | |
| 2439 (while (and (not (eobp)) | |
| 2440 (let ((prop | |
| 2441 (get-char-property (point) 'invisible))) | |
| 2442 (if (eq buffer-invisibility-spec t) | |
| 2443 prop | |
| 2444 (or (memq prop buffer-invisibility-spec) | |
| 2445 (assq prop buffer-invisibility-spec))))) | |
| 2446 (if (get-text-property (point) 'invisible) | |
| 2447 (goto-char (next-single-property-change (point) 'invisible)) | |
| 2448 (goto-char (next-extent-change (point))))) ; XEmacs | |
| 444 | 2449 (setq count (1- count))) |
| 2450 (while (< count 0) | |
| 428 | 2451 (beginning-of-line) |
| 2452 (and (zerop (vertical-motion -1)) | |
| 2453 (signal 'beginning-of-buffer nil)) | |
| 2454 (while (and (not (bobp)) | |
| 2455 (let ((prop | |
| 2456 (get-char-property (1- (point)) 'invisible))) | |
| 2457 (if (eq buffer-invisibility-spec t) | |
| 2458 prop | |
| 2459 (or (memq prop buffer-invisibility-spec) | |
| 2460 (assq prop buffer-invisibility-spec))))) | |
| 2461 (if (get-text-property (1- (point)) 'invisible) | |
| 2462 (goto-char (previous-single-property-change (point) 'invisible)) | |
| 2463 (goto-char (previous-extent-change (point))))) ; XEmacs | |
| 444 | 2464 (setq count (1+ count)))) |
| 428 | 2465 (move-to-column (or goal-column temporary-goal-column))) |
| 2466 ;; Remember where we moved to, go back home, | |
| 2467 ;; then do the motion over again | |
| 2468 ;; in just one step, with intangibility and point-motion hooks | |
| 2469 ;; enabled this time. | |
| 2470 (setq new (point)) | |
| 2471 (goto-char opoint) | |
| 2472 (setq inhibit-point-motion-hooks nil) | |
| 2473 (goto-char new))) | |
| 2474 nil) | |
| 2475 | |
| 2476 ;;; Many people have said they rarely use this feature, and often type | |
| 2477 ;;; it by accident. Maybe it shouldn't even be on a key. | |
| 2478 ;; It's not on a key, as of 20.2. So no need for this. | |
| 2479 ;(put 'set-goal-column 'disabled t) | |
| 2480 | |
| 444 | 2481 (defun set-goal-column (column) |
| 428 | 2482 "Set the current horizontal position as a goal for \\[next-line] and \\[previous-line]. |
| 2483 Those commands will move to this position in the line moved to | |
| 2484 rather than trying to keep the same horizontal position. | |
| 2485 With a non-nil argument, clears out the goal column | |
| 2486 so that \\[next-line] and \\[previous-line] resume vertical motion. | |
| 2487 The goal column is stored in the variable `goal-column'." | |
| 2488 (interactive "_P") ; XEmacs | |
| 444 | 2489 (if column |
| 428 | 2490 (progn |
| 2491 (setq goal-column nil) | |
| 2492 (display-message 'command "No goal column")) | |
| 2493 (setq goal-column (current-column)) | |
| 2494 (lmessage 'command | |
| 444 | 2495 "Goal column %d (use %s with a prefix arg to unset it)" |
| 428 | 2496 goal-column |
| 2497 (substitute-command-keys "\\[set-goal-column]"))) | |
| 2498 nil) | |
| 2499 | |
| 2500 ;; deleted FSFmacs terminal randomness hscroll-point-visible stuff. | |
| 2501 ;; hscroll-step | |
| 2502 ;; hscroll-point-visible | |
| 2503 ;; hscroll-window-column | |
| 2504 ;; right-arrow | |
| 2505 ;; left-arrow | |
| 2506 | |
| 2507 (defun scroll-other-window-down (lines) | |
| 2508 "Scroll the \"other window\" down. | |
| 2509 For more details, see the documentation for `scroll-other-window'." | |
| 2510 (interactive "P") | |
| 2511 (scroll-other-window | |
| 2512 ;; Just invert the argument's meaning. | |
| 2513 ;; We can do that without knowing which window it will be. | |
| 2514 (if (eq lines '-) nil | |
| 2515 (if (null lines) '- | |
| 2516 (- (prefix-numeric-value lines)))))) | |
| 2517 ;(define-key esc-map [?\C-\S-v] 'scroll-other-window-down) | |
| 2518 | |
| 2519 (defun beginning-of-buffer-other-window (arg) | |
| 2520 "Move point to the beginning of the buffer in the other window. | |
| 2521 Leave mark at previous position. | |
| 2522 With arg N, put point N/10 of the way from the true beginning." | |
| 2523 (interactive "P") | |
| 2524 (let ((orig-window (selected-window)) | |
| 2525 (window (other-window-for-scrolling))) | |
| 2526 ;; We use unwind-protect rather than save-window-excursion | |
| 2527 ;; because the latter would preserve the things we want to change. | |
| 2528 (unwind-protect | |
| 2529 (progn | |
| 2530 (select-window window) | |
| 2531 ;; Set point and mark in that window's buffer. | |
| 2532 (beginning-of-buffer arg) | |
| 2533 ;; Set point accordingly. | |
| 2534 (recenter '(t))) | |
| 2535 (select-window orig-window)))) | |
| 2536 | |
| 2537 (defun end-of-buffer-other-window (arg) | |
| 2538 "Move point to the end of the buffer in the other window. | |
| 2539 Leave mark at previous position. | |
| 2540 With arg N, put point N/10 of the way from the true end." | |
| 2541 (interactive "P") | |
| 2542 ;; See beginning-of-buffer-other-window for comments. | |
| 2543 (let ((orig-window (selected-window)) | |
| 2544 (window (other-window-for-scrolling))) | |
| 2545 (unwind-protect | |
| 2546 (progn | |
| 2547 (select-window window) | |
| 2548 (end-of-buffer arg) | |
| 2549 (recenter '(t))) | |
| 2550 (select-window orig-window)))) | |
| 2551 | |
| 2552 (defun transpose-chars (arg) | |
| 2553 "Interchange characters around point, moving forward one character. | |
| 2554 With prefix arg ARG, effect is to take character before point | |
| 2555 and drag it forward past ARG other characters (backward if ARG negative). | |
| 2556 If no argument and at end of line, the previous two chars are exchanged." | |
| 2557 (interactive "*P") | |
| 446 | 2558 (and (null arg) (eolp) (backward-char 1)) |
| 428 | 2559 (transpose-subr 'forward-char (prefix-numeric-value arg))) |
| 2560 | |
| 2561 ;;; A very old implementation of transpose-chars from the old days ... | |
| 2562 (defun transpose-preceding-chars (arg) | |
| 2563 "Interchange characters before point. | |
| 2564 With prefix arg ARG, effect is to take character before point | |
| 2565 and drag it forward past ARG other characters (backward if ARG negative). | |
| 2566 If no argument and not at start of line, the previous two chars are exchanged." | |
| 2567 (interactive "*P") | |
| 446 | 2568 (and (null arg) (not (bolp)) (backward-char 1)) |
| 428 | 2569 (transpose-subr 'forward-char (prefix-numeric-value arg))) |
| 2570 | |
| 2571 | |
| 2572 (defun transpose-words (arg) | |
| 2573 "Interchange words around point, leaving point at end of them. | |
| 2574 With prefix arg ARG, effect is to take word before or around point | |
| 2575 and drag it forward past ARG other words (backward if ARG negative). | |
| 2576 If ARG is zero, the words around or after point and around or after mark | |
| 2577 are interchanged." | |
| 2578 (interactive "*p") | |
| 2579 (transpose-subr 'forward-word arg)) | |
| 2580 | |
| 2581 (defun transpose-sexps (arg) | |
| 2582 "Like \\[transpose-words] but applies to sexps. | |
| 2583 Does not work on a sexp that point is in the middle of | |
| 2584 if it is a list or string." | |
| 2585 (interactive "*p") | |
| 2586 (transpose-subr 'forward-sexp arg)) | |
| 2587 | |
| 613 | 2588 (defun Simple-forward-line-creating-newline () |
| 2589 ;; Move forward over a line, | |
| 2590 ;; but create a newline if none exists yet. | |
| 2591 (end-of-line) | |
| 2592 (if (eobp) | |
| 2593 (newline) | |
| 2594 (forward-char 1))) | |
| 2595 | |
| 2596 (defun Simple-transpose-lines-mover (arg) | |
| 2597 (if (= arg 1) | |
| 2598 (Simple-forward-line-creating-newline) | |
| 2599 (forward-line arg))) | |
| 2600 | |
| 428 | 2601 (defun transpose-lines (arg) |
| 2602 "Exchange current line and previous line, leaving point after both. | |
| 2603 With argument ARG, takes previous line and moves it past ARG lines. | |
| 2604 With argument 0, interchanges line point is in with line mark is in." | |
| 2605 (interactive "*p") | |
| 613 | 2606 (transpose-subr 'Simple-transpose-lines-mover arg)) |
| 428 | 2607 |
| 442 | 2608 (defun transpose-line-up (arg) |
| 2609 "Move current line one line up, leaving point at beginning of that line. | |
| 613 | 2610 With argument ARG, move it ARG lines up. This can be run repeatedly |
| 2611 to move the current line up a number of lines. | |
| 2612 | |
| 2613 If the region is active, move the region up one line (or ARG lines, | |
| 2614 if specified). The region will not be selected afterwards, but this | |
| 2615 command can still be run repeatedly to move the region up a number | |
| 2616 of lines." | |
| 442 | 2617 (interactive "*p") |
| 613 | 2618 (transpose-line-down (- arg))) |
| 442 | 2619 |
| 2620 (defun transpose-line-down (arg) | |
| 2621 "Move current line one line down, leaving point at beginning of that line. | |
| 613 | 2622 With argument ARG, move it ARG lines down. This can be run repeatedly |
| 2623 to move the current line down a number of lines. | |
| 2624 | |
| 2625 If the region is active, move the region down one line (or ARG lines, | |
| 2626 if specified). The region will not be selected afterwards, but this | |
| 2627 command can still be run repeatedly to move the region down a number | |
| 2628 of lines." | |
| 442 | 2629 (interactive "*p") |
| 613 | 2630 (if (or (region-active-p) |
| 2631 (getf last-command-properties 'transpose-region-by-line-command)) | |
| 2632 (progn | |
| 2633 (transpose-subr 'Simple-transpose-lines-mover arg t) | |
| 2634 (putf this-command-properties 'transpose-region-by-line-command t)) | |
| 2635 (Simple-forward-line-creating-newline) | |
| 2636 (transpose-subr 'Simple-transpose-lines-mover arg) | |
| 2637 (forward-line -1))) | |
| 2638 | |
| 2639 (defun transpose-subr (mover arg &optional move-region) | |
| 428 | 2640 (let (start1 end1 start2 end2) |
| 442 | 2641 ;; XEmacs -- use flet instead of defining a separate function and |
| 613 | 2642 ;; relying on dynamic scope; use (mark t) etc; add code to support |
| 2643 ;; the new MOVE-REGION arg. | |
| 442 | 2644 (flet ((transpose-subr-1 () |
| 2645 (if (> (min end1 end2) (max start1 start2)) | |
| 2646 (error "Don't have two things to transpose")) | |
| 2647 (let ((word1 (buffer-substring start1 end1)) | |
| 2648 (word2 (buffer-substring start2 end2))) | |
| 2649 (delete-region start2 end2) | |
| 2650 (goto-char start2) | |
| 2651 (insert word1) | |
| 2652 (goto-char (if (< start1 start2) start1 | |
| 2653 (+ start1 (- (length word1) (length word2))))) | |
| 2654 (delete-char (length word1)) | |
| 2655 (insert word2)))) | |
| 2656 (if (= arg 0) | |
| 2657 (progn | |
| 2658 (save-excursion | |
| 2659 (funcall mover 1) | |
| 2660 (setq end2 (point)) | |
| 2661 (funcall mover -1) | |
| 2662 (setq start2 (point)) | |
| 613 | 2663 (goto-char (mark t)) |
| 442 | 2664 (funcall mover 1) |
| 2665 (setq end1 (point)) | |
| 2666 (funcall mover -1) | |
| 2667 (setq start1 (point)) | |
| 2668 (transpose-subr-1)) | |
| 613 | 2669 (exchange-point-and-mark t))) |
| 2670 (if move-region | |
| 2671 (let ((rbeg (region-beginning)) | |
| 2672 (rend (region-end))) | |
| 2673 (while (> arg 0) | |
| 2674 (goto-char rend) | |
| 2675 (funcall mover 1) | |
| 2676 (setq end2 (point)) | |
| 2677 (funcall mover -1) | |
| 2678 (setq start2 (point)) | |
| 2679 (setq start1 rbeg end1 rend) | |
| 2680 (transpose-subr-1) | |
| 2681 (incf rbeg (- end2 start2)) | |
| 2682 (incf rend (- end2 start2)) | |
| 2683 (setq arg (1- arg))) | |
| 2684 (while (< arg 0) | |
| 2685 (goto-char rbeg) | |
| 2686 (funcall mover -1) | |
| 2687 (setq start1 (point)) | |
| 2688 (funcall mover 1) | |
| 2689 (setq end1 (point)) | |
| 2690 (setq start2 rbeg end2 rend) | |
| 2691 (transpose-subr-1) | |
| 2692 (decf rbeg (- end1 start1)) | |
| 2693 (decf rend (- end1 start1)) | |
| 2694 (setq arg (1+ arg))) | |
| 2695 (set-mark rbeg) | |
| 2696 (goto-char rend)) | |
| 2697 (while (> arg 0) | |
| 2698 (funcall mover -1) | |
| 2699 (setq start1 (point)) | |
| 2700 (funcall mover 1) | |
| 2701 (setq end1 (point)) | |
| 2702 (funcall mover 1) | |
| 2703 (setq end2 (point)) | |
| 2704 (funcall mover -1) | |
| 2705 (setq start2 (point)) | |
| 2706 (transpose-subr-1) | |
| 2707 (goto-char end2) | |
| 2708 (setq arg (1- arg))) | |
| 2709 (while (< arg 0) | |
| 2710 (funcall mover -1) | |
| 2711 (setq start2 (point)) | |
| 2712 (funcall mover -1) | |
| 2713 (setq start1 (point)) | |
| 2714 (funcall mover 1) | |
| 2715 (setq end1 (point)) | |
| 2716 (funcall mover 1) | |
| 2717 (setq end2 (point)) | |
| 2718 (transpose-subr-1) | |
| 2719 (setq arg (1+ arg))))))) | |
| 442 | 2720 |
| 428 | 2721 |
| 2722 ;; XEmacs | |
| 2723 (defun prefix-region (prefix) | |
| 2724 "Add a prefix string to each line between mark and point." | |
| 2725 (interactive "sPrefix string: ") | |
| 2726 (if prefix | |
| 2727 (let ((count (count-lines (mark) (point)))) | |
| 2728 (goto-char (min (mark) (point))) | |
| 2729 (while (> count 0) | |
| 2730 (setq count (1- count)) | |
| 2731 (beginning-of-line 1) | |
| 2732 (insert prefix) | |
| 2733 (end-of-line 1) | |
| 2734 (forward-char 1))))) | |
| 2735 | |
| 2736 | |
| 446 | 2737 (defun backward-word (&optional count buffer) |
| 2738 "Move point backward COUNT words (forward if COUNT is negative). | |
| 2739 Normally t is returned, but if an edge of the buffer is reached, | |
| 2740 point is left there and nil is returned. | |
| 2741 | |
| 462 | 2742 COUNT defaults to 1, and BUFFER defaults to the current buffer. |
| 2743 | |
| 2744 The characters that are moved over may be added to the current selection | |
| 2745 \(i.e. active region) if the Shift key is held down, a motion key is used | |
| 2746 to invoke this command, and `shifted-motion-keys-select-region' is t; see | |
| 2747 the documentation for this variable for more details." | |
| 446 | 2748 (interactive "_p") |
| 2749 (forward-word (- (or count 1)) buffer)) | |
| 2750 | |
| 2751 (defun mark-word (&optional count) | |
| 2752 "Mark the text from point until encountering the end of a word. | |
| 2753 With optional argument COUNT, mark COUNT words." | |
| 428 | 2754 (interactive "p") |
| 446 | 2755 (mark-something 'mark-word 'forward-word count)) |
| 2756 | |
| 844 | 2757 (defcustom kill-word-into-kill-ring t |
| 2758 "*Non-nil means `kill-word' saves word killed into kill ring. | |
| 2759 \(Normally, this also affects the clipboard.) | |
| 2760 Nil means word is just deleted, without being remembered. | |
| 2761 This also applies to `backward-kill-word' and `backward-or-forward-kill-word'." | |
| 2762 :type 'boolean | |
| 2763 :group 'editing-basics) | |
| 2764 | |
| 446 | 2765 (defun kill-word (&optional count) |
| 428 | 2766 "Kill characters forward until encountering the end of a word. |
| 446 | 2767 With optional argument COUNT, do this that many times." |
| 2768 (interactive "*p") | |
| 844 | 2769 (if kill-word-into-kill-ring |
| 2770 (kill-region (point) (save-excursion (forward-word count) (point))) | |
| 2771 (delete-region (point) (save-excursion (forward-word count) (point))))) | |
| 446 | 2772 |
| 2773 (defun backward-kill-word (&optional count) | |
| 2774 "Kill characters backward until encountering the end of a word. | |
| 428 | 2775 With argument, do this that many times." |
| 2776 (interactive "*p") | |
| 446 | 2777 (kill-word (- (or count 1)))) |
| 428 | 2778 |
| 2779 (defun current-word (&optional strict) | |
| 2780 "Return the word point is on (or a nearby word) as a string. | |
| 2781 If optional arg STRICT is non-nil, return nil unless point is within | |
| 2782 or adjacent to a word. | |
| 2783 If point is not between two word-constituent characters, but immediately | |
| 2784 follows one, move back first. | |
| 2785 Otherwise, if point precedes a word constituent, move forward first. | |
| 2786 Otherwise, move backwards until a word constituent is found and get that word; | |
| 2787 if you a newlines is reached first, move forward instead." | |
| 2788 (save-excursion | |
| 2789 (let ((oldpoint (point)) (start (point)) (end (point))) | |
| 2790 (skip-syntax-backward "w_") (setq start (point)) | |
| 2791 (goto-char oldpoint) | |
| 2792 (skip-syntax-forward "w_") (setq end (point)) | |
| 2793 (if (and (eq start oldpoint) (eq end oldpoint)) | |
| 2794 ;; Point is neither within nor adjacent to a word. | |
| 2795 (and (not strict) | |
| 2796 (progn | |
| 2797 ;; Look for preceding word in same line. | |
| 2798 (skip-syntax-backward "^w_" | |
| 2799 (save-excursion | |
| 2800 (beginning-of-line) (point))) | |
| 2801 (if (bolp) | |
| 2802 ;; No preceding word in same line. | |
| 2803 ;; Look for following word in same line. | |
| 2804 (progn | |
| 2805 (skip-syntax-forward "^w_" | |
| 2806 (save-excursion | |
| 2807 (end-of-line) (point))) | |
| 2808 (setq start (point)) | |
| 2809 (skip-syntax-forward "w_") | |
| 2810 (setq end (point))) | |
| 2811 (setq end (point)) | |
| 2812 (skip-syntax-backward "w_") | |
| 2813 (setq start (point))) | |
| 2814 (buffer-substring start end))) | |
| 2815 (buffer-substring start end))))) | |
| 2816 | |
| 2817 (defcustom fill-prefix nil | |
| 2818 "*String for filling to insert at front of new line, or nil for none. | |
| 2819 Setting this variable automatically makes it local to the current buffer." | |
| 2820 :type '(choice (const :tag "None" nil) | |
| 2821 string) | |
| 2822 :group 'fill) | |
| 2823 (make-variable-buffer-local 'fill-prefix) | |
| 2824 | |
| 2825 (defcustom auto-fill-inhibit-regexp nil | |
| 2826 "*Regexp to match lines which should not be auto-filled." | |
| 2827 :type '(choice (const :tag "None" nil) | |
| 2828 regexp) | |
| 2829 :group 'fill) | |
| 2830 | |
| 2831 (defvar comment-line-break-function 'indent-new-comment-line | |
| 2832 "*Mode-specific function which line breaks and continues a comment. | |
| 2833 | |
| 2834 This function is only called during auto-filling of a comment section. | |
| 2835 The function should take a single optional argument which is a flag | |
| 2836 indicating whether soft newlines should be inserted.") | |
| 2837 | |
| 2838 ;; This function is the auto-fill-function of a buffer | |
| 2839 ;; when Auto-Fill mode is enabled. | |
| 2840 ;; It returns t if it really did any work. | |
| 2841 ;; XEmacs: This function is totally different. | |
| 2842 (defun do-auto-fill () | |
| 2843 (let (give-up) | |
| 2844 (or (and auto-fill-inhibit-regexp | |
| 2845 (save-excursion (beginning-of-line) | |
| 2846 (looking-at auto-fill-inhibit-regexp))) | |
| 2847 (while (and (not give-up) (> (current-column) fill-column)) | |
| 2848 ;; Determine where to split the line. | |
| 2849 (let ((fill-prefix fill-prefix) | |
| 2850 (fill-point | |
| 2851 (let ((opoint (point)) | |
| 2852 bounce | |
| 502 | 2853 (re-break-point ;; Kinsoku processing |
| 2854 (if (featurep 'mule) | |
| 771 | 2855 (with-boundp 'word-across-newline |
| 2856 (concat "[ \t\n]\\|" word-across-newline | |
| 2857 ".\\|." word-across-newline)) | |
| 502 | 2858 "[ \t\n]")) |
| 428 | 2859 (first t)) |
| 2860 (save-excursion | |
| 2861 (move-to-column (1+ fill-column)) | |
| 2862 ;; Move back to a word boundary. | |
| 2863 (while (or first | |
| 2864 ;; If this is after period and a single space, | |
| 2865 ;; move back once more--we don't want to break | |
| 2866 ;; the line there and make it look like a | |
| 2867 ;; sentence end. | |
| 2868 (and (not (bobp)) | |
| 2869 (not bounce) | |
| 2870 sentence-end-double-space | |
| 446 | 2871 (save-excursion (backward-char 1) |
| 428 | 2872 (and (looking-at "\\. ") |
| 2873 (not (looking-at "\\. ")))))) | |
| 2874 (setq first nil) | |
| 502 | 2875 ;; XEmacs: change for Kinsoku processing |
| 428 | 2876 (fill-move-backward-to-break-point re-break-point) |
| 2877 ;; If we find nowhere on the line to break it, | |
| 2878 ;; break after one word. Set bounce to t | |
| 2879 ;; so we will not keep going in this while loop. | |
| 2880 (if (bolp) | |
| 2881 (progn | |
| 502 | 2882 ;; XEmacs: change for Kinsoku processing |
| 428 | 2883 (fill-move-forward-to-break-point re-break-point |
| 2884 opoint) | |
| 2885 (setq bounce t))) | |
| 2886 (skip-chars-backward " \t")) | |
| 2887 (if (and (featurep 'mule) | |
| 502 | 2888 (or bounce (bolp))) |
| 2889 (declare-fboundp (kinsoku-process))) | |
| 428 | 2890 ;; Let fill-point be set to the place where we end up. |
| 2891 (point))))) | |
| 2892 | |
| 2893 ;; I'm not sure why Stig made this change but it breaks | |
| 2894 ;; auto filling in at least C mode so I'm taking it back | |
| 2895 ;; out. --cet | |
| 2896 ;; XEmacs - adaptive fill. | |
| 2897 ;;(maybe-adapt-fill-prefix | |
| 2898 ;; (or from (setq from (save-excursion (beginning-of-line) | |
| 2899 ;; (point)))) | |
| 2900 ;; (or to (setq to (save-excursion (beginning-of-line 2) | |
| 2901 ;; (point)))) | |
| 2902 ;; t) | |
| 2903 | |
| 2904 ;; If that place is not the beginning of the line, | |
| 2905 ;; break the line there. | |
| 2906 (if (save-excursion | |
| 2907 (goto-char fill-point) | |
| 502 | 2908 ;; during kinsoku processing it is possible to move beyond |
| 2909 (not (or (bolp) (eolp)))) | |
| 428 | 2910 (let ((prev-column (current-column))) |
| 2911 ;; If point is at the fill-point, do not `save-excursion'. | |
| 2912 ;; Otherwise, if a comment prefix or fill-prefix is inserted, | |
| 2913 ;; point will end up before it rather than after it. | |
| 2914 (if (save-excursion | |
| 2915 (skip-chars-backward " \t") | |
| 2916 (= (point) fill-point)) | |
| 2917 ;; 1999-09-17 hniksic: turn off Kinsoku until | |
| 2918 ;; it's debugged. | |
| 444 | 2919 (funcall comment-line-break-function) |
| 502 | 2920 ;; XEmacs: Kinsoku processing |
| 428 | 2921 ; ;(indent-new-comment-line) |
| 2922 ; (let ((spacep (memq (char-before (point)) '(?\ ?\t)))) | |
| 2923 ; (funcall comment-line-break-function) | |
| 2924 ; ;; if user type space explicitly, leave SPC | |
| 2925 ; ;; even if there is no WAN. | |
| 2926 ; (if spacep | |
| 2927 ; (save-excursion | |
| 2928 ; (goto-char fill-point) | |
| 2929 ; ;; put SPC except that there is SPC | |
| 2930 ; ;; already or there is sentence end. | |
| 2931 ; (or (memq (char-after (point)) '(?\ ?\t)) | |
| 2932 ; (fill-end-of-sentence-p) | |
| 2933 ; (insert ?\ ))))) | |
| 2934 (save-excursion | |
| 2935 (goto-char fill-point) | |
| 2936 (funcall comment-line-break-function))) | |
| 2937 ;; If making the new line didn't reduce the hpos of | |
| 2938 ;; the end of the line, then give up now; | |
| 2939 ;; trying again will not help. | |
| 2940 (if (>= (current-column) prev-column) | |
| 2941 (setq give-up t))) | |
| 2942 ;; No place to break => stop trying. | |
| 2943 (setq give-up t))))))) | |
| 2944 | |
| 2945 ;; Put FSF one in until I can one or the other working properly, then the | |
| 2946 ;; other one is history. | |
| 2947 ;(defun fsf:do-auto-fill () | |
| 2948 ; (let (fc justify | |
| 2949 ; ;; bol | |
| 2950 ; give-up | |
| 2951 ; (fill-prefix fill-prefix)) | |
| 2952 ; (if (or (not (setq justify (current-justification))) | |
| 2953 ; (null (setq fc (current-fill-column))) | |
| 2954 ; (and (eq justify 'left) | |
| 2955 ; (<= (current-column) fc)) | |
| 2956 ; (save-excursion (beginning-of-line) | |
| 2957 ; ;; (setq bol (point)) | |
| 2958 ; (and auto-fill-inhibit-regexp | |
| 2959 ; (looking-at auto-fill-inhibit-regexp)))) | |
| 2960 ; nil ;; Auto-filling not required | |
| 2961 ; (if (memq justify '(full center right)) | |
| 2962 ; (save-excursion (unjustify-current-line))) | |
| 2963 | |
| 2964 ; ;; Choose a fill-prefix automatically. | |
| 2965 ; (if (and adaptive-fill-mode | |
| 2966 ; (or (null fill-prefix) (string= fill-prefix ""))) | |
| 2967 ; (let ((prefix | |
| 2968 ; (fill-context-prefix | |
| 2969 ; (save-excursion (backward-paragraph 1) (point)) | |
| 2970 ; (save-excursion (forward-paragraph 1) (point)) | |
| 2971 ; ;; Don't accept a non-whitespace fill prefix | |
| 2972 ; ;; from the first line of a paragraph. | |
| 2973 ; "^[ \t]*$"))) | |
| 2974 ; (and prefix (not (equal prefix "")) | |
| 2975 ; (setq fill-prefix prefix)))) | |
| 2976 | |
| 2977 ; (while (and (not give-up) (> (current-column) fc)) | |
| 2978 ; ;; Determine where to split the line. | |
| 2979 ; (let ((fill-point | |
| 2980 ; (let ((opoint (point)) | |
| 2981 ; bounce | |
| 2982 ; (first t)) | |
| 2983 ; (save-excursion | |
| 2984 ; (move-to-column (1+ fc)) | |
| 2985 ; ;; Move back to a word boundary. | |
| 2986 ; (while (or first | |
| 2987 ; ;; If this is after period and a single space, | |
| 2988 ; ;; move back once more--we don't want to break | |
| 2989 ; ;; the line there and make it look like a | |
| 2990 ; ;; sentence end. | |
| 2991 ; (and (not (bobp)) | |
| 2992 ; (not bounce) | |
| 2993 ; sentence-end-double-space | |
| 446 | 2994 ; (save-excursion (backward-char 1) |
| 428 | 2995 ; (and (looking-at "\\. ") |
| 2996 ; (not (looking-at "\\. ")))))) | |
| 2997 ; (setq first nil) | |
| 2998 ; (skip-chars-backward "^ \t\n") | |
| 2999 ; ;; If we find nowhere on the line to break it, | |
| 3000 ; ;; break after one word. Set bounce to t | |
| 3001 ; ;; so we will not keep going in this while loop. | |
| 3002 ; (if (bolp) | |
| 3003 ; (progn | |
| 3004 ; (re-search-forward "[ \t]" opoint t) | |
| 3005 ; (setq bounce t))) | |
| 3006 ; (skip-chars-backward " \t")) | |
| 3007 ; ;; Let fill-point be set to the place where we end up. | |
| 3008 ; (point))))) | |
| 3009 ; ;; If that place is not the beginning of the line, | |
| 3010 ; ;; break the line there. | |
| 3011 ; (if (save-excursion | |
| 3012 ; (goto-char fill-point) | |
| 3013 ; (not (bolp))) | |
| 3014 ; (let ((prev-column (current-column))) | |
| 3015 ; ;; If point is at the fill-point, do not `save-excursion'. | |
| 3016 ; ;; Otherwise, if a comment prefix or fill-prefix is inserted, | |
| 3017 ; ;; point will end up before it rather than after it. | |
| 3018 ; (if (save-excursion | |
| 3019 ; (skip-chars-backward " \t") | |
| 3020 ; (= (point) fill-point)) | |
| 3021 ; (funcall comment-line-break-function t) | |
| 3022 ; (save-excursion | |
| 3023 ; (goto-char fill-point) | |
| 3024 ; (funcall comment-line-break-function t))) | |
| 3025 ; ;; Now do justification, if required | |
| 3026 ; (if (not (eq justify 'left)) | |
| 3027 ; (save-excursion | |
| 3028 ; (end-of-line 0) | |
| 3029 ; (justify-current-line justify nil t))) | |
| 3030 ; ;; If making the new line didn't reduce the hpos of | |
| 3031 ; ;; the end of the line, then give up now; | |
| 3032 ; ;; trying again will not help. | |
| 3033 ; (if (>= (current-column) prev-column) | |
| 3034 ; (setq give-up t))) | |
| 3035 ; ;; No place to break => stop trying. | |
| 3036 ; (setq give-up t)))) | |
| 3037 ; ;; Justify last line. | |
| 3038 ; (justify-current-line justify t t) | |
| 3039 ; t))) | |
| 3040 | |
| 3041 (defvar normal-auto-fill-function 'do-auto-fill | |
| 3042 "The function to use for `auto-fill-function' if Auto Fill mode is turned on. | |
| 3043 Some major modes set this.") | |
| 3044 | |
| 3045 (defun auto-fill-mode (&optional arg) | |
| 3046 "Toggle auto-fill mode. | |
| 3047 With arg, turn auto-fill mode on if and only if arg is positive. | |
| 3048 In Auto-Fill mode, inserting a space at a column beyond `current-fill-column' | |
| 3049 automatically breaks the line at a previous space. | |
| 3050 | |
| 3051 The value of `normal-auto-fill-function' specifies the function to use | |
| 3052 for `auto-fill-function' when turning Auto Fill mode on." | |
| 3053 (interactive "P") | |
| 3054 (prog1 (setq auto-fill-function | |
| 3055 (if (if (null arg) | |
| 3056 (not auto-fill-function) | |
| 3057 (> (prefix-numeric-value arg) 0)) | |
| 3058 normal-auto-fill-function | |
| 3059 nil)) | |
| 3060 (redraw-modeline))) | |
| 3061 | |
| 3062 ;; This holds a document string used to document auto-fill-mode. | |
| 3063 (defun auto-fill-function () | |
| 3064 "Automatically break line at a previous space, in insertion of text." | |
| 3065 nil) | |
| 3066 | |
| 3067 (defun turn-on-auto-fill () | |
| 3068 "Unconditionally turn on Auto Fill mode." | |
| 444 | 3069 (interactive) |
| 428 | 3070 (auto-fill-mode 1)) |
| 3071 | |
|
4681
64ac4337298b
Implement turn-off-auto-fill.
Malcolm Purvis <malcolmp@xemacs.org>
parents:
4680
diff
changeset
|
3072 (defun turn-off-auto-fill () |
|
64ac4337298b
Implement turn-off-auto-fill.
Malcolm Purvis <malcolmp@xemacs.org>
parents:
4680
diff
changeset
|
3073 "Unconditionally turn off Auto Fill mode." |
|
64ac4337298b
Implement turn-off-auto-fill.
Malcolm Purvis <malcolmp@xemacs.org>
parents:
4680
diff
changeset
|
3074 (interactive) |
|
64ac4337298b
Implement turn-off-auto-fill.
Malcolm Purvis <malcolmp@xemacs.org>
parents:
4680
diff
changeset
|
3075 (auto-fill-mode -1)) |
|
64ac4337298b
Implement turn-off-auto-fill.
Malcolm Purvis <malcolmp@xemacs.org>
parents:
4680
diff
changeset
|
3076 |
| 428 | 3077 (defun set-fill-column (arg) |
| 3078 "Set `fill-column' to specified argument. | |
| 3079 Just \\[universal-argument] as argument means to use the current column | |
| 3080 The variable `fill-column' has a separate value for each buffer." | |
| 3081 (interactive "_P") ; XEmacs | |
| 3082 (cond ((integerp arg) | |
| 3083 (setq fill-column arg)) | |
| 3084 ((consp arg) | |
| 3085 (setq fill-column (current-column))) | |
| 3086 ;; Disallow missing argument; it's probably a typo for C-x C-f. | |
| 3087 (t | |
| 3088 (error "set-fill-column requires an explicit argument"))) | |
| 3089 (lmessage 'command "fill-column set to %d" fill-column)) | |
| 3090 | |
| 1333 | 3091 |
| 3092 ;; BEGIN SYNCHED WITH FSF 21.2. | |
| 3093 | |
| 428 | 3094 (defun set-selective-display (arg) |
| 3095 "Set `selective-display' to ARG; clear it if no arg. | |
| 3096 When the value of `selective-display' is a number > 0, | |
| 3097 lines whose indentation is >= that value are not displayed. | |
| 3098 The variable `selective-display' has a separate value for each buffer." | |
| 3099 (interactive "P") | |
| 3100 (if (eq selective-display t) | |
| 3101 (error "selective-display already in use for marked lines")) | |
| 3102 (let ((current-vpos | |
| 3103 (save-restriction | |
| 3104 (narrow-to-region (point-min) (point)) | |
| 3105 (goto-char (window-start)) | |
| 3106 (vertical-motion (window-height))))) | |
| 3107 (setq selective-display | |
| 3108 (and arg (prefix-numeric-value arg))) | |
| 3109 (recenter current-vpos)) | |
| 3110 (set-window-start (selected-window) (window-start (selected-window))) | |
| 3111 ;; #### doesn't localize properly: | |
| 3112 (princ "selective-display set to " t) | |
| 3113 (prin1 selective-display t) | |
| 3114 (princ "." t)) | |
| 3115 | |
| 3116 ;; XEmacs | |
| 3117 (defun nuke-selective-display () | |
| 3118 "Ensure that the buffer is not in selective-display mode. | |
| 3119 If `selective-display' is t, then restore the buffer text to its original | |
| 3120 state before disabling selective display." | |
| 3121 ;; by Stig@hackvan.com | |
| 3122 (interactive) | |
| 3123 (and (eq t selective-display) | |
| 3124 (save-excursion | |
| 3125 (save-restriction | |
| 3126 (widen) | |
| 3127 (goto-char (point-min)) | |
| 3128 (let ((mod-p (buffer-modified-p)) | |
| 3129 (buffer-read-only nil)) | |
| 3130 (while (search-forward "\r" nil t) | |
| 3131 (delete-char -1) | |
| 3132 (insert "\n")) | |
| 3133 (set-buffer-modified-p mod-p) | |
| 3134 )))) | |
| 3135 (setq selective-display nil)) | |
| 3136 | |
| 3137 (add-hook 'change-major-mode-hook 'nuke-selective-display) | |
| 3138 | |
| 1333 | 3139 (defvar overwrite-mode-textual " Ovwrt" |
| 428 | 3140 "The string displayed in the mode line when in overwrite mode.") |
| 1333 | 3141 (defvar overwrite-mode-binary " Bin Ovwrt" |
| 428 | 3142 "The string displayed in the mode line when in binary overwrite mode.") |
| 3143 | |
| 3144 (defun overwrite-mode (arg) | |
| 3145 "Toggle overwrite mode. | |
| 1333 | 3146 With arg, turn overwrite mode on iff arg is positive. |
| 428 | 3147 In overwrite mode, printing characters typed in replace existing text |
| 3148 on a one-for-one basis, rather than pushing it to the right. At the | |
| 3149 end of a line, such characters extend the line. Before a tab, | |
| 3150 such characters insert until the tab is filled in. | |
| 3151 \\[quoted-insert] still inserts characters in overwrite mode; this | |
| 3152 is supposed to make it easier to insert characters when necessary." | |
| 3153 (interactive "P") | |
| 3154 (setq overwrite-mode | |
| 3155 (if (if (null arg) (not overwrite-mode) | |
| 3156 (> (prefix-numeric-value arg) 0)) | |
| 3157 'overwrite-mode-textual)) | |
| 3158 (redraw-modeline)) | |
| 3159 | |
| 3160 (defun binary-overwrite-mode (arg) | |
| 3161 "Toggle binary overwrite mode. | |
| 1333 | 3162 With arg, turn binary overwrite mode on iff arg is positive. |
| 428 | 3163 In binary overwrite mode, printing characters typed in replace |
| 3164 existing text. Newlines are not treated specially, so typing at the | |
| 3165 end of a line joins the line to the next, with the typed character | |
| 3166 between them. Typing before a tab character simply replaces the tab | |
| 3167 with the character typed. | |
| 3168 \\[quoted-insert] replaces the text at the cursor, just as ordinary | |
| 3169 typing characters do. | |
| 3170 | |
| 3171 Note that binary overwrite mode is not its own minor mode; it is a | |
| 3172 specialization of overwrite-mode, entered by setting the | |
| 3173 `overwrite-mode' variable to `overwrite-mode-binary'." | |
| 3174 (interactive "P") | |
| 3175 (setq overwrite-mode | |
| 3176 (if (if (null arg) | |
| 3177 (not (eq overwrite-mode 'overwrite-mode-binary)) | |
| 3178 (> (prefix-numeric-value arg) 0)) | |
| 3179 'overwrite-mode-binary)) | |
| 3180 (redraw-modeline)) | |
| 1333 | 3181 |
| 3182 ;; END SYNCHED WITH FSF 21.2. | |
| 3183 | |
| 428 | 3184 |
| 771 | 3185 (defcustom line-number-mode t |
| 428 | 3186 "*Non-nil means display line number in modeline." |
| 3187 :type 'boolean | |
| 3188 :group 'editing-basics) | |
| 3189 | |
| 3190 (defun line-number-mode (arg) | |
| 3191 "Toggle Line Number mode. | |
| 444 | 3192 With arg, enable Line Number mode if arg is positive, else disable. |
| 428 | 3193 When Line Number mode is enabled, the line number appears |
| 3194 in the mode line." | |
| 3195 (interactive "P") | |
| 3196 (setq line-number-mode | |
| 3197 (if (null arg) (not line-number-mode) | |
| 3198 (> (prefix-numeric-value arg) 0))) | |
| 3199 (redraw-modeline)) | |
| 3200 | |
| 771 | 3201 (defcustom column-number-mode t |
| 428 | 3202 "*Non-nil means display column number in mode line." |
| 3203 :type 'boolean | |
| 3204 :group 'editing-basics) | |
| 3205 | |
| 3206 (defun column-number-mode (arg) | |
| 3207 "Toggle Column Number mode. | |
| 444 | 3208 With arg, enable Column Number mode if arg is positive, else disable. |
| 428 | 3209 When Column Number mode is enabled, the column number appears |
| 3210 in the mode line." | |
| 3211 (interactive "P") | |
| 3212 (setq column-number-mode | |
| 3213 (if (null arg) (not column-number-mode) | |
| 3214 (> (prefix-numeric-value arg) 0))) | |
| 3215 (redraw-modeline)) | |
| 3216 | |
| 3217 | |
| 3218 (defcustom blink-matching-paren t | |
| 3219 "*Non-nil means show matching open-paren when close-paren is inserted." | |
| 3220 :type 'boolean | |
| 3221 :group 'paren-blinking) | |
| 3222 | |
| 3223 (defcustom blink-matching-paren-on-screen t | |
| 3224 "*Non-nil means show matching open-paren when it is on screen. | |
| 3225 nil means don't show it (but the open-paren can still be shown | |
| 3226 when it is off screen." | |
| 3227 :type 'boolean | |
| 3228 :group 'paren-blinking) | |
| 3229 | |
| 3230 (defcustom blink-matching-paren-distance 12000 | |
| 3231 "*If non-nil, is maximum distance to search for matching open-paren." | |
| 3232 :type '(choice integer (const nil)) | |
| 3233 :group 'paren-blinking) | |
| 3234 | |
| 3235 (defcustom blink-matching-delay 1 | |
| 3236 "*The number of seconds that `blink-matching-open' will delay at a match." | |
| 3237 :type 'number | |
| 3238 :group 'paren-blinking) | |
| 3239 | |
| 3240 (defcustom blink-matching-paren-dont-ignore-comments nil | |
| 3241 "*Non-nil means `blink-matching-paren' should not ignore comments." | |
| 3242 :type 'boolean | |
| 3243 :group 'paren-blinking) | |
| 3244 | |
| 3245 (defun blink-matching-open () | |
| 3246 "Move cursor momentarily to the beginning of the sexp before point." | |
| 3247 (interactive "_") ; XEmacs | |
| 3248 (and (> (point) (1+ (point-min))) | |
| 3249 blink-matching-paren | |
| 3250 ;; Verify an even number of quoting characters precede the close. | |
| 3251 (= 1 (logand 1 (- (point) | |
| 3252 (save-excursion | |
| 446 | 3253 (backward-char 1) |
| 428 | 3254 (skip-syntax-backward "/\\") |
| 3255 (point))))) | |
| 3256 (let* ((oldpos (point)) | |
| 3257 (blinkpos) | |
| 3258 (mismatch)) | |
| 3259 (save-excursion | |
| 3260 (save-restriction | |
| 3261 (if blink-matching-paren-distance | |
| 3262 (narrow-to-region (max (point-min) | |
| 3263 (- (point) blink-matching-paren-distance)) | |
| 3264 oldpos)) | |
| 3265 (condition-case () | |
| 3266 (let ((parse-sexp-ignore-comments | |
| 3267 (and parse-sexp-ignore-comments | |
| 3268 (not blink-matching-paren-dont-ignore-comments)))) | |
| 3269 (setq blinkpos (scan-sexps oldpos -1))) | |
| 3270 (error nil))) | |
| 3271 (and blinkpos | |
| 3272 (/= (char-syntax (char-after blinkpos)) | |
| 3273 ?\$) | |
| 3274 (setq mismatch | |
| 3275 (or (null (matching-paren (char-after blinkpos))) | |
| 3276 (/= (char-after (1- oldpos)) | |
| 3277 (matching-paren (char-after blinkpos)))))) | |
| 3278 (if mismatch (setq blinkpos nil)) | |
| 3279 (if blinkpos | |
| 3280 (progn | |
| 3281 (goto-char blinkpos) | |
| 3282 (if (pos-visible-in-window-p) | |
| 3283 (and blink-matching-paren-on-screen | |
| 3284 (progn | |
| 3285 (auto-show-make-point-visible) | |
| 3286 (sit-for blink-matching-delay))) | |
| 3287 (goto-char blinkpos) | |
| 3288 (lmessage 'command "Matches %s" | |
| 3289 ;; Show what precedes the open in its line, if anything. | |
| 3290 (if (save-excursion | |
| 3291 (skip-chars-backward " \t") | |
| 3292 (not (bolp))) | |
| 3293 (buffer-substring (progn (beginning-of-line) (point)) | |
| 3294 (1+ blinkpos)) | |
| 3295 ;; Show what follows the open in its line, if anything. | |
| 3296 (if (save-excursion | |
| 3297 (forward-char 1) | |
| 3298 (skip-chars-forward " \t") | |
| 3299 (not (eolp))) | |
| 3300 (buffer-substring blinkpos | |
| 3301 (progn (end-of-line) (point))) | |
| 3302 ;; Otherwise show the previous nonblank line, | |
| 3303 ;; if there is one. | |
| 3304 (if (save-excursion | |
| 3305 (skip-chars-backward "\n \t") | |
| 3306 (not (bobp))) | |
| 3307 (concat | |
| 3308 (buffer-substring (progn | |
| 3309 (skip-chars-backward "\n \t") | |
| 3310 (beginning-of-line) | |
| 3311 (point)) | |
| 3312 (progn (end-of-line) | |
| 3313 (skip-chars-backward " \t") | |
| 3314 (point))) | |
| 3315 ;; Replace the newline and other whitespace with `...'. | |
| 3316 "..." | |
| 3317 (buffer-substring blinkpos (1+ blinkpos))) | |
| 3318 ;; There is nothing to show except the char itself. | |
| 3319 (buffer-substring blinkpos (1+ blinkpos)))))))) | |
| 3320 (cond (mismatch | |
| 3321 (display-message 'no-log "Mismatched parentheses")) | |
| 3322 ((not blink-matching-paren-distance) | |
| 3323 (display-message 'no-log "Unmatched parenthesis")))))))) | |
| 3324 | |
| 3325 ;Turned off because it makes dbx bomb out. | |
| 3326 (setq blink-paren-function 'blink-matching-open) | |
| 3327 | |
| 3328 | |
| 3329 ;; XEmacs: Some functions moved to cmdloop.el: | |
| 3330 ;; keyboard-quit | |
| 3331 ;; buffer-quit-function | |
| 3332 ;; keyboard-escape-quit | |
| 3333 | |
| 442 | 3334 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 3335 ;; mail composition code ;; | |
| 3336 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| 3337 | |
| 1333 | 3338 ;; BEGIN SYNCHED WITH FSF 21.2. |
| 3339 | |
| 2768 | 3340 (defcustom mail-user-agent 'xemacs-default-mail-user-agent |
| 428 | 3341 "*Your preference for a mail composition package. |
| 1333 | 3342 Various Emacs Lisp packages (e.g. Reporter) require you to compose an |
| 428 | 3343 outgoing email message. This variable lets you specify which |
| 3344 mail-sending package you prefer. | |
| 3345 | |
| 2768 | 3346 Valid values may include: |
| 3347 | |
| 3348 `vm-user-agent' -- use Kyle Jones' VM, as documented in the `(vm)' | |
| 3349 Info node. Compatible with `sendmail-user-agent' | |
| 3350 and can handle attachments and non-ASCII content, | |
| 3351 which the former can't. | |
| 3352 `sendmail-user-agent' -- use the default, bare-bones, Emacs Mail | |
| 3353 package. See Info node `(xemacs)Sending Mail'. | |
| 1333 | 3354 `mh-e-user-agent' -- use the Emacs interface to the MH mail system. |
| 3355 See Info node `(mh-e)'. | |
| 3356 `message-user-agent' -- use the Gnus Message package. | |
| 3357 See Info node `(message)'. | |
| 3358 `gnus-user-agent' -- like `message-user-agent', but with Gnus | |
| 3359 paraphernalia, particularly the Gcc: header for | |
| 3360 archiving. | |
| 428 | 3361 |
| 2768 | 3362 If you examine the value of this variable before setting it or composing a |
| 3363 mail, it will have another value, `xemacs-default-mail-user-agent'--this is to | |
| 3364 allow XEmacs to suggest that you use another email client instead of | |
| 3365 `sendmail-user-agent'. The latter, while part of the base XEmacs Lisp code, | |
| 3366 and very lightweight, doesn't support MIME, a considerable disadvantage | |
| 3367 today. | |
| 3368 | |
| 428 | 3369 Additional valid symbols may be available; check with the author of |
| 1333 | 3370 your package for details. The function should return non-nil if it |
| 3371 succeeds. | |
| 3372 | |
| 3373 See also `read-mail-command' concerning reading mail." | |
| 2768 | 3374 :type '(radio (function-item :tag "VM mail package" |
| 3375 :format "%t\n" | |
| 3376 vm-user-agent) | |
| 3377 (function-item :tag "Bare-bones Emacs mail" | |
| 428 | 3378 :format "%t\n" |
| 3379 sendmail-user-agent) | |
| 1333 | 3380 (function-item :tag "Emacs interface to MH" |
| 3381 :format "%t\n" | |
| 3382 mh-e-user-agent) | |
| 3383 (function-item :tag "Gnus Message package" | |
| 428 | 3384 :format "%t\n" |
| 3385 message-user-agent) | |
| 1333 | 3386 (function-item :tag "Gnus Message with full Gnus features" |
| 3387 :format "%t\n" | |
| 3388 gnus-user-agent) | |
| 428 | 3389 (function :tag "Other")) |
| 3390 :group 'mail) | |
| 3391 | |
| 3392 (defun define-mail-user-agent (symbol composefunc sendfunc | |
| 3393 &optional abortfunc hookvar) | |
| 3394 "Define a symbol to identify a mail-sending package for `mail-user-agent'. | |
| 3395 | |
| 3396 SYMBOL can be any Lisp symbol. Its function definition and/or | |
| 3397 value as a variable do not matter for this usage; we use only certain | |
| 3398 properties on its property list, to encode the rest of the arguments. | |
| 3399 | |
| 3400 COMPOSEFUNC is program callable function that composes an outgoing | |
| 3401 mail message buffer. This function should set up the basics of the | |
| 3402 buffer without requiring user interaction. It should populate the | |
| 3403 standard mail headers, leaving the `to:' and `subject:' headers blank | |
| 3404 by default. | |
| 3405 | |
| 3406 COMPOSEFUNC should accept several optional arguments--the same | |
| 3407 arguments that `compose-mail' takes. See that function's documentation. | |
| 3408 | |
| 3409 SENDFUNC is the command a user would run to send the message. | |
| 3410 | |
| 3411 Optional ABORTFUNC is the command a user would run to abort the | |
| 3412 message. For mail packages that don't have a separate abort function, | |
| 3413 this can be `kill-buffer' (the equivalent of omitting this argument). | |
| 3414 | |
| 3415 Optional HOOKVAR is a hook variable that gets run before the message | |
| 3416 is actually sent. Callers that use the `mail-user-agent' may | |
| 3417 install a hook function temporarily on this hook variable. | |
| 3418 If HOOKVAR is nil, `mail-send-hook' is used. | |
| 3419 | |
| 3420 The properties used on SYMBOL are `composefunc', `sendfunc', | |
| 3421 `abortfunc', and `hookvar'." | |
| 3422 (put symbol 'composefunc composefunc) | |
| 3423 (put symbol 'sendfunc sendfunc) | |
| 3424 (put symbol 'abortfunc (or abortfunc 'kill-buffer)) | |
| 3425 (put symbol 'hookvar (or hookvar 'mail-send-hook))) | |
| 3426 | |
| 2768 | 3427 (define-mail-user-agent 'vm-user-agent |
| 3428 'vm-compose-mail | |
| 3429 'vm-mail-send-and-exit) | |
| 3430 | |
| 428 | 3431 (define-mail-user-agent 'sendmail-user-agent |
| 3432 'sendmail-user-agent-compose 'mail-send-and-exit) | |
| 3433 | |
| 2768 | 3434 ;; Recent GNU sendmail.el does have MIME support, but it's buggy (as of |
| 3435 ;; 2005-05-01.) For example, if you FCC to a file more than once with | |
| 3436 ;; different coding systems, your non-ASCII data will get | |
| 3437 ;; trashed. quoted-printable encoding isn't done by default, attachments | |
| 3438 ;; just add a line: | |
| 3439 ;; | |
| 3440 ;; ===File /path/to/file/here================= | |
| 3441 ;; | |
| 3442 ;; the file's contents, | |
| 3443 ;; | |
| 3444 ;; =========================================== | |
| 3445 ;; | |
| 3446 ;; and hope for the best. Not code we want to use, IMO. | |
| 3447 | |
| 4293 | 3448 (defvar xemacs-default-composefunc-dont-nag nil |
| 3449 "Disable the `xemacs-default-composefunc' nagging; for bug reports.") | |
| 3450 | |
| 2768 | 3451 (defun xemacs-default-composefunc (&rest args) |
| 3452 "Warn that the default mail-reading package is heinously underfeatured; | |
| 3453 compose a mail using it, all the same. " | |
| 4293 | 3454 (unless (or noninteractive xemacs-default-composefunc-dont-nag) |
| 2977 | 3455 (warn " |
| 2768 | 3456 |
| 3457 Defaulting to the GNU Emacs-derived `sendmail.el' mail client. This facility, | |
| 3458 while part of base XEmacs, is heinously underfeatured, and not going to get | |
| 3459 better in the medium term. We include it so that bug reports work without | |
| 3460 packages; we suggest that you choose and/or install one of the other mail | |
| 3461 clients from packages if you're doing something other than M-x | |
| 3462 report-xemacs-bug , or even if you are reporting bugs regularly. | |
| 3463 | |
| 3464 To choose a package from those installed, click on \"Options\" -> | |
| 3465 \"Internet\" -> \"Compose Mail With ...\" and decide on one from the | |
| 3466 list. Gnus and VM are full-featured and have active user communities. | |
| 3467 | |
| 3468 To disable this warning and stick with the old behavior, you can explicitly | |
| 2977 | 3469 initialize `mail-user-agent' to 'sendmail-user-agent . ")) |
| 2768 | 3470 (setq mail-user-agent 'sendmail-user-agent) |
| 3471 (apply (get 'sendmail-user-agent 'composefunc) args)) | |
| 3472 | |
| 3473 (defun xemacs-default-sendfunc (&rest args) | |
| 3474 "Set `mail-user-agent' to `sendmail-user-agent'; call the send function | |
| 3475 associated with that package, passing it the supplied arguments. " | |
| 3476 (setq mail-user-agent 'sendmail-user-agent) | |
| 3477 (apply (get 'sendmail-user-agent 'sendfunc) args)) | |
| 3478 | |
| 3479 (define-mail-user-agent 'xemacs-default-mail-user-agent | |
| 3480 'xemacs-default-composefunc 'xemacs-default-sendfunc) | |
| 3481 | |
| 428 | 3482 (define-mail-user-agent 'message-user-agent |
| 3483 'message-mail 'message-send-and-exit | |
| 3484 'message-kill-buffer 'message-send-hook) | |
| 3485 | |
| 1333 | 3486 (defun rfc822-goto-eoh () |
| 3487 ;; Go to header delimiter line in a mail message, following RFC822 rules | |
| 3488 (goto-char (point-min)) | |
| 3489 (while (looking-at "^[^: \n]+:\\|^[ \t]") | |
| 3490 (forward-line 1)) | |
| 3491 (point)) | |
| 3492 | |
| 428 | 3493 (defun sendmail-user-agent-compose (&optional to subject other-headers continue |
| 3494 switch-function yank-action | |
| 3495 send-actions) | |
| 3496 (if switch-function | |
| 3497 (let ((special-display-buffer-names nil) | |
| 3498 (special-display-regexps nil) | |
| 3499 (same-window-buffer-names nil) | |
| 3500 (same-window-regexps nil)) | |
| 3501 (funcall switch-function "*mail*"))) | |
| 3502 (let ((cc (cdr (assoc-ignore-case "cc" other-headers))) | |
| 1333 | 3503 (in-reply-to (cdr (assoc-ignore-case "in-reply-to" other-headers))) |
| 3504 (body (cdr (assoc-ignore-case "body" other-headers)))) | |
| 776 | 3505 (or (declare-fboundp |
| 3506 (mail continue to subject in-reply-to cc yank-action send-actions)) | |
| 428 | 3507 continue |
| 3508 (error "Message aborted")) | |
| 3509 (save-excursion | |
| 1333 | 3510 (rfc822-goto-eoh) |
| 428 | 3511 (while other-headers |
| 1333 | 3512 (unless (member* (car (car other-headers)) |
| 3513 '("in-reply-to" "cc" "body") | |
| 3514 :test 'equalp) | |
| 428 | 3515 (insert (car (car other-headers)) ": " |
| 3516 (cdr (car other-headers)) "\n")) | |
| 3517 (setq other-headers (cdr other-headers))) | |
| 1333 | 3518 (when body |
| 3519 (forward-line 1) | |
| 3520 (insert body)) | |
| 428 | 3521 t))) |
| 3522 | |
| 3523 (define-mail-user-agent 'mh-e-user-agent | |
| 1333 | 3524 'mh-smail-batch 'mh-send-letter 'mh-fully-kill-draft |
| 428 | 3525 'mh-before-send-letter-hook) |
| 3526 | |
| 3527 (defun compose-mail (&optional to subject other-headers continue | |
| 3528 switch-function yank-action send-actions) | |
| 3529 "Start composing a mail message to send. | |
| 3530 This uses the user's chosen mail composition package | |
| 3531 as selected with the variable `mail-user-agent'. | |
| 3532 The optional arguments TO and SUBJECT specify recipients | |
| 3533 and the initial Subject field, respectively. | |
| 3534 | |
| 3535 OTHER-HEADERS is an alist specifying additional | |
| 3536 header fields. Elements look like (HEADER . VALUE) where both | |
| 3537 HEADER and VALUE are strings. | |
| 3538 | |
| 3539 CONTINUE, if non-nil, says to continue editing a message already | |
| 3540 being composed. | |
| 3541 | |
| 3542 SWITCH-FUNCTION, if non-nil, is a function to use to | |
| 3543 switch to and display the buffer used for mail composition. | |
| 3544 | |
| 3545 YANK-ACTION, if non-nil, is an action to perform, if and when necessary, | |
| 3546 to insert the raw text of the message being replied to. | |
| 3547 It has the form (FUNCTION . ARGS). The user agent will apply | |
| 3548 FUNCTION to ARGS, to insert the raw text of the original message. | |
| 3549 \(The user agent will also run `mail-citation-hook', *after* the | |
| 3550 original text has been inserted in this way.) | |
| 3551 | |
| 3552 SEND-ACTIONS is a list of actions to call when the message is sent. | |
| 3553 Each action has the form (FUNCTION . ARGS)." | |
| 3554 (interactive | |
| 3555 (list nil nil nil current-prefix-arg)) | |
| 3556 (let ((function (get mail-user-agent 'composefunc))) | |
| 3557 (funcall function to subject other-headers continue | |
| 3558 switch-function yank-action send-actions))) | |
| 3559 | |
| 3560 (defun compose-mail-other-window (&optional to subject other-headers continue | |
| 3561 yank-action send-actions) | |
| 3562 "Like \\[compose-mail], but edit the outgoing message in another window." | |
| 3563 (interactive | |
| 3564 (list nil nil nil current-prefix-arg)) | |
| 3565 (compose-mail to subject other-headers continue | |
| 3566 'switch-to-buffer-other-window yank-action send-actions)) | |
| 3567 | |
| 3568 | |
| 3569 (defun compose-mail-other-frame (&optional to subject other-headers continue | |
| 3570 yank-action send-actions) | |
| 3571 "Like \\[compose-mail], but edit the outgoing message in another frame." | |
| 3572 (interactive | |
| 3573 (list nil nil nil current-prefix-arg)) | |
| 3574 (compose-mail to subject other-headers continue | |
| 3575 'switch-to-buffer-other-frame yank-action send-actions)) | |
| 3576 | |
| 3577 | |
| 442 | 3578 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 3579 ;; set variable ;; | |
| 3580 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| 3581 | |
| 1333 | 3582 (defvar set-variable-value-history nil |
| 3583 "History of values entered with `set-variable'.") | |
| 3584 | |
| 428 | 3585 (defun set-variable (var val) |
| 3586 "Set VARIABLE to VALUE. VALUE is a Lisp object. | |
| 1333 | 3587 When using this interactively, enter a Lisp object for VALUE. |
| 428 | 3588 If you want VALUE to be a string, you must surround it with doublequotes. |
| 1333 | 3589 VALUE is used literally, not evaluated. |
| 3590 | |
| 428 | 3591 If VARIABLE is a specifier, VALUE is added to it as an instantiator in |
| 3592 the 'global locale with nil tag set (see `set-specifier'). | |
| 3593 | |
| 3594 If VARIABLE has a `variable-interactive' property, that is used as if | |
| 1333 | 3595 it were the arg to `interactive' (which see) to interactively read VALUE. |
| 3596 | |
| 3597 If VARIABLE has been defined with `defcustom', then the type information | |
| 3598 in the definition is used to check that VALUE is valid." | |
| 428 | 3599 (interactive |
| 1333 | 3600 (let* ((default-var (variable-at-point)) |
| 3601 (var (if (symbolp default-var) | |
| 3602 (read-variable (format "Set variable (default %s): " default-var) | |
| 3603 default-var) | |
| 3604 (read-variable "Set variable: "))) | |
| 3605 (minibuffer-help-form '(describe-variable var)) | |
| 3606 (prop (get var 'variable-interactive)) | |
| 3607 (prompt (format "Set %s to value: " var)) | |
| 3608 (val (if prop | |
| 3609 ;; Use VAR's `variable-interactive' property | |
| 3610 ;; as an interactive spec for prompting. | |
| 3611 (call-interactively `(lambda (arg) | |
| 3612 (interactive ,prop) | |
| 3613 arg)) | |
| 3614 (read | |
| 3615 (read-string prompt nil | |
| 3616 'set-variable-value-history))))) | |
| 3617 (list var val))) | |
| 3618 | |
| 3619 (let ((type (get var 'custom-type))) | |
| 3620 (when type | |
| 3621 ;; Match with custom type. | |
| 3622 (require 'cus-edit) | |
| 3623 (setq type (widget-convert type)) | |
| 3624 (unless (widget-apply type :match val) | |
| 3625 (error "Value `%S' does not match type %S of %S" | |
| 3626 val (car type) var)))) | |
| 428 | 3627 (if (and (boundp var) (specifierp (symbol-value var))) |
| 3628 (set-specifier (symbol-value var) val) | |
| 1333 | 3629 (set var val)) |
| 3630 | |
| 3631 ;; Force a thorough redisplay for the case that the variable | |
| 3632 ;; has an effect on the display, like `tab-width' has. | |
| 3633 (force-mode-line-update)) | |
| 3634 | |
| 3635 | |
| 3636 | |
| 3637 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| 3638 ;; forking a twin copy of a buffer ;; | |
| 3639 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| 3640 | |
| 3641 (defvar clone-buffer-hook nil | |
| 3642 "Normal hook to run in the new buffer at the end of `clone-buffer'.") | |
| 3643 | |
| 3644 (defun clone-process (process &optional newname) | |
| 3645 "Create a twin copy of PROCESS. | |
| 3646 If NEWNAME is nil, it defaults to PROCESS' name; | |
| 3647 NEWNAME is modified by adding or incrementing <N> at the end as necessary. | |
| 3648 If PROCESS is associated with a buffer, the new process will be associated | |
| 3649 with the current buffer instead. | |
| 3650 Returns nil if PROCESS has already terminated." | |
| 3651 (setq newname (or newname (process-name process))) | |
| 3652 (if (string-match "<[0-9]+>\\'" newname) | |
| 3653 (setq newname (substring newname 0 (match-beginning 0)))) | |
| 3654 (when (memq (process-status process) '(run stop open)) | |
| 3655 (let* ((process-connection-type (process-tty-name process)) | |
| 3656 (old-kwoq (process-kill-without-query process nil)) | |
| 3657 (new-process | |
| 3658 (if (memq (process-status process) '(open)) | |
| 3659 (apply 'open-network-stream newname | |
| 3660 (if (process-buffer process) (current-buffer)) | |
| 3661 ;; FSF: (process-contact process) | |
| 3662 (process-command process)) | |
| 3663 (apply 'start-process newname | |
| 3664 (if (process-buffer process) (current-buffer)) | |
| 3665 (process-command process))))) | |
| 3666 (process-kill-without-query new-process old-kwoq) | |
| 3667 (process-kill-without-query process old-kwoq) | |
| 3668 ;; FSF 21.2: | |
| 3669 ; (set-process-inherit-coding-system-flag | |
| 3670 ; new-process (process-inherit-coding-system-flag process)) | |
| 3671 (set-process-filter new-process (process-filter process)) | |
| 3672 (set-process-sentinel new-process (process-sentinel process)) | |
| 3673 new-process))) | |
| 3674 | |
| 3675 ;; things to maybe add (currently partly covered by `funcall mode': | |
| 3676 ;; - syntax-table | |
| 3677 ;; - overlays | |
| 3678 (defun clone-buffer (&optional newname display-flag) | |
| 3679 "Create a twin copy of the current buffer. | |
| 3680 If NEWNAME is nil, it defaults to the current buffer's name; | |
| 3681 NEWNAME is modified by adding or incrementing <N> at the end as necessary. | |
| 3682 | |
| 3683 If DISPLAY-FLAG is non-nil, the new buffer is shown with `pop-to-buffer'. | |
| 3684 This runs the normal hook `clone-buffer-hook' in the new buffer | |
| 3685 after it has been set up properly in other respects." | |
| 3686 (interactive (list (if current-prefix-arg (read-string "Name: ")) | |
| 3687 t)) | |
| 3688 (if buffer-file-name | |
| 3689 (error "Cannot clone a file-visiting buffer")) | |
| 3690 (if (get major-mode 'no-clone) | |
| 3691 (error "Cannot clone a buffer in %s mode" mode-name)) | |
| 3692 (setq newname (or newname (buffer-name))) | |
| 3693 (if (string-match "<[0-9]+>\\'" newname) | |
| 3694 (setq newname (substring newname 0 (match-beginning 0)))) | |
| 3695 (let ((buf (current-buffer)) | |
| 3696 (ptmin (point-min)) | |
| 3697 (ptmax (point-max)) | |
| 3698 (pt (point)) | |
| 3699 (mk (mark t)) ;(if mark-active (mark t))) | |
| 3700 (modified (buffer-modified-p)) | |
| 3701 (mode major-mode) | |
| 3702 (lvars (buffer-local-variables)) | |
| 3703 (process (get-buffer-process (current-buffer))) | |
| 3704 (new (generate-new-buffer (or newname (buffer-name))))) | |
| 3705 (save-restriction | |
| 3706 (widen) | |
| 3707 (with-current-buffer new | |
| 3708 (insert-buffer-substring buf))) | |
| 3709 (with-current-buffer new | |
| 3710 (narrow-to-region ptmin ptmax) | |
| 3711 (goto-char pt) | |
| 3712 (if mk (set-mark mk)) | |
| 3713 (set-buffer-modified-p modified) | |
| 3714 | |
| 3715 ;; Clone the old buffer's process, if any. | |
| 3716 (when process (clone-process process)) | |
| 3717 | |
| 3718 ;; Now set up the major mode. | |
| 3719 (funcall mode) | |
| 3720 | |
| 3721 ;; Set up other local variables. | |
|
4783
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4687
diff
changeset
|
3722 (mapc (lambda (v) |
|
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4687
diff
changeset
|
3723 (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
|
3724 (if (symbolp v) |
|
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4687
diff
changeset
|
3725 (makunbound v) |
|
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4687
diff
changeset
|
3726 (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
|
3727 (error nil))) |
|
e29fcfd8df5f
Eliminate most core code byte-compile warnings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4687
diff
changeset
|
3728 lvars) |
| 1333 | 3729 |
| 3730 ;; Run any hooks (typically set up by the major mode | |
| 3731 ;; for cloning to work properly). | |
| 3732 (run-hooks 'clone-buffer-hook)) | |
| 3733 (if display-flag (pop-to-buffer new)) | |
| 3734 new)) | |
| 3735 | |
| 3736 | |
| 3737 (defun clone-indirect-buffer (newname display-flag &optional norecord) | |
| 3738 "Create an indirect buffer that is a twin copy of the current buffer. | |
| 3739 | |
| 3740 Give the indirect buffer name NEWNAME. Interactively, read NEW-NAME | |
| 3741 from the minibuffer when invoked with a prefix arg. If NEWNAME is nil | |
| 3742 or if not called with a prefix arg, NEWNAME defaults to the current | |
| 3743 buffer's name. The name is modified by adding a `<N>' suffix to it | |
| 3744 or by incrementing the N in an existing suffix. | |
| 3745 | |
| 3746 DISPLAY-FLAG non-nil means show the new buffer with `pop-to-buffer'. | |
| 3747 This is always done when called interactively. | |
| 3748 | |
| 3749 Optional last arg NORECORD non-nil means do not put this buffer at the | |
| 3750 front of the list of recently selected ones." | |
| 3751 (interactive (list (if current-prefix-arg | |
| 3752 (read-string "BName of indirect buffer: ")) | |
| 3753 t)) | |
| 3754 (setq newname (or newname (buffer-name))) | |
| 3755 (if (string-match "<[0-9]+>\\'" newname) | |
| 3756 (setq newname (substring newname 0 (match-beginning 0)))) | |
| 3757 (let* ((name (generate-new-buffer-name newname)) | |
| 3758 (buffer (make-indirect-buffer (current-buffer) name t))) | |
| 3759 (when display-flag | |
| 3760 (pop-to-buffer buffer norecord)) | |
| 3761 buffer)) | |
| 3762 | |
| 3763 | |
| 3764 (defun clone-indirect-buffer-other-window (buffer &optional norecord) | |
| 3765 "Create an indirect buffer that is a twin copy of BUFFER. | |
| 3766 Select the new buffer in another window. | |
| 3767 Optional second arg NORECORD non-nil means do not put this buffer at | |
| 3768 the front of the list of recently selected ones." | |
| 3769 (interactive "bClone buffer in other window: ") | |
| 3770 (let ((pop-up-windows t)) | |
| 3771 (set-buffer buffer) | |
| 3772 (clone-indirect-buffer nil t norecord))) | |
| 3773 | |
| 3774 ;; END SYNCHED WITH FSF 21.2. | |
| 442 | 3775 |
| 428 | 3776 |
| 442 | 3777 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 3778 ;; case changing code ;; | |
| 3779 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| 428 | 3780 |
| 3781 ;; A bunch of stuff was moved elsewhere: | |
| 3782 ;; completion-list-mode-map | |
| 3783 ;; completion-reference-buffer | |
| 3784 ;; completion-base-size | |
| 3785 ;; delete-completion-window | |
| 3786 ;; previous-completion | |
| 3787 ;; next-completion | |
| 3788 ;; choose-completion | |
| 3789 ;; choose-completion-delete-max-match | |
| 3790 ;; choose-completion-string | |
| 3791 ;; completion-list-mode | |
| 3792 ;; completion-fixup-function | |
| 3793 ;; completion-setup-function | |
| 3794 ;; switch-to-completions | |
| 3795 ;; event stuffs | |
| 3796 ;; keypad stuffs | |
| 3797 | |
| 3798 ;; The rest of this file is not in Lisp in FSF | |
| 3799 (defun capitalize-region-or-word (arg) | |
| 3800 "Capitalize the selected region or the following word (or ARG words)." | |
| 3801 (interactive "p") | |
| 3802 (if (region-active-p) | |
| 3803 (capitalize-region (region-beginning) (region-end)) | |
| 3804 (capitalize-word arg))) | |
| 3805 | |
| 3806 (defun upcase-region-or-word (arg) | |
| 3807 "Upcase the selected region or the following word (or ARG words)." | |
| 3808 (interactive "p") | |
| 3809 (if (region-active-p) | |
| 3810 (upcase-region (region-beginning) (region-end)) | |
| 3811 (upcase-word arg))) | |
| 3812 | |
| 3813 (defun downcase-region-or-word (arg) | |
| 3814 "Downcase the selected region or the following word (or ARG words)." | |
| 3815 (interactive "p") | |
| 3816 (if (region-active-p) | |
| 3817 (downcase-region (region-beginning) (region-end)) | |
| 3818 (downcase-word arg))) | |
| 3819 | |
| 442 | 3820 ;; #### not localized |
| 3821 (defvar uncapitalized-title-words | |
| 3822 '("the" "a" "an" "in" "of" "for" "to" "and" "but" "at" "on" "as" "by")) | |
| 3823 | |
| 3824 (defvar uncapitalized-title-word-regexp | |
| 3825 (concat "[ \t]*\\(" (mapconcat #'identity uncapitalized-title-words "\\|") | |
| 3826 "\\)\\>")) | |
| 3827 | |
| 3828 (defun capitalize-string-as-title (string) | |
| 3829 "Capitalize the words in the string, except for small words (as in titles). | |
| 3830 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
|
3831 (with-string-as-buffer-contents string |
|
9b5d4b35f8d7
(main branch) redo capitalize-string-as-title
Ben Wing <ben@xemacs.org>
parents:
4869
diff
changeset
|
3832 (capitalize-region-as-title (point-min) (point-max)))) |
| 442 | 3833 |
| 3834 (defun capitalize-region-as-title (b e &optional buffer) | |
| 3835 "Capitalize the words in the region, except for small words (as in titles). | |
| 3836 The words not capitalized are specified in `uncapitalized-title-words'." | |
| 3837 (interactive "r") | |
| 3838 (save-excursion | |
| 3839 (and buffer | |
| 3840 (set-buffer buffer)) | |
| 3841 (save-restriction | |
| 3842 (narrow-to-region b e) | |
| 3843 (goto-char (point-min)) | |
| 3844 (let ((first t)) | |
| 3845 (while (< (point) (point-max)) | |
| 3846 (if (or first | |
| 3847 (not (looking-at uncapitalized-title-word-regexp))) | |
| 3848 (capitalize-word 1) | |
| 3849 (forward-word 1)) | |
| 3850 (setq first nil)))))) | |
| 3851 | |
| 3852 | |
| 3853 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| 3854 ;; zmacs active region code ;; | |
| 3855 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| 3856 | |
| 428 | 3857 ;; Most of the zmacs code is now in elisp. The only thing left in C |
| 3858 ;; are the variables zmacs-regions, zmacs-region-active-p and | |
| 3859 ;; zmacs-region-stays plus the function zmacs_update_region which | |
| 3860 ;; simply calls the lisp level zmacs-update-region. It must remain | |
| 3861 ;; for convenience, since it is called by core C code. | |
| 3862 | |
| 442 | 3863 ;; XEmacs |
| 3864 (defun activate-region () | |
| 3865 "Activate the region, if `zmacs-regions' is true. | |
| 3866 Setting `zmacs-regions' to true causes LISPM-style active regions to be used. | |
| 3867 This function has no effect if `zmacs-regions' is false." | |
| 3868 (interactive) | |
| 3869 (and zmacs-regions (zmacs-activate-region))) | |
| 3870 | |
| 3871 ;; XEmacs | |
| 3872 (defsubst region-exists-p () | |
| 3873 "Return t if the region exists. | |
| 3874 If active regions are in use (i.e. `zmacs-regions' is true), this means that | |
| 3875 the region is active. Otherwise, this means that the user has pushed | |
| 3876 a mark in this buffer at some point in the past. | |
| 3877 The functions `region-beginning' and `region-end' can be used to find the | |
| 502 | 3878 limits of the region. |
| 3879 | |
| 3880 You should use this, *NOT* `region-active-p', in a menu item | |
| 3881 specification that you want grayed out when the region is not active: | |
| 3882 | |
| 3883 [ ... ... :active (region-exists-p)] | |
| 3884 | |
| 3885 This correctly caters to the user's setting of `zmacs-regions'." | |
| 442 | 3886 (not (null (mark)))) |
| 3887 | |
| 3888 ;; XEmacs | |
| 3889 (defun region-active-p () | |
| 2611 | 3890 "Return non-nil if the region is active in the current buffer. |
| 442 | 3891 If `zmacs-regions' is true, this is equivalent to `region-exists-p'. |
| 502 | 3892 Otherwise, this function always returns false. |
| 3893 | |
| 3894 You should generally *NOT* use this in a menu item specification that you | |
| 3895 want grayed out when the region is not active. Instead, use this: | |
| 3896 | |
| 3897 [ ... ... :active (region-exists-p)] | |
| 3898 | |
| 3899 Which correctly caters to the user's setting of `zmacs-regions'." | |
| 2611 | 3900 (and zmacs-regions zmacs-region-extent |
| 3901 (eq (current-buffer) (zmacs-region-buffer)))) | |
| 442 | 3902 |
| 428 | 3903 (defvar zmacs-activate-region-hook nil |
| 3904 "Function or functions called when the region becomes active; | |
| 3905 see the variable `zmacs-regions'.") | |
| 3906 | |
| 3907 (defvar zmacs-deactivate-region-hook nil | |
| 3908 "Function or functions called when the region becomes inactive; | |
| 3909 see the variable `zmacs-regions'.") | |
| 3910 | |
| 3911 (defvar zmacs-update-region-hook nil | |
| 3912 "Function or functions called when the active region changes. | |
| 3913 This is called after each command that sets `zmacs-region-stays' to t. | |
| 3914 See the variable `zmacs-regions'.") | |
| 3915 | |
| 487 | 3916 (add-hook 'zmacs-deactivate-region-hook 'disown-selection) |
| 3917 (add-hook 'zmacs-activate-region-hook 'activate-region-as-selection) | |
| 3918 (add-hook 'zmacs-update-region-hook 'activate-region-as-selection) | |
| 3919 | |
| 428 | 3920 (defvar zmacs-region-extent nil |
| 3921 "The extent of the zmacs region; don't use this.") | |
| 3922 | |
| 3923 (defvar zmacs-region-rectangular-p nil | |
| 3924 "Whether the zmacs region is a rectangle; don't use this.") | |
| 3925 | |
| 3926 (defun zmacs-make-extent-for-region (region) | |
| 3927 ;; Given a region, this makes an extent in the buffer which holds that | |
| 3928 ;; region, for highlighting purposes. If the region isn't associated | |
| 3929 ;; with a buffer, this does nothing. | |
| 3930 (let ((buffer nil) | |
| 3931 (valid (and (extentp zmacs-region-extent) | |
| 3932 (extent-object zmacs-region-extent) | |
| 3933 (buffer-live-p (extent-object zmacs-region-extent)))) | |
| 3934 start end) | |
| 3935 (cond ((consp region) | |
| 3936 (setq start (min (car region) (cdr region)) | |
| 3937 end (max (car region) (cdr region)) | |
| 3938 valid (and valid | |
| 3939 (eq (marker-buffer (car region)) | |
| 3940 (extent-object zmacs-region-extent))) | |
| 3941 buffer (marker-buffer (car region)))) | |
| 3942 (t | |
| 3943 (signal 'error (list "Invalid region" region)))) | |
| 3944 | |
| 3945 (if valid | |
| 3946 nil | |
| 3947 ;; The condition case is in case any of the extents are dead or | |
| 3948 ;; otherwise incapacitated. | |
| 3949 (condition-case () | |
| 3950 (if (listp zmacs-region-extent) | |
| 3951 (mapc 'delete-extent zmacs-region-extent) | |
| 3952 (delete-extent zmacs-region-extent)) | |
| 3953 (error nil))) | |
| 3954 | |
| 3955 (if valid | |
| 3956 (set-extent-endpoints zmacs-region-extent start end) | |
| 3957 (setq zmacs-region-extent (make-extent start end buffer)) | |
| 3958 | |
| 3959 ;; Make the extent be closed on the right, which means that if | |
| 3960 ;; characters are inserted exactly at the end of the extent, the | |
| 3961 ;; extent will grow to cover them. This is important for shell | |
| 3962 ;; buffers - suppose one makes a region, and one end is at point-max. | |
| 3963 ;; If the shell produces output, that marker will remain at point-max | |
| 3964 ;; (its position will increase). So it's important that the extent | |
| 3965 ;; exhibit the same behavior, lest the region covered by the extent | |
| 3966 ;; (the visual indication), and the region between point and mark | |
| 3967 ;; (the actual region value) become different! | |
| 3968 (set-extent-property zmacs-region-extent 'end-open nil) | |
| 3969 | |
| 3970 ;; use same priority as mouse-highlighting so that conflicts between | |
| 3971 ;; the region extent and a mouse-highlighted extent are resolved by | |
| 3972 ;; the usual size-and-endpoint-comparison method. | |
| 3973 (set-extent-priority zmacs-region-extent mouse-highlight-priority) | |
| 3974 (set-extent-face zmacs-region-extent 'zmacs-region) | |
| 3975 | |
| 3976 ;; #### It might be better to actually break | |
| 3977 ;; default-mouse-track-next-move-rect out of mouse.el so that we | |
| 3978 ;; can use its logic here. | |
| 3979 (cond | |
| 3980 (zmacs-region-rectangular-p | |
| 3981 (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
|
3982 (when-fboundp 'default-mouse-track-next-move-rect |
| 4222 | 3983 (default-mouse-track-next-move-rect start end zmacs-region-extent)) |
| 428 | 3984 )) |
| 3985 | |
| 3986 zmacs-region-extent))) | |
| 3987 | |
| 3988 (defun zmacs-region-buffer () | |
| 3989 "Return the buffer containing the zmacs region, or nil." | |
| 3990 ;; #### this is horrible and kludgy! This stuff needs to be rethought. | |
| 3991 (and zmacs-regions zmacs-region-active-p | |
| 3992 (or (marker-buffer (mark-marker t)) | |
| 3993 (and (extent-live-p zmacs-region-extent) | |
| 3994 (buffer-live-p (extent-object zmacs-region-extent)) | |
| 3995 (extent-object zmacs-region-extent))))) | |
| 3996 | |
| 3997 (defun zmacs-activate-region () | |
| 3998 "Make the region between `point' and `mark' be active (highlighted), | |
| 3999 if `zmacs-regions' is true. Only a very small number of commands | |
| 4000 should ever do this. Calling this function will call the hook | |
| 4001 `zmacs-activate-region-hook', if the region was previously inactive. | |
| 4002 Calling this function ensures that the region stays active after the | |
| 4003 current command terminates, even if `zmacs-region-stays' is not set. | |
| 4004 Returns t if the region was activated (i.e. if `zmacs-regions' if t)." | |
| 4005 (if (not zmacs-regions) | |
| 4006 nil | |
| 4007 (setq zmacs-region-active-p t | |
| 4008 zmacs-region-stays t | |
| 4222 | 4009 zmacs-region-rectangular-p (and-boundp 'mouse-track-rectangle-p |
| 4010 mouse-track-rectangle-p)) | |
| 428 | 4011 (if (marker-buffer (mark-marker t)) |
| 4012 (zmacs-make-extent-for-region (cons (point-marker t) (mark-marker t)))) | |
| 4013 (run-hooks 'zmacs-activate-region-hook) | |
| 4014 t)) | |
| 4015 | |
| 4016 (defun zmacs-deactivate-region () | |
| 4017 "Make the region between `point' and `mark' no longer be active, | |
| 4018 if `zmacs-regions' is true. You shouldn't need to call this; the | |
| 4019 command loop calls it when appropriate. Calling this function will | |
| 4020 call the hook `zmacs-deactivate-region-hook', if the region was | |
| 4021 previously active. Returns t if the region had been active, nil | |
| 4022 otherwise." | |
| 4023 (if (not zmacs-region-active-p) | |
| 4024 nil | |
| 4025 (setq zmacs-region-active-p nil | |
| 4026 zmacs-region-stays nil | |
| 4027 zmacs-region-rectangular-p nil) | |
| 4028 (if zmacs-region-extent | |
| 4029 (let ((inhibit-quit t)) | |
| 4030 (if (listp zmacs-region-extent) | |
| 4031 (mapc 'delete-extent zmacs-region-extent) | |
| 4032 (delete-extent zmacs-region-extent)) | |
| 4033 (setq zmacs-region-extent nil))) | |
| 4034 (run-hooks 'zmacs-deactivate-region-hook) | |
| 4035 t)) | |
| 4036 | |
| 4037 (defun zmacs-update-region () | |
| 4038 "Update the highlighted region between `point' and `mark'. | |
| 4039 You shouldn't need to call this; the command loop calls it | |
| 4040 when appropriate. Calling this function will call the hook | |
| 4041 `zmacs-update-region-hook', if the region is active." | |
| 4042 (when zmacs-region-active-p | |
| 4043 (when (marker-buffer (mark-marker t)) | |
| 4044 (zmacs-make-extent-for-region (cons (point-marker t) | |
| 4045 (mark-marker t)))) | |
| 4046 (run-hooks 'zmacs-update-region-hook))) | |
| 4047 | |
| 442 | 4048 |
| 4049 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| 4050 ;; message logging code ;; | |
| 4051 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| 428 | 4052 |
| 4053 ;;; #### Should this be moved to a separate file, for clarity? | |
| 4054 ;;; -hniksic | |
| 4055 | |
| 4056 ;;; The `message-stack' is an alist of labels with messages; the first | |
| 4057 ;;; message in this list is always in the echo area. A call to | |
| 4058 ;;; `display-message' inserts a label/message pair at the head of the | |
| 4059 ;;; list, and removes any other pairs with that label. Calling | |
| 4060 ;;; `clear-message' causes any pair with matching label to be removed, | |
| 4061 ;;; and this may cause the displayed message to change or vanish. If | |
| 4062 ;;; the label arg is nil, the entire message stack is cleared. | |
| 4063 ;;; | |
| 4064 ;;; Message/error filtering will be a little tricker to implement than | |
| 4065 ;;; logging, since messages can be built up incrementally | |
| 4066 ;;; using clear-message followed by repeated calls to append-message | |
| 4067 ;;; (this happens with error messages). For messages which aren't | |
| 4068 ;;; created this way, filtering could be implemented at display-message | |
| 4069 ;;; very easily. | |
| 4070 ;;; | |
| 4071 ;;; Bits of the logging code are borrowed from log-messages.el by | |
| 4072 ;;; Robert Potter (rpotter@grip.cis.upenn.edu). | |
| 4073 | |
| 4074 ;; need this to terminate the currently-displayed message | |
| 4075 ;; ("Loading simple ...") | |
| 4076 (when (and | |
| 4077 (not (fboundp 'display-message)) | |
| 4078 (not (featurep 'debug))) | |
| 1346 | 4079 (set-device-clear-left-side nil nil) |
| 428 | 4080 (send-string-to-terminal "\n")) |
| 4081 | |
| 4082 (defvar message-stack nil | |
| 4083 "An alist of label/string pairs representing active echo-area messages. | |
| 4084 The first element in the list is currently displayed in the echo area. | |
| 4085 Do not modify this directly--use the `message' or | |
| 4086 `display-message'/`clear-message' functions.") | |
| 4087 | |
| 4088 (defvar remove-message-hook 'log-message | |
| 4089 "A function or list of functions to be called when a message is removed | |
| 4090 from the echo area at the bottom of the frame. The label of the removed | |
| 4091 message is passed as the first argument, and the text of the message | |
| 4092 as the second argument.") | |
| 4093 | |
| 4094 (defcustom log-message-max-size 50000 | |
| 4095 "Maximum size of the \" *Message-Log*\" buffer. See `log-message'." | |
| 4096 :type 'integer | |
| 4097 :group 'log-message) | |
| 4098 (make-compatible-variable 'message-log-max 'log-message-max-size) | |
| 4099 | |
| 4100 ;; We used to reject quite a lot of stuff here, but it was a bad idea, | |
| 4101 ;; for two reasons: | |
| 4102 ;; | |
| 4103 ;; a) In most circumstances, you *want* to see the message in the log. | |
| 4104 ;; The explicitly non-loggable messages should be marked as such by | |
| 4105 ;; the issuer. Gratuitous non-displaying of random regexps made | |
| 4106 ;; debugging harder, too (because various reasonable debugging | |
| 4107 ;; messages would get eaten). | |
| 4108 ;; | |
| 4109 ;; b) It slowed things down. Yes, visibly. | |
| 4110 ;; | |
| 4111 ;; So, I left only a few of the really useless ones on this kill-list. | |
| 4112 ;; | |
| 4113 ;; --hniksic | |
| 4114 (defcustom log-message-ignore-regexps | |
| 4115 '(;; Note: adding entries to this list slows down messaging | |
| 440 | 4116 ;; significantly. Wherever possible, use message labels. |
| 428 | 4117 |
| 4118 ;; Often-seen messages | |
| 4119 "\\`\\'" ; empty message | |
| 4120 "\\`\\(Beginning\\|End\\) of buffer\\'" | |
| 4121 ;;"^Quit$" | |
| 4122 ;; completions | |
| 4123 ;; Many packages print this -- impossible to categorize | |
| 4124 ;;"^Making completion list" | |
| 4125 ;; Gnus | |
| 4126 ;; "^No news is no news$" | |
| 4127 ;; "^No more\\( unread\\)? newsgroups$" | |
| 4128 ;; "^Opening [^ ]+ server\\.\\.\\." | |
| 4129 ;; "^[^:]+: Reading incoming mail" | |
| 4130 ;; "^Getting mail from " | |
| 4131 ;; "^\\(Generating Summary\\|Sorting threads\\|Making sparse threads\\|Scoring\\|Checking new news\\|Expiring articles\\|Sending\\)\\.\\.\\." | |
| 4132 ;; "^\\(Fetching headers for\\|Retrieving newsgroup\\|Reading active file\\)" | |
| 4133 ;; "^No more\\( unread\\)? articles" | |
| 4134 ;; "^Deleting article " | |
| 4135 ;; W3 | |
| 4136 ;; "^Parsed [0-9]+ of [0-9]+ ([0-9]+%)" | |
| 4137 ) | |
| 4138 "List of regular expressions matching messages which shouldn't be logged. | |
| 4139 See `log-message'. | |
| 4140 | |
| 3929 | 4141 Adding entries to this list slows down messaging significantly. Wherever |
| 4142 possible, messages which might need to be ignored should be labeled with | |
| 4143 'progress, 'prompt, or 'no-log, so they can be filtered by | |
| 4144 log-message-ignore-labels." | |
| 428 | 4145 :type '(repeat regexp) |
| 4146 :group 'log-message) | |
| 4147 | |
| 4148 (defcustom log-message-ignore-labels | |
| 4149 '(help-echo command progress prompt no-log garbage-collecting auto-saving) | |
| 4150 "List of symbols indicating labels of messages which shouldn't be logged. | |
| 4151 See `display-message' for some common labels. See also `log-message'." | |
| 4152 :type '(repeat (symbol :tag "Label")) | |
| 4153 :group 'log-message) | |
| 4154 | |
| 1703 | 4155 (defcustom redisplay-echo-area-function 'redisplay-echo-area |
| 4156 "The function to call to display echo area buffer." | |
| 4157 :type 'function | |
| 4158 :group 'log-message) | |
| 4159 | |
| 4160 (defcustom undisplay-echo-area-function nil | |
| 3929 | 4161 "The function to call to undisplay echo area buffer. |
| 4162 WARNING: any problem with your function is likely to result in an | |
| 4163 uninterruptible infinite loop. Use of custom functions is therefore not | |
| 4164 recommended." | |
| 4165 :type '(choice (const nil) | |
| 4166 function) | |
| 4167 :group 'log-message) | |
| 4168 | |
| 4169 (defvar undisplay-echo-area-resize-window-allowed t | |
| 4170 "INTERNAL USE ONLY. | |
| 4171 Guards against `undisplay-echo-area-resize-window' infloops. | |
| 4172 Touch this at your own risk.") | |
| 4173 | |
| 4174 (defun undisplay-echo-area-resize-window () | |
| 4175 "Resize idle echo area window to `resize-minibuffer-idle-height'. | |
| 4176 If either `resize-minibuffer-idle-height' or `resize-minibuffer-mode' is nil, | |
| 4177 does nothing. If `resize-minibuffer-window-exactly' is non-nil, always resize | |
| 4178 to this height exactly, otherwise if current height is no larger than this, | |
| 4179 leave it as is." | |
| 4180 (when (default-value undisplay-echo-area-resize-window-allowed) | |
| 4181 (setq-default undisplay-echo-area-resize-window-allowed nil) | |
| 4182 (let* ((mbw (minibuffer-window)) | |
| 4183 (height (window-height mbw))) | |
| 4184 (with-boundp '(resize-minibuffer-idle-height) | |
| 4185 (and resize-minibuffer-mode | |
| 4186 (numberp resize-minibuffer-idle-height) | |
| 4187 (> resize-minibuffer-idle-height 0) | |
| 4188 (unless (if resize-minibuffer-window-exactly | |
| 4189 (= resize-minibuffer-idle-height height) | |
| 4190 (<= resize-minibuffer-idle-height height)) | |
| 4191 (enlarge-window (- resize-minibuffer-idle-height height) | |
| 4192 nil mbw)))) | |
| 4193 (setq-default undisplay-echo-area-resize-window-allowed t)))) | |
| 1703 | 4194 |
| 428 | 4195 ;;Subsumed by view-lossage |
| 4196 ;; Not really, I'm adding it back by popular demand. -slb | |
| 4197 (defun show-message-log () | |
| 4198 "Show the \" *Message-Log*\" buffer, which contains old messages and errors." | |
| 4199 (interactive) | |
| 793 | 4200 (view-lossage t)) |
| 428 | 4201 |
| 4202 (defvar log-message-filter-function 'log-message-filter | |
| 4203 "Value must be a function of two arguments: a symbol (label) and | |
| 4204 a string (message). It should return non-nil to indicate a message | |
| 4205 should be logged. Possible values include 'log-message-filter and | |
| 4206 'log-message-filter-errors-only.") | |
| 4207 | |
| 4208 (defun log-message-filter (label message) | |
| 4209 "Default value of `log-message-filter-function'. | |
| 4210 Messages whose text matches one of the `log-message-ignore-regexps' | |
| 4211 or whose label appears in `log-message-ignore-labels' are not saved." | |
| 4212 (let ((r log-message-ignore-regexps) | |
| 4213 (ok (not (memq label log-message-ignore-labels)))) | |
| 4214 (save-match-data | |
| 4215 (while (and r ok) | |
| 4216 (when (string-match (car r) message) | |
| 4217 (setq ok nil)) | |
| 4218 (setq r (cdr r)))) | |
| 4219 ok)) | |
| 4220 | |
| 4221 (defun log-message-filter-errors-only (label message) | |
| 4222 "For use as the `log-message-filter-function'. Only logs error messages." | |
| 4223 (eq label 'error)) | |
| 4224 | |
| 4225 (defun log-message (label message) | |
| 4226 "Stuff a copy of the message into the \" *Message-Log*\" buffer, | |
| 4227 if it satisfies the `log-message-filter-function'. | |
| 4228 | |
| 4229 For use on `remove-message-hook'." | |
| 4230 (when (and (not noninteractive) | |
| 4231 (funcall log-message-filter-function label message)) | |
| 4232 ;; Use save-excursion rather than save-current-buffer because we | |
| 4233 ;; change the value of point. | |
| 4234 (save-excursion | |
| 4235 (set-buffer (get-buffer-create " *Message-Log*")) | |
| 4236 (goto-char (point-max)) | |
| 4237 ;(insert (concat (upcase (symbol-name label)) ": " message "\n")) | |
| 4238 (let (extent) | |
| 4239 ;; Mark multiline message with an extent, which `view-lossage' | |
| 4240 ;; will recognize. | |
| 793 | 4241 (save-match-data |
| 4242 (when (string-match "\n" message) | |
| 4243 (setq extent (make-extent (point) (point))) | |
| 4244 (set-extent-properties extent '(end-open nil message-multiline t))) | |
| 4245 ) | |
| 428 | 4246 (insert message "\n") |
| 4247 (when extent | |
| 4248 (set-extent-property extent 'end-open t))) | |
| 4249 (when (> (point-max) (max log-message-max-size (point-min))) | |
| 4250 ;; Trim log to ~90% of max size. | |
| 4251 (goto-char (max (- (point-max) | |
| 4252 (truncate (* 0.9 log-message-max-size))) | |
| 4253 (point-min))) | |
| 4254 (forward-line 1) | |
| 4255 (delete-region (point-min) (point)))))) | |
| 4256 | |
| 4257 (defun message-displayed-p (&optional return-string frame) | |
| 4258 "Return a non-nil value if a message is presently displayed in the\n\ | |
| 4259 minibuffer's echo area. If optional argument RETURN-STRING is non-nil,\n\ | |
| 4260 return a string containing the message, otherwise just return t." | |
| 4261 ;; by definition, a message is displayed if the echo area buffer is | |
| 4262 ;; non-empty (see also echo_area_active()). It had better also | |
| 4263 ;; be the case that message-stack is nil exactly when the echo area | |
| 4264 ;; is non-empty. | |
| 4265 (let ((buffer (get-buffer " *Echo Area*"))) | |
| 4266 (and (< (point-min buffer) (point-max buffer)) | |
| 4267 (if return-string | |
| 4268 (buffer-substring nil nil buffer) | |
| 4269 t)))) | |
| 4270 | |
| 4271 ;;; Returns the string which remains in the echo area, or nil if none. | |
| 4272 ;;; If label is nil, the whole message stack is cleared. | |
| 4273 (defun clear-message (&optional label frame stdout-p no-restore) | |
| 4274 "Remove any message with the given LABEL from the message-stack, | |
| 4275 erasing it from the echo area if it's currently displayed there. | |
| 4276 If a message remains at the head of the message-stack and NO-RESTORE | |
| 4277 is nil, it will be displayed. The string which remains in the echo | |
| 4278 area will be returned, or nil if the message-stack is now empty. | |
| 4279 If LABEL is nil, the entire message-stack is cleared. | |
| 3929 | 4280 STDOUT-P is ignored, except for output to stream devices. For streams, |
| 4281 STDOUT-P non-nil directs output to stdout, otherwise to stderr. \(This is | |
| 4282 used only in case of restoring an earlier message from the stack.) | |
| 428 | 4283 |
| 4284 Unless you need the return value or you need to specify a label, | |
| 4285 you should just use (message nil)." | |
| 4286 (or frame (setq frame (selected-frame))) | |
| 4287 (let ((clear-stream (and message-stack (eq 'stream (frame-type frame))))) | |
| 4288 (remove-message label frame) | |
| 502 | 4289 (let ((inhibit-read-only t)) |
| 428 | 4290 (erase-buffer " *Echo Area*")) |
| 1703 | 4291 (if undisplay-echo-area-function |
| 4292 (funcall undisplay-echo-area-function)) | |
| 1346 | 4293 ;; If outputting to the terminal, make sure we clear the left side. |
| 4294 (when (or clear-stream | |
| 4295 (and (eq 'stream (frame-type frame)) | |
| 4296 (not (device-left-side-clear-p (frame-device frame))))) | |
| 4297 (set-device-clear-left-side (frame-device frame) nil) | |
| 4298 (send-string-to-terminal ?\n stdout-p)) | |
| 428 | 4299 (if no-restore |
| 4300 nil ; just preparing to put another msg up | |
| 4301 (if message-stack | |
| 4302 (let ((oldmsg (cdr (car message-stack)))) | |
| 4303 (raw-append-message oldmsg frame stdout-p) | |
| 4304 oldmsg) | |
| 4305 ;; #### Should we (redisplay-echo-area) here? Messes some | |
| 4306 ;; things up. | |
| 4307 nil)))) | |
| 4308 | |
| 4309 (defun remove-message (&optional label frame) | |
| 4310 ;; If label is nil, we want to remove all matching messages. | |
| 4311 ;; Must reverse the stack first to log them in the right order. | |
| 4312 (let ((log nil)) | |
| 4313 (while (and message-stack | |
| 4314 (or (null label) ; null label means clear whole stack | |
| 4315 (eq label (car (car message-stack))))) | |
| 4316 (push (car message-stack) log) | |
| 4317 (setq message-stack (cdr message-stack))) | |
| 4318 (let ((s message-stack)) | |
| 4319 (while (cdr s) | |
| 4320 (let ((msg (car (cdr s)))) | |
| 4321 (if (eq label (car msg)) | |
| 4322 (progn | |
| 4323 (push msg log) | |
| 4324 (setcdr s (cdr (cdr s)))) | |
| 4325 (setq s (cdr s)))))) | |
| 4326 ;; (possibly) log each removed message | |
| 4327 (while log | |
| 793 | 4328 (with-trapping-errors |
| 4329 :operation 'remove-message-hook | |
| 4330 :class 'message-log | |
| 4331 :error-form (progn | |
| 4332 (setq remove-message-hook nil) | |
| 4333 (let ((inhibit-read-only t)) | |
| 4334 (erase-buffer " *Echo Area*"))) | |
| 4335 :resignal t | |
| 4336 (run-hook-with-args 'remove-message-hook | |
| 4337 (car (car log)) (cdr (car log)))) | |
| 428 | 4338 (setq log (cdr log))))) |
| 4339 | |
| 4340 (defun append-message (label message &optional frame stdout-p) | |
| 3929 | 4341 "Add MESSAGE to the message-stack, or append it to the existing text. |
| 4342 LABEL is the class of the message. If it is the same as that of the top of | |
| 4343 the message stack, MESSAGE is appended to the existing message, otherwise | |
| 4344 it is pushed on the stack. | |
| 4345 FRAME determines the minibuffer window to send the message to. | |
| 4346 STDOUT-P is ignored, except for output to stream devices. For streams, | |
| 4347 STDOUT-P non-nil directs output to stdout, otherwise to stderr." | |
| 428 | 4348 (or frame (setq frame (selected-frame))) |
| 1346 | 4349 ;; If outputting to the terminal, make sure output from anyone else clears |
| 4350 ;; the left side first, but don't do it ourselves, otherwise we won't be | |
| 4351 ;; able to append to an existing message. | |
| 4352 (if (eq 'stream (frame-type frame)) | |
| 4353 (set-device-clear-left-side (frame-device frame) nil)) | |
| 428 | 4354 (let ((top (car message-stack))) |
| 4355 (if (eq label (car top)) | |
| 4356 (setcdr top (concat (cdr top) message)) | |
| 4357 (push (cons label message) message-stack))) | |
| 1346 | 4358 (raw-append-message message frame stdout-p) |
| 4359 (if (eq 'stream (frame-type frame)) | |
| 4360 (set-device-clear-left-side (frame-device frame) t))) | |
| 428 | 4361 |
| 3929 | 4362 ;; Really append the message to the echo area. No fiddling with |
| 428 | 4363 ;; message-stack. |
| 4364 (defun raw-append-message (message &optional frame stdout-p) | |
| 4365 (unless (equal message "") | |
| 502 | 4366 (let ((inhibit-read-only t)) |
| 3652 | 4367 (with-current-buffer " *Echo Area*" |
| 4368 (insert-string message) | |
| 3929 | 4369 ;; #### This needs to be conditional; cf discussion by Stefan Monnier |
| 4370 ;; et al on emacs-devel in mid-to-late April 2007. One problem is | |
| 4371 ;; there is no known good way to guess whether the user wants to have | |
| 4372 ;; the echo area height changed on him asynchronously, especially | |
| 4373 ;; after message display. | |
| 4374 ;; There is also a problem where Lisp backtraces get sent to the echo | |
| 4375 ;; area, thus maxing out the window height. Unfortunately, it doesn't | |
| 4376 ;; return to a reasonable size very quickly. | |
| 4377 ;; It is not clear that echo area and minibuffer behavior should be | |
| 4378 ;; linked as we do here. It's OK for now; at least this obeys the | |
| 4379 ;; minibuffer resizing conventions which seem a pretty good guess | |
| 4380 ;; at user preference. | |
| 4381 (when resize-minibuffer-mode | |
| 4382 ;; #### interesting idea, unbearable implementation | |
| 4383 ;; (fill-region (point-min) (point-max)) | |
| 4384 ;; | |
| 4385 ;; #### We'd like to be able to do something like | |
| 4386 ;; | |
| 4387 ;; (save-window-excursion | |
| 4388 ;; (select-window (minibuffer-window frame)) | |
| 4389 ;; (resize-minibuffer-window)))) | |
| 4390 ;; | |
| 4391 ;; but that can't work, because the echo area isn't a real window! | |
| 4392 ;; We should fix that, but this is an approximation, duplicating the | |
| 4393 ;; resize-minibuffer code. | |
| 4394 (let* ((mbw (minibuffer-window frame)) | |
| 4395 (height (window-height mbw)) | |
| 4396 (lines (ceiling (/ (- (point-max) (point-min)) | |
| 4397 (- (window-width mbw) 1.0))))) | |
| 4398 (and (numberp resize-minibuffer-window-max-height) | |
| 4399 (> resize-minibuffer-window-max-height 0) | |
| 4400 (setq lines (min lines | |
| 4401 resize-minibuffer-window-max-height))) | |
| 4402 (or (if resize-minibuffer-window-exactly | |
| 4403 (= lines height) | |
| 4404 (<= lines height)) | |
| 4405 (enlarge-window (- lines height) nil mbw))))) | |
| 428 | 4406 |
| 4407 ;; Don't redisplay the echo area if we are executing a macro. | |
| 4408 (if (not executing-kbd-macro) | |
| 3929 | 4409 ;; Conditionalizing on the device type in this way isn't clean, but |
| 4410 ;; neither is having a device method, as I originally implemented | |
| 4411 ;; it: all non-stream devices behave in the same way. Perhaps | |
| 4412 ;; the cleanest way is to make the concept of a "redisplayable" | |
| 4413 ;; device, which stream devices are not. Look into this more if | |
| 4414 ;; we ever create another non-redisplayable device type (e.g. | |
| 4415 ;; processes? printers?). | |
| 428 | 4416 (if (eq 'stream (frame-type frame)) |
| 4417 (send-string-to-terminal message stdout-p (frame-device frame)) | |
| 1703 | 4418 (funcall redisplay-echo-area-function)))))) |
| 428 | 4419 |
| 4420 (defun display-message (label message &optional frame stdout-p) | |
| 4421 "Print a one-line message at the bottom of the frame. First argument | |
| 4422 LABEL is an identifier for this message. MESSAGE is the string to display. | |
| 4423 Use `clear-message' to remove a labelled message. | |
| 3929 | 4424 STDOUT-P is ignored, except for output to stream devices. For streams, |
| 4425 STDOUT-P non-nil directs output to stdout, otherwise to stderr. | |
| 428 | 4426 |
| 4427 Here are some standard labels (those marked with `*' are not logged | |
| 4428 by default--see the `log-message-ignore-labels' variable): | |
| 4429 message default label used by the `message' function | |
| 4430 error default label used for reporting errors | |
| 4431 * progress progress indicators like \"Converting... 45%\" | |
| 4432 * prompt prompt-like messages like \"I-search: foo\" | |
| 4433 * command helper command messages like \"Mark set\" | |
| 4434 * no-log messages that should never be logged" | |
| 4435 (clear-message label frame stdout-p t) | |
| 4436 (append-message label message frame stdout-p)) | |
| 4437 | |
| 4438 (defun current-message (&optional frame) | |
| 4439 "Return the current message in the echo area, or nil. | |
| 4440 The FRAME argument is currently unused." | |
| 4441 (cdr (car message-stack))) | |
| 4442 | |
| 4443 ;;; may eventually be frame-dependent | |
| 4444 (defun current-message-label (&optional frame) | |
| 4445 (car (car message-stack))) | |
| 4446 | |
| 4447 (defun message (fmt &rest args) | |
| 4448 "Print a one-line message at the bottom of the frame. | |
| 4449 The arguments are the same as to `format'. | |
| 4450 | |
| 4451 If the only argument is nil, clear any existing message; let the | |
| 4452 minibuffer contents show." | |
| 4453 ;; questionable junk in the C code | |
| 4454 ;; (if (framep default-minibuffer-frame) | |
| 4455 ;; (make-frame-visible default-minibuffer-frame)) | |
| 4456 (if (and (null fmt) (null args)) | |
| 4457 (prog1 nil | |
| 4458 (clear-message nil)) | |
| 4459 (let ((str (apply 'format fmt args))) | |
| 4460 (display-message 'message str) | |
| 4461 str))) | |
| 4462 | |
| 4463 (defun lmessage (label fmt &rest args) | |
| 4464 "Print a one-line message at the bottom of the frame. | |
| 4465 First argument LABEL is an identifier for this message. The rest of the | |
| 4466 arguments are the same as to `format'. | |
| 4467 | |
| 4468 See `display-message' for a list of standard labels." | |
| 4469 (if (and (null fmt) (null args)) | |
| 4470 (prog1 nil | |
| 4471 (clear-message label nil)) | |
| 4472 (let ((str (apply 'format fmt args))) | |
| 4473 (display-message label str) | |
| 4474 str))) | |
| 4475 | |
| 442 | 4476 |
| 4477 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| 4478 ;; warning code ;; | |
| 4479 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| 428 | 4480 |
| 4481 (defcustom log-warning-minimum-level 'info | |
| 4482 "Minimum level of warnings that should be logged. | |
| 4483 The warnings in levels below this are completely ignored, as if they never | |
| 4484 happened. | |
| 4485 | |
| 4486 The recognized warning levels, in decreasing order of priority, are | |
| 793 | 4487 'emergency, 'critical, 'error, 'warning, 'alert, 'notice, 'info, and |
| 428 | 4488 'debug. |
| 4489 | |
| 4490 See also `display-warning-minimum-level'. | |
| 4491 | |
| 4492 You can also control which warnings are displayed on a class-by-class | |
| 4493 basis. See `display-warning-suppressed-classes' and | |
| 793 | 4494 `log-warning-suppressed-classes'. |
| 4495 | |
| 3064 | 4496 For a description of the meaning of the levels, see `display-warning'." |
| 793 | 4497 :type '(choice (const emergency) (const critical) |
| 4498 (const error) (const warning) (const alert) (const notice) | |
| 428 | 4499 (const info) (const debug)) |
| 4500 :group 'warnings) | |
| 4501 | |
| 793 | 4502 (defcustom display-warning-minimum-level 'warning |
| 4503 "Minimum level of warnings that cause the warnings buffer to be displayed. | |
| 4504 Warnings at this level or higher will force the *Warnings* buffer, in which | |
| 4505 the warnings are logged, to be displayed. The warnings in levels below | |
| 4506 this, but at least as high as `log-warning-suppressed-classes', will be | |
| 4507 shown in the minibuffer. | |
| 428 | 4508 |
| 4509 The recognized warning levels, in decreasing order of priority, are | |
| 793 | 4510 'emergency, 'critical, 'error, 'warning, 'alert, 'notice, 'info, and |
| 428 | 4511 'debug. |
| 4512 | |
| 4513 See also `log-warning-minimum-level'. | |
| 4514 | |
| 4515 You can also control which warnings are displayed on a class-by-class | |
| 4516 basis. See `display-warning-suppressed-classes' and | |
| 793 | 4517 `log-warning-suppressed-classes'. |
| 4518 | |
| 3064 | 4519 For a description of the meaning of the levels, see `display-warning'." |
| 793 | 4520 :type '(choice (const emergency) (const critical) |
| 4521 (const error) (const warning) (const alert) (const notice) | |
| 428 | 4522 (const info) (const debug)) |
| 4523 :group 'warnings) | |
| 4524 | |
| 4525 (defvar log-warning-suppressed-classes nil | |
| 4526 "List of classes of warnings that shouldn't be logged or displayed. | |
| 4527 If any of the CLASS symbols associated with a warning is the same as | |
| 4528 any of the symbols listed here, the warning will be completely ignored, | |
| 4529 as it they never happened. | |
| 4530 | |
| 4531 NOTE: In most circumstances, you should *not* set this variable. | |
| 4532 Set `display-warning-suppressed-classes' instead. That way the suppressed | |
| 4533 warnings are not displayed but are still unobtrusively logged. | |
| 4534 | |
| 4535 See also `log-warning-minimum-level' and `display-warning-minimum-level'.") | |
| 4536 | |
| 4537 (defcustom display-warning-suppressed-classes nil | |
| 4538 "List of classes of warnings that shouldn't be displayed. | |
| 4539 If any of the CLASS symbols associated with a warning is the same as | |
| 4540 any of the symbols listed here, the warning will not be displayed. | |
| 4541 The warning will still logged in the *Warnings* buffer (unless also | |
| 4542 contained in `log-warning-suppressed-classes'), but the buffer will | |
| 4543 not be automatically popped up. | |
| 4544 | |
| 4545 See also `log-warning-minimum-level' and `display-warning-minimum-level'." | |
| 4546 :type '(repeat symbol) | |
| 4547 :group 'warnings) | |
| 4548 | |
| 4549 (defvar warning-count 0 | |
| 4550 "Count of the number of warning messages displayed so far.") | |
| 4551 | |
| 4552 (defconst warning-level-alist '((emergency . 8) | |
| 793 | 4553 (critical . 7) |
| 4554 (error . 6) | |
| 4555 (warning . 5) | |
| 4556 (alert . 4) | |
| 428 | 4557 (notice . 3) |
| 4558 (info . 2) | |
| 4559 (debug . 1))) | |
| 4560 | |
| 4561 (defun warning-level-p (level) | |
| 4562 "Non-nil if LEVEL specifies a warning level." | |
| 4563 (and (symbolp level) (assq level warning-level-alist))) | |
| 4564 | |
| 793 | 4565 (defun warning-level-< (level1 level2) |
| 4566 "Non-nil if warning level LEVEL1 is lower than LEVEL2." | |
| 4567 (check-argument-type 'warning-level-p level1) | |
| 4568 (check-argument-type 'warning-level-p level2) | |
| 4569 (< (cdr (assq level1 warning-level-alist)) | |
| 4570 (cdr (assq level2 warning-level-alist)))) | |
| 4571 | |
| 428 | 4572 ;; If you're interested in rewriting this function, be aware that it |
| 4573 ;; could be called at arbitrary points in a Lisp program (when a | |
| 4574 ;; built-in function wants to issue a warning, it will call out to | |
| 4575 ;; this function the next time some Lisp code is evaluated). Therefore, | |
| 4576 ;; this function *must* not permanently modify any global variables | |
| 4577 ;; (e.g. the current buffer) except those that specifically apply | |
| 4578 ;; to the warning system. | |
| 4579 | |
| 4580 (defvar before-init-deferred-warnings nil) | |
| 4581 | |
| 4582 (defun after-init-display-warnings () | |
| 4583 "Display warnings deferred till after the init file is run. | |
| 4584 Warnings that occur before then are deferred so that warning | |
| 4585 suppression in the .emacs file will be honored." | |
| 4586 (while before-init-deferred-warnings | |
| 4587 (apply 'display-warning (car before-init-deferred-warnings)) | |
| 4588 (setq before-init-deferred-warnings | |
| 4589 (cdr before-init-deferred-warnings)))) | |
| 4590 | |
| 4591 (add-hook 'after-init-hook 'after-init-display-warnings) | |
| 4592 | |
| 4593 (defun display-warning (class message &optional level) | |
| 4594 "Display a warning message. | |
| 793 | 4595 |
| 4596 \[This is the most basic entry point for displaying a warning. In practice, | |
| 4597 `lwarn' or `warn' are probably more convenient for most usages.] | |
| 4598 | |
| 4599 CLASS should be a symbol describing what sort of warning this is, such as | |
| 4600 `resource' or `key-mapping' -- this refers, more or less, to the module in | |
| 4601 which the warning is generated and serves to group warnings together with | |
| 4602 similar semantics. A list of such symbols is also accepted. | |
| 4603 | |
| 4604 Optional argument LEVEL can be used to specify a priority for the warning, | |
| 4605 other than default priority `warning'. The currently defined levels are, | |
| 4606 from highest to lowest: | |
| 4607 | |
| 4608 Level Meaning | |
| 4609 ----------------------------------------------------------------------------- | |
| 4610 emergency A fatal or near-fatal error. XEmacs is likely to crash. | |
| 4611 | |
| 4612 critical A serious, nonrecoverable problem has occurred -- e.g., the | |
| 4613 loss of a major subsystem, such as the crash of the X server | |
| 4614 when XEmacs is connected to the server. | |
| 4615 | |
| 4616 error A warning about a problematic condition that should be fixed, | |
| 4617 and XEmacs cannot work around it -- it causes a failure of an | |
| 4618 operation. (In most circumstances, consider just signalling | |
| 4619 an error). However, there is no permanent damage and the | |
| 4620 situation is ultimately recoverable. | |
| 4621 | |
| 4622 warning A warning about a problematic condition that should be fixed, | |
| 4623 but XEmacs can work around it. | |
| 4624 | |
| 4625 \[By default, warnings above here, as well as being logged, cause the | |
| 4626 *Warnings* buffer to be forcibly displayed, so that the warning (and | |
| 4627 previous warnings, since often a whole series of warnings are issued at | |
| 4628 once) can be examined in detail. Also, the annoying presence of the | |
| 4629 *Warnings* buffer will encourage people to go out and fix the | |
| 4630 problem. Warnings below here are displayed in the minibuffer as well as | |
| 4631 logged in the *Warnings* buffer. but the *Warnings* buffer will not be | |
| 4632 forcibly shown, as these represent conditions the user is not expected to | |
| 4633 fix.] | |
| 4634 | |
| 4635 alert A warning about a problematic condition that can't easily be | |
| 4636 fixed (often having to do with the external environment), and | |
| 4637 causes a failure. We don't force the *Warnings* buffer to be | |
| 4638 displayed because the purpose of doing that is to force the | |
| 4639 user to fix the problem so that the buffer no longer appears. | |
| 4640 When the problem is outside the user's control, forcing the | |
| 4641 buffer is pointless and annoying. | |
| 4642 | |
| 4643 notice A warning about a problematic condition that can't easily be | |
| 4644 fixed (often having to do with the external environment), | |
| 4645 but XEmacs can work around it. | |
| 4646 | |
| 4647 info Random info about something new or unexpected that was noticed; | |
| 4648 does not generally indicate a problem. | |
| 4649 | |
| 4650 \[By default, warnings below here are ignored entirely. All warnings above | |
| 4651 here are logged in the *Warnings* buffer.] | |
| 4652 | |
| 4653 debug A debugging notice; normally, not seen at all. | |
| 4654 | |
| 4655 NOTE: `specifier-instance' outputs warnings at level `debug' when errors occur | |
| 4656 in the process of trying to instantiate a particular instantiator. If you | |
| 4657 want to see these, change `log-warning-minimum-level'. | |
| 4658 | |
| 4659 There are two sets of variables. One controls the lower level (see the | |
| 4660 above diagram) -- i.e. ignored entirely. One controls the upper level -- | |
| 4661 whether the *Warnings* buffer is forcibly displayed. In particular: | |
| 4662 | |
| 4663 `display-warning-minimum-level' sets the upper level (see above), and | |
| 4664 `log-warning-minimum-level' the lower level. | |
| 4665 | |
| 4666 Individual classes can be suppressed. `log-warning-suppressed-classes' | |
| 4667 specifies a list of classes where warnings on those classes will be treated | |
| 4668 as if their level is below `log-warning-minimum-level' (i.e. they will be | |
| 4669 ignored completely), regardless of their actual level. Similarly, | |
| 4670 `display-warning-suppressed-classes' specifies a list of classes where | |
| 4671 warnings on those classes will be treated as if their level is below | |
| 4672 `display-warning-minimum-level', but above `log-warning-minimum-level' so | |
| 4673 long as they're not listed in that variable as well." | |
| 428 | 4674 (or level (setq level 'warning)) |
| 4675 (or (listp class) (setq class (list class))) | |
| 4676 (check-argument-type 'warning-level-p level) | |
|
5228
5efbd1253905
Remove all support for InfoDock.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4957
diff
changeset
|
4677 (if (not init-file-loaded) |
| 428 | 4678 (push (list class message level) before-init-deferred-warnings) |
| 4679 (catch 'ignored | |
| 4680 (let ((display-p t) | |
| 4681 (level-num (cdr (assq level warning-level-alist)))) | |
| 4682 (if (< level-num (cdr (assq log-warning-minimum-level | |
| 4683 warning-level-alist))) | |
| 4684 (throw 'ignored nil)) | |
| 4685 (if (intersection class log-warning-suppressed-classes) | |
| 4686 (throw 'ignored nil)) | |
| 4687 | |
| 4688 (if (< level-num (cdr (assq display-warning-minimum-level | |
| 4689 warning-level-alist))) | |
| 4690 (setq display-p nil)) | |
| 4691 (if (and display-p | |
| 4692 (intersection class display-warning-suppressed-classes)) | |
| 4693 (setq display-p nil)) | |
| 4694 (let ((buffer (get-buffer-create "*Warnings*"))) | |
| 4695 (when display-p | |
| 4696 ;; The C code looks at display-warning-tick to determine | |
| 4697 ;; when it should call `display-warning-buffer'. Change it | |
| 4698 ;; to get the C code's attention. | |
| 4699 (incf display-warning-tick)) | |
| 4700 (with-current-buffer buffer | |
| 4701 (goto-char (point-max)) | |
| 4702 (incf warning-count) | |
| 793 | 4703 (let ((start (point))) |
| 4704 (princ (format "(%d) (%s/%s) " | |
| 4705 warning-count | |
| 4706 (mapconcat 'symbol-name class ",") | |
| 4707 level) | |
| 4708 buffer) | |
| 4709 (princ message buffer) | |
| 4710 (terpri buffer) | |
| 4711 (terpri buffer) | |
| 4712 (let ((ex (make-extent start (point)))) | |
| 4713 (set-extent-properties ex | |
| 4714 `(warning t warning-count ,warning-count | |
| 4715 warning-class ,class | |
| 4716 warning-level ,level))))) | |
| 4717 (message "%s: %s" (capitalize (symbol-name level)) message)))))) | |
| 428 | 4718 |
| 4719 (defun warn (&rest args) | |
| 793 | 4720 "Display a formatted warning message at default class and level. |
| 428 | 4721 The message is constructed by passing all args to `format'. The message |
| 4722 is placed in the *Warnings* buffer, which will be popped up at the next | |
| 793 | 4723 redisplay. The class of the warning is `general'; the level is `warning'. |
| 4724 | |
| 4725 See `display-warning' for more info." | |
| 4726 (display-warning 'default (apply 'format args))) | |
| 428 | 4727 |
| 4728 (defun lwarn (class level &rest args) | |
| 793 | 4729 "Display a formatted warning message at specified class and level. |
| 4730 The message is constructed by passing all args to `format'. The message | |
| 4731 is placed in the *Warnings* buffer, which will be popped up at the next | |
| 4732 redisplay. | |
| 4733 | |
| 4734 See `display-warning' for more info." | |
| 428 | 4735 (display-warning class (apply 'format args) |
| 4736 (or level 'warning))) | |
| 4737 | |
| 4738 (defvar warning-marker nil) | |
| 4739 | |
| 4740 ;; When this function is called by the C code, all non-local exits are | |
| 4741 ;; trapped and C-g is inhibited; therefore, it would be a very, very | |
| 4742 ;; bad idea for this function to get into an infinite loop. | |
| 4743 | |
| 4744 (defun display-warning-buffer () | |
| 4745 "Make the buffer that contains the warnings be visible. | |
| 4746 The C code calls this periodically, right before redisplay." | |
| 4747 (let ((buffer (get-buffer-create "*Warnings*"))) | |
| 4748 (when (or (not warning-marker) | |
| 4749 (not (eq (marker-buffer warning-marker) buffer))) | |
| 4750 (setq warning-marker (make-marker)) | |
| 4751 (set-marker warning-marker 1 buffer)) | |
| 4752 (if temp-buffer-show-function | |
| 442 | 4753 (progn |
| 4754 (funcall temp-buffer-show-function buffer) | |
| 4755 (mapc #'(lambda (win) (set-window-start win warning-marker)) | |
| 4756 (windows-of-buffer buffer nil t))) | |
| 428 | 4757 (set-window-start (display-buffer buffer) warning-marker)) |
| 4758 (set-marker warning-marker (point-max buffer) buffer))) | |
| 4759 | |
| 442 | 4760 |
| 4761 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| 4762 ;; misc junk ;; | |
| 4763 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| 4764 | |
| 428 | 4765 (defun emacs-name () |
| 4766 "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
|
4767 (cond ((featurep 'xemacs) "XEmacs") |
| 428 | 4768 (t "Emacs"))) |
| 4769 | |
| 793 | 4770 (defun debug-print-1 (&rest args) |
| 4771 "Send a debugging-type string to standard output. | |
| 4772 If the first argument is a string, it is considered to be a format | |
| 4773 specifier if there are sufficient numbers of other args, and the string is | |
| 4774 formatted using (apply #'format args). Otherwise, each argument is printed | |
| 4775 individually in a numbered list." | |
| 4776 (let ((standard-output 'external-debugging-output) | |
| 4777 (fmt (condition-case nil | |
| 4778 (and (stringp (first args)) | |
| 4779 (apply #'format args)) | |
| 4780 (error nil)))) | |
| 4781 (if fmt | |
| 4782 (progn | |
| 3064 | 4783 (princ (apply #'format args)) |
| 793 | 4784 (terpri)) |
| 4785 (princ "--> ") | |
| 4786 (let ((i 1)) | |
| 4787 (dolist (sgra args) | |
| 4788 (if (> i 1) (princ " ")) | |
| 4789 (princ (format "%d. " i)) | |
| 4790 (prin1 sgra) | |
| 4791 (incf i)) | |
| 4792 (terpri))))) | |
| 4793 | |
| 4794 (defun debug-print (&rest args) | |
| 442 | 4795 "Send a string to the debugging output. |
| 793 | 4796 If the first argument is a string, it is considered to be a format |
| 4797 specifier if there are sufficient numbers of other args, and the string is | |
| 4798 formatted using (apply #'format args). Otherwise, each argument is printed | |
| 4799 individually in a numbered list." | |
| 4800 (let ((standard-output 'external-debugging-output)) | |
| 4801 (apply #'debug-print-1 args))) | |
| 4802 | |
| 4803 (defun debug-backtrace () | |
| 4804 "Send a backtrace to the debugging output." | |
| 4805 (let ((standard-output 'external-debugging-output)) | |
| 4806 (backtrace nil t) | |
| 4807 (terpri))) | |
| 444 | 4808 |
| 428 | 4809 ;;; simple.el ends here |
