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