(rmail-forward-separator-regex): Fix typo in docstring.
[bpt/emacs.git] / lisp / simple.el
index 36b640f..ba661e5 100644 (file)
@@ -51,8 +51,6 @@ wait this many seconds after Emacs becomes idle before doing an update."
   "Highlight (un)matching of parens and expressions."
   :group 'matching)
 
-(define-key global-map [?\C-x right] 'next-buffer)
-(define-key global-map [?\C-x left] 'prev-buffer)
 (defun next-buffer ()
   "Switch to the next buffer in cyclic order."
   (interactive)
@@ -258,8 +256,6 @@ See variables `compilation-parse-errors-function' and
 (defalias 'goto-next-locus 'next-error)
 (defalias 'next-match 'next-error)
 
-(define-key ctl-x-map "`" 'next-error)
-
 (defun previous-error (&optional n)
   "Visit previous next-error message and corresponding source code.
 
@@ -924,21 +920,21 @@ in *Help* buffer.  See also the command `describe-char'."
 (defvar read-expression-history nil)
 
 (defcustom eval-expression-print-level 4
-  "*Value to use for `print-level' when printing value in `eval-expression'.
+  "Value for `print-level' while printing value in `eval-expression'.
 A value of nil means no limit."
   :group 'lisp
   :type '(choice (const :tag "No Limit" nil) integer)
   :version "21.1")
 
 (defcustom eval-expression-print-length 12
-  "*Value to use for `print-length' when printing value in `eval-expression'.
+  "Value for `print-length' while printing value in `eval-expression'.
 A value of nil means no limit."
   :group 'lisp
   :type '(choice (const :tag "No Limit" nil) integer)
   :version "21.1")
 
 (defcustom eval-expression-debug-on-error t
-  "*Non-nil means set `debug-on-error' when evaluating in `eval-expression'.
+  "If non-nil set `debug-on-error' to t in `eval-expression'.
 If nil, don't change the value of `debug-on-error'."
   :group 'lisp
   :type 'boolean
@@ -1279,7 +1275,9 @@ Return 0 if current buffer is not a mini-buffer."
 (defalias 'advertised-undo 'undo)
 
 (defconst undo-equiv-table (make-hash-table :test 'eq :weakness t)
-  "Table mapping redo records to the corresponding undo one.")
+  "Table mapping redo records to the corresponding undo one.
+A redo record for undo-in-region maps to t.
+A redo record for ordinary undo maps to the following (earlier) undo.")
 
 (defvar undo-in-region nil
   "Non-nil if `pending-undo-list' is not just a tail of `buffer-undo-list'.")
@@ -1339,7 +1337,7 @@ as an argument limits undo to changes within the current region."
          (message (if undo-in-region
                       (if equiv "Redo in region!" "Undo in region!")
                     (if equiv "Redo!" "Undo!"))))
-      (when (and equiv undo-no-redo)
+      (when (and (consp equiv) undo-no-redo)
        ;; The equiv entry might point to another redo record if we have done
        ;; undo-redo-undo-redo-... so skip to the very last equiv.
        (while (let ((next (gethash equiv undo-equiv-table)))
@@ -1350,10 +1348,13 @@ as an argument limits undo to changes within the current region."
         (prefix-numeric-value arg)
        1))
     ;; Record the fact that the just-generated undo records come from an
-    ;; undo operation, so we can skip them later on.
+    ;; undo operation--that is, they are redo records.
+    ;; In the ordinary case (not within a region), map the redo
+    ;; record to the following undos.
     ;; I don't know how to do that in the undo-in-region case.
-    (unless undo-in-region
-      (puthash buffer-undo-list pending-undo-list undo-equiv-table))
+    (puthash buffer-undo-list
+            (if undo-in-region t pending-undo-list)
+            undo-equiv-table)
     ;; Don't specify a position in the undo record for the undo command.
     ;; Instead, undoing this should move point to where the change is.
     (let ((tail buffer-undo-list)
@@ -1393,9 +1394,6 @@ A numeric argument serves as a repeat count.
 Contrary to `undo', this will not redo a previous undo."
   (interactive "*p")
   (let ((undo-no-redo t)) (undo arg)))
-;; Richard said that we should not use C-x <uppercase letter> and I have
-;; no idea whereas to bind it.  Any suggestion welcome.  -stef
-;; (define-key ctl-x-map "U" 'undo-only)
 
 (defvar undo-in-progress nil
   "Non-nil while performing an undo.
@@ -2249,7 +2247,7 @@ is nil, the buffer substring is returned unaltered.
 If DELETE is non-nil, the text between BEG and END is deleted
 from the buffer.
 
-Point is temporarily set to BEG before caling
+Point is temporarily set to BEG before calling
 `buffer-substring-filters', in case the functions need to know
 where the text came from.
 
@@ -2543,7 +2541,7 @@ The argument is used for internal purposes; do not supply one."
 ;; This is actually used in subr.el but defcustom does not work there.
 (defcustom yank-excluded-properties
   '(read-only invisible intangible field mouse-face help-echo local-map keymap
-    yank-handler)
+    yank-handler follow-link)
   "*Text properties to discard when yanking.
 The value should be a list of text properties to discard or t,
 which means to discard all text properties."
@@ -2570,7 +2568,11 @@ With argument N, insert the Nth previous kill.
 If N is negative, this is a more recent kill.
 
 The sequence of kills wraps around, so that after the oldest one
-comes the newest one."
+comes the newest one.
+
+When this command inserts killed text into the buffer, it honors
+`yank-excluded-properties' and `yank-handler' as described in the
+doc string for `insert-for-yank-1', which see."
   (interactive "*p")
   (if (not (eq last-command 'yank))
       (error "Previous command was not a yank"))
@@ -2602,6 +2604,11 @@ killed OR yanked.  Put point at end, and set mark at beginning.
 With just \\[universal-argument] as argument, same but put point at beginning (and mark at end).
 With argument N, reinsert the Nth most recently killed stretch of killed
 text.
+
+When this command inserts killed text into the buffer, it honors
+`yank-excluded-properties' and `yank-handler' as described in the
+doc string for `insert-for-yank-1', which see.
+
 See also the command \\[yank-pop]."
   (interactive "*P")
   (setq yank-window-start (window-start))
@@ -3201,6 +3208,14 @@ Invoke \\[apropos-documentation] and type \"transient\" or
 commands which are sensitive to the Transient Mark mode."
   :global t :group 'editing-basics :require nil)
 
+(defvar widen-automatically t
+  "Non-nil means it is ok for commands to call `widen' when they want to.
+Some commands will do this in order to go to positions outside
+the current accessible part of the buffer.
+
+If `widen-automatically' is nil, these commands will do something else
+as a fallback, and won't change the buffer bounds.")
+
 (defun pop-global-mark ()
   "Pop off global mark ring and jump to the top location."
   (interactive)
@@ -3217,7 +3232,9 @@ commands which are sensitive to the Transient Mark mode."
     (set-buffer buffer)
     (or (and (>= position (point-min))
             (<= position (point-max)))
-       (widen))
+       (if widen-automatically
+           (error "Global mark position is outside accessible part of buffer")
+         (widen)))
     (goto-char position)
     (switch-to-buffer buffer)))
 \f
@@ -3325,34 +3342,43 @@ Outline mode sets this."
       (or (memq prop buffer-invisibility-spec)
          (assq prop buffer-invisibility-spec)))))
 
-;; Perform vertical scrolling of tall images if necessary.
-;; Don't vscroll in a keyboard macro.
+;; This is like line-move-1 except that it also performs
+;; vertical scrolling of tall images if appropriate.
+;; That is not really a clean thing to do, since it mixes
+;; scrolling with cursor motion.  But so far we don't have
+;; a cleaner solution to the problem of making C-n do something
+;; useful given a tall image.
 (defun line-move (arg &optional noerror to-end try-vscroll)
   (if (and auto-window-vscroll try-vscroll
+          ;; But don't vscroll in a keyboard macro.
           (not defining-kbd-macro)
           (not executing-kbd-macro))
       (let ((forward (> arg 0))
            (part (nth 2 (pos-visible-in-window-p (point) nil t))))
        (if (and (consp part)
-                (> (setq part (if forward (cdr part) (car part))) 0))
+                (> (if forward (cdr part) (car part)) 0))
            (set-window-vscroll nil
                                (if forward
                                    (+ (window-vscroll nil t)
-                                      (min part
+                                      (min (cdr part)
                                            (* (frame-char-height) arg)))
                                  (max 0
                                       (- (window-vscroll nil t)
-                                         (min part
+                                         (min (car part)
                                               (* (frame-char-height) (- arg))))))
                                t)
          (set-window-vscroll nil 0)
          (when (line-move-1 arg noerror to-end)
-           (sit-for 0)
-           (if (and (not forward)
-                    (setq part (nth 2 (pos-visible-in-window-p
-                                       (line-beginning-position) nil t)))
-                    (> (cdr part) 0))
-               (set-window-vscroll nil (cdr part) t))
+           (when (not forward)
+             ;; Update display before calling pos-visible-in-window-p,
+             ;; because it depends on window-start being up-to-date.
+             (sit-for 0)
+             ;; If the current line is partly hidden at the bottom,
+             ;; scroll it partially up so as to unhide the bottom.
+             (if (and (setq part (nth 2 (pos-visible-in-window-p
+                                         (line-beginning-position) nil t)))
+                      (> (cdr part) 0))
+                 (set-window-vscroll nil (cdr part) t)))
            t)))
     (line-move-1 arg noerror to-end)))
 
@@ -3405,19 +3431,40 @@ Outline mode sets this."
                  (goto-char (next-char-property-change (point))))
                ;; Now move a line.
                (end-of-line)
-               (and (zerop (vertical-motion 1))
-                    (if (not noerror)
-                        (signal 'end-of-buffer nil)
-                      (setq done t)))
+               ;; If there's no invisibility here, move over the newline.
+               (if (and (not (integerp selective-display))
+                        (not (line-move-invisible-p (point))))
+                   ;; We avoid vertical-motion when possible
+                   ;; because that has to fontify.
+                   (if (eobp)
+                       (if (not noerror)
+                           (signal 'end-of-buffer nil)
+                         (setq done t))
+                     (forward-line 1))
+                 ;; Otherwise move a more sophisticated way.
+                 ;; (What's the logic behind this code?)
+                 (and (zerop (vertical-motion 1))
+                      (if (not noerror)
+                          (signal 'end-of-buffer nil)
+                        (setq done t))))
                (unless done
                  (setq arg (1- arg))))
+             ;; The logic of this is the same as the loop above,
+             ;; it just goes in the other direction.
              (while (and (< arg 0) (not done))
                (beginning-of-line)
-
-               (if (zerop (vertical-motion -1))
-                   (if (not noerror)
-                       (signal 'beginning-of-buffer nil)
-                     (setq done t)))
+               (if (or (bobp)
+                       (and (not (integerp selective-display))
+                            (not (line-move-invisible-p (1- (point))))))
+                   (if (bobp)
+                       (if (not noerror)
+                           (signal 'beginning-of-buffer nil)
+                         (setq done t))
+                     (forward-line -1))
+                 (if (zerop (vertical-motion -1))
+                     (if (not noerror)
+                         (signal 'beginning-of-buffer nil)
+                       (setq done t))))
                (unless done
                  (setq arg (1+ arg))
                  (while (and ;; Don't move over previous invis lines
@@ -3626,7 +3673,6 @@ For more details, see the documentation for `scroll-other-window'."
    (if (eq lines '-) nil
      (if (null lines) '-
        (- (prefix-numeric-value lines))))))
-(define-key esc-map [?\C-\S-v] 'scroll-other-window-down)
 
 (defun beginning-of-buffer-other-window (arg)
   "Move point to the beginning of the buffer in the other window.
@@ -4196,11 +4242,12 @@ when it is off screen)."
                   (setq blinkpos (scan-sexps oldpos -1)))
               (error nil)))
           (and blinkpos
-               (not (eq (car (syntax-after blinkpos)) 8)) ;Not syntax '$'.
+                ;; Not syntax '$'.
+               (not (eq (syntax-class (syntax-after blinkpos)) 8))
                (setq matching-paren
                      (let ((syntax (syntax-after blinkpos)))
                        (and (consp syntax)
-                            (eq (logand (car syntax) 255) 4)
+                            (eq (syntax-class syntax) 4)
                             (cdr syntax)))
                      mismatch
                      (or (null matching-paren)
@@ -4270,8 +4317,6 @@ At top-level, as an editor command, this simply beeps."
   (setq defining-kbd-macro nil)
   (signal 'quit nil))
 
-(define-key global-map "\C-g" 'keyboard-quit)
-
 (defvar buffer-quit-function nil
   "Function to call to \"quit\" the current buffer, or nil if none.
 \\[keyboard-escape-quit] calls this function when its more local actions
@@ -4314,7 +4359,6 @@ specification for `play-sound'."
     (push 'sound sound)
     (play-sound sound)))
 
-(define-key global-map "\e\e\e" 'keyboard-escape-quit)
 \f
 (defcustom read-mail-command 'rmail
   "*Your preference for a mail reading package.
@@ -4727,7 +4771,7 @@ Use \\<completion-list-mode-map>\\[mouse-choose-completion] to select one\
   (setq major-mode 'completion-list-mode)
   (make-local-variable 'completion-base-size)
   (setq completion-base-size nil)
-  (run-hooks 'completion-list-mode-hook))
+  (run-mode-hooks 'completion-list-mode-hook))
 
 (defun completion-list-mode-finish ()
   "Finish setup of the completions buffer.
@@ -4796,7 +4840,11 @@ of the differing parts is, by contrast, slightly highlighted."
                    (- (point) (minibuffer-prompt-end)))))
        ;; Otherwise, in minibuffer, the whole input is being completed.
        (if (minibufferp mainbuf)
-           (setq completion-base-size 0)))
+           (if (and (symbolp minibuffer-completion-table)
+                    (get minibuffer-completion-table 'completion-base-size-function))
+               (setq completion-base-size 
+                     (funcall (get minibuffer-completion-table 'completion-base-size-function)))
+             (setq completion-base-size 0))))
       ;; Put faces on first uncommon characters and common parts.
       (when completion-base-size
        (let* ((common-string-length
@@ -5107,7 +5155,6 @@ the front of the list of recently selected ones."
     (set-buffer buffer)
     (clone-indirect-buffer nil t norecord)))
 
-(define-key ctl-x-4-map "c" 'clone-indirect-buffer-other-window)
 \f
 ;;; Handling of Backspace and Delete keys.