Doc fix.
[bpt/emacs.git] / lisp / simple.el
index d4e3404..3f1ed22 100644 (file)
@@ -28,6 +28,8 @@
 ;;; Code:
 
 (eval-when-compile
+  (autoload 'widget-convert "wid-edit")
+  (autoload 'shell-mode "shell")
   (require 'cl))
 
 
   "Killing and yanking commands"
   :group 'editing)
 
-(defgroup fill-comments nil
-  "Indenting and filling of comments."
-  :prefix "comment-"
-  :group 'fill)
-
 (defgroup paren-matching nil
   "Highlight (un)matching of parens and expressions."
   :group 'matching)
 Other major modes are defined by comparison with this one."
   (interactive)
   (kill-all-local-variables))
-\f
+
 ;; Making and deleting lines.
 
 (defun newline (&optional arg)
   "Insert a newline, and move to left margin of the new line if it's blank.
 The newline is marked with the text-property `hard'.
-With arg, insert that many newlines.
+With ARG, insert that many newlines.
 In Auto Fill mode, if no numeric arg, break the preceding line if it's long."
   (interactive "*P")
   (barf-if-buffer-read-only)
@@ -68,8 +65,6 @@ In Auto Fill mode, if no numeric arg, break the preceding line if it's long."
                   (bolp)
                   ;; Make sure no functions want to be told about
                   ;; the range of the changes.
-                  (not after-change-function)
-                  (not before-change-function)
                   (not after-change-functions)
                   (not before-change-functions)
                   ;; Make sure there are no markers here.
@@ -137,7 +132,7 @@ In Auto Fill mode, if no numeric arg, break the preceding line if it's long."
     (if (and (listp sticky) (not (memq 'hard sticky)))
        (put-text-property from (point) 'rear-nonsticky
                           (cons 'hard sticky)))))
-\f
+
 (defun open-line (arg)
   "Insert a newline and leave point before it.
 If there is a fill prefix and/or a left-margin, insert them on the new line
@@ -189,7 +184,7 @@ With argument, join this line to following line."
        (fixup-whitespace))))
 
 (defalias 'join-line #'delete-indentation) ; easier to find
-\f
+
 (defun delete-blank-lines ()
   "On blank line, delete all surrounding blank lines, leaving just one.
 On isolated blank line, delete that one.
@@ -230,6 +225,18 @@ On nonblank line, delete any immediately following blank lines."
     (if (looking-at "^[ \t]*\n\\'")
        (delete-region (point) (point-max)))))
 
+(defun delete-trailing-whitespace ()
+  "Delete all the trailing whitespace across the current buffer.
+All whitespace after the last non-whitespace character in a line is deleted.
+This respects narrowing, created by \\[narrow-to-region] and friends."
+  (interactive "*")
+  (save-match-data
+    (save-excursion
+      (goto-char (point-min))
+      (while (re-search-forward "\\s-$" nil t)
+       (skip-syntax-backward "-" (save-excursion (forward-line 0) (point)))
+       (delete-region (point) (match-end 0))))))
+
 (defun newline-and-indent ()
   "Insert a newline, then indent according to major mode.
 Indentation is done using the value of `indent-line-function'.
@@ -237,7 +244,7 @@ In programming language modes, this is the same as TAB.
 In some text modes, where TAB inserts a tab, this command indents to the
 column specified by the function `current-left-margin'."
   (interactive "*")
-  (delete-region (point) (progn (skip-chars-backward " \t") (point)))
+  (delete-horizontal-space t)
   (newline)
   (indent-according-to-mode))
 
@@ -250,11 +257,11 @@ In some text modes, where TAB inserts a tab, this indents to the
 column specified by the function `current-left-margin'."
   (interactive "*")
   (save-excursion
-    (delete-region (point) (progn (skip-chars-backward " \t") (point)))
+    (delete-horizontal-space t)
     (indent-according-to-mode))
   (newline)
   (indent-according-to-mode))
-\f
+
 (defun quoted-insert (arg)
   "Read next input character and insert it.
 This is useful for inserting control characters.
@@ -292,7 +299,7 @@ useful for editing binary files."
     (while (> arg 0)
       (insert-and-inherit char)
       (setq arg (1- arg)))))
-\f
+
 (defun forward-to-indentation (arg)
   "Move forward ARG lines and position at first nonblank character."
   (interactive "p")
@@ -323,22 +330,33 @@ Leave one space or none, according to the context."
        nil
       (insert ?\ ))))
 
-(defun delete-horizontal-space ()
-  "Delete all spaces and tabs around point."
+(defun delete-horizontal-space (&optional backward-only)
+  "Delete all spaces and tabs around point.
+If BACKWARD-ONLY is non-nil, only delete spaces before point."
   (interactive "*")
-  (skip-chars-backward " \t")
-  (delete-region (point) (progn (skip-chars-forward " \t") (point))))
+  (delete-region
+   (if backward-only
+       (point)
+     (progn
+       (skip-chars-forward " \t" (field-end))
+       (point)))
+   (progn
+     (skip-chars-backward " \t" (field-beginning nil t))
+     (point))))
 
 (defun just-one-space ()
   "Delete all spaces and tabs around point, leaving one space."
   (interactive "*")
-  (skip-chars-backward " \t")
+  (skip-chars-backward " \t" (field-beginning))
   (if (= (following-char) ? )
       (forward-char 1)
     (insert ? ))
-  (delete-region (point) (progn (skip-chars-forward " \t") (point))))
+  (delete-region
+   (point)
+   (progn
+     (skip-chars-forward " \t" (field-end nil t))
+     (point))))
 
-\f
 (defun beginning-of-buffer (&optional arg)
   "Move point to the beginning of the buffer; leave mark at previous position.
 With arg N, put point N/10 of the way from the beginning.
@@ -399,7 +417,8 @@ that uses or sets the mark."
   (push-mark (point))
   (push-mark (point-max) nil t)
   (goto-char (point-min)))
-\f
+
+
 ;; Counting lines, one way or another.
 
 (defun goto-line (arg)
@@ -459,7 +478,7 @@ and the greater of them is not at the start of a line."
                  (1+ done)
                done)))
        (- (buffer-size) (forward-line (buffer-size)))))))
-\f
+
 (defun what-cursor-position (&optional detail)
   "Print info on cursor position (on screen and within buffer).
 Also describe the character after point, and give its character code
@@ -471,10 +490,8 @@ character safely.  If the character is encoded into one byte, that
 code is shown in hex.  If the character is encoded into more than one
 byte, just \"...\" is shown.
 
-With prefix argument, print additional details about that character,
-instead of the cursor position.  This includes the character set name,
-the codes that identify the character within that character set.  In
-addition, the encoding is fully shown."
+In addition, with prefix argument, show details about that character
+in *Help* buffer.  See also the command `describe-char-after'."
   (interactive "P")
   (let* ((char (following-char))
         (beg (point-min))
@@ -491,9 +508,9 @@ addition, the encoding is fully shown."
         (col (current-column)))
     (if (= pos end)
        (if (or (/= beg 1) (/= end (1+ total)))
-           (message "point=%d of %d(%d%%) <%d - %d>  column %d %s"
+           (message "point=%d of %d (%d%%) <%d - %d> column %d %s"
                     pos total percent beg end col hscroll)
-         (message "point=%d of %d(%d%%)  column %d %s"
+         (message "point=%d of %d (%d%%) column %d %s"
                   pos total percent col hscroll))
       (let ((coding buffer-file-coding-system)
            encoded encoding-msg)
@@ -506,38 +523,33 @@ addition, the encoding is fully shown."
          (setq encoded (and (>= char 128) (encode-coding-char char coding)))
          (setq encoding-msg
                (if encoded
-                   (format "(0%o, %d, 0x%x, ext %s)"
+                   (format "(0%o, %d, 0x%x, file %s)"
                            char char char
-                           (if (and (not detail)
-                                    (> (length encoded) 1))
+                           (if (> (length encoded) 1)
                                "..."
-                             (concat
-                              (encoded-string-description encoded coding)
-                              (if (nth 2 (find-composition (point)))
-                                  " (composed)" ""))))
+                             (encoded-string-description encoded coding)))
                  (format "(0%o, %d, 0x%x)" char char char))))
        (if detail
-           ;; We show the detailed information of CHAR.
-           (message "Char: %s %s %s"
-                    (if (< char 256)
-                        (single-key-description char)
-                      (buffer-substring-no-properties (point) (1+ (point))))
-                    encoding-msg (split-char char))
-         (if (or (/= beg 1) (/= end (1+ total)))
-             (message "Char: %s %s point=%d of %d(%d%%) <%d - %d>  column %d %s"
-                      (if (< char 256)
-                          (single-key-description char)
-                        (buffer-substring-no-properties (point) (1+ (point))))
-                      encoding-msg pos total percent beg end col hscroll)
-           (message "Char: %s %s point=%d of %d(%d%%)  column %d %s"
+           ;; We show the detailed information about CHAR.
+           (describe-char-after (point)))
+       (if (or (/= beg 1) (/= end (1+ total)))
+           (message "Char: %s %s point=%d of %d (%d%%) <%d - %d> column %d %s"
                     (if (< char 256)
                         (single-key-description char)
                       (buffer-substring-no-properties (point) (1+ (point))))
-                    encoding-msg pos total percent col hscroll)))))))
-\f
-(defvar read-expression-map (cons 'keymap minibuffer-local-map)
+                    encoding-msg pos total percent beg end col hscroll)
+         (message "Char: %s %s point=%d of %d (%d%%) column %d %s"
+                  (if (< char 256)
+                      (single-key-description char)
+                    (buffer-substring-no-properties (point) (1+ (point))))
+                  encoding-msg pos total percent col hscroll))))))
+
+(defvar read-expression-map
+  (let ((m (make-sparse-keymap)))
+    (define-key m "\M-\t" 'lisp-complete-symbol)
+    (set-keymap-parent m minibuffer-local-map)
+    m)
   "Minibuffer keymap used for reading Lisp expressions.")
-(define-key read-expression-map "\M-\t" 'lisp-complete-symbol)
 
 (defvar read-expression-history nil)
 
@@ -550,7 +562,7 @@ addition, the encoding is fully shown."
 (defcustom eval-expression-print-length 12
   "*Value to use for `print-length' when printing value in `eval-expression'."
   :group 'lisp
-  :type 'integer
+  :type '(choice (const nil) integer)
   :version "21.1")
 
 (defcustom eval-expression-debug-on-error t
@@ -571,7 +583,7 @@ Value is also consed on to front of the variable `values'."
                               nil read-expression-map t
                               'read-expression-history)
         current-prefix-arg))
-  
+
   (if (null eval-expression-debug-on-error)
       (setq values (cons (eval eval-expression-arg) values))
     (let ((old-value (make-symbol "t")) new-value)
@@ -584,7 +596,7 @@ Value is also consed on to front of the variable `values'."
       ;; propagate that change to the global binding.
       (unless (eq old-value new-value)
        (setq debug-on-error new-value))))
-    
+
   (let ((print-length eval-expression-print-length)
        (print-level eval-expression-print-level))
     (prin1 (car values)
@@ -642,7 +654,7 @@ to get different commands to edit and resubmit."
              (setq command-history (cons newcmd command-history)))
          (eval newcmd))
       (ding))))
-\f
+
 (defvar minibuffer-history nil
   "Default minibuffer history list.
 This is used for all minibuffer input
@@ -697,6 +709,10 @@ in this use of the minibuffer.")
 (defun minibuffer-history-initialize ()
   (setq minibuffer-text-before-history nil))
 
+(defun minibuffer-avoid-prompt (new old)
+  "A point-motion hook for the minibuffer, that moves point out of the prompt."
+  (constrain-to-field nil (point-max)))
+
 (defcustom minibuffer-history-case-insensitive-variables nil
   "*Minibuffer history variables for which matching should ignore case.
 If a history variable is a member of this list, then the
@@ -726,44 +742,49 @@ See also `minibuffer-history-case-insensitive-variables'."
                 (error "No previous history search regexp"))
             regexp)
           (prefix-numeric-value current-prefix-arg))))
-  (if (and (zerop minibuffer-history-position)
-          (null minibuffer-text-before-history))
-      (setq minibuffer-text-before-history (field-string (point-max))))
-  (let ((history (symbol-value minibuffer-history-variable))
-       (case-fold-search
-        (if (isearch-no-upper-case-p regexp t) ; assume isearch.el is dumped
-            ;; On some systems, ignore case for file names.
-            (if (memq minibuffer-history-variable
-                      minibuffer-history-case-insensitive-variables)
-                t
-              ;; Respect the user's setting for case-fold-search:
-              case-fold-search)
-          nil))
-       prevpos
-       (pos minibuffer-history-position))
-    (while (/= n 0)
-      (setq prevpos pos)
-      (setq pos (min (max 1 (+ pos (if (< n 0) -1 1))) (length history)))
-      (if (= pos prevpos)
+  (unless (zerop n)
+    (if (and (zerop minibuffer-history-position)
+            (null minibuffer-text-before-history))
+       (setq minibuffer-text-before-history (field-string (point-max))))
+    (let ((history (symbol-value minibuffer-history-variable))
+         (case-fold-search
+          (if (isearch-no-upper-case-p regexp t) ; assume isearch.el is dumped
+              ;; On some systems, ignore case for file names.
+              (if (memq minibuffer-history-variable
+                        minibuffer-history-case-insensitive-variables)
+                  t
+                ;; Respect the user's setting for case-fold-search:
+                case-fold-search)
+            nil))
+         prevpos
+         match-string
+         match-offset
+         (pos minibuffer-history-position))
+      (while (/= n 0)
+       (setq prevpos pos)
+       (setq pos (min (max 1 (+ pos (if (< n 0) -1 1))) (length history)))
+       (when (= pos prevpos)
          (error (if (= pos 1)
                     "No later matching history item"
                   "No earlier matching history item")))
-      (if (string-match regexp
-                       (if (eq minibuffer-history-sexp-flag
-                               (minibuffer-depth))
-                           (let ((print-level nil))
-                             (prin1-to-string (nth (1- pos) history)))
-                         (nth (1- pos) history)))
-         (setq n (+ n (if (< n 0) 1 -1)))))
-    (setq minibuffer-history-position pos)
-    (goto-char (point-max))
-    (delete-field)
-    (let ((elt (nth (1- pos) history)))
-      (insert (if (eq minibuffer-history-sexp-flag (minibuffer-depth))
+       (setq match-string
+             (if (eq minibuffer-history-sexp-flag (minibuffer-depth))
                  (let ((print-level nil))
-                   (prin1-to-string elt))
-               elt)))
-      (goto-char (field-beginning)))
+                   (prin1-to-string (nth (1- pos) history)))
+               (nth (1- pos) history)))
+       (setq match-offset
+             (if (< n 0)
+                 (and (string-match regexp match-string)
+                      (match-end 0))
+               (and (string-match (concat ".*\\(" regexp "\\)") match-string)
+                    (match-beginning 1))))
+       (when match-offset
+         (setq n (+ n (if (< n 0) 1 -1)))))
+      (setq minibuffer-history-position pos)
+      (goto-char (point-max))
+      (delete-field)
+      (insert match-string)
+      (goto-char (+ (field-beginning) match-offset))))
   (if (or (eq (car (car command-history)) 'previous-matching-history-element)
          (eq (car (car command-history)) 'next-matching-history-element))
       (setq command-history (cdr command-history))))
@@ -789,6 +810,8 @@ An uppercase letter in REGEXP makes the search case-sensitive."
           (prefix-numeric-value current-prefix-arg))))
   (previous-matching-history-element regexp (- n)))
 
+(defvar minibuffer-temporary-goal-position nil)
+
 (defun next-history-element (n)
   "Insert the next element of the minibuffer history into the minibuffer."
   (interactive "p")
@@ -805,6 +828,13 @@ An uppercase letter in REGEXP makes the search case-sensitive."
              (error "End of history; no default available")))
        (if (> narg (length (symbol-value minibuffer-history-variable)))
            (error "Beginning of history; no preceding item"))
+       (unless (or (eq last-command 'next-history-element)
+                   (eq last-command 'previous-history-element))
+         (let ((prompt-end (field-beginning (point-max))))
+           (set (make-local-variable 'minibuffer-temporary-goal-position)
+                (cond ((<= (point) prompt-end) prompt-end)
+                      ((eobp) nil)
+                      (t (point))))))
        (goto-char (point-max))
        (delete-field)
        (setq minibuffer-history-position narg)
@@ -822,7 +852,7 @@ An uppercase letter in REGEXP makes the search case-sensitive."
             (let ((print-level nil))
               (prin1-to-string elt))
           elt))
-       (goto-char (field-beginning)))))
+       (goto-char (or minibuffer-temporary-goal-position (point-max))))))
 
 (defun previous-history-element (n)
   "Inserts the previous element of the minibuffer history into the minibuffer."
@@ -864,10 +894,24 @@ Return 0 if current buffer is not a mini-buffer."
 
 (defun minibuffer-prompt-end ()
   "Return the buffer position of the end of the minibuffer prompt.
-Return 0 if current buffer is not a mini-buffer."
+Return (point-min) if current buffer is not a mini-buffer."
   (field-beginning (point-max)))
 
-\f
+(defun minibuffer-contents ()
+  "Return the user input in a minbuffer as a string.
+The current buffer must be a minibuffer."
+  (field-string (point-max)))
+
+(defun minibuffer-contents-no-properties ()
+  "Return the user input in a minbuffer as a string, without text-properties.
+The current buffer must be a minibuffer."
+  (field-string-no-properties (point-max)))
+
+(defun delete-minibuffer-contents  ()
+  "Delete all user input in a minibuffer.
+The current buffer must be a minibuffer."
+  (delete-field (point-max)))
+
 ;Put this on C-x u, so we can force that rather than C-_ into startup msg
 (defalias 'advertised-undo 'undo)
 
@@ -876,9 +920,9 @@ Return 0 if current buffer is not a mini-buffer."
 Repeat this command to undo more changes.
 A numeric argument serves as a repeat count.
 
-Just C-u as argument requests selective undo,
-limited to changes within the current region.
-Likewise in Transient Mark mode when the mark is active."
+In Transient Mark mode when the mark is active, only undo changes within
+the current region.  Similarly, when not in Transient Mark mode, just C-u
+as an argument limits undo to changes within the current region."
   (interactive "*P")
   ;; If we don't get all the way thru, make last-command indicate that
   ;; for the following command.
@@ -887,12 +931,16 @@ Likewise in Transient Mark mode when the mark is active."
        (recent-save (recent-auto-save-p)))
     (or (eq (selected-window) (minibuffer-window))
        (message "Undo!"))
-    (or (eq last-command 'undo)
-       (progn (if (or arg (and transient-mark-mode mark-active))
-                  (undo-start (region-beginning) (region-end))
-                (undo-start))
-              (undo-more 1)))
-    (undo-more (if arg (prefix-numeric-value arg) 1))
+    (unless (eq last-command 'undo)
+      (if (if transient-mark-mode mark-active (and arg (not (numberp arg))))
+         (undo-start (region-beginning) (region-end))
+       (undo-start))
+      ;; get rid of initial undo boundary
+      (undo-more 1))
+    (undo-more
+     (if (or transient-mark-mode (numberp arg))
+        (prefix-numeric-value arg)
+       1))
     ;; 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)
@@ -1085,7 +1133,7 @@ is not *inside* the region START...END."
            (t
             '(0 . 0)))
     '(0 . 0)))
-\f
+
 (defvar shell-command-history nil
   "History list for some commands that read shell commands.")
 
@@ -1100,17 +1148,19 @@ stdout will be intermixed in the output stream.")
 
 (defun shell-command (command &optional output-buffer error-buffer)
   "Execute string COMMAND in inferior shell; display output, if any.
+With prefix argument, insert the COMMAND's output at point.
 
 If COMMAND ends in ampersand, execute it asynchronously.
 The output appears in the buffer `*Async Shell Command*'.
 That buffer is in shell mode.
 
-Otherwise, COMMAND is executed synchronously.  The output appears in the
-buffer `*Shell Command Output*'.
-If the output is one line, it is displayed in the echo area *as well*,
-but it is nonetheless available in buffer `*Shell Command Output*',
-even though that buffer is not automatically displayed.
-If there is no output, or if output is inserted in the current buffer,
+Otherwise, COMMAND is executed synchronously.  The output appears in
+the buffer `*Shell Command Output*'.  If the output is short enough to
+display in the echo area (which is determined by the variables
+`resize-mini-windows' and `max-mini-window-height'), it is shown
+there, but it is nonetheless available in buffer `*Shell Command
+Output*' even though that buffer is not automatically displayed.  If
+there is no output, or if output is inserted in the current buffer,
 then `*Shell Command Output*' is deleted.
 
 To specify a coding system for converting non-ASCII characters
@@ -1215,7 +1265,71 @@ specifies the value of ERROR-BUFFER."
                  ))
            (shell-command-on-region (point) (point) command
                                     output-buffer nil error-buffer)))))))
-\f
+
+(defun display-message-or-buffer (message
+                                 &optional buffer-name not-this-window frame)
+  "Display MESSAGE in the echo area if possible, otherwise in a pop-up buffer.
+MESSAGE may be either a string or a buffer.
+
+A buffer is displayed using `display-buffer' if MESSAGE is too long for
+the maximum height of the echo area, as defined by `max-mini-window-height'
+if `resize-mini-windows' is non-nil.
+
+Returns either the string shown in the echo area, or when a pop-up
+buffer is used, the window used to display it.
+
+If MESSAGE is a string, then the optional argument BUFFER-NAME is the
+name of the buffer used to display it in the case where a pop-up buffer
+is used, defaulting to `*Message*'.  In the case where MESSAGE is a
+string and it is displayed in the echo area, it is not specified whether
+the contents are inserted into the buffer anyway.
+
+Optional arguments NOT-THIS-WINDOW and FRAME are as for `display-buffer',
+and only used if a buffer is displayed."
+  (cond ((and (stringp message) (not (string-match "\n" message)))
+        ;; Trivial case where we can use the echo area
+        (message "%s" message))
+       ((and (stringp message)
+             (= (string-match "\n" message) (1- (length message))))
+        ;; Trivial case where we can just remove single trailing newline
+        (message "%s" (substring message 0 (1- (length message)))))
+       (t
+        ;; General case
+        (with-current-buffer
+            (if (bufferp message)
+                message
+              (get-buffer-create (or buffer-name "*Message*")))
+
+          (unless (bufferp message)
+            (erase-buffer)
+            (insert message))
+
+          (let ((lines
+                 (if (= (buffer-size) 0)
+                     0
+                   (count-lines (point-min) (point-max)))))
+            (cond ((or (<= lines 1)
+                       (<= lines
+                           (if resize-mini-windows
+                               (cond ((floatp max-mini-window-height)
+                                      (* (frame-height)
+                                         max-mini-window-height))
+                                     ((integerp max-mini-window-height)
+                                      max-mini-window-height)
+                                     (t
+                                      1))
+                             1)))
+                   ;; Echo area
+                   (goto-char (point-max))
+                   (when (bolp)
+                     (backward-char 1))
+                   (message "%s" (buffer-substring (point-min) (point))))
+                  (t
+                   ;; Buffer
+                   (goto-char (point-min))
+                   (display-buffer message not-this-window frame))))))))
+
+
 ;; We have a sentinel to prevent insertion of a termination message
 ;; in the buffer itself.
 (defun shell-command-sentinel (process signal)
@@ -1244,11 +1358,13 @@ REPLACE, ERROR-BUFFER.  Noninteractive callers can specify coding
 systems by binding `coding-system-for-read' and
 `coding-system-for-write'.
 
-If the output is one line, it is displayed in the echo area,
-but it is nonetheless available in buffer `*Shell Command Output*'
-even though that buffer is not automatically displayed.
-If there is no output, or if output is inserted in the current buffer,
-then `*Shell Command Output*' is deleted.
+If the output is short enough to display in the echo area (which is
+determined by the variable `max-mini-window-height' if
+`resize-mini-windows' is non-nil), it is shown there, but it is
+nonetheless available in buffer `*Shell Command Output*' even though
+that buffer is not automatically displayed.  If there is no output, or
+if output is inserted in the current buffer, then `*Shell Command
+Output*' is deleted.
 
 If the optional fourth argument OUTPUT-BUFFER is non-nil,
 that says to put the output in some other buffer.
@@ -1330,10 +1446,13 @@ specifies the value of ERROR-BUFFER."
                                                  command)))
              ;; Clear the output buffer, then run the command with
              ;; output there.
-             (save-excursion
-               (set-buffer buffer)
-               (setq buffer-read-only nil)
-               (erase-buffer))
+             (let ((directory default-directory))
+               (save-excursion
+                 (set-buffer buffer)
+                 (setq buffer-read-only nil)
+                 (if (not output-buffer)
+                     (setq default-directory directory))
+                 (erase-buffer)))
              (setq exit-status
                    (call-process-region start end shell-file-name nil
                                         (if error-file
@@ -1342,35 +1461,17 @@ specifies the value of ERROR-BUFFER."
                                         nil shell-command-switch command)))
          (setq success (and exit-status (equal 0 exit-status)))
          ;; Report the amount of output.
-         (let ((lines (save-excursion
-                        (set-buffer buffer)
-                        (if (= (buffer-size) 0)
-                            0
-                          (count-lines (point-min) (point-max))))))
-           (cond ((= lines 0)
-                  (if (and error-file
-                           (< 0 (nth 7 (file-attributes error-file))))
-                      (message "(Shell command %sed with some error output)"
-                               (if (equal 0 exit-status)
-                                   "succeed"
-                                 "fail"))
-                    (message "(Shell command %sed with no output)"
-                             (if (equal 0 exit-status)
-                                 "succeed"
-                               "fail")))
-                  (kill-buffer buffer))
-                 ((= lines 1)
-                  (message "%s"
-                           (save-excursion
-                             (set-buffer buffer)
-                             (goto-char (point-min))
-                             (buffer-substring (point)
-                                               (progn (end-of-line) (point))))))
-                 (t
-                  (save-excursion
-                    (set-buffer buffer)
-                    (goto-char (point-min)))
-                  (display-buffer buffer)))))))
+         (if (with-current-buffer buffer (> (point-max) (point-min)))
+             ;; There's some output, display it
+             (display-message-or-buffer buffer)
+           ;; No output; error?
+           (message (if (and error-file
+                             (< 0 (nth 7 (file-attributes error-file))))
+                        "(Shell command %sed with some error output)"
+                      "(Shell command %sed with no output)")
+                    (if (equal 0 exit-status) "succeed" "fail"))
+           (kill-buffer buffer)))))
+
     (when (and error-file (file-exists-p error-file))
       (if (< 0 (nth 7 (file-attributes error-file)))
          (with-current-buffer (get-buffer-create error-buffer)
@@ -1393,7 +1494,7 @@ specifies the value of ERROR-BUFFER."
     (with-current-buffer
       standard-output
       (call-process shell-file-name nil t nil shell-command-switch command))))
-\f
+
 (defvar universal-argument-map
   (let ((map (make-sparse-keymap)))
     (define-key map [t] 'universal-argument-other-key)
@@ -1411,6 +1512,17 @@ specifies the value of ERROR-BUFFER."
     (define-key map [?7] 'digit-argument)
     (define-key map [?8] 'digit-argument)
     (define-key map [?9] 'digit-argument)
+    (define-key map [kp-0] 'digit-argument)
+    (define-key map [kp-1] 'digit-argument)
+    (define-key map [kp-2] 'digit-argument)
+    (define-key map [kp-3] 'digit-argument)
+    (define-key map [kp-4] 'digit-argument)
+    (define-key map [kp-5] 'digit-argument)
+    (define-key map [kp-6] 'digit-argument)
+    (define-key map [kp-7] 'digit-argument)
+    (define-key map [kp-8] 'digit-argument)
+    (define-key map [kp-9] 'digit-argument)
+    (define-key map [kp-subtract] 'universal-argument-minus)
     map)
   "Keymap used while processing \\[universal-argument].")
 
@@ -1463,7 +1575,10 @@ These commands include \\[set-mark-command] and \\[start-kbd-macro]."
   "Part of the numeric argument for the next command.
 \\[universal-argument] following digits or minus sign ends the argument."
   (interactive "P")
-  (let ((digit (- (logand last-command-char ?\177) ?0)))
+  (let* ((char (if (integerp last-command-char)
+                  last-command-char
+                (get last-command-char 'ascii-character)))
+        (digit (- (logand char ?\177) ?0)))
     (cond ((integerp arg)
           (setq prefix-arg (+ (* arg 10)
                               (if (< arg 0) (- digit) digit))))
@@ -1495,7 +1610,7 @@ These commands include \\[set-mark-command] and \\[start-kbd-macro]."
                  unread-command-events)))
   (reset-this-command-lengths)
   (setq overriding-terminal-local-map nil))
-\f
+
 ;;;; Window system cut and paste hooks.
 
 (defvar interprogram-cut-function nil
@@ -1534,7 +1649,7 @@ current string, it is probably good enough to return nil if the string
 is equal (according to `string=') to the last text Emacs provided.")
 
 
-\f
+
 ;;;; The kill ring data structure.
 
 (defvar kill-ring nil
@@ -1563,7 +1678,7 @@ Optional second argument REPLACE non-nil means that STRING will replace
 the front of the kill ring, rather than being added to the list."
   (and (fboundp 'menu-bar-update-yank-menu)
        (menu-bar-update-yank-menu string (and replace (car kill-ring))))
-  (if replace
+  (if (and replace kill-ring)
       (setcar kill-ring string)
     (setq kill-ring (cons string kill-ring))
     (if (> (length kill-ring) kill-ring-max)
@@ -1609,7 +1724,7 @@ yanking point; just return the Nth kill forward."
        (car ARGth-kill-element)))))
 
 
-\f
+
 ;;;; Commands for manipulating the kill ring.
 
 (defcustom kill-read-only-ok nil
@@ -1637,7 +1752,7 @@ Any command that calls this function is a \"kill command\".
 If the previous command was also a kill command,
 the text killed this time appends to the text killed last time
 to make one entry in the kill ring."
-  (interactive "*r")
+  (interactive "r")
   (condition-case nil
       (let ((string (delete-and-extract-region beg end)))
        (when string                    ;STRING is nil if BEG = END
@@ -1727,7 +1842,7 @@ The argument is used for internal purposes; do not supply one."
        (setq this-command 'kill-region)
        (message "If the next command is a kill, it will append"))
     (setq last-command 'kill-region)))
-\f
+
 ;; Yanking.
 
 (defun yank-pop (arg)
@@ -1798,7 +1913,7 @@ See also the command \\[yank-pop]."
 With argument, rotate that many kills forward (or backward, if negative)."
   (interactive "p")
   (current-kill arg))
-\f
+
 ;; Some kill commands.
 
 ;; Internal subroutine of delete-char
@@ -1856,12 +1971,12 @@ and KILLP is t if a prefix arg was specified."
   "Kill up to and including ARG'th occurrence of CHAR.
 Case is ignored if `case-fold-search' is non-nil in the current buffer.
 Goes backward if ARG is negative; error if CHAR not found."
-  (interactive "*p\ncZap to char: ")
+  (interactive "p\ncZap to char: ")
   (kill-region (point) (progn
                         (search-forward (char-to-string char) nil nil arg)
 ;                       (goto-char (if (> arg 0) (1- (point)) (1+ (point))))
                         (point))))
-\f
+
 ;; kill-line and its subroutines.
 
 (defcustom kill-whole-line nil
@@ -1873,6 +1988,7 @@ Goes backward if ARG is negative; error if CHAR not found."
   "Kill the rest of the current line; if no nonblanks there, kill thru newline.
 With prefix argument, kill that many lines from point.
 Negative arguments kill lines backward.
+With zero argument, kills the text before point on the current line.
 
 When calling from a program, nil means \"no arg\",
 a number counts as a prefix arg.
@@ -1884,7 +2000,7 @@ If `kill-whole-line' is non-nil, then this command kills the whole line
 including its terminating newline, when used at the beginning of a line
 with no argument.  As a consequence, you can always kill a whole line
 by typing \\[beginning-of-line] \\[kill-line]."
-  (interactive "*P")
+  (interactive "P")
   (kill-region (point)
               ;; It is better to move point to the other end of the kill
               ;; before killing.  That way, in a read-only buffer, point
@@ -1970,7 +2086,7 @@ If ARG is zero, move to the beginning of the current line."
        (goto-char (next-single-property-change (point) 'invisible))
       (goto-char (next-overlay-change (point))))
     (end-of-line)))
-\f
+
 (defun insert-buffer (buffer)
   "Insert after point the contents of BUFFER.
 Puts mark after the inserted text.
@@ -2011,9 +2127,16 @@ START and END specify the portion of the current buffer to be copied."
         (region-beginning) (region-end)))
   (let ((oldbuf (current-buffer)))
     (save-excursion
-      (set-buffer (get-buffer-create buffer))
-      (barf-if-buffer-read-only)
-      (insert-buffer-substring oldbuf start end))))
+      (let* ((append-to (get-buffer-create buffer))
+            (windows (get-buffer-window-list append-to t t))
+            point)
+       (set-buffer append-to)
+       (setq point (point))
+       (barf-if-buffer-read-only)
+       (insert-buffer-substring oldbuf start end)
+       (dolist (window windows)
+         (when (= (window-point window) point)
+           (set-window-point window (point))))))))
 
 (defun prepend-to-buffer (buffer start end)
   "Prepend to specified buffer the text of the region.
@@ -2045,7 +2168,7 @@ START and END specify the portion of the current buffer to be copied."
       (erase-buffer)
       (save-excursion
        (insert-buffer-substring oldbuf start end)))))
-\f
+
 (put 'mark-inactive 'error-conditions '(mark-inactive error))
 (put 'mark-inactive 'error-message "The mark is not active now")
 
@@ -2238,8 +2361,8 @@ incremental search, \\[beginning-of-buffer], and \\[end-of-buffer]."
        (widen))
     (goto-char position)
     (switch-to-buffer buffer)))
-\f
-(defcustom next-line-add-newlines t
+
+(defcustom next-line-add-newlines nil
   "*If non-nil, `next-line' inserts newline to avoid `end of buffer' error."
   :type 'boolean
   :group 'editing-basics)
@@ -2302,7 +2425,7 @@ to use and more reliable (no dependence on goal column, etc.)."
        ((beginning-of-buffer end-of-buffer) (ding)))
     (line-move (- arg)))
   nil)
-\f
+
 (defcustom track-eol nil
   "*Non-nil means vertical motion starting at end of line keeps to ends of lines.
 This means moving to the end of each line moved onto.
@@ -2422,7 +2545,8 @@ Outline mode sets this."
       ;; with intangibility and point-motion hooks enabled this time.
       (goto-char opoint)
       (setq inhibit-point-motion-hooks nil)
-      (goto-char (constrain-to-field new opoint t t))
+      (goto-char (constrain-to-field new opoint nil t
+                                    'inhibit-line-move-field-capture))
       ;; If intangibility processing moved us to a different line,
       ;; readjust the horizontal position within the line we ended up at.
       (when (or (< (point) line-beg) (> (point) line-end))
@@ -2437,7 +2561,8 @@ Outline mode sets this."
            (setq new (point)))
        (goto-char (point-min))
        (setq inhibit-point-motion-hooks nil)
-       (goto-char (constrain-to-field new opoint t t))
+       (goto-char (constrain-to-field new opoint nil t
+                                      'inhibit-line-move-field-capture))
        )))
   nil)
 
@@ -2462,7 +2587,7 @@ The goal column is stored in the variable `goal-column'."
              "Goal column %d (use \\[set-goal-column] with an arg to unset it)")
             goal-column))
   nil)
-\f
+
 
 (defun scroll-other-window-down (lines)
   "Scroll the \"other window\" down.
@@ -2508,7 +2633,7 @@ With arg N, put point N/10 of the way from the true end."
          (end-of-buffer arg)
          (recenter '(t)))
       (select-window orig-window))))
-\f
+
 (defun transpose-chars (arg)
   "Interchange characters around point, moving forward one character.
 With prefix arg ARG, effect is to take character before point
@@ -2615,272 +2740,10 @@ With argument 0, interchanges line point is in with line mark is in."
                 (+ transpose-subr-start1 (- len1 len2))))
     (delete-region (point) (+ (point) len1))
     (insert word2)))
-\f
-(defcustom comment-column 32
-  "*Column to indent right-margin comments to.
-Setting this variable automatically makes it local to the current buffer.
-Each mode establishes a different default value for this variable; you
-can set the value for a particular mode using that mode's hook."
-  :type 'integer
-  :group 'fill-comments)
-(make-variable-buffer-local 'comment-column)
-
-(defcustom comment-start nil
-  "*String to insert to start a new comment, or nil if no comment syntax."
-  :type '(choice (const :tag "None" nil)
-                string)
-  :group 'fill-comments)
 
-(defcustom comment-start-skip nil
-  "*Regexp to match the start of a comment plus everything up to its body.
-If there are any \\(...\\) pairs, the comment delimiter text is held to begin
-at the place matched by the close of the first pair."
-  :type '(choice (const :tag "None" nil)
-                regexp)
-  :group 'fill-comments)
-
-(defcustom comment-end ""
-  "*String to insert to end a new comment.
-Should be an empty string if comments are terminated by end-of-line."
-  :type 'string
-  :group 'fill-comments)
-
-(defvar comment-indent-hook nil
-  "Obsolete variable for function to compute desired indentation for a comment.
-This function is called with no args with point at the beginning of
-the comment's starting delimiter.")
-
-(defvar comment-indent-function
-  (lambda () comment-column)
-  "Function to compute desired indentation for a comment.
-This function is called with no args with point at the beginning of
-the comment's starting delimiter.")
-
-(defcustom block-comment-start nil
-  "*String to insert to start a new comment on a line by itself.
-If nil, use `comment-start' instead.
-Note that the regular expression `comment-start-skip' should skip this string
-as well as the `comment-start' string."
-  :type '(choice (const :tag "Use comment-start" nil)
-                string)
-  :group 'fill-comments)
-
-(defcustom block-comment-end nil
-  "*String to insert to end a new comment on a line by itself.
-Should be an empty string if comments are terminated by end-of-line.
-If nil, use `comment-end' instead."
-  :type '(choice (const :tag "Use comment-end" nil)
-                string)
-  :group 'fill-comments)
-
-(defun indent-for-comment ()
-  "Indent this line's comment to comment column, or insert an empty comment."
-  (interactive "*")
-  (let* ((empty (save-excursion (beginning-of-line)
-                               (looking-at "[ \t]*$")))
-        (starter (or (and empty block-comment-start) comment-start))
-        (ender (or (and empty block-comment-end) comment-end)))
-    (cond
-     ((null starter)
-      (error "No comment syntax defined"))
-     ((null comment-start-skip)
-      (error "This mode doesn't define `comment-start-skip'"))
-     (t (let* ((eolpos (save-excursion (end-of-line) (point)))
-               cpos indent begpos)
-          (beginning-of-line)
-          (if (re-search-forward comment-start-skip eolpos 'move)
-              (progn (setq cpos (point-marker))
-                     ;; Find the start of the comment delimiter.
-                     ;; If there were paren-pairs in comment-start-skip,
-                     ;; position at the end of the first pair.
-                     (if (match-end 1)
-                         (goto-char (match-end 1))
-                       ;; If comment-start-skip matched a string with
-                       ;; internal whitespace (not final whitespace) then
-                       ;; the delimiter start at the end of that
-                       ;; whitespace.  Otherwise, it starts at the
-                       ;; beginning of what was matched.
-                       (skip-syntax-backward " " (match-beginning 0))
-                       (skip-syntax-backward "^ " (match-beginning 0)))))
-          (setq begpos (point))
-          ;; Compute desired indent.
-          (if (= (current-column)
-                 (setq indent (if comment-indent-hook
-                                  (funcall comment-indent-hook)
-                                (funcall comment-indent-function))))
-              (goto-char begpos)
-            ;; If that's different from current, change it.
-            (skip-chars-backward " \t")
-            (delete-region (point) begpos)
-            (indent-to indent))
-          ;; An existing comment?
-          (if cpos
-              (progn (goto-char cpos)
-                     (set-marker cpos nil))
-            ;; No, insert one.
-            (insert starter)
-            (save-excursion
-              (insert ender))))))))
-
-(defun set-comment-column (arg)
-  "Set the comment column based on point.
-With no arg, set the comment column to the current column.
-With just minus as arg, kill any comment on this line.
-With any other arg, set comment column to indentation of the previous comment
- and then align or create a comment on this line at that column."
-  (interactive "P")
-  (if (eq arg '-)
-      (kill-comment nil)
-    (if arg
-       (progn
-         (save-excursion
-           (beginning-of-line)
-           (re-search-backward comment-start-skip)
-           (beginning-of-line)
-           (re-search-forward comment-start-skip)
-           (goto-char (match-beginning 0))
-           (setq comment-column (current-column))
-           (message "Comment column set to %d" comment-column))
-         (indent-for-comment))
-      (setq comment-column (current-column))
-      (message "Comment column set to %d" comment-column))))
-
-(defun kill-comment (arg)
-  "Kill the comment on this line, if any.
-With argument, kill comments on that many lines starting with this one."
-  ;; this function loses in a lot of situations.  it incorrectly recognises
-  ;; comment delimiters sometimes (ergo, inside a string), doesn't work
-  ;; with multi-line comments, can kill extra whitespace if comment wasn't
-  ;; through end-of-line, et cetera.
-  (interactive "P")
-  (or comment-start-skip (error "No comment syntax defined"))
-  (let ((count (prefix-numeric-value arg)) endc)
-    (while (> count 0)
-      (save-excursion
-       (end-of-line)
-       (setq endc (point))
-       (beginning-of-line)
-       (and (string< "" comment-end)
-            (setq endc
-                  (progn
-                    (re-search-forward (regexp-quote comment-end) endc 'move)
-                    (skip-chars-forward " \t")
-                    (point))))
-       (beginning-of-line)
-       (if (re-search-forward comment-start-skip endc t)
-           (progn
-             (goto-char (match-beginning 0))
-             (skip-chars-backward " \t")
-             (kill-region (point) endc)
-             ;; to catch comments a line beginnings
-             (indent-according-to-mode))))
-      (if arg (forward-line 1))
-      (setq count (1- count)))))
-
-(defvar comment-padding 1
-  "Number of spaces `comment-region' puts between comment chars and text.
-
-Extra spacing between the comment characters and the comment text
-makes the comment easier to read.  Default is 1.  Nil means 0 and is
-more efficient.")
-
-(defun comment-region (beg end &optional arg)
-  "Comment or uncomment each line in the region.
-With just C-u prefix arg, uncomment each line in region.
-Numeric prefix arg ARG means use ARG comment characters.
-If ARG is negative, delete that many comment characters instead.
-Comments are terminated on each line, even for syntax in which newline does
-not end the comment.  Blank lines do not get comments.
-
-The strings used as comment starts are build from
-`comment-start' without trailing spaces and `comment-padding'."
-  ;; if someone wants it to only put a comment-start at the beginning and
-  ;; comment-end at the end then typing it, C-x C-x, closing it, C-x C-x
-  ;; is easy enough.  No option is made here for other than commenting
-  ;; every line.
-  (interactive "*r\nP")
-  (or comment-start (error "No comment syntax is defined"))
-  (if (> beg end) (let (mid) (setq mid beg beg end end mid)))
-  (save-excursion
-    (save-restriction
-      (let* ((comment-start
-             (substring comment-start 0
-                        (string-match "[ \t]*$" comment-start)))
-            (cs comment-start) (ce comment-end)
-            (cp (when comment-padding
-                  (make-string comment-padding ? )))
-            numarg)
-       (if (consp arg) (setq numarg t)
-         (setq numarg (prefix-numeric-value arg))
-         ;; For positive arg > 1, replicate the comment delims now,
-         ;; then insert the replicated strings just once.
-         (while (> numarg 1)
-           (setq cs (concat cs comment-start)
-                 ce (concat ce comment-end))
-           (setq numarg (1- numarg))))
-       ;; Loop over all lines from BEG to END.
-       (narrow-to-region beg end)
-       (goto-char beg)
-       (if (or (eq numarg t) (< numarg 0))
-           (while (not (eobp))
-             (let (found-comment)
-               ;; Delete comment start from beginning of line.
-               (if (eq numarg t)
-                   (while (looking-at (regexp-quote cs))
-                     (setq found-comment t)
-                     (delete-char (length cs)))
-                 (let ((count numarg))
-                   (while (and (> 1 (setq count (1+ count)))
-                               (looking-at (regexp-quote cs)))
-                     (setq found-comment t)
-                     (delete-char (length cs)))))
-               ;; Delete comment padding from beginning of line
-               (when (and found-comment comment-padding
-                          (looking-at (regexp-quote cp)))
-                 (delete-char comment-padding))
-               ;; Delete comment end from end of line.
-               (if (string= "" ce)
-                   nil
-                 (if (eq numarg t)
-                     (progn
-                       (end-of-line)
-                       ;; This is questionable if comment-end ends in
-                       ;; whitespace.  That is pretty brain-damaged,
-                       ;; though.
-                       (while (progn (skip-chars-backward " \t")
-                                     (and (>= (- (point) (point-min)) (length ce))
-                                          (save-excursion
-                                            (backward-char (length ce))
-                                            (looking-at (regexp-quote ce)))))
-                           (delete-char (- (length ce)))))
-                   (let ((count numarg))
-                     (while (> 1 (setq count (1+ count)))
-                       (end-of-line)
-                       ;; this is questionable if comment-end ends in whitespace
-                       ;; that is pretty brain-damaged though
-                       (skip-chars-backward " \t")
-                       (if (>= (- (point) (point-min)) (length ce))
-                           (save-excursion
-                             (backward-char (length ce))
-                             (if (looking-at (regexp-quote ce))
-                                 (delete-char (length ce)))))))))
-               (forward-line 1)))
-
-         (when comment-padding
-           (setq cs (concat cs cp)))
-         (while (not (eobp))
-           ;; Insert at beginning and at end.
-           (if (looking-at "[ \t]*$") ()
-             (insert cs)
-             (if (string= "" ce) ()
-               (end-of-line)
-               (insert ce)))
-           (search-forward "\n" nil 'move)))))))
-\f
 (defun backward-word (arg)
   "Move backward until encountering the end of a word.
-With argument, do this that many times.
-In programs, it is faster to call `forward-word' with negative arg."
+With argument, do this that many times."
   (interactive "p")
   (forward-word (- arg)))
 
@@ -2896,13 +2759,13 @@ In programs, it is faster to call `forward-word' with negative arg."
 (defun kill-word (arg)
   "Kill characters forward until encountering the end of a word.
 With argument, do this that many times."
-  (interactive "*p")
+  (interactive "p")
   (kill-region (point) (progn (forward-word arg) (point))))
 
 (defun backward-kill-word (arg)
   "Kill characters backward until encountering the end of a word.
 With argument, do this that many times."
-  (interactive "*p")
+  (interactive "p")
   (kill-word (- arg)))
 
 (defun current-word (&optional strict)
@@ -2937,7 +2800,7 @@ or adjacent to a word."
                   (setq start (point)))
                 (buffer-substring-no-properties start end)))
        (buffer-substring-no-properties start end)))))
-\f
+
 (defcustom fill-prefix nil
   "*String for filling to insert at front of new line, or nil for none.
 Setting this variable automatically makes it local to the current buffer."
@@ -2952,7 +2815,7 @@ Setting this variable automatically makes it local to the current buffer."
                 regexp)
   :group 'fill)
 
-(defvar comment-line-break-function 'indent-new-comment-line
+(defvar comment-line-break-function 'comment-indent-new-line
   "*Mode-specific function which line breaks and continues a comment.
 
 This function is only called during auto-filling of a comment section.
@@ -3130,6 +2993,11 @@ for `auto-fill-function' when turning Auto Fill mode on."
 (defun turn-on-auto-fill ()
   "Unconditionally turn on Auto Fill mode."
   (auto-fill-mode 1))
+
+(defun turn-off-auto-fill ()
+  "Unconditionally turn off Auto Fill mode."
+  (auto-fill-mode -1))
+
 (custom-add-option 'text-mode-hook 'turn-on-auto-fill)
 
 (defun set-fill-column (arg)
@@ -3144,96 +3012,7 @@ Just \\[universal-argument] as argument means to use the current column."
       (error "set-fill-column requires an explicit argument")
     (message "Fill column set to %d (was %d)" arg fill-column)
     (setq fill-column arg)))
-\f
-(defcustom comment-multi-line nil
-  "*Non-nil means \\[indent-new-comment-line] should continue same comment
-on new line, with no new terminator or starter.
-This is obsolete because you might as well use \\[newline-and-indent]."
-  :type 'boolean
-  :group 'fill-comments)
-
-(defun indent-new-comment-line (&optional soft)
-  "Break line at point and indent, continuing comment if within one.
-This indents the body of the continued comment
-under the previous comment line.
-
-This command is intended for styles where you write a comment per line,
-starting a new comment (and terminating it if necessary) on each line.
-If you want to continue one comment across several lines, use \\[newline-and-indent].
 
-If a fill column is specified, it overrides the use of the comment column
-or comment indentation.
-
-The inserted newline is marked hard if `use-hard-newlines' is true,
-unless optional argument SOFT is non-nil."
-  (interactive)
-  (let (comcol comstart)
-    (skip-chars-backward " \t")
-    (delete-region (point)
-                  (progn (skip-chars-forward " \t")
-                         (point)))
-    (if soft (insert-and-inherit ?\n) (newline 1))
-    (if fill-prefix
-       (progn
-         (indent-to-left-margin)
-         (insert-and-inherit fill-prefix))
-      (if (not comment-multi-line)
-         (save-excursion
-           (if (and comment-start-skip
-                    (let ((opoint (1- (point)))
-                          inside)
-                      (forward-line -1)
-                      ;; Determine (more or less) whether
-                      ;; target position is inside a comment.
-                      (while (and (re-search-forward comment-start-skip opoint t)
-                                  (not (setq inside (or (equal comment-end "")
-                                                        (not (search-forward comment-end opoint t)))))))
-                      inside))
-               ;; The old line has a comment and point was inside the comment.
-               ;; Set WIN to the pos of the comment-start.
-               ;; But if the comment is empty, look at preceding lines
-               ;; to find one that has a nonempty comment.
-
-               ;; If comment-start-skip contains a \(...\) pair,
-               ;; the real comment delimiter starts at the end of that pair.
-               (let ((win (or (match-end 1) (match-beginning 0))))
-                 (while (and (eolp) (not (bobp))
-                             (let (opoint)
-                               (beginning-of-line)
-                               (setq opoint (point))
-                               (forward-line -1)
-                               (re-search-forward comment-start-skip opoint t)))
-                   (setq win (or (match-end 1) (match-beginning 0))))
-                 ;; Indent this line like what we found.
-                 (goto-char win)
-                 (setq comcol (current-column))
-                 (setq comstart
-                       (buffer-substring (point) (match-end 0)))))))
-      (if comcol
-         (let ((comment-column comcol)
-               (comment-start comstart)
-               (comment-end comment-end))
-           (and comment-end (not (equal comment-end ""))
-  ;           (if (not comment-multi-line)
-                    (progn
-                      (forward-char -1)
-                      (insert comment-end)
-                      (forward-char 1))
-  ;             (setq comment-column (+ comment-column (length comment-start))
-  ;                   comment-start "")
-  ;               )
-                )
-           (if (not (eolp))
-               (setq comment-end ""))
-           (insert-and-inherit ?\n)
-           (forward-char -1)
-           (indent-for-comment)
-           (save-excursion
-             ;; Make sure we delete the newline inserted above.
-             (end-of-line)
-             (delete-char 1)))
-       (indent-according-to-mode)))))
-\f
 (defun set-selective-display (arg)
   "Set `selective-display' to ARG; clear it if no arg.
 When the value of `selective-display' is a number > 0,
@@ -3297,7 +3076,7 @@ specialization of overwrite-mode, entered by setting the
              (> (prefix-numeric-value arg) 0))
            'overwrite-mode-binary))
   (force-mode-line-update))
-\f
+
 (defcustom line-number-mode t
   "*Non-nil means display line number in mode line."
   :type 'boolean
@@ -3493,27 +3272,10 @@ or go back to just one window (by deleting all but the selected window)."
 
 (define-key global-map "\e\e\e" 'keyboard-escape-quit)
 
-(defcustom input-mode-8-bit t
-  "Control acceptance of 8-bit keyboard input.
-This may be useful for inputting non-ASCII characters if your keyboard
-can generate them.  It is not necessary to change this under a window
-system which can distinguish 8-bit characters and Meta keys.
-Setting this variable directly does not take effect;
-use either M-x customize or the function `set-input-mode'."
-  :set (lambda (symbol value)
-        (let ((mode (current-input-mode)))
-          (set-input-mode (nth 0 mode) (nth 1 mode) value)))
-  :initialize 'custom-initialize-default
-  :type '(choice (const :tag "8-bit input for a Meta key" t)
-                (const :tag "Direct 8-bit character input" 0)
-                (const :tag "Assume top bit is parity and ignore" nil))
-  :version "21.1"
-  :link '(custom-manual "Single-Byte European Support")
-  :group 'keyboard)
-\f
 (defcustom read-mail-command 'rmail
   "*Your preference for a mail reading package.
-This is used by some keybindings which support reading mail."
+This is used by some keybindings which support reading mail.
+See also `mail-user-agent' concerning sending mail."
   :type '(choice (function-item rmail)
                 (function-item gnus)
                 (function-item mh-rmail)
@@ -3523,27 +3285,39 @@ This is used by some keybindings which support reading mail."
 
 (defcustom mail-user-agent 'sendmail-user-agent
   "*Your preference for a mail composition package.
-Various Emacs Lisp packages (e.g. reporter) require you to compose an
+Various Emacs Lisp packages (e.g. Reporter) require you to compose an
 outgoing email message.  This variable lets you specify which
 mail-sending package you prefer.
 
 Valid values include:
 
-    `sendmail-user-agent' -- use the default Emacs Mail package
-    `mh-e-user-agent'     -- use the Emacs interface to the MH mail system
-    `message-user-agent'  -- use the GNUS mail sending package
+  `sendmail-user-agent' -- use the default Emacs Mail package.
+                           See Info node `(emacs)Sending Mail'.
+  `mh-e-user-agent'     -- use the Emacs interface to the MH mail system.
+                           See Info node `(mh-e)'.
+  `message-user-agent'  -- use the Gnus Message package.
+                           See Info node `(message)'.
+  `gnus-user-agent'     -- like `message-user-agent', but with Gnus
+                           paraphernalia, particularly the Gcc: header for
+                           archiving.
 
 Additional valid symbols may be available; check with the author of
-your package for details."
+your package for details.  The function should return non-nil if it
+succeeds.
+
+See also `read-mail-command' concerning reading mail."
   :type '(radio (function-item :tag "Default Emacs mail"
                               :format "%t\n"
                               sendmail-user-agent)
                (function-item :tag "Emacs interface to MH"
                               :format "%t\n"
                               mh-e-user-agent)
-               (function-item :tag "Gnus mail sending package"
+               (function-item :tag "Gnus Message package"
                               :format "%t\n"
                               message-user-agent)
+               (function-item :tag "Gnus Message with full Gnus features"
+                              :format "%t\n"
+                              gnus-user-agent)
                (function :tag "Other"))
   :group 'mail)
 
@@ -3603,18 +3377,22 @@ The properties used on SYMBOL are `composefunc', `sendfunc',
            (same-window-regexps nil))
        (funcall switch-function "*mail*")))
   (let ((cc (cdr (assoc-ignore-case "cc" other-headers)))
-       (in-reply-to (cdr (assoc-ignore-case "in-reply-to" other-headers))))
+       (in-reply-to (cdr (assoc-ignore-case "in-reply-to" other-headers)))
+       (body (cdr (assoc-ignore-case "body" other-headers))))
     (or (mail continue to subject in-reply-to cc yank-action send-actions)
        continue
        (error "Message aborted"))
     (save-excursion
       (rfc822-goto-eoh)
       (while other-headers
-       (if (not (assoc-ignore-case (car (car other-headers))
-                                   '(("in-reply-to") ("cc"))))
+       (unless (member-ignore-case (car (car other-headers))
+                                   '("in-reply-to" "cc" "body"))
            (insert (car (car other-headers)) ": "
                    (cdr (car other-headers)) "\n"))
        (setq other-headers (cdr other-headers)))
+      (when body
+       (forward-line 1)
+       (insert body))
       t)))
 
 (define-mail-user-agent 'mh-e-user-agent
@@ -3670,7 +3448,7 @@ Each action has the form (FUNCTION . ARGS)."
    (list nil nil nil current-prefix-arg))
   (compose-mail to subject other-headers continue
                'switch-to-buffer-other-frame yank-action send-actions))
-\f
+
 (defvar set-variable-value-history nil
   "History of values entered with `set-variable'.")
 
@@ -3714,7 +3492,7 @@ in the definition is used to check that VALUE is valid."
        (error "Value `%S' does not match type %S of %S"
               val (car type) var))))
   (set var val))
-\f
+
 ;; Define the major mode for lists of completions.
 
 (defvar completion-list-mode-map nil
@@ -3770,27 +3548,29 @@ Go to the window from which completion was requested."
   "Move to the next item in the completion list.
 With prefix argument N, move N items (negative N means move backward)."
   (interactive "p")
-  (while (and (> n 0) (not (eobp)))
-    (let ((prop (get-text-property (point) 'mouse-face))
-         (end (point-max)))
+  (let ((beg (point-min)) (end (point-max)))
+    (while (and (> n 0) (not (eobp)))
       ;; If in a completion, move to the end of it.
-      (if prop
-         (goto-char (next-single-property-change (point) 'mouse-face nil end)))
+      (when (get-text-property (point) 'mouse-face)
+       (goto-char (next-single-property-change (point) 'mouse-face nil end)))
       ;; Move to start of next one.
-      (goto-char (next-single-property-change (point) 'mouse-face nil end)))
-    (setq n (1- n)))
-  (while (and (< n 0) (not (bobp)))
-    (let ((prop (get-text-property (1- (point)) 'mouse-face))
-         (end (point-min)))
-      ;; If in a completion, move to the start of it.
-      (if prop
+      (unless (get-text-property (point) 'mouse-face)
+       (goto-char (next-single-property-change (point) 'mouse-face nil end)))
+      (setq n (1- n)))
+    (while (and (< n 0) (not (bobp)))
+      (let ((prop (get-text-property (1- (point)) 'mouse-face)))
+       ;; If in a completion, move to the start of it.
+       (when (and prop (eq prop (get-text-property (point) 'mouse-face)))
+         (goto-char (previous-single-property-change
+                     (point) 'mouse-face nil beg)))
+       ;; Move to end of the previous completion.
+       (unless (or (bobp) (get-text-property (1- (point)) 'mouse-face))
          (goto-char (previous-single-property-change
-                     (point) 'mouse-face nil end)))
-      ;; Move to end of the previous completion.
-      (goto-char (previous-single-property-change (point) 'mouse-face nil end))
-      ;; Move to the start of that one.
-      (goto-char (previous-single-property-change (point) 'mouse-face nil end)))
-    (setq n (1+ n))))
+                     (point) 'mouse-face nil beg)))
+       ;; Move to the start of that one.
+       (goto-char (previous-single-property-change
+                   (point) 'mouse-face nil beg))
+       (setq n (1+ n))))))
 
 (defun choose-completion ()
   "Choose the completion that point is in or next to."
@@ -3924,7 +3704,7 @@ The completion list buffer is available as the value of `standard-output'.")
                            (buffer-name mainbuf))
              (setq completion-base-size 0))))
       (goto-char (point-min))
-      (if window-system
+      (if (display-mouse-p)
          (insert (substitute-command-keys
                   "Click \\[mouse-choose-completion] on a completion to select it.\n")))
       (insert (substitute-command-keys
@@ -3954,7 +3734,7 @@ select the completion near point.\n\n")))))
       (goto-char (point-min))
       (search-forward "\n\n")
       (forward-line 1))))
-\f
+
 ;; Support keyboard commands to turn on various modifiers.
 
 ;; These functions -- which are not commands -- each add one modifier
@@ -4020,7 +3800,7 @@ PREFIX is the string that represents this modifier in an event type symbol."
 (define-key function-key-map [?\C-x ?@ ?a] 'event-apply-alt-modifier)
 (define-key function-key-map [?\C-x ?@ ?S] 'event-apply-shift-modifier)
 (define-key function-key-map [?\C-x ?@ ?c] 'event-apply-control-modifier)
-\f
+
 ;;;; Keypad support.
 
 ;;; Make the keypad keys act like ordinary typing keys.  If people add
@@ -4145,4 +3925,144 @@ after it has been set up properly in other respects."
     (if display-flag (pop-to-buffer new))
     new))
 
+
+(defun clone-indirect-buffer (newname display-flag &optional norecord)
+  "Create an indirect buffer that is a twin copy of the current buffer.
+
+Give the indirect buffer name NEWNAME.  Interactively, read NEW-NAME
+from the minibuffer when invoked with a prefix arg.  If NEWNAME is nil
+or if not called with a prefix arg, NEWNAME defaults to the current
+buffer's name.  The name is modified by adding a `<N>' suffix to it
+or by incrementing the N in an existing suffix.
+
+DISPLAY-FLAG non-nil means show the new buffer with `pop-to-buffer'.
+This is always done when called interactively.
+
+Optional last arg NORECORD non-nil means do not put this buffer at the
+front of the list of recently selected ones."
+  (interactive (list (if current-prefix-arg
+                        (read-string "BName of indirect buffer: "))
+                    t))
+  (setq newname (or newname (buffer-name)))
+  (if (string-match "<[0-9]+>\\'" newname)
+      (setq newname (substring newname 0 (match-beginning 0))))
+  (let* ((name (generate-new-buffer-name newname))
+        (buffer (make-indirect-buffer (current-buffer) name t)))
+    (when display-flag
+      (pop-to-buffer buffer norecord))
+    buffer))
+
+
+(defun clone-indirect-buffer-other-window (buffer &optional norecord)
+  "Create an indirect buffer that is a twin copy of BUFFER.
+Select the new buffer in another window.
+Optional second arg NORECORD non-nil means do not put this buffer at
+the front of the list of recently selected ones."
+  (interactive "bClone buffer in other window: ")
+  (let ((popup-windows t))
+    (set-buffer buffer)
+    (clone-indirect-buffer nil t norecord)))
+
+(define-key ctl-x-4-map "c" 'clone-indirect-buffer-other-window)
+
+
+;;; Syntax stuff.
+
+(defconst syntax-code-table
+    '((?\ 0 "whitespace")
+      (?- 0 "whitespace")
+      (?. 1 "punctuation")
+      (?w 2 "word")
+      (?_ 3 "symbol")
+      (?\( 4 "open parenthesis")
+      (?\) 5 "close parenthesis")
+      (?\' 6 "expression prefix")
+      (?\" 7 "string quote")
+      (?$ 8 "paired delimiter")
+      (?\\ 9 "escape")
+      (?/ 10 "character quote")
+      (?< 11 "comment start")
+      (?> 12 "comment end")
+      (?@ 13 "inherit")
+      (nil 14 "comment fence")
+      (nil 15 "string fence"))
+    "Alist of forms (CHAR CODE DESCRIPTION) mapping characters to syntax info.
+CHAR is a character that is allowed as first char in the string
+specifying the syntax when calling `modify-syntax-entry'.  CODE is the
+corresponing syntax code as it is stored in a syntax cell, and
+can be used as value of a `syntax-table' property.
+DESCRIPTION is the descriptive string for the syntax.")
+
+
+;;; Handling of Backspace and Delete keys.
+
+(defcustom delete-key-deletes-forward nil
+  "Whether the Delete key should delete forward or not.
+
+On window systems, the default value of this option is chosen
+according to the keyboard used.  If the keyboard has both a Backspace
+key and a Delete key, and both are mapped to their usual meanings, the
+option's default value is set to t, so that Backspace can be used to
+delete backward, and Delete can be used used to delete forward
+
+If not running under a window system, setting this option accomplishes
+a similar effect by mapping C-h, which is usually generated by the
+Backspace key, to DEL, and by mapping DEL to C-d via
+`keyboard-translate'.  The former functionality of C-h is available on
+the F1 key.  You should probably not use this setting if you don't
+have both Backspace, Delete and F1 keys."
+  :type 'boolean
+  :group 'editing-basics
+  :version "21.1"
+  :set (lambda (symbol value)
+        ;; The fboundp is because of a problem with :set when
+        ;; dumping Emacs.  It doesn't really matter.
+        (if (fboundp 'delete-key-deletes-forward-mode)
+            (delete-key-deletes-forward-mode (or value 0))
+          (set-default symbol value))))
+
+
+(defun delete-key-deletes-forward-mode (&optional arg)
+  "Toggle Delete key deleting forward or backward.
+With numeric arg, turn the mode on if and only iff ARG is positive.
+For more details, see `delete-key-deletes-forward'."
+  (interactive "P")
+  (setq delete-key-deletes-forward
+       (if arg
+           (> (prefix-numeric-value arg) 0)
+         (not delete-key-deletes-forward)))
+
+  (cond ((or (memq window-system '(x w32 mac pc))
+            (memq system-type '(ms-dos windows-nt)))
+        (if delete-key-deletes-forward
+            (progn
+              (define-key global-map [delete] 'delete-char)
+              (define-key global-map [C-delete] 'kill-word)
+              (define-key esc-map [C-delete] 'kill-sexp)
+              (define-key global-map [C-M-delete] 'kill-sexp))
+          (define-key esc-map [C-delete] 'backward-kill-sexp)
+          (define-key global-map [C-M-delete] 'backward-kill-sexp)
+          (define-key global-map [C-delete] 'backward-kill-word)
+          (define-key global-map [delete] 'delete-backward-char)))
+        (t
+         (if delete-key-deletes-forward
+             (progn
+               (keyboard-translate ?\C-h ?\C-?)
+               (keyboard-translate ?\C-? ?\C-d))
+           (keyboard-translate ?\C-h ?\C-h)
+           (keyboard-translate ?\C-? ?\C-?))))
+
+  (run-hooks 'delete-key-deletes-forward-hook)
+  (if (interactive-p)
+      (message "Delete key deletes %s" 
+              (if delete-key-deletes-forward "forward" "backward"))))
+
+  
+;;; Misc
+
+(defun byte-compiling-files-p ()
+  "Return t if currently byte-compiling files."
+  (and (boundp 'byte-compile-current-file)
+       (stringp byte-compile-current-file)))
+
 ;;; simple.el ends here