comparison lisp/prim/simple.el @ 72:b9518feda344 r20-0b31

Import from CVS: tag r20-0b31
author cvs
date Mon, 13 Aug 2007 09:03:46 +0200
parents 131b0175ea99
children 54cc21c15cbb
comparison
equal deleted inserted replaced
71:bae944334fa4 72:b9518feda344
14 ;; WITHOUT ANY WARRANTY; without even the implied warranty of 14 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 ;; General Public License for more details. 16 ;; General Public License for more details.
17 17
18 ;; You should have received a copy of the GNU General Public License 18 ;; You should have received a copy of the GNU General Public License
19 ;; along with XEmacs; see the file COPYING. If not, write to the 19 ;; along with XEmacs; see the file COPYING. If not, write to the Free
20 ;; Free Software Foundation, 59 Temple Place - Suite 330, 20 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21 ;; Boston, MA 02111-1307, USA. 21 ;; 02111-1307, USA.
22 22
23 ;;; Synched up with: FSF 19.30. 23 ;;; Synched up with: FSF 19.34 [But not very closely].
24 24
25 ;;; Commentary: 25 ;;; Commentary:
26 26
27 ;; A grab-bag of basic XEmacs commands not specifically related to some 27 ;; A grab-bag of basic XEmacs commands not specifically related to some
28 ;; major mode or to file-handling. 28 ;; major mode or to file-handling.
29 29
30 ;;; Changes for zmacs-style active-regions: 30 ;; Changes for zmacs-style active-regions:
31 ;;; 31 ;;
32 ;;; beginning-of-buffer, end-of-buffer, count-lines-region, 32 ;; beginning-of-buffer, end-of-buffer, count-lines-region,
33 ;;; count-lines-buffer, what-line, what-cursor-position, set-goal-column, 33 ;; count-lines-buffer, what-line, what-cursor-position, set-goal-column,
34 ;;; set-fill-column, prefix-arg-internal, and line-move (which is used by 34 ;; set-fill-column, prefix-arg-internal, and line-move (which is used by
35 ;;; next-line and previous-line) set zmacs-region-stays to t, so that they 35 ;; next-line and previous-line) set zmacs-region-stays to t, so that they
36 ;;; don't affect the current region-hilighting state. 36 ;; don't affect the current region-hilighting state.
37 ;;; 37 ;;
38 ;;; mark-whole-buffer, mark-word, exchange-point-and-mark, and 38 ;; mark-whole-buffer, mark-word, exchange-point-and-mark, and
39 ;;; set-mark-command (without an argument) call zmacs-activate-region. 39 ;; set-mark-command (without an argument) call zmacs-activate-region.
40 ;;; 40 ;;
41 ;;; mark takes an optional arg like the new Fmark_marker() does. When 41 ;; mark takes an optional arg like the new Fmark_marker() does. When
42 ;;; the region is not active, mark returns nil unless the optional arg is true. 42 ;; the region is not active, mark returns nil unless the optional arg is true.
43 ;;; 43 ;;
44 ;;; push-mark, pop-mark, exchange-point-and-mark, and set-marker, and 44 ;; push-mark, pop-mark, exchange-point-and-mark, and set-marker, and
45 ;;; set-mark-command use (mark t) so that they can access the mark whether 45 ;; set-mark-command use (mark t) so that they can access the mark whether
46 ;;; the region is active or not. 46 ;; the region is active or not.
47 ;;; 47 ;;
48 ;;; shell-command, shell-command-on-region, yank, and yank-pop (which all 48 ;; shell-command, shell-command-on-region, yank, and yank-pop (which all
49 ;;; push a mark) have been altered to call exchange-point-and-mark with an 49 ;; push a mark) have been altered to call exchange-point-and-mark with an
50 ;;; argument, meaning "don't activate the region". These commands only use 50 ;; argument, meaning "don't activate the region". These commands only use
51 ;;; exchange-point-and-mark to position the newly-pushed mark correctly, so 51 ;; exchange-point-and-mark to position the newly-pushed mark correctly, so
52 ;;; this isn't a user-visible change. These functions have also been altered 52 ;; this isn't a user-visible change. These functions have also been altered
53 ;;; to use (mark t) for the same reason. 53 ;; to use (mark t) for the same reason.
54 54
55 ;;; Code: 55 ;;; Code:
56 56
57 (defun newline (&optional arg) 57 (defun newline (&optional arg)
58 "Insert a newline, and move to left margin of the new line if it's blank. 58 "Insert a newline, and move to left margin of the new line if it's blank.
65 ;; try_window_id than inserting at the beginning of a line, and the textual 65 ;; try_window_id than inserting at the beginning of a line, and the textual
66 ;; result is the same. So, if we're at beginning of line, pretend to be at 66 ;; result is the same. So, if we're at beginning of line, pretend to be at
67 ;; the end of the previous line. 67 ;; the end of the previous line.
68 (let ((flag (and (not (bobp)) 68 (let ((flag (and (not (bobp))
69 (bolp) 69 (bolp)
70 ;; Make sure the newline before point isn't intangible.
71 (not (get-char-property (1- (point)) 'intangible))
72 ;; Make sure the newline before point isn't read-only.
73 (not (get-char-property (1- (point)) 'read-only))
74 ;; Make sure the newline before point isn't invisible.
75 (not (get-char-property (1- (point)) 'invisible))
76 ;; Make sure the newline before point has the same
77 ;; properties as the char before it (if any).
70 (< (or (previous-extent-change (point)) -2) 78 (< (or (previous-extent-change (point)) -2)
71 (- (point) 2)))) 79 (- (point) 2))))
72 (was-page-start (and (bolp) 80 (was-page-start (and (bolp)
73 (looking-at page-delimiter))) 81 (looking-at page-delimiter)))
74 (beforepos (point))) 82 (beforepos (point)))
87 ;; If we did *not* get an error, cancel that forward-char. 95 ;; If we did *not* get an error, cancel that forward-char.
88 (if flag (backward-char 1)) 96 (if flag (backward-char 1))
89 ;; Mark the newline(s) `hard'. 97 ;; Mark the newline(s) `hard'.
90 (if use-hard-newlines 98 (if use-hard-newlines
91 (let* ((from (- (point) (if arg (prefix-numeric-value arg) 1))) 99 (let* ((from (- (point) (if arg (prefix-numeric-value arg) 1)))
92 (sticky (get-text-property from 'end-open))) 100 (sticky (get-text-property from 'end-open))) ; XEmacs
93 (put-text-property from (point) 'hard 't) 101 (put-text-property from (point) 'hard 't)
94 ;; If end-open is not "t", add 'hard to end-open list 102 ;; If end-open is not "t", add 'hard to end-open list
95 (if (and (listp sticky) (not (memq 'hard sticky))) 103 (if (and (listp sticky) (not (memq 'hard sticky)))
96 (put-text-property from (point) 'end-open 104 (put-text-property from (point) 'end-open ; XEmacs
97 (cons 'hard sticky))))) 105 (cons 'hard sticky)))))
98 ;; If the newline leaves the previous line blank, 106 ;; If the newline leaves the previous line blank,
99 ;; and we have a left margin, delete that from the blank line. 107 ;; and we have a left margin, delete that from the blank line.
100 (or flag 108 (or flag
101 (save-excursion 109 (save-excursion
115 (defun open-line (arg) 123 (defun open-line (arg)
116 "Insert a newline and leave point before it. 124 "Insert a newline and leave point before it.
117 If there is a fill prefix and/or a left-margin, insert them on the new line 125 If there is a fill prefix and/or a left-margin, insert them on the new line
118 if the line would have been blank. 126 if the line would have been blank.
119 With arg N, insert N newlines." 127 With arg N, insert N newlines."
120 ;; "Insert a newline and leave point before it.
121 ;; If there is a fill prefix, insert the fill prefix on the new line
122 ;; if the line would have been empty.
123 ;; With arg N, insert N newlines."
124 (interactive "*p") 128 (interactive "*p")
125 (let* ((do-fill-prefix (and fill-prefix (bolp))) 129 (let* ((do-fill-prefix (and fill-prefix (bolp)))
126 ;well, I'm going to re-enable this. --ben
127 ;(do-fill-prefix nil) ;; screw this -- says JWZ
128 (do-left-margin (and (bolp) (> (current-left-margin) 0))) 130 (do-left-margin (and (bolp) (> (current-left-margin) 0)))
129 (loc (point))) 131 (loc (point)))
130 (newline arg) 132 (newline arg)
131 (goto-char loc) 133 (goto-char loc)
132 (while (> arg 0) 134 (while (> arg 0)
212 (delete-region (point) (progn (skip-chars-forward " \t") (point)))) 214 (delete-region (point) (progn (skip-chars-forward " \t") (point))))
213 215
214 (defun just-one-space () 216 (defun just-one-space ()
215 "Delete all spaces and tabs around point, leaving one space." 217 "Delete all spaces and tabs around point, leaving one space."
216 (interactive "*") 218 (interactive "*")
217 (if abbrev-mode 219 (if abbrev-mode ; XEmacs
218 (expand-abbrev)) 220 (expand-abbrev))
219 (skip-chars-backward " \t") 221 (skip-chars-backward " \t")
220 (if (= (following-char) ? ) 222 (if (= (following-char) ? )
221 (forward-char 1) 223 (forward-char 1)
222 (insert ? )) 224 (insert ? ))
262 (if (looking-at "^[ \t]*\n\\'") 264 (if (looking-at "^[ \t]*\n\\'")
263 (delete-region (point) (point-max))))) 265 (delete-region (point) (point-max)))))
264 266
265 (defun back-to-indentation () 267 (defun back-to-indentation ()
266 "Move point to the first non-whitespace character on this line." 268 "Move point to the first non-whitespace character on this line."
269 ;; XEmacs change
267 (interactive "_") 270 (interactive "_")
268 (beginning-of-line 1) 271 (beginning-of-line 1)
269 (skip-chars-forward " \t")) 272 (skip-chars-forward " \t"))
270 273
271 (defun newline-and-indent () 274 (defun newline-and-indent ()
321 (insert-char ?\ col) 324 (insert-char ?\ col)
322 (delete-char 1))) 325 (delete-char 1)))
323 (forward-char -1) 326 (forward-char -1)
324 (setq count (1- count))))) 327 (setq count (1- count)))))
325 (delete-backward-char arg killp) 328 (delete-backward-char arg killp)
326 ;; In overwrite mode, back over columns while clearing them out, 329 ;; XEmacs: In overwrite mode, back over columns while clearing them out,
327 ;; unless at end of line. 330 ;; unless at end of line.
328 (and overwrite-mode (not (eolp)) 331 (and overwrite-mode (not (eolp))
329 (save-excursion (insert-char ?\ arg)))) 332 (save-excursion (insert-char ?\ arg))))
330 333
331 (defun zap-to-char (arg char) 334 (defun zap-to-char (arg char)
344 If the buffer is narrowed, this command uses the beginning and size 347 If the buffer is narrowed, this command uses the beginning and size
345 of the accessible part of the buffer. 348 of the accessible part of the buffer.
346 349
347 Don't use this command in Lisp programs! 350 Don't use this command in Lisp programs!
348 \(goto-char (point-min)) is faster and avoids clobbering the mark." 351 \(goto-char (point-min)) is faster and avoids clobbering the mark."
352 ;; XEmacs change
349 (interactive "_P") 353 (interactive "_P")
350 (push-mark) 354 (push-mark)
351 (let ((size (- (point-max) (point-min)))) 355 (let ((size (- (point-max) (point-min))))
352 (goto-char (if arg 356 (goto-char (if arg
353 (+ (point-min) 357 (+ (point-min)
366 If the buffer is narrowed, this command uses the beginning and size 370 If the buffer is narrowed, this command uses the beginning and size
367 of the accessible part of the buffer. 371 of the accessible part of the buffer.
368 372
369 Don't use this command in Lisp programs! 373 Don't use this command in Lisp programs!
370 \(goto-char (point-max)) is faster and avoids clobbering the mark." 374 \(goto-char (point-max)) is faster and avoids clobbering the mark."
375 ;; XEmacs change
371 (interactive "_P") 376 (interactive "_P")
372 (push-mark) 377 (push-mark)
373 ;; XEmacs changes here. 378 ;; XEmacs changes here.
374 (let ((scroll-to-end (not (pos-visible-in-window-p (point-max)))) 379 (let ((scroll-to-end (not (pos-visible-in-window-p (point-max))))
375 (size (- (point-max) (point-min)))) 380 (size (- (point-max) (point-min))))
383 (point-max))) 388 (point-max)))
384 (cond (arg 389 (cond (arg
385 ;; If we went to a place in the middle of the buffer, 390 ;; If we went to a place in the middle of the buffer,
386 ;; adjust it to the beginning of a line. 391 ;; adjust it to the beginning of a line.
387 (forward-line 1)) 392 (forward-line 1))
393 ;; XEmacs change
388 (scroll-to-end 394 (scroll-to-end
389 ;; If the end of the buffer is not already on the screen, 395 ;; If the end of the buffer is not already on the screen,
390 ;; then scroll specially to put it near, but not at, the bottom. 396 ;; then scroll specially to put it near, but not at, the bottom.
391 (recenter -3))))) 397 (recenter -3)))))
392 398
399 ;; XEmacs (not in FSF)
393 (defun mark-beginning-of-buffer (&optional arg) 400 (defun mark-beginning-of-buffer (&optional arg)
394 "Push a mark at the beginning of the buffer; leave point where it is. 401 "Push a mark at the beginning of the buffer; leave point where it is.
395 With arg N, push mark N/10 of the way from the true beginning." 402 With arg N, push mark N/10 of the way from the true beginning."
396 (interactive "P") 403 (interactive "P")
397 (push-mark (if arg 404 (push-mark (if arg
403 (point-min)) 410 (point-min))
404 nil 411 nil
405 t)) 412 t))
406 (define-function 'mark-bob 'mark-beginning-of-buffer) 413 (define-function 'mark-bob 'mark-beginning-of-buffer)
407 414
415 ;; XEmacs (not in FSF)
408 (defun mark-end-of-buffer (&optional arg) 416 (defun mark-end-of-buffer (&optional arg)
409 "Push a mark at the end of the buffer; leave point where it is. 417 "Push a mark at the end of the buffer; leave point where it is.
410 With arg N, push mark N/10 of the way from the true end." 418 With arg N, push mark N/10 of the way from the true end."
411 (interactive "P") 419 (interactive "P")
412 (push-mark (if arg 420 (push-mark (if arg
429 (interactive) 437 (interactive)
430 (push-mark (point)) 438 (push-mark (point))
431 (push-mark (point-max) nil t) 439 (push-mark (point-max) nil t)
432 (goto-char (point-min))) 440 (goto-char (point-min)))
433 441
442 ;; XEmacs
434 (defun eval-current-buffer (&optional printflag) 443 (defun eval-current-buffer (&optional printflag)
435 "Evaluate the current buffer as Lisp code. 444 "Evaluate the current buffer as Lisp code.
436 Programs can pass argument PRINTFLAG which controls printing of output: 445 Programs can pass argument PRINTFLAG which controls printing of output:
437 nil means discard it; anything else is stream for print." 446 nil means discard it; anything else is stream for print."
438 (interactive) 447 (interactive)
439 (eval-buffer (current-buffer) printflag)) 448 (eval-buffer (current-buffer) printflag))
440 449
450 ;; XEmacs
441 (defun count-words-buffer (b) 451 (defun count-words-buffer (b)
442 (interactive "b") 452 (interactive "b")
443 (save-excursion 453 (save-excursion
444 (let ((buf (or b (current-buffer)))) 454 (let ((buf (or b (current-buffer))))
445 (set-buffer buf) 455 (set-buffer buf)
446 (message "Buffer has %d words" 456 (message "Buffer has %d words"
447 (count-words-region (point-min) (point-max)))))) 457 (count-words-region (point-min) (point-max))))))
448 458
459 ;; XEmacs
449 (defun count-words-region (start end) 460 (defun count-words-region (start end)
450 (interactive "r") 461 (interactive "r")
451 (save-excursion 462 (save-excursion
452 (let ((n 0)) 463 (let ((n 0))
453 (goto-char start) 464 (goto-char start)
457 (message "Region has %d words" n) 468 (message "Region has %d words" n)
458 n))) 469 n)))
459 470
460 (defun count-lines-region (start end) 471 (defun count-lines-region (start end)
461 "Print number of lines and characters in the region." 472 "Print number of lines and characters in the region."
473 ;; XEmacs change
462 (interactive "_r") 474 (interactive "_r")
463 (let ((n (count-lines start end))) 475 (message "Region has %d lines, %d characters"
464 (message "Region has %d lines, %d characters" 476 (count-lines start end) (- end start)))
465 n (- end start)) 477
466 n)) 478 ;; XEmacs
467
468 (defun count-lines-buffer (b) 479 (defun count-lines-buffer (b)
469 "Print number of lines and charcters in the specified buffer." 480 "Print number of lines and charcters in the specified buffer."
470 (interactive "_b") 481 (interactive "_b")
471 (save-excursion 482 (save-excursion
472 (let ((buf (or b (current-buffer))) 483 (let ((buf (or b (current-buffer)))
473 cnt) 484 cnt)
474 (set-buffer buf) 485 (set-buffer buf)
475 (setq cnt (count-lines (point-min) (point-max))) 486 (setq cnt (count-lines (point-min) (point-max)))
476 (message "Region has %d lines, %d characters" 487 (message "Buffer has %d lines, %d characters"
477 cnt (- (point-max) (point-min))) 488 cnt (- (point-max) (point-min)))
478 cnt))) 489 cnt)))
479 490
480 (defun what-line () 491 (defun what-line ()
481 "Print the current buffer line number and narrowed line number of point." 492 "Print the current buffer line number and narrowed line number of point."
493 ;; XEmacs change
482 (interactive "_") 494 (interactive "_")
483 (let ((opoint (point)) start) 495 (let ((opoint (point)) start)
484 (save-excursion 496 (save-excursion
485 (save-restriction 497 (save-restriction
486 (goto-char (point-min)) 498 (goto-char (point-min))
519 done))) 531 done)))
520 (- (buffer-size) (forward-line (buffer-size))))))) 532 (- (buffer-size) (forward-line (buffer-size)))))))
521 533
522 (defun what-cursor-position () 534 (defun what-cursor-position ()
523 "Print info on cursor position (on screen and within buffer)." 535 "Print info on cursor position (on screen and within buffer)."
536 ;; XEmacs change
524 (interactive "_") 537 (interactive "_")
525 (let* ((char (following-char)) 538 (let* ((char (following-char))
526 (beg (point-min)) 539 (beg (point-min))
527 (end (point-max)) 540 (end (point-max))
528 (pos (point)) 541 (pos (point))
539 (if (or (/= beg 1) (/= end (1+ total))) 552 (if (or (/= beg 1) (/= end (1+ total)))
540 (message "point=%d of %d(%d%%) <%d - %d> column %d %s" 553 (message "point=%d of %d(%d%%) <%d - %d> column %d %s"
541 pos total percent beg end col hscroll) 554 pos total percent beg end col hscroll)
542 (message "point=%d of %d(%d%%) column %d %s" 555 (message "point=%d of %d(%d%%) column %d %s"
543 pos total percent col hscroll)) 556 pos total percent col hscroll))
557 ;; XEmacs: don't use single-key-description
544 (if (or (/= beg 1) (/= end (1+ total))) 558 (if (or (/= beg 1) (/= end (1+ total)))
545 (message "Char: %s (0%o, %d, 0x%x) point=%d of %d(%d%%) <%d - %d> column %d %s" 559 (message "Char: %s (0%o, %d, 0x%x) point=%d of %d(%d%%) <%d - %d> column %d %s"
546 (text-char-description char) char char char pos total 560 (text-char-description char) char char char pos total
547 percent beg end col hscroll) 561 percent beg end col hscroll)
548 (message "Char: %s (0%o, %d, 0x%x) point=%d of %d(%d%%) column %d %s" 562 (message "Char: %s (0%o, %d, 0x%x) point=%d of %d(%d%%) column %d %s"
553 "Major mode not specialized for anything in particular. 567 "Major mode not specialized for anything in particular.
554 Other major modes are defined by comparison with this one." 568 Other major modes are defined by comparison with this one."
555 (interactive) 569 (interactive)
556 (kill-all-local-variables)) 570 (kill-all-local-variables))
557 571
572 ;; XEmacs the following are declared elsewhere
573 ;(defvar read-expression-map (cons 'keymap minibuffer-local-map)
574 ; "Minibuffer keymap used for reading Lisp expressions.")
575 ;(define-key read-expression-map "\M-\t" 'lisp-complete-symbol)
576
577 ;(put 'eval-expression 'disabled t)
578
579 ;(defvar read-expression-history nil)
558 580
559 ;; We define this, rather than making `eval' interactive, 581 ;; We define this, rather than making `eval' interactive,
560 ;; for the sake of completion of names like eval-region, eval-current-buffer. 582 ;; for the sake of completion of names like eval-region, eval-current-buffer.
561 (defun eval-expression (expression) 583 (defun eval-expression (expression)
562 "Evaluate EXPRESSION and print value in minibuffer. 584 "Evaluate EXPRESSION and print value in minibuffer.
563 Value is also consed on to front of the variable `values'." 585 Value is also consed on to front of the variable `values'."
564 (interactive "xEval: ") 586 ;(interactive "xEval: ")
587 (interactive
588 (list (read-from-minibuffer "Eval: "
589 nil read-expression-map t
590 'read-expression-history)))
565 (setq values (cons (eval expression) values)) 591 (setq values (cons (eval expression) values))
566 (prin1 (car values) t)) 592 (prin1 (car values) t))
567 593
594 ;; XEmacs -- extra parameter (variant, but equivalent logic)
568 (defun edit-and-eval-command (prompt command &optional history) 595 (defun edit-and-eval-command (prompt command &optional history)
569 "Prompting with PROMPT, let user edit COMMAND and eval result. 596 "Prompting with PROMPT, let user edit COMMAND and eval result.
570 COMMAND is a Lisp expression. Let user edit that expression in 597 COMMAND is a Lisp expression. Let user edit that expression in
571 the minibuffer, then read and evaluate the result." 598 the minibuffer, then read and evaluate the result."
572 (let ((command (read-expression prompt 599 (let ((command (read-expression prompt
601 If the command has been changed or is not the most recent previous command 628 If the command has been changed or is not the most recent previous command
602 it is added to the front of the command history. 629 it is added to the front of the command history.
603 You can use the minibuffer history commands \\<minibuffer-local-map>\\[next-history-element] and \\[previous-history-element] 630 You can use the minibuffer history commands \\<minibuffer-local-map>\\[next-history-element] and \\[previous-history-element]
604 to get different commands to edit and resubmit." 631 to get different commands to edit and resubmit."
605 (interactive "p") 632 (interactive "p")
633 ;; XEmacs: It looks like our version is better -sb
606 (let ((print-level nil)) 634 (let ((print-level nil))
607 (edit-and-eval-command "Redo: " 635 (edit-and-eval-command "Redo: "
608 (or (nth (1- arg) command-history) 636 (or (nth (1- arg) command-history)
609 (error "")) 637 (error ""))
610 (cons 'command-history arg)))) 638 (cons 'command-history arg))))
639
640 ;; XEmacs: Functions moved to minibuf.el
641 ;; previous-matching-history-element
642 ;; next-matching-history-element
643 ;; next-history-element
644 ;; previous-history-element
645 ;; next-complete-history-element
646 ;; previous-complete-history-element
611 647
612 (defun goto-line (arg) 648 (defun goto-line (arg)
613 "Goto line ARG, counting from line 1 at beginning of buffer." 649 "Goto line ARG, counting from line 1 at beginning of buffer."
614 (interactive "NGoto line: ") 650 (interactive "NGoto line: ")
615 (setq arg (prefix-numeric-value arg)) 651 (setq arg (prefix-numeric-value arg))
634 (let ((modified (buffer-modified-p)) 670 (let ((modified (buffer-modified-p))
635 (recent-save (recent-auto-save-p))) 671 (recent-save (recent-auto-save-p)))
636 (or (eq (selected-window) (minibuffer-window)) 672 (or (eq (selected-window) (minibuffer-window))
637 (message "Undo!")) 673 (message "Undo!"))
638 (or (and (eq last-command 'undo) 674 (or (and (eq last-command 'undo)
639 (eq (current-buffer) last-undo-buffer)) 675 (eq (current-buffer) last-undo-buffer)) ; XEmacs
640 (progn (undo-start) 676 (progn (undo-start)
641 (undo-more 1))) 677 (undo-more 1)))
642 (undo-more (or arg 1)) 678 (undo-more (or arg 1))
643 ;; Don't specify a position in the undo record for the undo command. 679 ;; Don't specify a position in the undo record for the undo command.
644 ;; Instead, undoing this should move point to where the change is. 680 ;; Instead, undoing this should move point to where the change is.
656 (setq this-command 'undo)) 692 (setq this-command 'undo))
657 693
658 (defvar pending-undo-list nil 694 (defvar pending-undo-list nil
659 "Within a run of consecutive undo commands, list remaining to be undone.") 695 "Within a run of consecutive undo commands, list remaining to be undone.")
660 696
661 (defvar last-undo-buffer nil) 697 (defvar last-undo-buffer nil) ; XEmacs
662 698
663 (defun undo-start () 699 (defun undo-start ()
664 "Set `pending-undo-list' to the front of the undo list. 700 "Set `pending-undo-list' to the front of the undo list.
665 The next call to `undo-more' will undo the most recently made change." 701 The next call to `undo-more' will undo the most recently made change."
666 (if (eq buffer-undo-list t) 702 (if (eq buffer-undo-list t)
672 Call `undo-start' to get ready to undo recent changes, 708 Call `undo-start' to get ready to undo recent changes,
673 then call `undo-more' one or more times to undo them." 709 then call `undo-more' one or more times to undo them."
674 (or pending-undo-list 710 (or pending-undo-list
675 (error "No further undo information")) 711 (error "No further undo information"))
676 (setq pending-undo-list (primitive-undo count pending-undo-list) 712 (setq pending-undo-list (primitive-undo count pending-undo-list)
677 last-undo-buffer (current-buffer))) 713 last-undo-buffer (current-buffer))) ; XEmacs
678 714
715 ;; XEmacs
679 (defun call-with-transparent-undo (fn &rest args) 716 (defun call-with-transparent-undo (fn &rest args)
680 "Apply FN to ARGS, and then undo all changes made by FN to the current 717 "Apply FN to ARGS, and then undo all changes made by FN to the current
681 buffer. The undo records are processed even if FN returns non-locally. 718 buffer. The undo records are processed even if FN returns non-locally.
682 There is no trace of the changes made by FN in the buffer's undo history. 719 There is no trace of the changes made by FN in the buffer's undo history.
683 720
700 (let ((tail buffer-undo-list)) 737 (let ((tail buffer-undo-list))
701 (setq buffer-undo-list t) 738 (setq buffer-undo-list t)
702 (while tail 739 (while tail
703 (setq tail (primitive-undo (length tail) tail)))))))))) 740 (setq tail (primitive-undo (length tail) tail))))))))))
704 741
742 ;; XEmacs: The following are in other files
743 ;; shell-command-history
744 ;; shell-command-switch
745 ;; shell-command
746 ;; shell-command-sentinel
747
705 748
706 (defconst universal-argument-map 749 (defconst universal-argument-map
707 (let ((map (make-sparse-keymap))) 750 (let ((map (make-sparse-keymap)))
708 (set-keymap-default-binding map 'universal-argument-other-key) 751 (set-keymap-default-binding map 'universal-argument-other-key)
709 ;FSFmacs (define-key map [switch-frame] nil) 752 ;FSFmacs (define-key map [switch-frame] nil)
753 (define-key map [(t)] 'universal-argument-other-key)
754 (define-key map [(meta t)] 'universal-argument-other-key)
710 (define-key map [(control u)] 'universal-argument-more) 755 (define-key map [(control u)] 'universal-argument-more)
711 (define-key map ?- 'universal-argument-minus) 756 (define-key map [?-] 'universal-argument-minus)
712 (define-key map ?0 'digit-argument) 757 (define-key map [?0] 'digit-argument)
713 (define-key map ?1 'digit-argument) 758 (define-key map [?1] 'digit-argument)
714 (define-key map ?2 'digit-argument) 759 (define-key map [?2] 'digit-argument)
715 (define-key map ?3 'digit-argument) 760 (define-key map [?3] 'digit-argument)
716 (define-key map ?4 'digit-argument) 761 (define-key map [?4] 'digit-argument)
717 (define-key map ?5 'digit-argument) 762 (define-key map [?5] 'digit-argument)
718 (define-key map ?6 'digit-argument) 763 (define-key map [?6] 'digit-argument)
719 (define-key map ?7 'digit-argument) 764 (define-key map [?7] 'digit-argument)
720 (define-key map ?8 'digit-argument) 765 (define-key map [?8] 'digit-argument)
721 (define-key map ?9 'digit-argument) 766 (define-key map [?9] 'digit-argument)
722 map) 767 map)
723 "Keymap used while processing \\[universal-argument].") 768 "Keymap used while processing \\[universal-argument].")
724 769
725 (defvar universal-argument-num-events nil 770 (defvar universal-argument-num-events nil
726 "Number of argument-specifying events read by `universal-argument'. 771 "Number of argument-specifying events read by `universal-argument'.
734 \\[universal-argument] without digits or minus sign provides 4 as argument. 779 \\[universal-argument] without digits or minus sign provides 4 as argument.
735 Repeating \\[universal-argument] without digits or minus sign 780 Repeating \\[universal-argument] without digits or minus sign
736 multiplies the argument by 4 each time." 781 multiplies the argument by 4 each time."
737 (interactive) 782 (interactive)
738 (setq prefix-arg (list 4)) 783 (setq prefix-arg (list 4))
739 (setq zmacs-region-stays t) 784 (setq zmacs-region-stays t) ; XEmacs
740 (setq universal-argument-num-events (length (this-command-keys))) 785 (setq universal-argument-num-events (length (this-command-keys)))
741 (setq overriding-terminal-local-map universal-argument-map)) 786 (setq overriding-terminal-local-map universal-argument-map))
742 787
743 ;; A subsequent C-u means to multiply the factor by 4 if we've typed 788 ;; A subsequent C-u means to multiply the factor by 4 if we've typed
744 ;; nothing but C-u's; otherwise it means to terminate the prefix arg. 789 ;; nothing but C-u's; otherwise it means to terminate the prefix arg.
746 (interactive "P") 791 (interactive "P")
747 (if (consp arg) 792 (if (consp arg)
748 (setq prefix-arg (list (* 4 (car arg)))) 793 (setq prefix-arg (list (* 4 (car arg))))
749 (setq prefix-arg arg) 794 (setq prefix-arg arg)
750 (setq overriding-terminal-local-map nil)) 795 (setq overriding-terminal-local-map nil))
751 (setq zmacs-region-stays t) 796 (setq zmacs-region-stays t) ; XEmacs
752 (setq universal-argument-num-events (length (this-command-keys)))) 797 (setq universal-argument-num-events (length (this-command-keys))))
753 798
754 (defun negative-argument (arg) 799 (defun negative-argument (arg)
755 "Begin a negative numeric argument for the next command. 800 "Begin a negative numeric argument for the next command.
756 \\[universal-argument] following digits or minus sign ends the argument." 801 \\[universal-argument] following digits or minus sign ends the argument."
759 (setq prefix-arg (- arg))) 804 (setq prefix-arg (- arg)))
760 ((eq arg '-) 805 ((eq arg '-)
761 (setq prefix-arg nil)) 806 (setq prefix-arg nil))
762 (t 807 (t
763 (setq prefix-arg '-))) 808 (setq prefix-arg '-)))
764 (setq zmacs-region-stays t) 809 (setq zmacs-region-stays t) ; XEmacs
765 (setq universal-argument-num-events (length (this-command-keys))) 810 (setq universal-argument-num-events (length (this-command-keys)))
766 (setq overriding-terminal-local-map universal-argument-map)) 811 (setq overriding-terminal-local-map universal-argument-map))
767 812
813 ;; XEmacs: This function not synched with FSF
768 (defun digit-argument (arg) 814 (defun digit-argument (arg)
769 "Part of the numeric argument for the next command. 815 "Part of the numeric argument for the next command.
770 \\[universal-argument] following digits or minus sign ends the argument." 816 \\[universal-argument] following digits or minus sign ends the argument."
771 (interactive "P") 817 (interactive "P")
772 (let* ((event last-command-event) 818 (let* ((event last-command-event)
799 ;; Anything else terminates the argument and is left in the queue to be 845 ;; Anything else terminates the argument and is left in the queue to be
800 ;; executed as a command. 846 ;; executed as a command.
801 (defun universal-argument-other-key (arg) 847 (defun universal-argument-other-key (arg)
802 (interactive "P") 848 (interactive "P")
803 (setq prefix-arg arg) 849 (setq prefix-arg arg)
804 (setq zmacs-region-stays t) 850 (setq zmacs-region-stays t) ; XEmacs
805 (let* ((key (this-command-keys)) 851 (let* ((key (this-command-keys))
806 ;; FSF calls silly function `listify-key-sequence' here. 852 ;; FSF calls silly function `listify-key-sequence' here.
807 (keylist (append key nil))) 853 (keylist (append key nil)))
808 (setq unread-command-events 854 (setq unread-command-events
809 (append (nthcdr universal-argument-num-events keylist) 855 (append (nthcdr universal-argument-num-events keylist)
810 unread-command-events))) 856 unread-command-events)))
811 (reset-this-command-lengths) 857 (reset-this-command-lengths)
812 (setq overriding-terminal-local-map nil)) 858 (setq overriding-terminal-local-map nil))
813 859
814 860
861 ;; XEmacs -- shouldn't these functions keep the zmacs region active?
815 (defun forward-to-indentation (arg) 862 (defun forward-to-indentation (arg)
816 "Move forward ARG lines and position at first nonblank character." 863 "Move forward ARG lines and position at first nonblank character."
817 (interactive "p") 864 (interactive "p")
818 (forward-line arg) 865 (forward-line arg)
819 (skip-chars-forward " \t")) 866 (skip-chars-forward " \t"))
839 when given no argument at the beginning of a line." 886 when given no argument at the beginning of a line."
840 (interactive "*P") 887 (interactive "*P")
841 (kill-region (point) 888 (kill-region (point)
842 ;; Don't shift point before doing the delete; that way, 889 ;; Don't shift point before doing the delete; that way,
843 ;; undo will record the right position of point. 890 ;; undo will record the right position of point.
891 ;; FSF
892 ; ;; It is better to move point to the other end of the kill
893 ; ;; before killing. That way, in a read-only buffer, point
894 ; ;; moves across the text that is copied to the kill ring.
895 ; ;; The choice has no effect on undo now that undo records
896 ; ;; the value of point from before the command was run.
897 ; (progn
844 (save-excursion 898 (save-excursion
845 (if arg 899 (if arg
846 (forward-line (prefix-numeric-value arg)) 900 (forward-line (prefix-numeric-value arg))
847 (if (eobp) 901 (if (eobp)
848 (signal 'end-of-buffer nil)) 902 (signal 'end-of-buffer nil))
849 (if (or (looking-at "[ \t]*$") (and kill-whole-line (bolp))) 903 (if (or (looking-at "[ \t]*$") (and kill-whole-line (bolp)))
850 (forward-line 1) 904 (forward-line 1)
851 (end-of-line))) 905 (end-of-line)))
852 (point)))) 906 (point))))
853 907
908 ;; XEmacs
854 (defun backward-kill-line nil 909 (defun backward-kill-line nil
855 "Kill back to the beginning of the line." 910 "Kill back to the beginning of the line."
856 (interactive) 911 (interactive)
857 (let ((point (point))) 912 (let ((point (point)))
858 (beginning-of-line nil) 913 (beginning-of-line nil)
911 966
912 ;;;; The kill ring data structure. 967 ;;;; The kill ring data structure.
913 968
914 (defvar kill-ring nil 969 (defvar kill-ring nil
915 "List of killed text sequences. 970 "List of killed text sequences.
916 In order to maintain correct interaction with cut-and-paste facilities 971 Since the kill ring is supposed to interact nicely with cut-and-paste
917 offered by window systems, the functions `kill-new', `kill-append', and 972 facilities offered by window systems, use of this variable should
918 `current-kill' should be used to access the kill ring, instead of using 973 interact nicely with `interprogram-cut-function' and
919 this variable directly.") 974 `interprogram-paste-function'. The functions `kill-new',
920 975 `kill-append', and `current-kill' are supposed to implement this
921 (defvar kill-ring-max 30 976 interaction; you may want to use them instead of manipulating the kill
977 ring directly.")
978
979 (defconst kill-ring-max 30
922 "*Maximum length of kill ring before oldest elements are thrown away.") 980 "*Maximum length of kill ring before oldest elements are thrown away.")
923 981
924 (defvar kill-ring-yank-pointer nil 982 (defvar kill-ring-yank-pointer nil
925 "The tail of the kill ring whose car is the last thing yanked.") 983 "The tail of the kill ring whose car is the last thing yanked.")
926 984
967 ;;;; Commands for manipulating the kill ring. 1025 ;;;; Commands for manipulating the kill ring.
968 1026
969 ;;FSFmacs 1027 ;;FSFmacs
970 ;(defvar kill-read-only-ok nil 1028 ;(defvar kill-read-only-ok nil
971 ; "*Non-nil means don't signal an error for killing read-only text.") 1029 ; "*Non-nil means don't signal an error for killing read-only text.")
1030
1031 ;(put 'text-read-only 'error-conditions
1032 ; '(text-read-only buffer-read-only error))
1033 ;(put 'text-read-only 'error-message "Text is read-only")
972 1034
973 (defun kill-region (beg end &optional verbose) ; verbose is XEmacs addition 1035 (defun kill-region (beg end &optional verbose) ; verbose is XEmacs addition
974 "Kill between point and mark. 1036 "Kill between point and mark.
975 The text is deleted but saved in the kill ring. 1037 The text is deleted but saved in the kill ring.
976 The command \\[yank] can retrieve it from there. 1038 The command \\[yank] can retrieve it from there.
1004 (message "Killing %d characters" 1066 (message "Killing %d characters"
1005 (- (max beg end) (min beg end))))) 1067 (- (max beg end) (min beg end)))))
1006 (cond 1068 (cond
1007 1069
1008 ;; I don't like this large change in behavior -- jwz 1070 ;; I don't like this large change in behavior -- jwz
1071 ;; Read-Only text means it shouldn't be deleted, so I'm restoring
1072 ;; this code, but only for text-properties and not full extents. -sb
1009 ;; If the buffer is read-only, we should beep, in case the person 1073 ;; If the buffer is read-only, we should beep, in case the person
1010 ;; just isn't aware of this. However, there's no harm in putting 1074 ;; just isn't aware of this. However, there's no harm in putting
1011 ;; the region's text in the kill ring, anyway. 1075 ;; the region's text in the kill ring, anyway.
1012 ;;((or (and buffer-read-only (not inhibit-read-only)) 1076 ((or (and buffer-read-only (not inhibit-read-only))
1013 ;; (text-property-not-all beg end 'read-only nil)) 1077 (text-property-not-all beg end 'read-only nil))
1078 ;; This is redundant.
1014 ;; (if verbose (message "Copying %d characters" 1079 ;; (if verbose (message "Copying %d characters"
1015 ;; (- (max beg end) (min beg end)))) 1080 ;; (- (max beg end) (min beg end))))
1016 ;; (copy-region-as-kill beg end) 1081 (copy-region-as-kill beg end)
1017 ;; ;; This should always barf, and give us the correct error. 1082 ;; ;; This should always barf, and give us the correct error.
1018 ;; (if kill-read-only-ok 1083 ;; (if kill-read-only-ok
1019 ;; (message "Read only text copied to kill ring") 1084 ;; (message "Read only text copied to kill ring")
1020 ;; (setq this-command 'kill-region) 1085 (setq this-command 'kill-region)
1021 ;; (barf-if-buffer-read-only))) 1086 (barf-if-buffer-read-only)
1087 (signal 'text-read-only (list (current-buffer))))
1022 1088
1023 ;; In certain cases, we can arrange for the undo list and the kill 1089 ;; In certain cases, we can arrange for the undo list and the kill
1024 ;; ring to share the same string object. This code does that. 1090 ;; ring to share the same string object. This code does that.
1025 ((not (or (eq buffer-undo-list t) 1091 ((not (or (eq buffer-undo-list t)
1026 (eq last-command 'kill-region) 1092 (eq last-command 'kill-region)
1027 ;; Use = since positions may be numbers or markers. 1093 ;; Use = since positions may be numbers or markers.
1028 (= beg end))) 1094 (= beg end)))
1029 ;; Don't let the undo list be truncated before we can even access it. 1095 ;; Don't let the undo list be truncated before we can even access it.
1096 ;; FSF calls this `undo-strong-limit'
1030 (let ((undo-high-threshold (+ (- (max beg end) (min beg end)) 100)) 1097 (let ((undo-high-threshold (+ (- (max beg end) (min beg end)) 100))
1031 ;(old-list buffer-undo-list) 1098 ;(old-list buffer-undo-list)
1032 tail) 1099 tail)
1033 (delete-region beg end) 1100 (delete-region beg end)
1034 ;; Search back in buffer-undo-list for this string, 1101 ;; Search back in buffer-undo-list for this string,
1035 ;; in case a change hook made property changes. 1102 ;; in case a change hook made property changes.
1036 (setq tail buffer-undo-list) 1103 (setq tail buffer-undo-list)
1037 (while (not (stringp (car-safe (car-safe tail)))) 1104 (while (not (stringp (car-safe (car-safe tail)))) ; XEmacs
1038 (setq tail (cdr tail))) 1105 (setq tail (cdr tail)))
1039 ;; Take the same string recorded for undo 1106 ;; Take the same string recorded for undo
1040 ;; and put it in the kill-ring. 1107 ;; and put it in the kill-ring.
1041 (kill-new (car (car tail))))) 1108 (kill-new (car (car tail)))))
1042 1109
1072 ;; Inhibit quitting so we can make a quit here 1139 ;; Inhibit quitting so we can make a quit here
1073 ;; look like a C-g typed as a command. 1140 ;; look like a C-g typed as a command.
1074 (inhibit-quit t)) 1141 (inhibit-quit t))
1075 (if (pos-visible-in-window-p other-end (selected-window)) 1142 (if (pos-visible-in-window-p other-end (selected-window))
1076 (progn 1143 (progn
1144 ;; FSF (I'm not sure what this does -sb)
1145 ; ;; Swap point and mark.
1146 ; (set-marker (mark-marker) (point) (current-buffer))
1077 (goto-char other-end) 1147 (goto-char other-end)
1078 (sit-for 1) 1148 (sit-for 1)
1149 ; ;; Swap back.
1150 ; (set-marker (mark-marker) other-end (current-buffer))
1079 (goto-char opoint) 1151 (goto-char opoint)
1080 ;; If user quit, deactivate the mark 1152 ;; If user quit, deactivate the mark
1081 ;; as C-g would as a command. 1153 ;; as C-g would as a command.
1082 (and quit-flag (mark) 1154 (and quit-flag (mark)
1083 (zmacs-deactivate-region))) 1155 (zmacs-deactivate-region)))
1092 ; (substring killed-text 0 message-len)))) 1164 ; (substring killed-text 0 message-len))))
1093 )))) 1165 ))))
1094 1166
1095 (defun append-next-kill () 1167 (defun append-next-kill ()
1096 "Cause following command, if it kills, to append to previous kill." 1168 "Cause following command, if it kills, to append to previous kill."
1169 ;; XEmacs
1097 (interactive "_") 1170 (interactive "_")
1098 (if (interactive-p) 1171 (if (interactive-p)
1099 (progn 1172 (progn
1100 (setq this-command 'kill-region) 1173 (setq this-command 'kill-region)
1101 (message "If the next command is a kill, it will append")) 1174 (message "If the next command is a kill, it will append"))
1116 comes the newest one." 1189 comes the newest one."
1117 (interactive "*p") 1190 (interactive "*p")
1118 (if (not (eq last-command 'yank)) 1191 (if (not (eq last-command 'yank))
1119 (error "Previous command was not a yank")) 1192 (error "Previous command was not a yank"))
1120 (setq this-command 'yank) 1193 (setq this-command 'yank)
1121 (let ((before (< (point) (mark t)))) 1194 (let ((inhibit-read-only t)
1195 (before (< (point) (mark t))))
1122 (delete-region (point) (mark t)) 1196 (delete-region (point) (mark t))
1197 ;;(set-marker (mark-marker) (point) (current-buffer))
1123 (set-mark (point)) 1198 (set-mark (point))
1124 (insert (current-kill arg)) 1199 (insert (current-kill arg))
1125 (if before (exchange-point-and-mark t)))) 1200 (if before
1201 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
1202 ;; It is cleaner to avoid activation, even though the command
1203 ;; loop would deactivate the mark because we inserted text.
1204 (goto-char (prog1 (mark t)
1205 (set-marker (mark-marker) (point) (current-buffer))))))
1206 nil)
1207
1126 1208
1127 (defun yank (&optional arg) 1209 (defun yank (&optional arg)
1128 "Reinsert the last stretch of killed text. 1210 "Reinsert the last stretch of killed text.
1129 More precisely, reinsert the stretch of killed text most recently 1211 More precisely, reinsert the stretch of killed text most recently
1130 killed OR yanked. Put point at end, and set mark at beginning. 1212 killed OR yanked. Put point at end, and set mark at beginning.
1131 With just C-u as argument, same but put point at beginning (and mark at end). 1213 With just C-u as argument, same but put point at beginning (and mark at end).
1132 With argument N, reinsert the Nth most recently killed stretch of killed text. 1214 With argument N, reinsert the Nth most recently killed stretch of killed
1215 text.
1133 See also the command \\[yank-pop]." 1216 See also the command \\[yank-pop]."
1134 (interactive "*P") 1217 (interactive "*P")
1135 ;; If we don't get all the way through, make last-command indicate that 1218 ;; If we don't get all the way through, make last-command indicate that
1136 ;; for the following command. 1219 ;; for the following command.
1137 (setq this-command t) 1220 (setq this-command t)
1139 (insert (current-kill (cond 1222 (insert (current-kill (cond
1140 ((listp arg) 0) 1223 ((listp arg) 0)
1141 ((eq arg '-) -1) 1224 ((eq arg '-) -1)
1142 (t (1- arg))))) 1225 (t (1- arg)))))
1143 (if (consp arg) 1226 (if (consp arg)
1144 (exchange-point-and-mark t)) 1227 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
1145 ;; If we do get all the way through, make this-command indicate that. 1228 ;; It is cleaner to avoid activation, even though the command
1146 (setq this-command 'yank)) 1229 ;; loop would deactivate the mark because we inserted text.
1230 (goto-char (prog1 (mark t)
1231 (set-marker (mark-marker) (point) (current-buffer)))))
1232 ;; If we do get all the way thru, make this-command indicate that.
1233 (setq this-command 'yank)
1234 nil)
1147 1235
1148 (defun rotate-yank-pointer (arg) 1236 (defun rotate-yank-pointer (arg)
1149 "Rotate the yanking point in the kill ring. 1237 "Rotate the yanking point in the kill ring.
1150 With argument, rotate that many kills forward (or backward, if negative)." 1238 With argument, rotate that many kills forward (or backward, if negative)."
1151 (interactive "p") 1239 (interactive "p")
1154 1242
1155 (defun insert-buffer (buffer) 1243 (defun insert-buffer (buffer)
1156 "Insert after point the contents of BUFFER. 1244 "Insert after point the contents of BUFFER.
1157 Puts mark after the inserted text. 1245 Puts mark after the inserted text.
1158 BUFFER may be a buffer or a buffer name." 1246 BUFFER may be a buffer or a buffer name."
1159 (interactive (list (progn (barf-if-buffer-read-only) 1247 (interactive
1160 (read-buffer "Insert buffer: " 1248 (list
1161 ;; XEmacs: we have different args 1249 (progn
1162 (other-buffer (current-buffer) nil t) 1250 (barf-if-buffer-read-only)
1163 t)))) 1251 (read-buffer "Insert buffer: "
1252 ;; XEmacs: we have different args
1253 (other-buffer (current-buffer) nil t)
1254 t))))
1164 (or (bufferp buffer) 1255 (or (bufferp buffer)
1165 (setq buffer (get-buffer buffer))) 1256 (setq buffer (get-buffer buffer)))
1166 (let (start end newmark) 1257 (let (start end newmark)
1167 (save-excursion 1258 (save-excursion
1168 (save-excursion 1259 (save-excursion
1218 (erase-buffer) 1309 (erase-buffer)
1219 (save-excursion 1310 (save-excursion
1220 (insert-buffer-substring oldbuf start end))))) 1311 (insert-buffer-substring oldbuf start end)))))
1221 1312
1222 ;FSFmacs 1313 ;FSFmacs
1223 ;(define-error 'mark-inactive "The mark is not active now") 1314 ;(put 'mark-inactive 'error-conditions '(mark-inactive error))
1315 ;(put 'mark-inactive 'error-message "The mark is not active now")
1224 1316
1225 (defun mark (&optional force buffer) 1317 (defun mark (&optional force buffer)
1226 "Return this buffer's mark value as integer, or nil if no mark. 1318 "Return this buffer's mark value as integer, or nil if no mark.
1227 1319
1228 If `zmacs-regions' is true, then this returns nil unless the region is 1320 If `zmacs-regions' is true, then this returns nil unless the region is
1270 1362
1271 (let ((beg (point))) (forward-line 1) (delete-region beg (point)))." 1363 (let ((beg (point))) (forward-line 1) (delete-region beg (point)))."
1272 1364
1273 (setq buffer (decode-buffer buffer)) 1365 (setq buffer (decode-buffer buffer))
1274 (set-marker (mark-marker t buffer) pos buffer)) 1366 (set-marker (mark-marker t buffer) pos buffer))
1367 ;; FSF
1368 ; (if pos
1369 ; (progn
1370 ; (setq mark-active t)
1371 ; (run-hooks 'activate-mark-hook)
1372 ; (set-marker (mark-marker) pos (current-buffer)))
1373 ; ;; Normally we never clear mark-active except in Transient Mark mode.
1374 ; ;; But when we actually clear out the mark value too,
1375 ; ;; we must clear mark-active in any mode.
1376 ; (setq mark-active nil)
1377 ; (run-hooks 'deactivate-mark-hook)
1378 ; (set-marker (mark-marker) nil)))
1275 1379
1276 (defvar mark-ring nil 1380 (defvar mark-ring nil
1277 "The list of former marks of the current buffer, most recent first.") 1381 "The list of former marks of the current buffer, most recent first.")
1278 (make-variable-buffer-local 'mark-ring) 1382 (make-variable-buffer-local 'mark-ring)
1279 (put 'mark-ring 'permanent-local t) 1383 (put 'mark-ring 'permanent-local t)
1280 1384
1281 (defvar mark-ring-max 16 1385 (defconst mark-ring-max 16
1282 "*Maximum size of mark ring. Start discarding off end if gets this big.") 1386 "*Maximum size of mark ring. Start discarding off end if gets this big.")
1283 1387
1284 (defvar global-mark-ring nil 1388 (defvar global-mark-ring nil
1285 "The list of saved global marks, most recent first.") 1389 "The list of saved global marks, most recent first.")
1286 1390
1288 "*Maximum size of global mark ring. \ 1392 "*Maximum size of global mark ring. \
1289 Start discarding off end if gets this big.") 1393 Start discarding off end if gets this big.")
1290 1394
1291 (defun set-mark-command (arg) 1395 (defun set-mark-command (arg)
1292 "Set mark at where point is, or jump to mark. 1396 "Set mark at where point is, or jump to mark.
1293 With no prefix argument, set mark, push old mark position on local mark 1397 With no prefix argument, set mark, push old mark position on local mark
1294 ring, and push mark on global mark ring. 1398 ring, and push mark on global mark ring.
1295 With argument, jump to mark, and pop a new position for mark off the ring 1399 With argument, jump to mark, and pop a new position for mark off the ring
1296 \(does not affect global mark ring\). 1400 \(does not affect global mark ring\).
1297 1401
1298 Novice Emacs Lisp programmers often try to use the mark for the wrong 1402 Novice Emacs Lisp programmers often try to use the mark for the wrong
1303 (if (null (mark t)) 1407 (if (null (mark t))
1304 (error "No mark set in this buffer") 1408 (error "No mark set in this buffer")
1305 (goto-char (mark t)) 1409 (goto-char (mark t))
1306 (pop-mark)))) 1410 (pop-mark))))
1307 1411
1412 ;; XEmacs: Extra parameter
1308 (defun push-mark (&optional location nomsg activate-region buffer) 1413 (defun push-mark (&optional location nomsg activate-region buffer)
1309 "Set mark at LOCATION (point, by default) and push old mark on mark ring. 1414 "Set mark at LOCATION (point, by default) and push old mark on mark ring.
1310 If the last global mark pushed was not in the current buffer, 1415 If the last global mark pushed was not in the current buffer,
1311 also push LOCATION on the global mark ring. 1416 also push LOCATION on the global mark ring.
1312 Display `Mark set' unless the optional second arg NOMSG is non-nil. 1417 Display `Mark set' unless the optional second arg NOMSG is non-nil.
1313 Activate mark if optional third arg ACTIVATE-REGION non-nil. 1418 Activate mark if optional third arg ACTIVATE-REGION non-nil.
1314 1419
1315 Novice Emacs Lisp programmers often try to use the mark for the wrong 1420 Novice Emacs Lisp programmers often try to use the mark for the wrong
1316 purposes. See the documentation of `set-mark' for more information." 1421 purposes. See the documentation of `set-mark' for more information."
1317 (setq buffer (decode-buffer buffer)) 1422 (setq buffer (decode-buffer buffer)) ; XEmacs
1318 (if (null (mark t buffer)) 1423 (if (null (mark t buffer)) ; XEmacs
1319 nil 1424 nil
1320 ;; The save-excursion / set-buffer is necessary because mark-ring 1425 ;; The save-excursion / set-buffer is necessary because mark-ring
1321 ;; is a buffer local variable 1426 ;; is a buffer local variable
1322 (save-excursion 1427 (save-excursion
1323 (set-buffer buffer) 1428 (set-buffer buffer)
1325 (if (> (length mark-ring) mark-ring-max) 1430 (if (> (length mark-ring) mark-ring-max)
1326 (progn 1431 (progn
1327 (move-marker (car (nthcdr mark-ring-max mark-ring)) nil buffer) 1432 (move-marker (car (nthcdr mark-ring-max mark-ring)) nil buffer)
1328 (setcdr (nthcdr (1- mark-ring-max) mark-ring) nil))))) 1433 (setcdr (nthcdr (1- mark-ring-max) mark-ring) nil)))))
1329 (set-mark (or location (point buffer)) buffer) 1434 (set-mark (or location (point buffer)) buffer)
1435 ; (set-marker (mark-marker) (or location (point)) (current-buffer)) ; FSF
1330 ;; Now push the mark on the global mark ring. 1436 ;; Now push the mark on the global mark ring.
1331 (if (or (null global-mark-ring) 1437 (if (or (null global-mark-ring)
1332 (not (eq (marker-buffer (car global-mark-ring)) buffer))) 1438 (not (eq (marker-buffer (car global-mark-ring)) buffer)))
1333 ;; The last global mark pushed wasn't in this same buffer. 1439 ;; The last global mark pushed wasn't in this same buffer.
1334 (progn 1440 (progn
1343 (message "Mark set")) 1449 (message "Mark set"))
1344 (if activate-region 1450 (if activate-region
1345 (progn 1451 (progn
1346 (setq zmacs-region-stays t) 1452 (setq zmacs-region-stays t)
1347 (zmacs-activate-region))) 1453 (zmacs-activate-region)))
1454 ; (if (or activate (not transient-mark-mode)) ; FSF
1455 ; (set-mark (mark t))) ; FSF
1348 nil) 1456 nil)
1349 1457
1350 (defun pop-mark () 1458 (defun pop-mark ()
1351 "Pop off mark ring into the buffer's actual mark. 1459 "Pop off mark ring into the buffer's actual mark.
1352 Does not set point. Does nothing if mark ring is empty." 1460 Does not set point. Does nothing if mark ring is empty."
1366 (let ((omark (mark t))) 1474 (let ((omark (mark t)))
1367 (if (null omark) 1475 (if (null omark)
1368 (error "No mark set in this buffer")) 1476 (error "No mark set in this buffer"))
1369 (set-mark (point)) 1477 (set-mark (point))
1370 (goto-char omark) 1478 (goto-char omark)
1371 (or dont-activate-region (zmacs-activate-region)) 1479 (or dont-activate-region (zmacs-activate-region)) ; XEmacs
1372 nil)) 1480 nil))
1373 1481
1482 ;; XEmacs
1374 (defun mark-something (mark-fn movement-fn arg) 1483 (defun mark-something (mark-fn movement-fn arg)
1375 "internal function used by mark-sexp, mark-word, etc." 1484 "internal function used by mark-sexp, mark-word, etc."
1376 (let (newmark (pushp t)) 1485 (let (newmark (pushp t))
1377 (save-excursion 1486 (save-excursion
1378 (if (and (eq last-command mark-fn) (mark)) 1487 (if (and (eq last-command mark-fn) (mark))
1445 in `goal-column', which is nil when there is none. 1554 in `goal-column', which is nil when there is none.
1446 1555
1447 If you are thinking of using this in a Lisp program, consider 1556 If you are thinking of using this in a Lisp program, consider
1448 using `forward-line' instead. It is usually easier to use 1557 using `forward-line' instead. It is usually easier to use
1449 and more reliable (no dependence on goal column, etc.)." 1558 and more reliable (no dependence on goal column, etc.)."
1450 (interactive "_p") 1559 (interactive "_p") ; XEmacs
1451 (if (and next-line-add-newlines (= arg 1)) 1560 (if (and next-line-add-newlines (= arg 1))
1452 (let ((opoint (point))) 1561 (let ((opoint (point)))
1453 (end-of-line) 1562 (end-of-line)
1454 (if (eobp) 1563 (if (eobp)
1455 (newline 1) 1564 (newline 1)
1473 Then it does not try to move vertically. 1582 Then it does not try to move vertically.
1474 1583
1475 If you are thinking of using this in a Lisp program, consider using 1584 If you are thinking of using this in a Lisp program, consider using
1476 `forward-line' with a negative argument instead. It is usually easier 1585 `forward-line' with a negative argument instead. It is usually easier
1477 to use and more reliable (no dependence on goal column, etc.)." 1586 to use and more reliable (no dependence on goal column, etc.)."
1478 (interactive "_p") 1587 (interactive "_p") ; XEmacs
1479 (if (interactive-p) 1588 (if (interactive-p)
1480 (condition-case nil 1589 (condition-case nil
1481 (line-move (- arg)) 1590 (line-move (- arg))
1482 ((beginning-of-buffer end-of-buffer) (ding nil 'buffer-bound))) 1591 ((beginning-of-buffer end-of-buffer) (ding nil 'buffer-bound)))
1483 (line-move (- arg))) 1592 (line-move (- arg)))
1484 nil) 1593 nil)
1485 1594
1486 (defvar track-eol nil 1595 (defconst track-eol nil
1487 "*Non-nil means vertical motion starting at end of line keeps to ends of lines. 1596 "*Non-nil means vertical motion starting at end of line keeps to ends of lines.
1488 This means moving to the end of each line moved onto. 1597 This means moving to the end of each line moved onto.
1489 The beginning of a blank line does not count as the end of a line.") 1598 The beginning of a blank line does not count as the end of a line.")
1490 1599
1491 (defvar goal-column nil 1600 (defvar goal-column nil
1555 prop 1664 prop
1556 (or (memq prop buffer-invisibility-spec) 1665 (or (memq prop buffer-invisibility-spec)
1557 (assq prop buffer-invisibility-spec))))) 1666 (assq prop buffer-invisibility-spec)))))
1558 (if (get-text-property (point) 'invisible) 1667 (if (get-text-property (point) 'invisible)
1559 (goto-char (next-single-property-change (point) 'invisible)) 1668 (goto-char (next-single-property-change (point) 'invisible))
1560 (goto-char (next-extent-change (point))))) 1669 (goto-char (next-extent-change (point))))) ; XEmacs
1561 (setq arg (1- arg))) 1670 (setq arg (1- arg)))
1562 (while (< arg 0) 1671 (while (< arg 0)
1563 (beginning-of-line) 1672 (beginning-of-line)
1564 (and (zerop (vertical-motion -1)) 1673 (and (zerop (vertical-motion -1))
1565 (signal 'beginning-of-buffer nil)) 1674 (signal 'beginning-of-buffer nil))
1570 prop 1679 prop
1571 (or (memq prop buffer-invisibility-spec) 1680 (or (memq prop buffer-invisibility-spec)
1572 (assq prop buffer-invisibility-spec))))) 1681 (assq prop buffer-invisibility-spec)))))
1573 (if (get-text-property (1- (point)) 'invisible) 1682 (if (get-text-property (1- (point)) 'invisible)
1574 (goto-char (previous-single-property-change (point) 'invisible)) 1683 (goto-char (previous-single-property-change (point) 'invisible))
1575 (goto-char (previous-extent-change (point))))) 1684 (goto-char (previous-extent-change (point))))) ; XEmacs
1576 (setq arg (1+ arg)))) 1685 (setq arg (1+ arg))))
1577 (move-to-column (or goal-column temporary-goal-column))) 1686 (move-to-column (or goal-column temporary-goal-column)))
1578 ;; Remember where we moved to, go back home, 1687 ;; Remember where we moved to, go back home,
1579 ;; then do the motion over again 1688 ;; then do the motion over again
1580 ;; in just one step, with intangibility and point-motion hooks 1689 ;; in just one step, with intangibility and point-motion hooks
1594 Those commands will move to this position in the line moved to 1703 Those commands will move to this position in the line moved to
1595 rather than trying to keep the same horizontal position. 1704 rather than trying to keep the same horizontal position.
1596 With a non-nil argument, clears out the goal column 1705 With a non-nil argument, clears out the goal column
1597 so that \\[next-line] and \\[previous-line] resume vertical motion. 1706 so that \\[next-line] and \\[previous-line] resume vertical motion.
1598 The goal column is stored in the variable `goal-column'." 1707 The goal column is stored in the variable `goal-column'."
1599 (interactive "_P") 1708 (interactive "_P") ; XEmacs
1600 (if arg 1709 (if arg
1601 (progn 1710 (progn
1602 (setq goal-column nil) 1711 (setq goal-column nil)
1603 (message "No goal column")) 1712 (message "No goal column"))
1604 (setq goal-column (current-column)) 1713 (setq goal-column (current-column))
1605 (message (substitute-command-keys 1714 (message (substitute-command-keys
1606 "Goal column %d (use \\[set-goal-column] with an arg to unset it)") 1715 "Goal column %d (use \\[set-goal-column] with an arg to unset it)")
1607 goal-column)) 1716 goal-column))
1608 nil) 1717 nil)
1609 1718
1610 1719 ;; deleted FSFmacs terminal randomness hscroll-point-visible stuff.
1611 ;;; deleted FSFmacs terminal randomness hscroll-point-visible stuff. 1720 ;; hscroll-step
1721 ;; hscroll-point-visible
1722 ;; hscroll-window-column
1723 ;; right-arrow
1724 ;; left-arrow
1612 1725
1613 (defun scroll-other-window-down (lines) 1726 (defun scroll-other-window-down (lines)
1614 "Scroll the \"other window\" down. 1727 "Scroll the \"other window\" down.
1615 For more details, see the documentation for `scroll-other-window'." 1728 For more details, see the documentation for `scroll-other-window'."
1616 (interactive "P") 1729 (interactive "P")
1618 ;; Just invert the argument's meaning. 1731 ;; Just invert the argument's meaning.
1619 ;; We can do that without knowing which window it will be. 1732 ;; We can do that without knowing which window it will be.
1620 (if (eq lines '-) nil 1733 (if (eq lines '-) nil
1621 (if (null lines) '- 1734 (if (null lines) '-
1622 (- (prefix-numeric-value lines)))))) 1735 (- (prefix-numeric-value lines))))))
1736 ;(define-key esc-map [?\C-\S-v] 'scroll-other-window-down)
1623 1737
1624 (defun beginning-of-buffer-other-window (arg) 1738 (defun beginning-of-buffer-other-window (arg)
1625 "Move point to the beginning of the buffer in the other window. 1739 "Move point to the beginning of the buffer in the other window.
1626 Leave mark at previous position. 1740 Leave mark at previous position.
1627 With arg N, put point N/10 of the way from the true beginning." 1741 With arg N, put point N/10 of the way from the true beginning."
1711 (save-excursion 1825 (save-excursion
1712 (funcall mover 1) 1826 (funcall mover 1)
1713 (setq end2 (point)) 1827 (setq end2 (point))
1714 (funcall mover -1) 1828 (funcall mover -1)
1715 (setq start2 (point)) 1829 (setq start2 (point))
1716 (goto-char (mark t)) 1830 (goto-char (mark t)) ; XEmacs
1717 (funcall mover 1) 1831 (funcall mover 1)
1718 (setq end1 (point)) 1832 (setq end1 (point))
1719 (funcall mover -1) 1833 (funcall mover -1)
1720 (setq start1 (point)) 1834 (setq start1 (point))
1721 (transpose-subr-1)) 1835 (transpose-subr-1))
1722 (exchange-point-and-mark t))) 1836 (exchange-point-and-mark t))) ; XEmacs
1723 (while (> arg 0) 1837 (while (> arg 0)
1724 (funcall mover -1) 1838 (funcall mover -1)
1725 (setq start1 (point)) 1839 (setq start1 (point))
1726 (funcall mover 1) 1840 (funcall mover 1)
1727 (setq end1 (point)) 1841 (setq end1 (point))
1756 (goto-char (if (< start1 start2) start1 1870 (goto-char (if (< start1 start2) start1
1757 (+ start1 (- (length word1) (length word2))))) 1871 (+ start1 (- (length word1) (length word2)))))
1758 (delete-char (length word1)) 1872 (delete-char (length word1))
1759 (insert word2))) 1873 (insert word2)))
1760 1874
1761 (defvar comment-column 32 1875 (defconst comment-column 32
1762 "*Column to indent right-margin comments to. 1876 "*Column to indent right-margin comments to.
1763 Setting this variable automatically makes it local to the current buffer. 1877 Setting this variable automatically makes it local to the current buffer.
1764 Each mode establishes a different default value for this variable; you 1878 Each mode establishes a different default value for this variable; you
1765 can set the value for a particular mode using that mode's hook.") 1879 can set the value for a particular mode using that mode's hook.")
1766 (make-variable-buffer-local 'comment-column) 1880 (make-variable-buffer-local 'comment-column)
1767 1881
1768 (defvar comment-start nil 1882 (defconst comment-start nil
1769 "*String to insert to start a new comment, or nil if no comment syntax.") 1883 "*String to insert to start a new comment, or nil if no comment syntax.")
1770 1884
1771 (defvar comment-start-skip nil 1885 (defconst comment-start-skip nil
1772 "*Regexp to match the start of a comment plus everything up to its body. 1886 "*Regexp to match the start of a comment plus everything up to its body.
1773 If there are any \\(...\\) pairs, the comment delimiter text is held to begin 1887 If there are any \\(...\\) pairs, the comment delimiter text is held to begin
1774 at the place matched by the close of the first pair.") 1888 at the place matched by the close of the first pair.")
1775 1889
1776 (defvar comment-end "" 1890 (defconst comment-end ""
1777 "*String to insert to end a new comment. 1891 "*String to insert to end a new comment.
1778 Should be an empty string if comments are terminated by end-of-line.") 1892 Should be an empty string if comments are terminated by end-of-line.")
1779 1893
1780 (defconst comment-indent-hook nil 1894 (defconst comment-indent-hook nil
1781 "Obsolete variable for function to compute desired indentation for a comment. 1895 "Obsolete variable for function to compute desired indentation for a comment.
1782 Use `comment-indent-function' instead. 1896 Use `comment-indent-function' instead.
1783 This function is called with no args with point at the beginning of 1897 This function is called with no args with point at the beginning of
1784 the comment's starting delimiter.") 1898 the comment's starting delimiter.")
1785 1899
1786 (defvar comment-indent-function 1900 (defconst comment-indent-function
1787 ;; XEmacs - add at least one space after the end of the text on the 1901 ;; XEmacs - add at least one space after the end of the text on the
1788 ;; current line... 1902 ;; current line...
1789 (lambda () 1903 #'(lambda ()
1790 (save-excursion 1904 (save-excursion
1791 (beginning-of-line) 1905 (beginning-of-line)
1792 (let ((eol (save-excursion (end-of-line) (point)))) 1906 (let ((eol (save-excursion (end-of-line) (point))))
1793 (and comment-start-skip 1907 (and comment-start-skip
1794 (re-search-forward comment-start-skip eol t) 1908 (re-search-forward comment-start-skip eol t)
1795 (setq eol (match-beginning 0))) 1909 (setq eol (match-beginning 0)))
1796 (goto-char eol) 1910 (goto-char eol)
1797 (skip-chars-backward " \t") 1911 (skip-chars-backward " \t")
1798 (max comment-column (1+ (current-column)))))) 1912 (max comment-column (1+ (current-column))))))
1799 "Function to compute desired indentation for a comment. 1913 "Function to compute desired indentation for a comment.
1800 This function is called with no args with point at the beginning of 1914 This function is called with no args with point at the beginning of
1801 the comment's starting delimiter.") 1915 the comment's starting delimiter.")
1802 1916
1803 (defconst block-comment-start nil 1917 (defconst block-comment-start nil
1984 (if (string= "" ce) () 2098 (if (string= "" ce) ()
1985 (end-of-line) 2099 (end-of-line)
1986 (insert ce))) 2100 (insert ce)))
1987 (search-forward "\n" nil 'move))))))) 2101 (search-forward "\n" nil 'move)))))))
1988 2102
2103 ;; XEmacs
1989 (defun prefix-region (prefix) 2104 (defun prefix-region (prefix)
1990 "Add a prefix string to each line between mark and point." 2105 "Add a prefix string to each line between mark and point."
1991 (interactive "sPrefix string: ") 2106 (interactive "sPrefix string: ")
1992 (if prefix 2107 (if prefix
1993 (let ((count (count-lines (mark) (point)))) 2108 (let ((count (count-lines (mark) (point))))
1998 (insert prefix) 2113 (insert prefix)
1999 (end-of-line 1) 2114 (end-of-line 1)
2000 (forward-char 1))))) 2115 (forward-char 1)))))
2001 2116
2002 2117
2118 ;; XEmacs - extra parameter
2003 (defun backward-word (arg &optional buffer) 2119 (defun backward-word (arg &optional buffer)
2004 "Move backward until encountering the end of a word. 2120 "Move backward until encountering the end of a word.
2005 With argument, do this that many times. 2121 With argument, do this that many times.
2006 In programs, it is faster to call `forward-word' with negative arg." 2122 In programs, it is faster to call `forward-word' with negative arg."
2007 (interactive "_p") 2123 (interactive "_p") ; XEmacs
2008 (forward-word (- arg) buffer)) 2124 (forward-word (- arg) buffer))
2009 2125
2010 (defun mark-word (arg) 2126 (defun mark-word (arg)
2011 "Set mark arg words away from point." 2127 "Set mark arg words away from point."
2012 (interactive "p") 2128 (interactive "p")
2013 (mark-something 'mark-word 'forward-word arg)) 2129 (mark-something 'mark-word 'forward-word arg))
2014 2130
2131 ;; XEmacs modified
2015 (defun kill-word (arg) 2132 (defun kill-word (arg)
2016 "Kill characters forward until encountering the end of a word. 2133 "Kill characters forward until encountering the end of a word.
2017 With argument, do this that many times." 2134 With argument, do this that many times."
2018 (interactive "*p") 2135 (interactive "*p")
2019 (kill-region (point) (save-excursion (forward-word arg) (point)))) 2136 (kill-region (point) (save-excursion (forward-word arg) (point))))
2020 2137
2021 (defun backward-kill-word (arg) 2138 (defun backward-kill-word (arg)
2022 "Kill characters backward until encountering the end of a word. 2139 "Kill characters backward until encountering the end of a word.
2023 With argument, do this that many times." 2140 With argument, do this that many times."
2024 (interactive "*p") 2141 (interactive "*p") ; XEmacs
2025 (kill-word (- arg))) 2142 (kill-word (- arg)))
2026 2143
2027 (defun current-word (&optional strict) 2144 (defun current-word (&optional strict)
2028 "Return the word point is on (or a nearby word) as a string. 2145 "Return the word point is on (or a nearby word) as a string.
2029 If optional arg STRICT is non-nil, return nil unless point is within 2146 If optional arg STRICT is non-nil, return nil unless point is within
2060 (skip-syntax-backward "w_") 2177 (skip-syntax-backward "w_")
2061 (setq start (point))) 2178 (setq start (point)))
2062 (buffer-substring start end))) 2179 (buffer-substring start end)))
2063 (buffer-substring start end))))) 2180 (buffer-substring start end)))))
2064 2181
2065 (defvar fill-prefix nil 2182 (defconst fill-prefix nil
2066 "*String for filling to insert at front of new line, or nil for none. 2183 "*String for filling to insert at front of new line, or nil for none.
2067 Setting this variable automatically makes it local to the current buffer.") 2184 Setting this variable automatically makes it local to the current buffer.")
2068 (make-variable-buffer-local 'fill-prefix) 2185 (make-variable-buffer-local 'fill-prefix)
2069 2186
2070 (defvar auto-fill-inhibit-regexp nil 2187 (defconst auto-fill-inhibit-regexp nil
2071 "*Regexp to match lines which should not be auto-filled.") 2188 "*Regexp to match lines which should not be auto-filled.")
2072 2189
2190 ;; This function is the auto-fill-function of a buffer
2191 ;; when Auto-Fill mode is enabled.
2192 ;; It returns t if it really did any work.
2193 ;; XEmacs: This function is totally different.
2073 (defun do-auto-fill () 2194 (defun do-auto-fill ()
2074 (let (give-up) 2195 (let (give-up)
2075 (or (and auto-fill-inhibit-regexp 2196 (or (and auto-fill-inhibit-regexp
2076 (save-excursion (beginning-of-line) 2197 (save-excursion (beginning-of-line)
2077 (looking-at auto-fill-inhibit-regexp))) 2198 (looking-at auto-fill-inhibit-regexp)))
2142 (if (>= (current-column) prev-column) 2263 (if (>= (current-column) prev-column)
2143 (setq give-up t))) 2264 (setq give-up t)))
2144 ;; No place to break => stop trying. 2265 ;; No place to break => stop trying.
2145 (setq give-up t))))))) 2266 (setq give-up t)))))))
2146 2267
2268 ;; Put FSF one in until I can one or the other working properly, then the
2269 ;; other one is history.
2270 (defun fsf:do-auto-fill ()
2271 (let (fc justify bol give-up
2272 (fill-prefix fill-prefix))
2273 (if (or (not (setq justify (current-justification)))
2274 (null (setq fc (current-fill-column)))
2275 (and (eq justify 'left)
2276 (<= (current-column) fc))
2277 (save-excursion (beginning-of-line)
2278 (setq bol (point))
2279 (and auto-fill-inhibit-regexp
2280 (looking-at auto-fill-inhibit-regexp))))
2281 nil ;; Auto-filling not required
2282 (if (memq justify '(full center right))
2283 (save-excursion (unjustify-current-line)))
2284
2285 ;; Choose a fill-prefix automatically.
2286 (if (and adaptive-fill-mode
2287 (or (null fill-prefix) (string= fill-prefix "")))
2288 (let ((prefix
2289 (fill-context-prefix
2290 (save-excursion (backward-paragraph 1) (point))
2291 (save-excursion (forward-paragraph 1) (point))
2292 ;; Don't accept a non-whitespace fill prefix
2293 ;; from the first line of a paragraph.
2294 "^[ \t]*$")))
2295 (and prefix (not (equal prefix ""))
2296 (setq fill-prefix prefix))))
2297
2298 (while (and (not give-up) (> (current-column) fc))
2299 ;; Determine where to split the line.
2300 (let ((fill-point
2301 (let ((opoint (point))
2302 bounce
2303 (first t))
2304 (save-excursion
2305 (move-to-column (1+ fc))
2306 ;; Move back to a word boundary.
2307 (while (or first
2308 ;; If this is after period and a single space,
2309 ;; move back once more--we don't want to break
2310 ;; the line there and make it look like a
2311 ;; sentence end.
2312 (and (not (bobp))
2313 (not bounce)
2314 sentence-end-double-space
2315 (save-excursion (forward-char -1)
2316 (and (looking-at "\\. ")
2317 (not (looking-at "\\. "))))))
2318 (setq first nil)
2319 (skip-chars-backward "^ \t\n")
2320 ;; If we find nowhere on the line to break it,
2321 ;; break after one word. Set bounce to t
2322 ;; so we will not keep going in this while loop.
2323 (if (bolp)
2324 (progn
2325 (re-search-forward "[ \t]" opoint t)
2326 (setq bounce t)))
2327 (skip-chars-backward " \t"))
2328 ;; Let fill-point be set to the place where we end up.
2329 (point)))))
2330 ;; If that place is not the beginning of the line,
2331 ;; break the line there.
2332 (if (save-excursion
2333 (goto-char fill-point)
2334 (not (bolp)))
2335 (let ((prev-column (current-column)))
2336 ;; If point is at the fill-point, do not `save-excursion'.
2337 ;; Otherwise, if a comment prefix or fill-prefix is inserted,
2338 ;; point will end up before it rather than after it.
2339 (if (save-excursion
2340 (skip-chars-backward " \t")
2341 (= (point) fill-point))
2342 (indent-new-comment-line t)
2343 (save-excursion
2344 (goto-char fill-point)
2345 (indent-new-comment-line t)))
2346 ;; Now do justification, if required
2347 (if (not (eq justify 'left))
2348 (save-excursion
2349 (end-of-line 0)
2350 (justify-current-line justify nil t)))
2351 ;; If making the new line didn't reduce the hpos of
2352 ;; the end of the line, then give up now;
2353 ;; trying again will not help.
2354 (if (>= (current-column) prev-column)
2355 (setq give-up t)))
2356 ;; No place to break => stop trying.
2357 (setq give-up t))))
2358 ;; Justify last line.
2359 (justify-current-line justify t t)
2360 t)))
2361
2362 (defvar normal-auto-fill-function 'do-auto-fill
2363 "The function to use for `auto-fill-function' if Auto Fill mode is turned on.
2364 Some major modes set this.")
2365
2366 (defun auto-fill-mode (&optional arg)
2367 "Toggle auto-fill mode.
2368 With arg, turn auto-fill mode on if and only if arg is positive.
2369 In Auto-Fill mode, inserting a space at a column beyond `current-fill-column'
2370 automatically breaks the line at a previous space.
2371
2372 The value of `normal-auto-fill-function' specifies the function to use
2373 for `auto-fill-function' when turning Auto Fill mode on."
2374 (interactive "P")
2375 (prog1 (setq auto-fill-function
2376 (if (if (null arg)
2377 (not auto-fill-function)
2378 (> (prefix-numeric-value arg) 0))
2379 normal-auto-fill-function
2380 nil))
2381 (redraw-modeline)))
2382
2383 ;; This holds a document string used to document auto-fill-mode.
2384 (defun auto-fill-function ()
2385 "Automatically break line at a previous space, in insertion of text."
2386 nil)
2387
2388 (defun turn-on-auto-fill ()
2389 "Unconditionally turn on Auto Fill mode."
2390 (auto-fill-mode 1))
2391
2392 (defun set-fill-column (arg)
2393 "Set `fill-column' to current column, or to argument if given.
2394 The variable `fill-column' has a separate value for each buffer."
2395 (interactive "_P") ; XEmacs
2396 (cond ((integerp arg)
2397 (setq fill-column arg))
2398 ((consp arg)
2399 (setq fill-column (current-column)))
2400 ;; Disallow missing argument; it's probably a typo for C-x C-f.
2401 (t
2402 (error "set-fill-column requires an explicit argument")))
2403 (message "fill-column set to %d" fill-column))
2404
2147 (defvar comment-multi-line t ; XEmacs - this works well with adaptive fill 2405 (defvar comment-multi-line t ; XEmacs - this works well with adaptive fill
2148 "*Non-nil means \\[indent-new-comment-line] should continue same comment 2406 "*Non-nil means \\[indent-new-comment-line] should continue same comment
2149 on new line, with no new terminator or starter. 2407 on new line, with no new terminator or starter.
2150 This is obsolete because you might as well use \\[newline-and-indent].") 2408 This is obsolete because you might as well use \\[newline-and-indent].")
2151 2409
2227 ;; Make sure we delete the newline inserted above. 2485 ;; Make sure we delete the newline inserted above.
2228 (end-of-line) 2486 (end-of-line)
2229 (delete-char 1))) 2487 (delete-char 1)))
2230 (indent-according-to-mode))))) 2488 (indent-according-to-mode)))))
2231 2489
2232 (defun auto-fill-mode (&optional arg)
2233 "Toggle auto-fill mode.
2234 With arg, turn auto-fill mode on if and only if arg is positive.
2235 In Auto-Fill mode, inserting a space at a column beyond `current-fill-column'
2236 automatically breaks the line at a previous space."
2237 (interactive "P")
2238 (prog1 (setq auto-fill-function
2239 (if (if (null arg)
2240 (not auto-fill-function)
2241 (> (prefix-numeric-value arg) 0))
2242 'do-auto-fill
2243 nil))
2244 (redraw-modeline)))
2245
2246 ;; This holds a document string used to document auto-fill-mode.
2247 (defun auto-fill-function ()
2248 "Automatically break line at a previous space, in insertion of text."
2249 nil)
2250
2251 (defun turn-on-auto-fill ()
2252 "Unconditionally turn on Auto Fill mode."
2253 (auto-fill-mode 1))
2254
2255 (defun set-fill-column (arg)
2256 "Set `fill-column' to current column, or to argument if given.
2257 The variable `fill-column' has a separate value for each buffer."
2258 (interactive "_P")
2259 (setq fill-column (if (integerp arg) arg (current-column)))
2260 (message "fill-column set to %d" fill-column))
2261 2490
2262 (defun set-selective-display (arg) 2491 (defun set-selective-display (arg)
2263 "Set `selective-display' to ARG; clear it if no arg. 2492 "Set `selective-display' to ARG; clear it if no arg.
2264 When the value of `selective-display' is a number > 0, 2493 When the value of `selective-display' is a number > 0,
2265 lines whose indentation is >= that value are not displayed. 2494 lines whose indentation is >= that value are not displayed.
2279 ;; #### doesn't localize properly: 2508 ;; #### doesn't localize properly:
2280 (princ "selective-display set to " t) 2509 (princ "selective-display set to " t)
2281 (prin1 selective-display t) 2510 (prin1 selective-display t)
2282 (princ "." t)) 2511 (princ "." t))
2283 2512
2513 ;; XEmacs
2284 (defun nuke-selective-display () 2514 (defun nuke-selective-display ()
2285 "Ensure that the buffer is not in selective-display mode. 2515 "Ensure that the buffer is not in selective-display mode.
2286 If `selective-display' is t, then restore the buffer text to it's original 2516 If `selective-display' is t, then restore the buffer text to it's original
2287 state before disabling selective display." 2517 state before disabling selective display."
2288 ;; by Stig@hackvan.com 2518 ;; by Stig@hackvan.com
2301 )))) 2531 ))))
2302 (setq selective-display nil)) 2532 (setq selective-display nil))
2303 2533
2304 (add-hook 'change-major-mode-hook 'nuke-selective-display) 2534 (add-hook 'change-major-mode-hook 'nuke-selective-display)
2305 2535
2306 (defvar overwrite-mode-textual (purecopy " Ovwrt") 2536 (defconst overwrite-mode-textual (purecopy " Ovwrt")
2307 "The string displayed in the modeline when in overwrite mode.") 2537 "The string displayed in the mode line when in overwrite mode.")
2308 (defvar overwrite-mode-binary (purecopy " Bin Ovwrt") 2538 (defconst overwrite-mode-binary (purecopy " Bin Ovwrt")
2309 "The string displayed in the modeline when in binary overwrite mode.") 2539 "The string displayed in the mode line when in binary overwrite mode.")
2310 2540
2311 (defun overwrite-mode (arg) 2541 (defun overwrite-mode (arg)
2312 "Toggle overwrite mode. 2542 "Toggle overwrite mode.
2313 With arg, turn overwrite mode on iff arg is positive. 2543 With arg, turn overwrite mode on iff arg is positive.
2314 In overwrite mode, printing characters typed in replace existing text 2544 In overwrite mode, printing characters typed in replace existing text
2351 2581
2352 (defun line-number-mode (arg) 2582 (defun line-number-mode (arg)
2353 "Toggle Line Number mode. 2583 "Toggle Line Number mode.
2354 With arg, turn Line Number mode on iff arg is positive. 2584 With arg, turn Line Number mode on iff arg is positive.
2355 When Line Number mode is enabled, the line number appears 2585 When Line Number mode is enabled, the line number appears
2356 in the modeline." 2586 in the mode line."
2357 (interactive "P") 2587 (interactive "P")
2358 (setq line-number-mode 2588 (setq line-number-mode
2359 (if (null arg) (not line-number-mode) 2589 (if (null arg) (not line-number-mode)
2360 (> (prefix-numeric-value arg) 0))) 2590 (> (prefix-numeric-value arg) 0)))
2361 (redraw-modeline)) 2591 (redraw-modeline))
2362 2592
2363 (defvar column-number-mode nil 2593 (defvar column-number-mode nil
2364 "*Non-nil means display column number in modeline.") 2594 "*Non-nil means display column number in mode line.")
2365 2595
2366 (defun column-number-mode (arg) 2596 (defun column-number-mode (arg)
2367 "Toggle Column Number mode. 2597 "Toggle Column Number mode.
2368 With arg, turn Column Number mode on iff arg is positive. 2598 With arg, turn Column Number mode on iff arg is positive.
2369 When Column Number mode is enabled, the column number appears 2599 When Column Number mode is enabled, the column number appears
2370 in the modeline." 2600 in the mode line."
2371 (interactive "P") 2601 (interactive "P")
2372 (setq column-number-mode 2602 (setq column-number-mode
2373 (if (null arg) (not column-number-mode) 2603 (if (null arg) (not column-number-mode)
2374 (> (prefix-numeric-value arg) 0))) 2604 (> (prefix-numeric-value arg) 0)))
2375 (redraw-modeline)) 2605 (redraw-modeline))
2376 2606
2377 2607
2378 (defvar blink-matching-paren t 2608 (defvar blink-matching-paren t
2379 "*Non-nil means show matching open-paren when close-paren is inserted.") 2609 "*Non-nil means show matching open-paren when close-paren is inserted.")
2380 2610
2381 (defvar blink-matching-paren-distance 12000 2611 (defvar blink-matching-paren-on-screen t
2612 "*Non-nil means show matching open-paren when it is on screen.
2613 nil means don't show it (but the open-paren can still be shown
2614 when it is off screen.")
2615
2616 (defconst blink-matching-paren-distance 12000
2382 "*If non-nil, is maximum distance to search for matching open-paren.") 2617 "*If non-nil, is maximum distance to search for matching open-paren.")
2383 2618
2384 (defconst blink-matching-delay 1 2619 (defconst blink-matching-delay 1
2385 "*The number of seconds that `blink-matching-open' will delay at a match.") 2620 "*The number of seconds that `blink-matching-open' will delay at a match.")
2386 2621
2387 (defconst blink-matching-paren-dont-ignore-comments nil 2622 (defconst blink-matching-paren-dont-ignore-comments nil
2388 "*Non-nil means `blink-matching-paren' should not ignore comments.") 2623 "*Non-nil means `blink-matching-paren' should not ignore comments.")
2389 2624
2390 (defun blink-matching-open () 2625 (defun blink-matching-open ()
2391 "Move cursor momentarily to the beginning of the sexp before point." 2626 "Move cursor momentarily to the beginning of the sexp before point."
2392 (interactive "_") 2627 (interactive "_") ; XEmacs
2393 (and (> (point) (1+ (point-min))) 2628 (and (> (point) (1+ (point-min)))
2394 blink-matching-paren 2629 blink-matching-paren
2395 ;; Verify an even number of quoting characters precede the close. 2630 ;; Verify an even number of quoting characters precede the close.
2396 (= 1 (logand 1 (- (point) 2631 (= 1 (logand 1 (- (point)
2397 (save-excursion 2632 (save-excursion
2424 (if mismatch (setq blinkpos nil)) 2659 (if mismatch (setq blinkpos nil))
2425 (if blinkpos 2660 (if blinkpos
2426 (progn 2661 (progn
2427 (goto-char blinkpos) 2662 (goto-char blinkpos)
2428 (if (pos-visible-in-window-p) 2663 (if (pos-visible-in-window-p)
2429 (sit-for blink-matching-delay) 2664 (and blink-matching-paren-on-screen
2665 (sit-for blink-matching-delay))
2430 (goto-char blinkpos) 2666 (goto-char blinkpos)
2431 (message 2667 (message
2432 "Matches %s" 2668 "Matches %s"
2433 ;; Show what precedes the open in its line, if anything. 2669 ;; Show what precedes the open in its line, if anything.
2434 (if (save-excursion 2670 (if (save-excursion
2439 ;; Show what follows the open in its line, if anything. 2675 ;; Show what follows the open in its line, if anything.
2440 (if (save-excursion 2676 (if (save-excursion
2441 (forward-char 1) 2677 (forward-char 1)
2442 (skip-chars-forward " \t") 2678 (skip-chars-forward " \t")
2443 (not (eolp))) 2679 (not (eolp)))
2444 (buffer-substring blinkpos 2680 (buffer-substring blinkpos
2445 (progn (end-of-line) (point))) 2681 (progn (end-of-line) (point)))
2446 ;; Otherwise show the previous nonblank line, 2682 ;; Otherwise show the previous nonblank line,
2447 ;; if there is one. 2683 ;; if there is one.
2448 (if (save-excursion 2684 (if (save-excursion
2449 (skip-chars-backward "\n \t") 2685 (skip-chars-backward "\n \t")
2450 (not (bobp))) 2686 (not (bobp)))
2468 2704
2469 ;Turned off because it makes dbx bomb out. 2705 ;Turned off because it makes dbx bomb out.
2470 (setq blink-paren-function 'blink-matching-open) 2706 (setq blink-paren-function 'blink-matching-open)
2471 2707
2472 (eval-when-compile (defvar myhelp)) ; suppress compiler warning 2708 (eval-when-compile (defvar myhelp)) ; suppress compiler warning
2709
2710 ;; XEmacs: Some functions moved to cmdloop.el:
2711 ;; keyboard-quit
2712 ;; buffer-quit-function
2713 ;; keyboard-escape-quit
2473 2714
2474 (defun set-variable (var val) 2715 (defun set-variable (var val)
2475 "Set VARIABLE to VALUE. VALUE is a Lisp object. 2716 "Set VARIABLE to VALUE. VALUE is a Lisp object.
2476 When using this interactively, supply a Lisp expression for VALUE. 2717 When using this interactively, supply a Lisp expression for VALUE.
2477 If you want VALUE to be a string, you must surround it with doublequotes. 2718 If you want VALUE to be a string, you must surround it with doublequotes.
2508 (list 'interactive prop) 2749 (list 'interactive prop)
2509 'arg)) 2750 'arg))
2510 (eval-minibuffer (format "Set %s to value: " var))))))) 2751 (eval-minibuffer (format "Set %s to value: " var)))))))
2511 (set var val)) 2752 (set var val))
2512 2753
2754 ;; XEmacs
2513 (defun activate-region () 2755 (defun activate-region ()
2514 "Activate the region, if `zmacs-regions' is true. 2756 "Activate the region, if `zmacs-regions' is true.
2515 Setting `zmacs-regions' to true causes LISPM-style active regions to be used. 2757 Setting `zmacs-regions' to true causes LISPM-style active regions to be used.
2516 This function has no effect if `zmacs-regions' is false." 2758 This function has no effect if `zmacs-regions' is false."
2517 (interactive) 2759 (interactive)
2518 (and zmacs-regions (zmacs-activate-region))) 2760 (and zmacs-regions (zmacs-activate-region)))
2519 2761
2762 ;; XEmacs
2520 (defsubst region-exists-p () 2763 (defsubst region-exists-p ()
2521 "Non-nil iff the region exists. 2764 "Non-nil iff the region exists.
2522 If active regions are in use (i.e. `zmacs-regions' is true), this means that 2765 If active regions are in use (i.e. `zmacs-regions' is true), this means that
2523 the region is active. Otherwise, this means that the user has pushed 2766 the region is active. Otherwise, this means that the user has pushed
2524 a mark in this buffer at some point in the past. 2767 a mark in this buffer at some point in the past.
2525 The functions `region-beginning' and `region-end' can be used to find the 2768 The functions `region-beginning' and `region-end' can be used to find the
2526 limits of the region." 2769 limits of the region."
2527 (not (null (mark)))) 2770 (not (null (mark))))
2528 2771
2772 ;; XEmacs
2529 (defun region-active-p () 2773 (defun region-active-p ()
2530 "Non-nil iff the region is active. 2774 "Non-nil iff the region is active.
2531 If `zmacs-regions' is true, this is equivalent to `region-exists-p'. 2775 If `zmacs-regions' is true, this is equivalent to `region-exists-p'.
2532 Otherwise, this function always returns false." 2776 Otherwise, this function always returns false."
2533 (and zmacs-regions zmacs-region-extent)) 2777 (and zmacs-regions zmacs-region-extent))
2534 2778
2779 ;; A bunch of stuff was moved elsewhere:
2780 ;; completion-list-mode-map
2781 ;; completion-reference-buffer
2782 ;; completion-base-size
2783 ;; delete-completion-window
2784 ;; previous-completion
2785 ;; next-completion
2786 ;; choose-completion
2787 ;; choose-completion-delete-max-match
2788 ;; choose-completion-string
2789 ;; completion-list-mode
2790 ;; completion-fixup-function
2791 ;; completion-setup-function
2792 ;; switch-to-completions
2793 ;; event stuffs
2794 ;; keypad stuffs
2795
2796 ;; The rest of this file is not in Lisp in FSF
2535 (defun capitalize-region-or-word (arg) 2797 (defun capitalize-region-or-word (arg)
2536 "Capitalize the selected region or the following word (or ARG words)." 2798 "Capitalize the selected region or the following word (or ARG words)."
2537 (interactive "p") 2799 (interactive "p")
2538 (if (region-active-p) (capitalize-region (region-beginning) (region-end)) 2800 (if (region-active-p) (capitalize-region (region-beginning) (region-end))
2539 (capitalize-word arg))) 2801 (capitalize-word arg)))
3132 (progn 3394 (progn
3133 (setq warning-marker (make-marker)) 3395 (setq warning-marker (make-marker))
3134 (set-marker warning-marker 1 buffer))) 3396 (set-marker warning-marker 1 buffer)))
3135 (set-window-start (display-buffer buffer) warning-marker) 3397 (set-window-start (display-buffer buffer) warning-marker)
3136 (set-marker warning-marker (point-max buffer) buffer))) 3398 (set-marker warning-marker (point-max buffer) buffer)))
3399
3400 ;;; simple.el ends here