comparison lisp/prim/simple.el @ 4:b82b59fe008d r19-15b3

Import from CVS: tag r19-15b3
author cvs
date Mon, 13 Aug 2007 08:46:56 +0200
parents ac2d302a0011
children 27bc7f280385
comparison
equal deleted inserted replaced
3:30df88044ec6 4:b82b59fe008d
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 Free 19 ;; along with XEmacs; see the file COPYING. If not, write to the Free
20 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 20 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21 21 ;; 02111-1307, USA.
22 ;;; Synched up with: FSF 19.30. 22
23 ;;; Synched up with: FSF 19.34 [But not very closely].
23 24
24 ;;; Commentary: 25 ;;; Commentary:
25 26
26 ;; 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
27 ;; major mode or to file-handling. 28 ;; major mode or to file-handling.
28 29
29 ;;; Changes for zmacs-style active-regions: 30 ;; Changes for zmacs-style active-regions:
30 ;;; 31 ;;
31 ;;; beginning-of-buffer, end-of-buffer, count-lines-region, 32 ;; beginning-of-buffer, end-of-buffer, count-lines-region,
32 ;;; count-lines-buffer, what-line, what-cursor-position, set-goal-column, 33 ;; count-lines-buffer, what-line, what-cursor-position, set-goal-column,
33 ;;; 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
34 ;;; 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
35 ;;; don't affect the current region-hilighting state. 36 ;; don't affect the current region-hilighting state.
36 ;;; 37 ;;
37 ;;; mark-whole-buffer, mark-word, exchange-point-and-mark, and 38 ;; mark-whole-buffer, mark-word, exchange-point-and-mark, and
38 ;;; set-mark-command (without an argument) call zmacs-activate-region. 39 ;; set-mark-command (without an argument) call zmacs-activate-region.
39 ;;; 40 ;;
40 ;;; 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
41 ;;; 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.
42 ;;; 43 ;;
43 ;;; 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
44 ;;; 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
45 ;;; the region is active or not. 46 ;; the region is active or not.
46 ;;; 47 ;;
47 ;;; 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
48 ;;; 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
49 ;;; argument, meaning "don't activate the region". These commands only use 50 ;; argument, meaning "don't activate the region". These commands only use
50 ;;; 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
51 ;;; 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
52 ;;; to use (mark t) for the same reason. 53 ;; to use (mark t) for the same reason.
53 54
54 ;;; Code: 55 ;;; Code:
55 56
56 (defun newline (&optional arg) 57 (defun newline (&optional arg)
57 "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.
64 ;; 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
65 ;; 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
66 ;; the end of the previous line. 67 ;; the end of the previous line.
67 (let ((flag (and (not (bobp)) 68 (let ((flag (and (not (bobp))
68 (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).
69 (< (or (previous-extent-change (point)) -2) 78 (< (or (previous-extent-change (point)) -2)
70 (- (point) 2)))) 79 (- (point) 2))))
71 (was-page-start (and (bolp) 80 (was-page-start (and (bolp)
72 (looking-at page-delimiter))) 81 (looking-at page-delimiter)))
73 (beforepos (point))) 82 (beforepos (point)))
86 ;; If we did *not* get an error, cancel that forward-char. 95 ;; If we did *not* get an error, cancel that forward-char.
87 (if flag (backward-char 1)) 96 (if flag (backward-char 1))
88 ;; Mark the newline(s) `hard'. 97 ;; Mark the newline(s) `hard'.
89 (if use-hard-newlines 98 (if use-hard-newlines
90 (let* ((from (- (point) (if arg (prefix-numeric-value arg) 1))) 99 (let* ((from (- (point) (if arg (prefix-numeric-value arg) 1)))
91 (sticky (get-text-property from 'end-open))) 100 (sticky (get-text-property from 'end-open))) ; XEmacs
92 (put-text-property from (point) 'hard 't) 101 (put-text-property from (point) 'hard 't)
93 ;; 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
94 (if (and (listp sticky) (not (memq 'hard sticky))) 103 (if (and (listp sticky) (not (memq 'hard sticky)))
95 (put-text-property from (point) 'end-open 104 (put-text-property from (point) 'end-open ; XEmacs
96 (cons 'hard sticky))))) 105 (cons 'hard sticky)))))
97 ;; If the newline leaves the previous line blank, 106 ;; If the newline leaves the previous line blank,
98 ;; 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.
99 (or flag 108 (or flag
100 (save-excursion 109 (save-excursion
114 (defun open-line (arg) 123 (defun open-line (arg)
115 "Insert a newline and leave point before it. 124 "Insert a newline and leave point before it.
116 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
117 if the line would have been blank. 126 if the line would have been blank.
118 With arg N, insert N newlines." 127 With arg N, insert N newlines."
119 ;; "Insert a newline and leave point before it.
120 ;; If there is a fill prefix, insert the fill prefix on the new line
121 ;; if the line would have been empty.
122 ;; With arg N, insert N newlines."
123 (interactive "*p") 128 (interactive "*p")
124 (let* ((do-fill-prefix (and fill-prefix (bolp))) 129 (let* ((do-fill-prefix (and fill-prefix (bolp)))
125 ;well, I'm going to re-enable this. --ben
126 ;(do-fill-prefix nil) ;; screw this -- says JWZ
127 (do-left-margin (and (bolp) (> (current-left-margin) 0))) 130 (do-left-margin (and (bolp) (> (current-left-margin) 0)))
128 (loc (point))) 131 (loc (point)))
129 (newline arg) 132 (newline arg)
130 (goto-char loc) 133 (goto-char loc)
131 (while (> arg 0) 134 (while (> arg 0)
211 (delete-region (point) (progn (skip-chars-forward " \t") (point)))) 214 (delete-region (point) (progn (skip-chars-forward " \t") (point))))
212 215
213 (defun just-one-space () 216 (defun just-one-space ()
214 "Delete all spaces and tabs around point, leaving one space." 217 "Delete all spaces and tabs around point, leaving one space."
215 (interactive "*") 218 (interactive "*")
216 (if abbrev-mode 219 (if abbrev-mode ; XEmacs
217 (expand-abbrev)) 220 (expand-abbrev))
218 (skip-chars-backward " \t") 221 (skip-chars-backward " \t")
219 (if (= (following-char) ? ) 222 (if (= (following-char) ? )
220 (forward-char 1) 223 (forward-char 1)
221 (insert ? )) 224 (insert ? ))
261 (if (looking-at "^[ \t]*\n\\'") 264 (if (looking-at "^[ \t]*\n\\'")
262 (delete-region (point) (point-max))))) 265 (delete-region (point) (point-max)))))
263 266
264 (defun back-to-indentation () 267 (defun back-to-indentation ()
265 "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
266 (interactive "_") 270 (interactive "_")
267 (beginning-of-line 1) 271 (beginning-of-line 1)
268 (skip-chars-forward " \t")) 272 (skip-chars-forward " \t"))
269 273
270 (defun newline-and-indent () 274 (defun newline-and-indent ()
320 (insert-char ?\ col) 324 (insert-char ?\ col)
321 (delete-char 1))) 325 (delete-char 1)))
322 (forward-char -1) 326 (forward-char -1)
323 (setq count (1- count))))) 327 (setq count (1- count)))))
324 (delete-backward-char arg killp) 328 (delete-backward-char arg killp)
325 ;; In overwrite mode, back over columns while clearing them out, 329 ;; XEmacs: In overwrite mode, back over columns while clearing them out,
326 ;; unless at end of line. 330 ;; unless at end of line.
327 (and overwrite-mode (not (eolp)) 331 (and overwrite-mode (not (eolp))
328 (save-excursion (insert-char ?\ arg)))) 332 (save-excursion (insert-char ?\ arg))))
329 333
330 (defun zap-to-char (arg char) 334 (defun zap-to-char (arg char)
343 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
344 of the accessible part of the buffer. 348 of the accessible part of the buffer.
345 349
346 Don't use this command in Lisp programs! 350 Don't use this command in Lisp programs!
347 \(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
348 (interactive "_P") 353 (interactive "_P")
349 (push-mark) 354 (push-mark)
350 (let ((size (- (point-max) (point-min)))) 355 (let ((size (- (point-max) (point-min))))
351 (goto-char (if arg 356 (goto-char (if arg
352 (+ (point-min) 357 (+ (point-min)
365 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
366 of the accessible part of the buffer. 371 of the accessible part of the buffer.
367 372
368 Don't use this command in Lisp programs! 373 Don't use this command in Lisp programs!
369 \(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
370 (interactive "_P") 376 (interactive "_P")
371 (push-mark) 377 (push-mark)
372 ;; XEmacs changes here. 378 ;; XEmacs changes here.
373 (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))))
374 (size (- (point-max) (point-min)))) 380 (size (- (point-max) (point-min))))
382 (point-max))) 388 (point-max)))
383 (cond (arg 389 (cond (arg
384 ;; 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,
385 ;; adjust it to the beginning of a line. 391 ;; adjust it to the beginning of a line.
386 (forward-line 1)) 392 (forward-line 1))
393 ;; XEmacs change
387 (scroll-to-end 394 (scroll-to-end
388 ;; 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,
389 ;; 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.
390 (recenter -3))))) 397 (recenter -3)))))
391 398
399 ;; XEmacs (not in FSF)
392 (defun mark-beginning-of-buffer (&optional arg) 400 (defun mark-beginning-of-buffer (&optional arg)
393 "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.
394 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."
395 (interactive "P") 403 (interactive "P")
396 (push-mark (if arg 404 (push-mark (if arg
402 (point-min)) 410 (point-min))
403 nil 411 nil
404 t)) 412 t))
405 (define-function 'mark-bob 'mark-beginning-of-buffer) 413 (define-function 'mark-bob 'mark-beginning-of-buffer)
406 414
415 ;; XEmacs (not in FSF)
407 (defun mark-end-of-buffer (&optional arg) 416 (defun mark-end-of-buffer (&optional arg)
408 "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.
409 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."
410 (interactive "P") 419 (interactive "P")
411 (push-mark (if arg 420 (push-mark (if arg
428 (interactive) 437 (interactive)
429 (push-mark (point)) 438 (push-mark (point))
430 (push-mark (point-max) nil t) 439 (push-mark (point-max) nil t)
431 (goto-char (point-min))) 440 (goto-char (point-min)))
432 441
442 ;; XEmacs
433 (defun eval-current-buffer (&optional printflag) 443 (defun eval-current-buffer (&optional printflag)
434 "Evaluate the current buffer as Lisp code. 444 "Evaluate the current buffer as Lisp code.
435 Programs can pass argument PRINTFLAG which controls printing of output: 445 Programs can pass argument PRINTFLAG which controls printing of output:
436 nil means discard it; anything else is stream for print." 446 nil means discard it; anything else is stream for print."
437 (interactive) 447 (interactive)
438 (eval-buffer (current-buffer) printflag)) 448 (eval-buffer (current-buffer) printflag))
439 449
450 ;; XEmacs
440 (defun count-words-buffer (b) 451 (defun count-words-buffer (b)
441 (interactive "b") 452 (interactive "b")
442 (save-excursion 453 (save-excursion
443 (let ((buf (or b (current-buffer)))) 454 (let ((buf (or b (current-buffer))))
444 (set-buffer buf) 455 (set-buffer buf)
445 (message "Buffer has %d words" 456 (message "Buffer has %d words"
446 (count-words-region (point-min) (point-max)))))) 457 (count-words-region (point-min) (point-max))))))
447 458
459 ;; XEmacs
448 (defun count-words-region (start end) 460 (defun count-words-region (start end)
449 (interactive "r") 461 (interactive "r")
450 (save-excursion 462 (save-excursion
451 (let ((n 0)) 463 (let ((n 0))
452 (goto-char start) 464 (goto-char start)
456 (message "Region has %d words" n) 468 (message "Region has %d words" n)
457 n))) 469 n)))
458 470
459 (defun count-lines-region (start end) 471 (defun count-lines-region (start end)
460 "Print number of lines and characters in the region." 472 "Print number of lines and characters in the region."
473 ;; XEmacs change
461 (interactive "_r") 474 (interactive "_r")
462 (let ((n (count-lines start end))) 475 (message "Region has %d lines, %d characters"
463 (message "Region has %d lines, %d characters" 476 (count-lines start end) (- end start)))
464 n (- end start)) 477
465 n)) 478 ;; XEmacs
466
467 (defun count-lines-buffer (b) 479 (defun count-lines-buffer (b)
468 "Print number of lines and charcters in the specified buffer." 480 "Print number of lines and charcters in the specified buffer."
469 (interactive "_b") 481 (interactive "_b")
470 (save-excursion 482 (save-excursion
471 (let ((buf (or b (current-buffer))) 483 (let ((buf (or b (current-buffer)))
472 cnt) 484 cnt)
473 (set-buffer buf) 485 (set-buffer buf)
474 (setq cnt (count-lines (point-min) (point-max))) 486 (setq cnt (count-lines (point-min) (point-max)))
475 (message "Region has %d lines, %d characters" 487 (message "Buffer has %d lines, %d characters"
476 cnt (- (point-max) (point-min))) 488 cnt (- (point-max) (point-min)))
477 cnt))) 489 cnt)))
478 490
479 (defun what-line () 491 (defun what-line ()
480 "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
481 (interactive "_") 494 (interactive "_")
482 (let ((opoint (point)) start) 495 (let ((opoint (point)) start)
483 (save-excursion 496 (save-excursion
484 (save-restriction 497 (save-restriction
485 (goto-char (point-min)) 498 (goto-char (point-min))
518 done))) 531 done)))
519 (- (buffer-size) (forward-line (buffer-size))))))) 532 (- (buffer-size) (forward-line (buffer-size)))))))
520 533
521 (defun what-cursor-position () 534 (defun what-cursor-position ()
522 "Print info on cursor position (on screen and within buffer)." 535 "Print info on cursor position (on screen and within buffer)."
536 ;; XEmacs change
523 (interactive "_") 537 (interactive "_")
524 (let* ((char (following-char)) 538 (let* ((char (following-char))
525 (beg (point-min)) 539 (beg (point-min))
526 (end (point-max)) 540 (end (point-max))
527 (pos (point)) 541 (pos (point))
538 (if (or (/= beg 1) (/= end (1+ total))) 552 (if (or (/= beg 1) (/= end (1+ total)))
539 (message "point=%d of %d(%d%%) <%d - %d> column %d %s" 553 (message "point=%d of %d(%d%%) <%d - %d> column %d %s"
540 pos total percent beg end col hscroll) 554 pos total percent beg end col hscroll)
541 (message "point=%d of %d(%d%%) column %d %s" 555 (message "point=%d of %d(%d%%) column %d %s"
542 pos total percent col hscroll)) 556 pos total percent col hscroll))
557 ;; XEmacs: don't use single-key-description
543 (if (or (/= beg 1) (/= end (1+ total))) 558 (if (or (/= beg 1) (/= end (1+ total)))
544 (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"
545 (text-char-description char) char char char pos total 560 (text-char-description char) char char char pos total
546 percent beg end col hscroll) 561 percent beg end col hscroll)
547 (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"
552 "Major mode not specialized for anything in particular. 567 "Major mode not specialized for anything in particular.
553 Other major modes are defined by comparison with this one." 568 Other major modes are defined by comparison with this one."
554 (interactive) 569 (interactive)
555 (kill-all-local-variables)) 570 (kill-all-local-variables))
556 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)
557 580
558 ;; We define this, rather than making `eval' interactive, 581 ;; We define this, rather than making `eval' interactive,
559 ;; 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.
560 (defun eval-expression (expression) 583 (defun eval-expression (expression)
561 "Evaluate EXPRESSION and print value in minibuffer. 584 "Evaluate EXPRESSION and print value in minibuffer.
562 Value is also consed on to front of the variable `values'." 585 Value is also consed on to front of the variable `values'."
563 (interactive "xEval: ") 586 ;(interactive "xEval: ")
587 (interactive
588 (list (read-from-minibuffer "Eval: "
589 nil read-expression-map t
590 'read-expression-history)))
564 (setq values (cons (eval expression) values)) 591 (setq values (cons (eval expression) values))
565 (prin1 (car values) t)) 592 (prin1 (car values) t))
566 593
594 ;; XEmacs -- extra parameter (variant, but equivalent logic)
567 (defun edit-and-eval-command (prompt command &optional history) 595 (defun edit-and-eval-command (prompt command &optional history)
568 "Prompting with PROMPT, let user edit COMMAND and eval result. 596 "Prompting with PROMPT, let user edit COMMAND and eval result.
569 COMMAND is a Lisp expression. Let user edit that expression in 597 COMMAND is a Lisp expression. Let user edit that expression in
570 the minibuffer, then read and evaluate the result." 598 the minibuffer, then read and evaluate the result."
571 (let ((command (read-expression prompt 599 (let ((command (read-expression prompt
600 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
601 it is added to the front of the command history. 629 it is added to the front of the command history.
602 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]
603 to get different commands to edit and resubmit." 631 to get different commands to edit and resubmit."
604 (interactive "p") 632 (interactive "p")
633 ;; XEmacs: It looks like our version is better -sb
605 (let ((print-level nil)) 634 (let ((print-level nil))
606 (edit-and-eval-command "Redo: " 635 (edit-and-eval-command "Redo: "
607 (or (nth (1- arg) command-history) 636 (or (nth (1- arg) command-history)
608 (error "")) 637 (error ""))
609 (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
610 647
611 (defun goto-line (arg) 648 (defun goto-line (arg)
612 "Goto line ARG, counting from line 1 at beginning of buffer." 649 "Goto line ARG, counting from line 1 at beginning of buffer."
613 (interactive "NGoto line: ") 650 (interactive "NGoto line: ")
614 (setq arg (prefix-numeric-value arg)) 651 (setq arg (prefix-numeric-value arg))
633 (let ((modified (buffer-modified-p)) 670 (let ((modified (buffer-modified-p))
634 (recent-save (recent-auto-save-p))) 671 (recent-save (recent-auto-save-p)))
635 (or (eq (selected-window) (minibuffer-window)) 672 (or (eq (selected-window) (minibuffer-window))
636 (message "Undo!")) 673 (message "Undo!"))
637 (or (and (eq last-command 'undo) 674 (or (and (eq last-command 'undo)
638 (eq (current-buffer) last-undo-buffer)) 675 (eq (current-buffer) last-undo-buffer)) ; XEmacs
639 (progn (undo-start) 676 (progn (undo-start)
640 (undo-more 1))) 677 (undo-more 1)))
641 (undo-more (or arg 1)) 678 (undo-more (or arg 1))
642 ;; 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.
643 ;; Instead, undoing this should move point to where the change is. 680 ;; Instead, undoing this should move point to where the change is.
655 (setq this-command 'undo)) 692 (setq this-command 'undo))
656 693
657 (defvar pending-undo-list nil 694 (defvar pending-undo-list nil
658 "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.")
659 696
660 (defvar last-undo-buffer nil) 697 (defvar last-undo-buffer nil) ; XEmacs
661 698
662 (defun undo-start () 699 (defun undo-start ()
663 "Set `pending-undo-list' to the front of the undo list. 700 "Set `pending-undo-list' to the front of the undo list.
664 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."
665 (if (eq buffer-undo-list t) 702 (if (eq buffer-undo-list t)
671 Call `undo-start' to get ready to undo recent changes, 708 Call `undo-start' to get ready to undo recent changes,
672 then call `undo-more' one or more times to undo them." 709 then call `undo-more' one or more times to undo them."
673 (or pending-undo-list 710 (or pending-undo-list
674 (error "No further undo information")) 711 (error "No further undo information"))
675 (setq pending-undo-list (primitive-undo count pending-undo-list) 712 (setq pending-undo-list (primitive-undo count pending-undo-list)
676 last-undo-buffer (current-buffer))) 713 last-undo-buffer (current-buffer))) ; XEmacs
677 714
715 ;; XEmacs
678 (defun call-with-transparent-undo (fn &rest args) 716 (defun call-with-transparent-undo (fn &rest args)
679 "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
680 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.
681 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.
682 720
699 (let ((tail buffer-undo-list)) 737 (let ((tail buffer-undo-list))
700 (setq buffer-undo-list t) 738 (setq buffer-undo-list t)
701 (while tail 739 (while tail
702 (setq tail (primitive-undo (length tail) tail)))))))))) 740 (setq tail (primitive-undo (length tail) tail))))))))))
703 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
704 748
705 (defconst universal-argument-map 749 (defconst universal-argument-map
706 (let ((map (make-sparse-keymap))) 750 (let ((map (make-sparse-keymap)))
707 (set-keymap-default-binding map 'universal-argument-other-key) 751 (set-keymap-default-binding map 'universal-argument-other-key)
708 ;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)
709 (define-key map [(control u)] 'universal-argument-more) 755 (define-key map [(control u)] 'universal-argument-more)
710 (define-key map ?- 'universal-argument-minus) 756 (define-key map [?-] 'universal-argument-minus)
711 (define-key map ?0 'digit-argument) 757 (define-key map [?0] 'digit-argument)
712 (define-key map ?1 'digit-argument) 758 (define-key map [?1] 'digit-argument)
713 (define-key map ?2 'digit-argument) 759 (define-key map [?2] 'digit-argument)
714 (define-key map ?3 'digit-argument) 760 (define-key map [?3] 'digit-argument)
715 (define-key map ?4 'digit-argument) 761 (define-key map [?4] 'digit-argument)
716 (define-key map ?5 'digit-argument) 762 (define-key map [?5] 'digit-argument)
717 (define-key map ?6 'digit-argument) 763 (define-key map [?6] 'digit-argument)
718 (define-key map ?7 'digit-argument) 764 (define-key map [?7] 'digit-argument)
719 (define-key map ?8 'digit-argument) 765 (define-key map [?8] 'digit-argument)
720 (define-key map ?9 'digit-argument) 766 (define-key map [?9] 'digit-argument)
721 map) 767 map)
722 "Keymap used while processing \\[universal-argument].") 768 "Keymap used while processing \\[universal-argument].")
723 769
724 (defvar universal-argument-num-events nil 770 (defvar universal-argument-num-events nil
725 "Number of argument-specifying events read by `universal-argument'. 771 "Number of argument-specifying events read by `universal-argument'.
733 \\[universal-argument] without digits or minus sign provides 4 as argument. 779 \\[universal-argument] without digits or minus sign provides 4 as argument.
734 Repeating \\[universal-argument] without digits or minus sign 780 Repeating \\[universal-argument] without digits or minus sign
735 multiplies the argument by 4 each time." 781 multiplies the argument by 4 each time."
736 (interactive) 782 (interactive)
737 (setq prefix-arg (list 4)) 783 (setq prefix-arg (list 4))
738 (setq zmacs-region-stays t) 784 (setq zmacs-region-stays t) ; XEmacs
739 (setq universal-argument-num-events (length (this-command-keys))) 785 (setq universal-argument-num-events (length (this-command-keys)))
740 (setq overriding-terminal-local-map universal-argument-map)) 786 (setq overriding-terminal-local-map universal-argument-map))
741 787
742 ;; 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
743 ;; 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.
745 (interactive "P") 791 (interactive "P")
746 (if (consp arg) 792 (if (consp arg)
747 (setq prefix-arg (list (* 4 (car arg)))) 793 (setq prefix-arg (list (* 4 (car arg))))
748 (setq prefix-arg arg) 794 (setq prefix-arg arg)
749 (setq overriding-terminal-local-map nil)) 795 (setq overriding-terminal-local-map nil))
750 (setq zmacs-region-stays t) 796 (setq zmacs-region-stays t) ; XEmacs
751 (setq universal-argument-num-events (length (this-command-keys)))) 797 (setq universal-argument-num-events (length (this-command-keys))))
752 798
753 (defun negative-argument (arg) 799 (defun negative-argument (arg)
754 "Begin a negative numeric argument for the next command. 800 "Begin a negative numeric argument for the next command.
755 \\[universal-argument] following digits or minus sign ends the argument." 801 \\[universal-argument] following digits or minus sign ends the argument."
758 (setq prefix-arg (- arg))) 804 (setq prefix-arg (- arg)))
759 ((eq arg '-) 805 ((eq arg '-)
760 (setq prefix-arg nil)) 806 (setq prefix-arg nil))
761 (t 807 (t
762 (setq prefix-arg '-))) 808 (setq prefix-arg '-)))
763 (setq zmacs-region-stays t) 809 (setq zmacs-region-stays t) ; XEmacs
764 (setq universal-argument-num-events (length (this-command-keys))) 810 (setq universal-argument-num-events (length (this-command-keys)))
765 (setq overriding-terminal-local-map universal-argument-map)) 811 (setq overriding-terminal-local-map universal-argument-map))
766 812
813 ;; XEmacs: This function not synched with FSF
767 (defun digit-argument (arg) 814 (defun digit-argument (arg)
768 "Part of the numeric argument for the next command. 815 "Part of the numeric argument for the next command.
769 \\[universal-argument] following digits or minus sign ends the argument." 816 \\[universal-argument] following digits or minus sign ends the argument."
770 (interactive "P") 817 (interactive "P")
771 (let* ((event last-command-event) 818 (let* ((event last-command-event)
798 ;; 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
799 ;; executed as a command. 846 ;; executed as a command.
800 (defun universal-argument-other-key (arg) 847 (defun universal-argument-other-key (arg)
801 (interactive "P") 848 (interactive "P")
802 (setq prefix-arg arg) 849 (setq prefix-arg arg)
803 (setq zmacs-region-stays t) 850 (setq zmacs-region-stays t) ; XEmacs
804 (let* ((key (this-command-keys)) 851 (let* ((key (this-command-keys))
805 ;; FSF calls silly function `listify-key-sequence' here. 852 ;; FSF calls silly function `listify-key-sequence' here.
806 (keylist (append key nil))) 853 (keylist (append key nil)))
807 (setq unread-command-events 854 (setq unread-command-events
808 (append (nthcdr universal-argument-num-events keylist) 855 (append (nthcdr universal-argument-num-events keylist)
809 unread-command-events))) 856 unread-command-events)))
810 (reset-this-command-lengths) 857 (reset-this-command-lengths)
811 (setq overriding-terminal-local-map nil)) 858 (setq overriding-terminal-local-map nil))
812 859
813 860
861 ;; XEmacs -- shouldn't these functions keep the zmacs region active?
814 (defun forward-to-indentation (arg) 862 (defun forward-to-indentation (arg)
815 "Move forward ARG lines and position at first nonblank character." 863 "Move forward ARG lines and position at first nonblank character."
816 (interactive "p") 864 (interactive "p")
817 (forward-line arg) 865 (forward-line arg)
818 (skip-chars-forward " \t")) 866 (skip-chars-forward " \t"))
838 when given no argument at the beginning of a line." 886 when given no argument at the beginning of a line."
839 (interactive "*P") 887 (interactive "*P")
840 (kill-region (point) 888 (kill-region (point)
841 ;; Don't shift point before doing the delete; that way, 889 ;; Don't shift point before doing the delete; that way,
842 ;; 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
843 (save-excursion 898 (save-excursion
844 (if arg 899 (if arg
845 (forward-line (prefix-numeric-value arg)) 900 (forward-line (prefix-numeric-value arg))
846 (if (eobp) 901 (if (eobp)
847 (signal 'end-of-buffer nil)) 902 (signal 'end-of-buffer nil))
848 (if (or (looking-at "[ \t]*$") (and kill-whole-line (bolp))) 903 (if (or (looking-at "[ \t]*$") (and kill-whole-line (bolp)))
849 (forward-line 1) 904 (forward-line 1)
850 (end-of-line))) 905 (end-of-line)))
851 (point)))) 906 (point))))
852 907
908 ;; XEmacs
853 (defun backward-kill-line nil 909 (defun backward-kill-line nil
854 "Kill back to the beginning of the line." 910 "Kill back to the beginning of the line."
855 (interactive) 911 (interactive)
856 (let ((point (point))) 912 (let ((point (point)))
857 (beginning-of-line nil) 913 (beginning-of-line nil)
910 966
911 ;;;; The kill ring data structure. 967 ;;;; The kill ring data structure.
912 968
913 (defvar kill-ring nil 969 (defvar kill-ring nil
914 "List of killed text sequences. 970 "List of killed text sequences.
915 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
916 offered by window systems, the functions `kill-new', `kill-append', and 972 facilities offered by window systems, use of this variable should
917 `current-kill' should be used to access the kill ring, instead of using 973 interact nicely with `interprogram-cut-function' and
918 this variable directly.") 974 `interprogram-paste-function'. The functions `kill-new',
919 975 `kill-append', and `current-kill' are supposed to implement this
920 (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
921 "*Maximum length of kill ring before oldest elements are thrown away.") 980 "*Maximum length of kill ring before oldest elements are thrown away.")
922 981
923 (defvar kill-ring-yank-pointer nil 982 (defvar kill-ring-yank-pointer nil
924 "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.")
925 984
966 ;;;; Commands for manipulating the kill ring. 1025 ;;;; Commands for manipulating the kill ring.
967 1026
968 ;;FSFmacs 1027 ;;FSFmacs
969 ;(defvar kill-read-only-ok nil 1028 ;(defvar kill-read-only-ok nil
970 ; "*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")
971 1034
972 (defun kill-region (beg end &optional verbose) ; verbose is XEmacs addition 1035 (defun kill-region (beg end &optional verbose) ; verbose is XEmacs addition
973 "Kill between point and mark. 1036 "Kill between point and mark.
974 The text is deleted but saved in the kill ring. 1037 The text is deleted but saved in the kill ring.
975 The command \\[yank] can retrieve it from there. 1038 The command \\[yank] can retrieve it from there.
1003 (message "Killing %d characters" 1066 (message "Killing %d characters"
1004 (- (max beg end) (min beg end))))) 1067 (- (max beg end) (min beg end)))))
1005 (cond 1068 (cond
1006 1069
1007 ;; 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
1008 ;; 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
1009 ;; 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
1010 ;; the region's text in the kill ring, anyway. 1075 ;; the region's text in the kill ring, anyway.
1011 ;;((or (and buffer-read-only (not inhibit-read-only)) 1076 ((or (and buffer-read-only (not inhibit-read-only))
1012 ;; (text-property-not-all beg end 'read-only nil)) 1077 (text-property-not-all beg end 'read-only nil))
1078 ;; This is redundant.
1013 ;; (if verbose (message "Copying %d characters" 1079 ;; (if verbose (message "Copying %d characters"
1014 ;; (- (max beg end) (min beg end)))) 1080 ;; (- (max beg end) (min beg end))))
1015 ;; (copy-region-as-kill beg end) 1081 (copy-region-as-kill beg end)
1016 ;; ;; This should always barf, and give us the correct error. 1082 ;; ;; This should always barf, and give us the correct error.
1017 ;; (if kill-read-only-ok 1083 ;; (if kill-read-only-ok
1018 ;; (message "Read only text copied to kill ring") 1084 ;; (message "Read only text copied to kill ring")
1019 ;; (setq this-command 'kill-region) 1085 (setq this-command 'kill-region)
1020 ;; (barf-if-buffer-read-only))) 1086 (barf-if-buffer-read-only)
1087 (signal 'text-read-only (list (current-buffer))))
1021 1088
1022 ;; 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
1023 ;; ring to share the same string object. This code does that. 1090 ;; ring to share the same string object. This code does that.
1024 ((not (or (eq buffer-undo-list t) 1091 ((not (or (eq buffer-undo-list t)
1025 (eq last-command 'kill-region) 1092 (eq last-command 'kill-region)
1026 ;; Use = since positions may be numbers or markers. 1093 ;; Use = since positions may be numbers or markers.
1027 (= beg end))) 1094 (= beg end)))
1028 ;; 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'
1029 (let ((undo-high-threshold (+ (- (max beg end) (min beg end)) 100)) 1097 (let ((undo-high-threshold (+ (- (max beg end) (min beg end)) 100))
1030 ;(old-list buffer-undo-list) 1098 ;(old-list buffer-undo-list)
1031 tail) 1099 tail)
1032 (delete-region beg end) 1100 (delete-region beg end)
1033 ;; Search back in buffer-undo-list for this string, 1101 ;; Search back in buffer-undo-list for this string,
1034 ;; in case a change hook made property changes. 1102 ;; in case a change hook made property changes.
1035 (setq tail buffer-undo-list) 1103 (setq tail buffer-undo-list)
1036 (while (not (stringp (car-safe (car-safe tail)))) 1104 (while (not (stringp (car-safe (car-safe tail)))) ; XEmacs
1037 (setq tail (cdr tail))) 1105 (setq tail (cdr tail)))
1038 ;; Take the same string recorded for undo 1106 ;; Take the same string recorded for undo
1039 ;; and put it in the kill-ring. 1107 ;; and put it in the kill-ring.
1040 (kill-new (car (car tail))))) 1108 (kill-new (car (car tail)))))
1041 1109
1071 ;; Inhibit quitting so we can make a quit here 1139 ;; Inhibit quitting so we can make a quit here
1072 ;; look like a C-g typed as a command. 1140 ;; look like a C-g typed as a command.
1073 (inhibit-quit t)) 1141 (inhibit-quit t))
1074 (if (pos-visible-in-window-p other-end (selected-window)) 1142 (if (pos-visible-in-window-p other-end (selected-window))
1075 (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))
1076 (goto-char other-end) 1147 (goto-char other-end)
1077 (sit-for 1) 1148 (sit-for 1)
1149 ; ;; Swap back.
1150 ; (set-marker (mark-marker) other-end (current-buffer))
1078 (goto-char opoint) 1151 (goto-char opoint)
1079 ;; If user quit, deactivate the mark 1152 ;; If user quit, deactivate the mark
1080 ;; as C-g would as a command. 1153 ;; as C-g would as a command.
1081 (and quit-flag (mark) 1154 (and quit-flag (mark)
1082 (zmacs-deactivate-region))) 1155 (zmacs-deactivate-region)))
1091 ; (substring killed-text 0 message-len)))) 1164 ; (substring killed-text 0 message-len))))
1092 )))) 1165 ))))
1093 1166
1094 (defun append-next-kill () 1167 (defun append-next-kill ()
1095 "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
1096 (interactive "_") 1170 (interactive "_")
1097 (if (interactive-p) 1171 (if (interactive-p)
1098 (progn 1172 (progn
1099 (setq this-command 'kill-region) 1173 (setq this-command 'kill-region)
1100 (message "If the next command is a kill, it will append")) 1174 (message "If the next command is a kill, it will append"))
1115 comes the newest one." 1189 comes the newest one."
1116 (interactive "*p") 1190 (interactive "*p")
1117 (if (not (eq last-command 'yank)) 1191 (if (not (eq last-command 'yank))
1118 (error "Previous command was not a yank")) 1192 (error "Previous command was not a yank"))
1119 (setq this-command 'yank) 1193 (setq this-command 'yank)
1120 (let ((before (< (point) (mark t)))) 1194 (let ((inhibit-read-only t)
1195 (before (< (point) (mark t))))
1121 (delete-region (point) (mark t)) 1196 (delete-region (point) (mark t))
1197 ;;(set-marker (mark-marker) (point) (current-buffer))
1122 (set-mark (point)) 1198 (set-mark (point))
1123 (insert (current-kill arg)) 1199 (insert (current-kill arg))
1124 (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
1125 1208
1126 (defun yank (&optional arg) 1209 (defun yank (&optional arg)
1127 "Reinsert the last stretch of killed text. 1210 "Reinsert the last stretch of killed text.
1128 More precisely, reinsert the stretch of killed text most recently 1211 More precisely, reinsert the stretch of killed text most recently
1129 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.
1130 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).
1131 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.
1132 See also the command \\[yank-pop]." 1216 See also the command \\[yank-pop]."
1133 (interactive "*P") 1217 (interactive "*P")
1134 ;; 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
1135 ;; for the following command. 1219 ;; for the following command.
1136 (setq this-command t) 1220 (setq this-command t)
1138 (insert (current-kill (cond 1222 (insert (current-kill (cond
1139 ((listp arg) 0) 1223 ((listp arg) 0)
1140 ((eq arg '-) -1) 1224 ((eq arg '-) -1)
1141 (t (1- arg))))) 1225 (t (1- arg)))))
1142 (if (consp arg) 1226 (if (consp arg)
1143 (exchange-point-and-mark t)) 1227 ;; This is like exchange-point-and-mark, but doesn't activate the mark.
1144 ;; If we do get all the way through, make this-command indicate that. 1228 ;; It is cleaner to avoid activation, even though the command
1145 (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)
1146 1235
1147 (defun rotate-yank-pointer (arg) 1236 (defun rotate-yank-pointer (arg)
1148 "Rotate the yanking point in the kill ring. 1237 "Rotate the yanking point in the kill ring.
1149 With argument, rotate that many kills forward (or backward, if negative)." 1238 With argument, rotate that many kills forward (or backward, if negative)."
1150 (interactive "p") 1239 (interactive "p")
1153 1242
1154 (defun insert-buffer (buffer) 1243 (defun insert-buffer (buffer)
1155 "Insert after point the contents of BUFFER. 1244 "Insert after point the contents of BUFFER.
1156 Puts mark after the inserted text. 1245 Puts mark after the inserted text.
1157 BUFFER may be a buffer or a buffer name." 1246 BUFFER may be a buffer or a buffer name."
1158 (interactive (list (progn (barf-if-buffer-read-only) 1247 (interactive
1159 (read-buffer "Insert buffer: " 1248 (list
1160 ;; XEmacs: we have different args 1249 (progn
1161 (other-buffer (current-buffer) nil t) 1250 (barf-if-buffer-read-only)
1162 t)))) 1251 (read-buffer "Insert buffer: "
1252 ;; XEmacs: we have different args
1253 (other-buffer (current-buffer) nil t)
1254 t))))
1163 (or (bufferp buffer) 1255 (or (bufferp buffer)
1164 (setq buffer (get-buffer buffer))) 1256 (setq buffer (get-buffer buffer)))
1165 (let (start end newmark) 1257 (let (start end newmark)
1166 (save-excursion 1258 (save-excursion
1167 (save-excursion 1259 (save-excursion
1217 (erase-buffer) 1309 (erase-buffer)
1218 (save-excursion 1310 (save-excursion
1219 (insert-buffer-substring oldbuf start end))))) 1311 (insert-buffer-substring oldbuf start end)))))
1220 1312
1221 ;FSFmacs 1313 ;FSFmacs
1222 ;(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")
1223 1316
1224 (defun mark (&optional force buffer) 1317 (defun mark (&optional force buffer)
1225 "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.
1226 1319
1227 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
1269 1362
1270 (let ((beg (point))) (forward-line 1) (delete-region beg (point)))." 1363 (let ((beg (point))) (forward-line 1) (delete-region beg (point)))."
1271 1364
1272 (setq buffer (decode-buffer buffer)) 1365 (setq buffer (decode-buffer buffer))
1273 (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)))
1274 1379
1275 (defvar mark-ring nil 1380 (defvar mark-ring nil
1276 "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.")
1277 (make-variable-buffer-local 'mark-ring) 1382 (make-variable-buffer-local 'mark-ring)
1278 (put 'mark-ring 'permanent-local t) 1383 (put 'mark-ring 'permanent-local t)
1279 1384
1280 (defvar mark-ring-max 16 1385 (defconst mark-ring-max 16
1281 "*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.")
1282 1387
1283 (defvar global-mark-ring nil 1388 (defvar global-mark-ring nil
1284 "The list of saved global marks, most recent first.") 1389 "The list of saved global marks, most recent first.")
1285 1390
1287 "*Maximum size of global mark ring. \ 1392 "*Maximum size of global mark ring. \
1288 Start discarding off end if gets this big.") 1393 Start discarding off end if gets this big.")
1289 1394
1290 (defun set-mark-command (arg) 1395 (defun set-mark-command (arg)
1291 "Set mark at where point is, or jump to mark. 1396 "Set mark at where point is, or jump to mark.
1292 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
1293 ring, and push mark on global mark ring. 1398 ring, and push mark on global mark ring.
1294 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
1295 \(does not affect global mark ring\). 1400 \(does not affect global mark ring\).
1296 1401
1297 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
1302 (if (null (mark t)) 1407 (if (null (mark t))
1303 (error "No mark set in this buffer") 1408 (error "No mark set in this buffer")
1304 (goto-char (mark t)) 1409 (goto-char (mark t))
1305 (pop-mark)))) 1410 (pop-mark))))
1306 1411
1412 ;; XEmacs: Extra parameter
1307 (defun push-mark (&optional location nomsg activate-region buffer) 1413 (defun push-mark (&optional location nomsg activate-region buffer)
1308 "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.
1309 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,
1310 also push LOCATION on the global mark ring. 1416 also push LOCATION on the global mark ring.
1311 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.
1312 Activate mark if optional third arg ACTIVATE-REGION non-nil. 1418 Activate mark if optional third arg ACTIVATE-REGION non-nil.
1313 1419
1314 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
1315 purposes. See the documentation of `set-mark' for more information." 1421 purposes. See the documentation of `set-mark' for more information."
1316 (setq buffer (decode-buffer buffer)) 1422 (setq buffer (decode-buffer buffer)) ; XEmacs
1317 (if (null (mark t buffer)) 1423 (if (null (mark t buffer)) ; XEmacs
1318 nil 1424 nil
1319 ;; The save-excursion / set-buffer is necessary because mark-ring 1425 ;; The save-excursion / set-buffer is necessary because mark-ring
1320 ;; is a buffer local variable 1426 ;; is a buffer local variable
1321 (save-excursion 1427 (save-excursion
1322 (set-buffer buffer) 1428 (set-buffer buffer)
1324 (if (> (length mark-ring) mark-ring-max) 1430 (if (> (length mark-ring) mark-ring-max)
1325 (progn 1431 (progn
1326 (move-marker (car (nthcdr mark-ring-max mark-ring)) nil buffer) 1432 (move-marker (car (nthcdr mark-ring-max mark-ring)) nil buffer)
1327 (setcdr (nthcdr (1- mark-ring-max) mark-ring) nil))))) 1433 (setcdr (nthcdr (1- mark-ring-max) mark-ring) nil)))))
1328 (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
1329 ;; Now push the mark on the global mark ring. 1436 ;; Now push the mark on the global mark ring.
1330 (if (or (null global-mark-ring) 1437 (if (or (null global-mark-ring)
1331 (not (eq (marker-buffer (car global-mark-ring)) buffer))) 1438 (not (eq (marker-buffer (car global-mark-ring)) buffer)))
1332 ;; The last global mark pushed wasn't in this same buffer. 1439 ;; The last global mark pushed wasn't in this same buffer.
1333 (progn 1440 (progn
1342 (message "Mark set")) 1449 (message "Mark set"))
1343 (if activate-region 1450 (if activate-region
1344 (progn 1451 (progn
1345 (setq zmacs-region-stays t) 1452 (setq zmacs-region-stays t)
1346 (zmacs-activate-region))) 1453 (zmacs-activate-region)))
1454 ; (if (or activate (not transient-mark-mode)) ; FSF
1455 ; (set-mark (mark t))) ; FSF
1347 nil) 1456 nil)
1348 1457
1349 (defun pop-mark () 1458 (defun pop-mark ()
1350 "Pop off mark ring into the buffer's actual mark. 1459 "Pop off mark ring into the buffer's actual mark.
1351 Does not set point. Does nothing if mark ring is empty." 1460 Does not set point. Does nothing if mark ring is empty."
1365 (let ((omark (mark t))) 1474 (let ((omark (mark t)))
1366 (if (null omark) 1475 (if (null omark)
1367 (error "No mark set in this buffer")) 1476 (error "No mark set in this buffer"))
1368 (set-mark (point)) 1477 (set-mark (point))
1369 (goto-char omark) 1478 (goto-char omark)
1370 (or dont-activate-region (zmacs-activate-region)) 1479 (or dont-activate-region (zmacs-activate-region)) ; XEmacs
1371 nil)) 1480 nil))
1372 1481
1482 ;; XEmacs
1373 (defun mark-something (mark-fn movement-fn arg) 1483 (defun mark-something (mark-fn movement-fn arg)
1374 "internal function used by mark-sexp, mark-word, etc." 1484 "internal function used by mark-sexp, mark-word, etc."
1375 (let (newmark (pushp t)) 1485 (let (newmark (pushp t))
1376 (save-excursion 1486 (save-excursion
1377 (if (and (eq last-command mark-fn) (mark)) 1487 (if (and (eq last-command mark-fn) (mark))
1444 in `goal-column', which is nil when there is none. 1554 in `goal-column', which is nil when there is none.
1445 1555
1446 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
1447 using `forward-line' instead. It is usually easier to use 1557 using `forward-line' instead. It is usually easier to use
1448 and more reliable (no dependence on goal column, etc.)." 1558 and more reliable (no dependence on goal column, etc.)."
1449 (interactive "_p") 1559 (interactive "_p") ; XEmacs
1450 (if (and next-line-add-newlines (= arg 1)) 1560 (if (and next-line-add-newlines (= arg 1))
1451 (let ((opoint (point))) 1561 (let ((opoint (point)))
1452 (end-of-line) 1562 (end-of-line)
1453 (if (eobp) 1563 (if (eobp)
1454 (newline 1) 1564 (newline 1)
1472 Then it does not try to move vertically. 1582 Then it does not try to move vertically.
1473 1583
1474 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
1475 `forward-line' with a negative argument instead. It is usually easier 1585 `forward-line' with a negative argument instead. It is usually easier
1476 to use and more reliable (no dependence on goal column, etc.)." 1586 to use and more reliable (no dependence on goal column, etc.)."
1477 (interactive "_p") 1587 (interactive "_p") ; XEmacs
1478 (if (interactive-p) 1588 (if (interactive-p)
1479 (condition-case nil 1589 (condition-case nil
1480 (line-move (- arg)) 1590 (line-move (- arg))
1481 ((beginning-of-buffer end-of-buffer) (ding nil 'buffer-bound))) 1591 ((beginning-of-buffer end-of-buffer) (ding nil 'buffer-bound)))
1482 (line-move (- arg))) 1592 (line-move (- arg)))
1483 nil) 1593 nil)
1484 1594
1485 (defvar track-eol nil 1595 (defconst track-eol nil
1486 "*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.
1487 This means moving to the end of each line moved onto. 1597 This means moving to the end of each line moved onto.
1488 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.")
1489 1599
1490 (defvar goal-column nil 1600 (defvar goal-column nil
1554 prop 1664 prop
1555 (or (memq prop buffer-invisibility-spec) 1665 (or (memq prop buffer-invisibility-spec)
1556 (assq prop buffer-invisibility-spec))))) 1666 (assq prop buffer-invisibility-spec)))))
1557 (if (get-text-property (point) 'invisible) 1667 (if (get-text-property (point) 'invisible)
1558 (goto-char (next-single-property-change (point) 'invisible)) 1668 (goto-char (next-single-property-change (point) 'invisible))
1559 (goto-char (next-extent-change (point))))) 1669 (goto-char (next-extent-change (point))))) ; XEmacs
1560 (setq arg (1- arg))) 1670 (setq arg (1- arg)))
1561 (while (< arg 0) 1671 (while (< arg 0)
1562 (beginning-of-line) 1672 (beginning-of-line)
1563 (and (zerop (vertical-motion -1)) 1673 (and (zerop (vertical-motion -1))
1564 (signal 'beginning-of-buffer nil)) 1674 (signal 'beginning-of-buffer nil))
1569 prop 1679 prop
1570 (or (memq prop buffer-invisibility-spec) 1680 (or (memq prop buffer-invisibility-spec)
1571 (assq prop buffer-invisibility-spec))))) 1681 (assq prop buffer-invisibility-spec)))))
1572 (if (get-text-property (1- (point)) 'invisible) 1682 (if (get-text-property (1- (point)) 'invisible)
1573 (goto-char (previous-single-property-change (point) 'invisible)) 1683 (goto-char (previous-single-property-change (point) 'invisible))
1574 (goto-char (previous-extent-change (point))))) 1684 (goto-char (previous-extent-change (point))))) ; XEmacs
1575 (setq arg (1+ arg)))) 1685 (setq arg (1+ arg))))
1576 (move-to-column (or goal-column temporary-goal-column))) 1686 (move-to-column (or goal-column temporary-goal-column)))
1577 ;; Remember where we moved to, go back home, 1687 ;; Remember where we moved to, go back home,
1578 ;; then do the motion over again 1688 ;; then do the motion over again
1579 ;; in just one step, with intangibility and point-motion hooks 1689 ;; in just one step, with intangibility and point-motion hooks
1593 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
1594 rather than trying to keep the same horizontal position. 1704 rather than trying to keep the same horizontal position.
1595 With a non-nil argument, clears out the goal column 1705 With a non-nil argument, clears out the goal column
1596 so that \\[next-line] and \\[previous-line] resume vertical motion. 1706 so that \\[next-line] and \\[previous-line] resume vertical motion.
1597 The goal column is stored in the variable `goal-column'." 1707 The goal column is stored in the variable `goal-column'."
1598 (interactive "_P") 1708 (interactive "_P") ; XEmacs
1599 (if arg 1709 (if arg
1600 (progn 1710 (progn
1601 (setq goal-column nil) 1711 (setq goal-column nil)
1602 (message "No goal column")) 1712 (message "No goal column"))
1603 (setq goal-column (current-column)) 1713 (setq goal-column (current-column))
1604 (message (substitute-command-keys 1714 (message (substitute-command-keys
1605 "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)")
1606 goal-column)) 1716 goal-column))
1607 nil) 1717 nil)
1608 1718
1609 1719 ;; deleted FSFmacs terminal randomness hscroll-point-visible stuff.
1610 ;;; 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
1611 1725
1612 (defun scroll-other-window-down (lines) 1726 (defun scroll-other-window-down (lines)
1613 "Scroll the \"other window\" down. 1727 "Scroll the \"other window\" down.
1614 For more details, see the documentation for `scroll-other-window'." 1728 For more details, see the documentation for `scroll-other-window'."
1615 (interactive "P") 1729 (interactive "P")
1617 ;; Just invert the argument's meaning. 1731 ;; Just invert the argument's meaning.
1618 ;; We can do that without knowing which window it will be. 1732 ;; We can do that without knowing which window it will be.
1619 (if (eq lines '-) nil 1733 (if (eq lines '-) nil
1620 (if (null lines) '- 1734 (if (null lines) '-
1621 (- (prefix-numeric-value lines)))))) 1735 (- (prefix-numeric-value lines))))))
1736 ;(define-key esc-map [?\C-\S-v] 'scroll-other-window-down)
1622 1737
1623 (defun beginning-of-buffer-other-window (arg) 1738 (defun beginning-of-buffer-other-window (arg)
1624 "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.
1625 Leave mark at previous position. 1740 Leave mark at previous position.
1626 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."
1710 (save-excursion 1825 (save-excursion
1711 (funcall mover 1) 1826 (funcall mover 1)
1712 (setq end2 (point)) 1827 (setq end2 (point))
1713 (funcall mover -1) 1828 (funcall mover -1)
1714 (setq start2 (point)) 1829 (setq start2 (point))
1715 (goto-char (mark t)) 1830 (goto-char (mark t)) ; XEmacs
1716 (funcall mover 1) 1831 (funcall mover 1)
1717 (setq end1 (point)) 1832 (setq end1 (point))
1718 (funcall mover -1) 1833 (funcall mover -1)
1719 (setq start1 (point)) 1834 (setq start1 (point))
1720 (transpose-subr-1)) 1835 (transpose-subr-1))
1721 (exchange-point-and-mark t))) 1836 (exchange-point-and-mark t))) ; XEmacs
1722 (while (> arg 0) 1837 (while (> arg 0)
1723 (funcall mover -1) 1838 (funcall mover -1)
1724 (setq start1 (point)) 1839 (setq start1 (point))
1725 (funcall mover 1) 1840 (funcall mover 1)
1726 (setq end1 (point)) 1841 (setq end1 (point))
1755 (goto-char (if (< start1 start2) start1 1870 (goto-char (if (< start1 start2) start1
1756 (+ start1 (- (length word1) (length word2))))) 1871 (+ start1 (- (length word1) (length word2)))))
1757 (delete-char (length word1)) 1872 (delete-char (length word1))
1758 (insert word2))) 1873 (insert word2)))
1759 1874
1760 (defvar comment-column 32 1875 (defconst comment-column 32
1761 "*Column to indent right-margin comments to. 1876 "*Column to indent right-margin comments to.
1762 Setting this variable automatically makes it local to the current buffer. 1877 Setting this variable automatically makes it local to the current buffer.
1763 Each mode establishes a different default value for this variable; you 1878 Each mode establishes a different default value for this variable; you
1764 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.")
1765 (make-variable-buffer-local 'comment-column) 1880 (make-variable-buffer-local 'comment-column)
1766 1881
1767 (defvar comment-start nil 1882 (defconst comment-start nil
1768 "*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.")
1769 1884
1770 (defvar comment-start-skip nil 1885 (defconst comment-start-skip nil
1771 "*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.
1772 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
1773 at the place matched by the close of the first pair.") 1888 at the place matched by the close of the first pair.")
1774 1889
1775 (defvar comment-end "" 1890 (defconst comment-end ""
1776 "*String to insert to end a new comment. 1891 "*String to insert to end a new comment.
1777 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.")
1778 1893
1779 (defconst comment-indent-hook nil 1894 (defconst comment-indent-hook nil
1780 "Obsolete variable for function to compute desired indentation for a comment. 1895 "Obsolete variable for function to compute desired indentation for a comment.
1781 Use `comment-indent-function' instead. 1896 Use `comment-indent-function' instead.
1782 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
1783 the comment's starting delimiter.") 1898 the comment's starting delimiter.")
1784 1899
1785 (defvar comment-indent-function 1900 (defconst comment-indent-function
1786 ;; 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
1787 ;; current line... 1902 ;; current line...
1788 #'(lambda () 1903 #'(lambda ()
1789 (save-excursion 1904 (save-excursion
1790 (beginning-of-line) 1905 (beginning-of-line)
1983 (if (string= "" ce) () 2098 (if (string= "" ce) ()
1984 (end-of-line) 2099 (end-of-line)
1985 (insert ce))) 2100 (insert ce)))
1986 (search-forward "\n" nil 'move))))))) 2101 (search-forward "\n" nil 'move)))))))
1987 2102
2103 ;; XEmacs
1988 (defun prefix-region (prefix) 2104 (defun prefix-region (prefix)
1989 "Add a prefix string to each line between mark and point." 2105 "Add a prefix string to each line between mark and point."
1990 (interactive "sPrefix string: ") 2106 (interactive "sPrefix string: ")
1991 (if prefix 2107 (if prefix
1992 (let ((count (count-lines (mark) (point)))) 2108 (let ((count (count-lines (mark) (point))))
1997 (insert prefix) 2113 (insert prefix)
1998 (end-of-line 1) 2114 (end-of-line 1)
1999 (forward-char 1))))) 2115 (forward-char 1)))))
2000 2116
2001 2117
2118 ;; XEmacs - extra parameter
2002 (defun backward-word (arg &optional buffer) 2119 (defun backward-word (arg &optional buffer)
2003 "Move backward until encountering the end of a word. 2120 "Move backward until encountering the end of a word.
2004 With argument, do this that many times. 2121 With argument, do this that many times.
2005 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."
2006 (interactive "_p") 2123 (interactive "_p") ; XEmacs
2007 (forward-word (- arg) buffer)) 2124 (forward-word (- arg) buffer))
2008 2125
2009 (defun mark-word (arg) 2126 (defun mark-word (arg)
2010 "Set mark arg words away from point." 2127 "Set mark arg words away from point."
2011 (interactive "p") 2128 (interactive "p")
2012 (mark-something 'mark-word 'forward-word arg)) 2129 (mark-something 'mark-word 'forward-word arg))
2013 2130
2131 ;; XEmacs modified
2014 (defun kill-word (arg) 2132 (defun kill-word (arg)
2015 "Kill characters forward until encountering the end of a word. 2133 "Kill characters forward until encountering the end of a word.
2016 With argument, do this that many times." 2134 With argument, do this that many times."
2017 (interactive "*p") 2135 (interactive "*p")
2018 (kill-region (point) (save-excursion (forward-word arg) (point)))) 2136 (kill-region (point) (save-excursion (forward-word arg) (point))))
2019 2137
2020 (defun backward-kill-word (arg) 2138 (defun backward-kill-word (arg)
2021 "Kill characters backward until encountering the end of a word. 2139 "Kill characters backward until encountering the end of a word.
2022 With argument, do this that many times." 2140 With argument, do this that many times."
2023 (interactive "*p") 2141 (interactive "*p") ; XEmacs
2024 (kill-word (- arg))) 2142 (kill-word (- arg)))
2025 2143
2026 (defun current-word (&optional strict) 2144 (defun current-word (&optional strict)
2027 "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.
2028 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
2059 (skip-syntax-backward "w_") 2177 (skip-syntax-backward "w_")
2060 (setq start (point))) 2178 (setq start (point)))
2061 (buffer-substring start end))) 2179 (buffer-substring start end)))
2062 (buffer-substring start end))))) 2180 (buffer-substring start end)))))
2063 2181
2064 (defvar fill-prefix nil 2182 (defconst fill-prefix nil
2065 "*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.
2066 Setting this variable automatically makes it local to the current buffer.") 2184 Setting this variable automatically makes it local to the current buffer.")
2067 (make-variable-buffer-local 'fill-prefix) 2185 (make-variable-buffer-local 'fill-prefix)
2068 2186
2069 (defvar auto-fill-inhibit-regexp nil 2187 (defconst auto-fill-inhibit-regexp nil
2070 "*Regexp to match lines which should not be auto-filled.") 2188 "*Regexp to match lines which should not be auto-filled.")
2071 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.
2072 (defun do-auto-fill () 2194 (defun do-auto-fill ()
2073 (let (give-up) 2195 (let (give-up)
2074 (or (and auto-fill-inhibit-regexp 2196 (or (and auto-fill-inhibit-regexp
2075 (save-excursion (beginning-of-line) 2197 (save-excursion (beginning-of-line)
2076 (looking-at auto-fill-inhibit-regexp))) 2198 (looking-at auto-fill-inhibit-regexp)))
2141 (if (>= (current-column) prev-column) 2263 (if (>= (current-column) prev-column)
2142 (setq give-up t))) 2264 (setq give-up t)))
2143 ;; No place to break => stop trying. 2265 ;; No place to break => stop trying.
2144 (setq give-up t))))))) 2266 (setq give-up t)))))))
2145 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
2146 (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
2147 "*Non-nil means \\[indent-new-comment-line] should continue same comment 2406 "*Non-nil means \\[indent-new-comment-line] should continue same comment
2148 on new line, with no new terminator or starter. 2407 on new line, with no new terminator or starter.
2149 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].")
2150 2409
2226 ;; Make sure we delete the newline inserted above. 2485 ;; Make sure we delete the newline inserted above.
2227 (end-of-line) 2486 (end-of-line)
2228 (delete-char 1))) 2487 (delete-char 1)))
2229 (indent-according-to-mode))))) 2488 (indent-according-to-mode)))))
2230 2489
2231 (defun auto-fill-mode (&optional arg)
2232 "Toggle auto-fill mode.
2233 With arg, turn auto-fill mode on if and only if arg is positive.
2234 In Auto-Fill mode, inserting a space at a column beyond `current-fill-column'
2235 automatically breaks the line at a previous space."
2236 (interactive "P")
2237 (prog1 (setq auto-fill-function
2238 (if (if (null arg)
2239 (not auto-fill-function)
2240 (> (prefix-numeric-value arg) 0))
2241 'do-auto-fill
2242 nil))
2243 (redraw-modeline)))
2244
2245 ;; This holds a document string used to document auto-fill-mode.
2246 (defun auto-fill-function ()
2247 "Automatically break line at a previous space, in insertion of text."
2248 nil)
2249
2250 (defun turn-on-auto-fill ()
2251 "Unconditionally turn on Auto Fill mode."
2252 (auto-fill-mode 1))
2253
2254 (defun set-fill-column (arg)
2255 "Set `fill-column' to current column, or to argument if given.
2256 The variable `fill-column' has a separate value for each buffer."
2257 (interactive "_P")
2258 (setq fill-column (if (integerp arg) arg (current-column)))
2259 (message "fill-column set to %d" fill-column))
2260 2490
2261 (defun set-selective-display (arg) 2491 (defun set-selective-display (arg)
2262 "Set `selective-display' to ARG; clear it if no arg. 2492 "Set `selective-display' to ARG; clear it if no arg.
2263 When the value of `selective-display' is a number > 0, 2493 When the value of `selective-display' is a number > 0,
2264 lines whose indentation is >= that value are not displayed. 2494 lines whose indentation is >= that value are not displayed.
2278 ;; #### doesn't localize properly: 2508 ;; #### doesn't localize properly:
2279 (princ "selective-display set to " t) 2509 (princ "selective-display set to " t)
2280 (prin1 selective-display t) 2510 (prin1 selective-display t)
2281 (princ "." t)) 2511 (princ "." t))
2282 2512
2513 ;; XEmacs
2283 (defun nuke-selective-display () 2514 (defun nuke-selective-display ()
2284 "Ensure that the buffer is not in selective-display mode. 2515 "Ensure that the buffer is not in selective-display mode.
2285 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
2286 state before disabling selective display." 2517 state before disabling selective display."
2287 ;; by Stig@hackvan.com 2518 ;; by Stig@hackvan.com
2300 )))) 2531 ))))
2301 (setq selective-display nil)) 2532 (setq selective-display nil))
2302 2533
2303 (add-hook 'change-major-mode-hook 'nuke-selective-display) 2534 (add-hook 'change-major-mode-hook 'nuke-selective-display)
2304 2535
2305 (defvar overwrite-mode-textual (purecopy " Ovwrt") 2536 (defconst overwrite-mode-textual (purecopy " Ovwrt")
2306 "The string displayed in the modeline when in overwrite mode.") 2537 "The string displayed in the mode line when in overwrite mode.")
2307 (defvar overwrite-mode-binary (purecopy " Bin Ovwrt") 2538 (defconst overwrite-mode-binary (purecopy " Bin Ovwrt")
2308 "The string displayed in the modeline when in binary overwrite mode.") 2539 "The string displayed in the mode line when in binary overwrite mode.")
2309 2540
2310 (defun overwrite-mode (arg) 2541 (defun overwrite-mode (arg)
2311 "Toggle overwrite mode. 2542 "Toggle overwrite mode.
2312 With arg, turn overwrite mode on iff arg is positive. 2543 With arg, turn overwrite mode on iff arg is positive.
2313 In overwrite mode, printing characters typed in replace existing text 2544 In overwrite mode, printing characters typed in replace existing text
2350 2581
2351 (defun line-number-mode (arg) 2582 (defun line-number-mode (arg)
2352 "Toggle Line Number mode. 2583 "Toggle Line Number mode.
2353 With arg, turn Line Number mode on iff arg is positive. 2584 With arg, turn Line Number mode on iff arg is positive.
2354 When Line Number mode is enabled, the line number appears 2585 When Line Number mode is enabled, the line number appears
2355 in the modeline." 2586 in the mode line."
2356 (interactive "P") 2587 (interactive "P")
2357 (setq line-number-mode 2588 (setq line-number-mode
2358 (if (null arg) (not line-number-mode) 2589 (if (null arg) (not line-number-mode)
2359 (> (prefix-numeric-value arg) 0))) 2590 (> (prefix-numeric-value arg) 0)))
2360 (redraw-modeline)) 2591 (redraw-modeline))
2361 2592
2362 (defvar column-number-mode nil 2593 (defvar column-number-mode nil
2363 "*Non-nil means display column number in modeline.") 2594 "*Non-nil means display column number in mode line.")
2364 2595
2365 (defun column-number-mode (arg) 2596 (defun column-number-mode (arg)
2366 "Toggle Column Number mode. 2597 "Toggle Column Number mode.
2367 With arg, turn Column Number mode on iff arg is positive. 2598 With arg, turn Column Number mode on iff arg is positive.
2368 When Column Number mode is enabled, the column number appears 2599 When Column Number mode is enabled, the column number appears
2369 in the modeline." 2600 in the mode line."
2370 (interactive "P") 2601 (interactive "P")
2371 (setq column-number-mode 2602 (setq column-number-mode
2372 (if (null arg) (not column-number-mode) 2603 (if (null arg) (not column-number-mode)
2373 (> (prefix-numeric-value arg) 0))) 2604 (> (prefix-numeric-value arg) 0)))
2374 (redraw-modeline)) 2605 (redraw-modeline))
2375 2606
2376 2607
2377 (defvar blink-matching-paren t 2608 (defvar blink-matching-paren t
2378 "*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.")
2379 2610
2380 (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
2381 "*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.")
2382 2618
2383 (defconst blink-matching-delay 1 2619 (defconst blink-matching-delay 1
2384 "*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.")
2385 2621
2386 (defconst blink-matching-paren-dont-ignore-comments nil 2622 (defconst blink-matching-paren-dont-ignore-comments nil
2387 "*Non-nil means `blink-matching-paren' should not ignore comments.") 2623 "*Non-nil means `blink-matching-paren' should not ignore comments.")
2388 2624
2389 (defun blink-matching-open () 2625 (defun blink-matching-open ()
2390 "Move cursor momentarily to the beginning of the sexp before point." 2626 "Move cursor momentarily to the beginning of the sexp before point."
2391 (interactive "_") 2627 (interactive "_") ; XEmacs
2392 (and (> (point) (1+ (point-min))) 2628 (and (> (point) (1+ (point-min)))
2393 blink-matching-paren 2629 blink-matching-paren
2394 ;; Verify an even number of quoting characters precede the close. 2630 ;; Verify an even number of quoting characters precede the close.
2395 (= 1 (logand 1 (- (point) 2631 (= 1 (logand 1 (- (point)
2396 (save-excursion 2632 (save-excursion
2423 (if mismatch (setq blinkpos nil)) 2659 (if mismatch (setq blinkpos nil))
2424 (if blinkpos 2660 (if blinkpos
2425 (progn 2661 (progn
2426 (goto-char blinkpos) 2662 (goto-char blinkpos)
2427 (if (pos-visible-in-window-p) 2663 (if (pos-visible-in-window-p)
2428 (sit-for blink-matching-delay) 2664 (and blink-matching-paren-on-screen
2665 (sit-for blink-matching-delay))
2429 (goto-char blinkpos) 2666 (goto-char blinkpos)
2430 (message 2667 (message
2431 "Matches %s" 2668 "Matches %s"
2432 ;; Show what precedes the open in its line, if anything. 2669 ;; Show what precedes the open in its line, if anything.
2433 (if (save-excursion 2670 (if (save-excursion
2438 ;; Show what follows the open in its line, if anything. 2675 ;; Show what follows the open in its line, if anything.
2439 (if (save-excursion 2676 (if (save-excursion
2440 (forward-char 1) 2677 (forward-char 1)
2441 (skip-chars-forward " \t") 2678 (skip-chars-forward " \t")
2442 (not (eolp))) 2679 (not (eolp)))
2443 (buffer-substring blinkpos 2680 (buffer-substring blinkpos
2444 (progn (end-of-line) (point))) 2681 (progn (end-of-line) (point)))
2445 ;; Otherwise show the previous nonblank line, 2682 ;; Otherwise show the previous nonblank line,
2446 ;; if there is one. 2683 ;; if there is one.
2447 (if (save-excursion 2684 (if (save-excursion
2448 (skip-chars-backward "\n \t") 2685 (skip-chars-backward "\n \t")
2449 (not (bobp))) 2686 (not (bobp)))
2467 2704
2468 ;Turned off because it makes dbx bomb out. 2705 ;Turned off because it makes dbx bomb out.
2469 (setq blink-paren-function 'blink-matching-open) 2706 (setq blink-paren-function 'blink-matching-open)
2470 2707
2471 (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
2472 2714
2473 (defun set-variable (var val) 2715 (defun set-variable (var val)
2474 "Set VARIABLE to VALUE. VALUE is a Lisp object. 2716 "Set VARIABLE to VALUE. VALUE is a Lisp object.
2475 When using this interactively, supply a Lisp expression for VALUE. 2717 When using this interactively, supply a Lisp expression for VALUE.
2476 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.
2507 (list 'interactive prop) 2749 (list 'interactive prop)
2508 'arg)) 2750 'arg))
2509 (eval-minibuffer (format "Set %s to value: " var))))))) 2751 (eval-minibuffer (format "Set %s to value: " var)))))))
2510 (set var val)) 2752 (set var val))
2511 2753
2754 ;; XEmacs
2512 (defun activate-region () 2755 (defun activate-region ()
2513 "Activate the region, if `zmacs-regions' is true. 2756 "Activate the region, if `zmacs-regions' is true.
2514 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.
2515 This function has no effect if `zmacs-regions' is false." 2758 This function has no effect if `zmacs-regions' is false."
2516 (interactive) 2759 (interactive)
2517 (and zmacs-regions (zmacs-activate-region))) 2760 (and zmacs-regions (zmacs-activate-region)))
2518 2761
2762 ;; XEmacs
2519 (defsubst region-exists-p () 2763 (defsubst region-exists-p ()
2520 "Non-nil iff the region exists. 2764 "Non-nil iff the region exists.
2521 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
2522 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
2523 a mark in this buffer at some point in the past. 2767 a mark in this buffer at some point in the past.
2524 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
2525 limits of the region." 2769 limits of the region."
2526 (not (null (mark)))) 2770 (not (null (mark))))
2527 2771
2772 ;; XEmacs
2528 (defun region-active-p () 2773 (defun region-active-p ()
2529 "Non-nil iff the region is active. 2774 "Non-nil iff the region is active.
2530 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'.
2531 Otherwise, this function always returns false." 2776 Otherwise, this function always returns false."
2532 (and zmacs-regions zmacs-region-extent)) 2777 (and zmacs-regions zmacs-region-extent))
2533 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
2534 (defun capitalize-region-or-word (arg) 2797 (defun capitalize-region-or-word (arg)
2535 "Capitalize the selected region or the following word (or ARG words)." 2798 "Capitalize the selected region or the following word (or ARG words)."
2536 (interactive "p") 2799 (interactive "p")
2537 (if (region-active-p) (capitalize-region (region-beginning) (region-end)) 2800 (if (region-active-p) (capitalize-region (region-beginning) (region-end))
2538 (capitalize-word arg))) 2801 (capitalize-word arg)))
2720 ;;; Bits of the logging code are borrowed from log-messages.el by 2983 ;;; Bits of the logging code are borrowed from log-messages.el by
2721 ;;; Robert Potter (rpotter@grip.cis.upenn.edu). 2984 ;;; Robert Potter (rpotter@grip.cis.upenn.edu).
2722 2985
2723 ;; need this to terminate the currently-displayed message 2986 ;; need this to terminate the currently-displayed message
2724 ;; ("Loading simple ...") 2987 ;; ("Loading simple ...")
2725 (or (fboundp 'display-message) (send-string-to-terminal "\n")) 2988 (when (and
2989 (not (fboundp 'display-message))
2990 (not (featurep 'debug)))
2991 (send-string-to-terminal "\n"))
2726 2992
2727 (defvar message-stack nil 2993 (defvar message-stack nil
2728 "An alist of label/string pairs representing active echo-area messages. 2994 "An alist of label/string pairs representing active echo-area messages.
2729 The first element in the list is currently displayed in the echo area. 2995 The first element in the list is currently displayed in the echo area.
2730 Do not modify this directly--use the `message' or 2996 Do not modify this directly--use the `message' or
2844 If a message remains at the head of the message-stack and NO-RESTORE 3110 If a message remains at the head of the message-stack and NO-RESTORE
2845 is nil, it will be displayed. The string which remains in the echo 3111 is nil, it will be displayed. The string which remains in the echo
2846 area will be returned, or nil if the message-stack is now empty. 3112 area will be returned, or nil if the message-stack is now empty.
2847 If LABEL is nil, the entire message-stack is cleared. 3113 If LABEL is nil, the entire message-stack is cleared.
2848 3114
2849 Unless you need the return value or you need to specify a lable, 3115 Unless you need the return value or you need to specify a label,
2850 you should just use (message nil)." 3116 you should just use (message nil)."
2851 (or frame (setq frame (selected-frame))) 3117 (or frame (setq frame (selected-frame)))
2852 (let ((clear-stream (and message-stack (eq 'stream (frame-type frame))))) 3118 (let ((clear-stream (and message-stack (eq 'stream (frame-type frame)))))
2853 (remove-message label frame) 3119 (remove-message label frame)
2854 (let ((buffer (get-buffer " *Echo Area*")) 3120 (let ((buffer (get-buffer " *Echo Area*"))
3128 (progn 3394 (progn
3129 (setq warning-marker (make-marker)) 3395 (setq warning-marker (make-marker))
3130 (set-marker warning-marker 1 buffer))) 3396 (set-marker warning-marker 1 buffer)))
3131 (set-window-start (display-buffer buffer) warning-marker) 3397 (set-window-start (display-buffer buffer) warning-marker)
3132 (set-marker warning-marker (point-max buffer) buffer))) 3398 (set-marker warning-marker (point-max buffer) buffer)))
3399
3400 ;;; simple.el ends here