]> code.delx.au - gnu-emacs/blobdiff - lisp/simple.el
(ibuffer-forward-line): Just skip header if we're
[gnu-emacs] / lisp / simple.el
index 74821ae31169fbd972edbeecc5963836a4b7f0c7..c8ce9932011dc5746e71c84382160bfa6fbd88c0 100644 (file)
@@ -1,6 +1,6 @@
 ;;; simple.el --- basic editing commands for Emacs
 
-;; Copyright (C) 1985, 86, 87, 93, 94, 95, 96, 97, 98, 99, 2000, 2001
+;; Copyright (C) 1985, 86, 87, 93, 94, 95, 96, 97, 98, 99, 2000, 2001, 2002
 ;;        Free Software Foundation, Inc.
 
 ;; This file is part of GNU Emacs.
@@ -52,9 +52,11 @@ Other major modes are defined by comparison with this one."
 
 (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'.
+If `use-hard-newlines' is non-nil, the newline is marked with the
+text-property `hard'.
 With ARG, insert that many newlines.
-In Auto Fill mode, if no numeric arg, break the preceding line if it's long."
+Call `auto-fill-function' if the current column number is greater
+than the value of `fill-column' and ARG is `nil'."
   (interactive "*P")
   (barf-if-buffer-read-only)
   ;; Inserting a newline at the end of a line produces better redisplay in
@@ -370,7 +372,7 @@ If BACKWARD-ONLY is non-nil, only delete spaces before point."
      (progn
        (skip-chars-forward " \t")
        (constrain-to-field nil orig-pos t)))))
-
+\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.
@@ -431,7 +433,7 @@ 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.
 
@@ -557,7 +559,7 @@ in *Help* buffer.  See also the command `describe-char-after'."
                       (single-key-description char)
                     (buffer-substring-no-properties (point) (1+ (point))))
                   encoding-msg pos total percent col hscroll))))))
-
+\f
 (defvar read-expression-map
   (let ((m (make-sparse-keymap)))
     (define-key m "\M-\t" 'lisp-complete-symbol)
@@ -568,15 +570,17 @@ in *Help* buffer.  See also the command `describe-char-after'."
 (defvar read-expression-history nil)
 
 (defcustom eval-expression-print-level 4
-  "*Value to use for `print-level' when printing value in `eval-expression'."
+  "*Value to use for `print-level' when printing value in `eval-expression'.
+A value of nil means no limit."
   :group 'lisp
-  :type '(choice (const nil) integer)
+  :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 to use for `print-length' when printing value in `eval-expression'.
+A value of nil means no limit."
   :group 'lisp
-  :type '(choice (const nil) integer)
+  :type '(choice (const :tag "No Limit" nil) integer)
   :version "21.1")
 
 (defcustom eval-expression-debug-on-error t
@@ -671,7 +675,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
@@ -882,7 +886,7 @@ Return 0 if current buffer is not a mini-buffer."
   ;; Return the width of everything before the field at the end of
   ;; the buffer; this should be 0 for normal buffers.
   (1- (minibuffer-prompt-end)))
-
+\f
 ;Put this on C-x u, so we can force that rather than C-_ into startup msg
 (defalias 'advertised-undo 'undo)
 
@@ -895,9 +899,13 @@ 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.
-  (setq this-command t)
+  ;; Make last-command indicate for the next command that this was an undo.
+  ;; That way, another undo will undo more.
+  ;; If we get to the end of the undo history and get an error,
+  ;; another undo command will find the undo history empty
+  ;; and will get another error.  To begin undoing the undos,
+  ;; you must type some other command.
+  (setq this-command 'undo)
   (let ((modified (buffer-modified-p))
        (recent-save (recent-auto-save-p)))
     (or (eq (selected-window) (minibuffer-window))
@@ -934,9 +942,7 @@ as an argument limits undo to changes within the current region."
        (setq prev tail tail (cdr tail))))
 
     (and modified (not (buffer-modified-p))
-        (delete-auto-save-file-if-necessary recent-save)))
-  ;; If we do get all the way thru, make this-command indicate that.
-  (setq this-command 'undo))
+        (delete-auto-save-file-if-necessary recent-save))))
 
 (defvar pending-undo-list nil
   "Within a run of consecutive undo commands, list remaining to be undone.")
@@ -1116,34 +1122,6 @@ is not *inside* the region START...END."
            (t
             '(0 . 0)))
     '(0 . 0)))
-
-(defun undo-get-state ()
-  "Return a handler for the current state to which we might want to undo.
-The returned handler can then be passed to `undo-revert-to-handle'."
-  (unless (eq buffer-undo-list t)
-    buffer-undo-list))
-
-(defun undo-revert-to-state (handle)
-  "Revert to the state HANDLE earlier grabbed with `undo-get-handle'.
-This undoing is not itself undoable (aka redoable)."
-  (unless (eq buffer-undo-list t)
-    (let ((new-undo-list (cons (car handle) (cdr handle))))
-      ;; Truncate the undo log at `handle'.
-      (when handle
-       (setcar handle nil) (setcdr handle nil))
-      (unless (eq last-command 'undo) (undo-start))
-      ;; Make sure there's no confusion.
-      (when (and handle (not (eq handle (last pending-undo-list))))
-       (error "Undoing to some unrelated state"))
-      ;; Undo it all.
-      (while pending-undo-list (undo-more 1))
-      ;; Reset the modified cons cell to its original content.
-      (when handle
-       (setcar handle (car new-undo-list))
-       (setcdr handle (cdr new-undo-list)))
-      ;; Revert the undo info to what it was when we grabbed the state.
-      (setq buffer-undo-list handle))))
-  
 \f
 (defvar shell-command-history nil
   "History list for some commands that read shell commands.")
@@ -1186,6 +1164,21 @@ If OUTPUT-BUFFER is not a buffer and not nil,
 insert output in current buffer.  (This cannot be done asynchronously.)
 In either case, the output is inserted after point (leaving mark after it).
 
+If the command terminates without error, but generates output,
+and you did not specify \"insert it in the current buffer\",
+the output can be displayed in the echo area or in its buffer.
+If the output is short enough to display in the echo area
+\(determined by the variable `max-mini-window-height' if
+`resize-mini-windows' is non-nil), it is shown there.  Otherwise,
+the buffer containing the output is displayed.
+
+If there is output and an error, and you did not specify \"insert it
+in the current buffer\", a message about the error goes at the end
+of the output.
+
+If there is no output, or if output is inserted in the current buffer,
+then `*Shell Command Output*' is deleted.
+
 If the optional third argument ERROR-BUFFER is non-nil, it is a buffer
 or buffer name to which to direct the command's standard error output.
 If it is nil, error output is mingled with regular output.
@@ -1204,6 +1197,7 @@ specifies the value of ERROR-BUFFER."
        (funcall handler 'shell-command command output-buffer error-buffer)
       (if (and output-buffer
               (not (or (bufferp output-buffer)  (stringp output-buffer))))
+         ;; Output goes in current buffer.
          (let ((error-file
                 (if error-buffer
                     (make-temp-file
@@ -1244,6 +1238,7 @@ specifies the value of ERROR-BUFFER."
            (goto-char (prog1 (mark t)
                         (set-marker (mark-marker) (point)
                                     (current-buffer)))))
+       ;; Output goes in a separate buffer.
        ;; Preserve the match data in case called from a program.
        (save-match-data
          (if (string-match "[ \t]*&[ \t]*$" command)
@@ -1368,13 +1363,19 @@ REPLACE, ERROR-BUFFER.  Noninteractive callers can specify coding
 systems by binding `coding-system-for-read' and
 `coding-system-for-write'.
 
-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 command generates output, the output may be displayed
+in the echo area or in a buffer.
+If the output is short enough to display in the echo area
+\(determined by the variable `max-mini-window-height' if
+`resize-mini-windows' is non-nil), it is shown there.  Otherwise
+it is displayed in the buffer `*Shell Command Output*'.  The output
+is available in that buffer in both cases.
+
+If there is output and an error, a message about the error
+appears at the end of the output.
+
+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.
@@ -1392,13 +1393,15 @@ or buffer name to which to direct the command's standard error output.
 If it is nil, error output is mingled with regular output.
 In an interactive call, the variable `shell-command-default-error-buffer'
 specifies the value of ERROR-BUFFER."
-  (interactive (let ((string
-                     ;; Do this before calling region-beginning
-                     ;; and region-end, in case subprocess output
-                     ;; relocates them while we are in the minibuffer.
-                     (read-from-minibuffer "Shell command on region: "
-                                           nil nil nil
-                                           'shell-command-history)))
+  (interactive (let (string)
+                (unless (mark)
+                  (error "The mark is not set now, so there is no region"))
+                ;; Do this before calling region-beginning
+                ;; and region-end, in case subprocess output
+                ;; relocates them while we are in the minibuffer.
+                (setq string (read-from-minibuffer "Shell command on region: "
+                                                   nil nil nil
+                                                   'shell-command-history))
                 ;; call-interactively recognizes region-beginning and
                 ;; region-end specially, leaving them in the history.
                 (list (region-beginning) (region-end)
@@ -1421,7 +1424,7 @@ specifies the value of ERROR-BUFFER."
        (let ((swap (and replace (< start end))))
          ;; Don't muck with mark unless REPLACE says we should.
          (goto-char start)
-         (and replace (push-mark))
+         (and replace (push-mark (point) 'nomsg))
          (setq exit-status
                (call-process-region start end shell-file-name t
                                     (if error-file
@@ -1471,16 +1474,25 @@ specifies the value of ERROR-BUFFER."
                                           buffer)
                                         nil shell-command-switch command)))
          (setq success (and exit-status (equal 0 exit-status)))
-         ;; Report the amount of output.
+         ;; Report the output.
+         (with-current-buffer buffer
+           (setq mode-line-process 
+                 (if (not success)
+                   (concat (format " - Exit [%d]" exit-status)))))
          (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"))
+           (let ((output
+                  (if (and error-file
+                           (< 0 (nth 7 (file-attributes error-file))))
+                      "some error output"
+                    "no output")))
+             (if (equal 0 exit-status)
+                 (message "(Shell command succeeded with %s)"
+                          output)
+               (message "(Shell command failed with code %d and %s)"
+                        exit-status output)))
            ;; Don't kill: there might be useful info in the undo-log.
            ;; (kill-buffer buffer)
            ))))
@@ -1507,7 +1519,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)
@@ -1623,7 +1635,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
@@ -1660,7 +1672,7 @@ most recent string, the function should return nil.  If it is
 difficult to tell whether Emacs or some other program provided the
 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.
@@ -1685,7 +1697,7 @@ ring directly.")
 
 (defun kill-new (string &optional replace)
   "Make STRING the latest kill in the kill ring.
-Set the kill-ring-yank pointer to point to it.
+Set `kill-ring-yank-pointer' to point to it.
 If `interprogram-cut-function' is non-nil, apply it to STRING.
 Optional second argument REPLACE non-nil means that STRING will replace
 the front of the kill ring, rather than being added to the list."
@@ -1707,7 +1719,8 @@ If `interprogram-cut-function' is set, pass the resulting kill to
 it."
   (kill-new (if before-p
                (concat string (car kill-ring))
-             (concat (car kill-ring) string)) t))
+             (concat (car kill-ring) string))
+           t))
 
 (defun current-kill (n &optional do-not-move)
   "Rotate the yanking point by N places, and then return that kill.
@@ -1917,7 +1930,9 @@ See also the command \\[yank-pop]."
                           ((eq arg '-) -1)
                           (t (1- arg)))))
     (let ((inhibit-read-only t))
-      (remove-text-properties opoint (point) '(read-only nil))))
+      ;; Clear `field' property for the sake of copying from the
+      ;; minibuffer prompt or a *shell* prompt.
+      (remove-text-properties opoint (point) '(read-only nil field nil))))
   (if (consp arg)
       ;; This is like exchange-point-and-mark, but doesn't activate the mark.
       ;; It is cleaner to avoid activation, even though the command
@@ -1933,7 +1948,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
@@ -2114,7 +2129,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.
@@ -2196,7 +2211,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")
 
@@ -2401,14 +2416,14 @@ the Transient Mark mode."
        (widen))
     (goto-char position)
     (switch-to-buffer buffer)))
-
+\f
 (defcustom next-line-add-newlines nil
   "*If non-nil, `next-line' inserts newline to avoid `end of buffer' error."
   :type 'boolean
   :version "21.1"
   :group 'editing-basics)
 
-(defun next-line (arg)
+(defun next-line (&optional arg)
   "Move cursor vertically down ARG lines.
 If there is no character in the target line exactly under the current column,
 the cursor is positioned after the character in that line which spans this
@@ -2429,6 +2444,7 @@ If you are thinking of using this in a Lisp program, consider
 using `forward-line' instead.  It is usually easier to use
 and more reliable (no dependence on goal column, etc.)."
   (interactive "p")
+  (unless arg (setq arg 1))
   (if (and next-line-add-newlines (= arg 1))
       (if (save-excursion (end-of-line) (eobp))
          ;; When adding a newline, don't expand an abbrev.
@@ -2443,7 +2459,7 @@ and more reliable (no dependence on goal column, etc.)."
       (line-move arg)))
   nil)
 
-(defun previous-line (arg)
+(defun previous-line (&optional arg)
   "Move cursor vertically up ARG lines.
 If there is no character in the target line exactly over the current column,
 the cursor is positioned after the character in that line which spans this
@@ -2460,6 +2476,7 @@ If you are thinking of using this in a Lisp program, consider using
 `forward-line' with a negative argument instead.  It is usually easier
 to use and more reliable (no dependence on goal column, etc.)."
   (interactive "p")
+  (unless arg (setq arg 1))
   (if (interactive-p)
       (condition-case nil
          (line-move (- arg))
@@ -2493,6 +2510,15 @@ Outline mode sets this."
   :type 'boolean
   :group 'editing-basics)
 
+(defun line-move-invisible (pos)
+  "Return non-nil if the character after POS is currently invisible."
+  (let ((prop
+        (get-char-property pos 'invisible)))
+    (if (eq buffer-invisibility-spec t)
+       prop
+      (or (memq prop buffer-invisibility-spec)
+         (assq prop buffer-invisibility-spec)))))
+
 ;; This is the guts of next-line and previous-line.
 ;; Arg says how many lines to move.
 (defun line-move (arg)
@@ -2503,8 +2529,7 @@ Outline mode sets this."
        new line-end line-beg)
     (unwind-protect
        (progn
-         (if (not (or (eq last-command 'next-line)
-                      (eq last-command 'previous-line)))
+         (if (not (memq last-command '(next-line previous-line)))
              (setq temporary-goal-column
                    (if (and track-eol (eolp)
                             ;; Don't count beg of empty line as end of line
@@ -2515,98 +2540,125 @@ Outline mode sets this."
          (if (and (not (integerp selective-display))
                   (not line-move-ignore-invisible))
              ;; Use just newline characters.
+             ;; Set ARG to 0 if we move as many lines as requested.
              (or (if (> arg 0)
                      (progn (if (> arg 1) (forward-line (1- arg)))
                             ;; This way of moving forward ARG lines
                             ;; verifies that we have a newline after the last one.
                             ;; It doesn't get confused by intangible text.
                             (end-of-line)
-                            (zerop (forward-line 1)))
+                            (if (zerop (forward-line 1))
+                                (setq arg 0)))
                    (and (zerop (forward-line arg))
-                        (bolp)))
+                        (bolp)
+                        (setq arg 0)))
                  (signal (if (< arg 0)
                              'beginning-of-buffer
                            'end-of-buffer)
                          nil))
            ;; Move by arg lines, but ignore invisible ones.
            (while (> arg 0)
+             ;; If the following character is currently invisible,
+             ;; skip all characters with that same `invisible' property value.
+             (while (and (not (eobp)) (line-move-invisible (point)))
+               (goto-char (next-char-property-change (point))))
+             ;; Now move a line.
              (end-of-line)
              (and (zerop (vertical-motion 1))
                   (signal 'end-of-buffer nil))
-             ;; If the following character is currently invisible,
-             ;; skip all characters with that same `invisible' property value.
-             (while (and (not (eobp))
-                         (let ((prop
-                                (get-char-property (point) 'invisible)))
-                           (if (eq buffer-invisibility-spec t)
-                               prop
-                             (or (memq prop buffer-invisibility-spec)
-                                 (assq prop buffer-invisibility-spec)))))
-               (if (get-text-property (point) 'invisible)
-                   (goto-char (next-single-property-change (point) 'invisible))
-                 (goto-char (next-overlay-change (point)))))
              (setq arg (1- arg)))
            (while (< arg 0)
              (beginning-of-line)
              (and (zerop (vertical-motion -1))
                   (signal 'beginning-of-buffer nil))
-             (while (and (not (bobp))
-                         (let ((prop
-                                (get-char-property (1- (point)) 'invisible)))
-                           (if (eq buffer-invisibility-spec t)
-                               prop
-                             (or (memq prop buffer-invisibility-spec)
-                                 (assq prop buffer-invisibility-spec)))))
-               (if (get-text-property (1- (point)) 'invisible)
-                   (goto-char (previous-single-property-change (point) 'invisible))
-                 (goto-char (previous-overlay-change (point)))))
-             (setq arg (1+ arg))))
-         (let ((buffer-invisibility-spec nil))
-           (move-to-column (or goal-column temporary-goal-column))))
-      (setq new (point))
-      ;; If we are moving into some intangible text,
-      ;; look for following text on the same line which isn't intangible
-      ;; and move there.
-      (setq line-end (save-excursion (end-of-line) (point)))
-      (setq line-beg (save-excursion (beginning-of-line) (point)))
-      (let ((after (and (< new (point-max))
-                       (get-char-property new 'intangible)))
-           (before (and (> new (point-min))
-                        (get-char-property (1- new) 'intangible))))
-       (when (and before (eq before after)
-                  (not (bolp)))
-         (goto-char (point-min))
-         (let ((inhibit-point-motion-hooks nil))
-           (goto-char new))
-         (if (<= new line-end)
-             (setq new (point)))))
-      ;; NEW is where we want to move to.
-      ;; LINE-BEG and LINE-END are the beginning and end of the line.
-      ;; Move there in just one step, from our starting position,
-      ;; 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 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))
-       (setq new (point))
-       (setq inhibit-point-motion-hooks t)
-       (setq line-end (save-excursion (end-of-line) (point)))
-       (beginning-of-line)
-       (setq line-beg (point))
-       (let ((buffer-invisibility-spec nil))
-         (move-to-column (or goal-column temporary-goal-column)))
-       (if (<= (point) line-end)
-           (setq new (point)))
-       (goto-char (point-min))
-       (setq inhibit-point-motion-hooks nil)
-       (goto-char
-        (constrain-to-field new opoint nil t
-                            'inhibit-line-move-field-capture)))))
+             (setq arg (1+ arg))
+             (while (and (not (bobp)) (line-move-invisible (1- (point))))
+               (goto-char (previous-char-property-change (point)))))))
+
+      (cond ((> arg 0)
+            ;; If we did not move down as far as desired,
+            ;; at least go to end of line.
+            (end-of-line))
+           ((< arg 0)
+            ;; If we did not move down as far as desired,
+            ;; at least go to end of line.
+            (beginning-of-line))
+           (t
+            (line-move-finish (or goal-column temporary-goal-column) opoint)))))
   nil)
 
+(defun line-move-finish (column opoint)
+  (let ((repeat t))
+    (while repeat
+      ;; Set REPEAT to t to repeat the whole thing.
+      (setq repeat nil)
+
+      ;; Move to the desired column.
+      (line-move-to-column column)
+
+      (let ((new (point))
+           (line-beg (save-excursion (beginning-of-line) (point)))
+           (line-end (save-excursion (end-of-line) (point))))
+
+       ;; Process intangibility within a line.
+       ;; Move to the chosen destination position from above,
+       ;; with intangibility processing enabled.
+
+       (goto-char (point-min))
+       (let ((inhibit-point-motion-hooks nil))
+         (goto-char new)
+
+         ;; If intangibility moves us to a different (later) place
+         ;; in the same line, use that as the destination.
+         (if (<= (point) line-end)
+             (setq new (point))))
+
+       ;; Now move to the updated destination, processing fields
+       ;; as well as intangibility.
+       (goto-char opoint)
+       (let ((inhibit-point-motion-hooks nil))
+         (goto-char
+          (constrain-to-field new opoint nil t
+                              'inhibit-line-move-field-capture)))
+
+       ;; If intangibility processing moved us to a different line,
+       ;; retry everything within that new line.
+       (when (or (< (point) line-beg) (> (point) line-end))
+         ;; Repeat the intangibility and field processing.
+         (setq repeat t))))))
+
+(defun line-move-to-column (col)
+  "Try to find column COL, considering invisibility.
+This function works only in certain cases,
+because what we really need is for `move-to-column'
+and `current-column' to be able to ignore invisible text."
+  (if (zerop col)
+      (beginning-of-line)
+    (move-to-column col))
+
+  (when (and line-move-ignore-invisible
+            (not (bolp)) (line-move-invisible (1- (point))))
+    (let ((normal-location (point))
+         (normal-column (current-column)))
+      ;; If the following character is currently invisible,
+      ;; skip all characters with that same `invisible' property value.
+      (while (and (not (eobp))
+                 (line-move-invisible (point)))
+       (goto-char (next-char-property-change (point))))
+      ;; Have we advanced to a larger column position?
+      (if (> (current-column) normal-column)
+         ;; We have made some progress towards the desired column.
+         ;; See if we can make any further progress.
+         (line-move-to-column (+ (current-column) (- col normal-column)))
+       ;; Otherwise, go to the place we originally found
+       ;; and move back over invisible text.
+       ;; that will get us to the same place on the screen
+       ;; but with a more reasonable buffer position.
+       (goto-char normal-location)
+       (let ((line-beg (save-excursion (beginning-of-line) (point))))
+         (while (and (not (bolp)) (line-move-invisible (1- (point))))
+           (goto-char (previous-char-property-change (point) line-beg))))))))
+
 ;;; Many people have said they rarely use this feature, and often type
 ;;; it by accident.  Maybe it shouldn't even be on a key.
 (put 'set-goal-column 'disabled t)
@@ -2628,7 +2680,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.
@@ -2674,7 +2726,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
@@ -2690,6 +2742,7 @@ With prefix arg ARG, effect is to take word before or around point
 and drag it forward past ARG other words (backward if ARG negative).
 If ARG is zero, the words around or after point and around or after mark
 are interchanged."
+  ;; FIXME: `foo a!nd bar' should transpose into `bar and foo'.
   (interactive "*p")
   (transpose-subr 'forward-word arg))
 
@@ -2698,7 +2751,35 @@ are interchanged."
 Does not work on a sexp that point is in the middle of
 if it is a list or string."
   (interactive "*p")
-  (transpose-subr 'forward-sexp arg))
+  (transpose-subr
+   (lambda (arg)
+     ;; Here we should try to simulate the behavior of
+     ;; (cons (progn (forward-sexp x) (point))
+     ;;       (progn (forward-sexp (- x)) (point)))
+     ;; Except that we don't want to rely on the second forward-sexp
+     ;; putting us back to where we want to be, since forward-sexp-function
+     ;; might do funny things like infix-precedence.
+     (if (if (> arg 0)
+            (looking-at "\\sw\\|\\s_")
+          (and (not (bobp))
+               (save-excursion (forward-char -1) (looking-at "\\sw\\|\\s_"))))
+        ;; Jumping over a symbol.  We might be inside it, mind you.
+        (progn (funcall (if (> arg 0)
+                            'skip-syntax-backward 'skip-syntax-forward)
+                        "w_")
+               (cons (save-excursion (forward-sexp arg) (point)) (point)))
+       ;; Otherwise, we're between sexps.  Take a step back before jumping
+       ;; to make sure we'll obey the same precedence no matter which direction
+       ;; we're going.
+       (funcall (if (> arg 0) 'skip-syntax-backward 'skip-syntax-forward) " .")
+       (cons (save-excursion (forward-sexp arg) (point))
+            (progn (while (or (forward-comment (if (> arg 0) 1 -1))
+                              (not (zerop (funcall (if (> arg 0)
+                                                       'skip-syntax-forward
+                                                     'skip-syntax-backward)
+                                                   ".")))))
+                   (point)))))
+   arg 'special))
 
 (defun transpose-lines (arg)
   "Exchange current line and previous line, leaving point after both.
@@ -2751,12 +2832,14 @@ With argument 0, interchanges line point is in with line mark is in."
     (let ((swap pos1))
       (setq pos1 pos2 pos2 swap)))
   (if (> (cdr pos1) (car pos2)) (error "Don't have two things to transpose"))
-  (let ((word2 (delete-and-extract-region (car pos2) (cdr pos2))))
-    (goto-char (car pos2))
-    (insert (delete-and-extract-region (car pos1) (cdr pos1)))
-    (goto-char (car pos1))
-    (insert word2)))
-
+  (atomic-change-group
+   (let (word2)
+     (setq word2 (delete-and-extract-region (car pos2) (cdr pos2)))
+     (goto-char (car pos2))
+     (insert (delete-and-extract-region (car pos1) (cdr pos1)))
+     (goto-char (car pos1))
+     (insert word2))))
+\f
 (defun backward-word (arg)
   "Move backward until encountering the beginning of a word.
 With argument, do this that many times."
@@ -2764,13 +2847,22 @@ With argument, do this that many times."
   (forward-word (- arg)))
 
 (defun mark-word (arg)
-  "Set mark arg words away from point."
+  "Set mark arg words away from point.
+If this command is repeated, it marks the next ARG words after the ones
+already marked."
   (interactive "p")
-  (push-mark
-    (save-excursion
-      (forward-word arg)
-      (point))
-    nil t))
+  (cond ((and (eq last-command this-command) (mark t))
+        (set-mark
+         (save-excursion
+           (goto-char (mark))
+           (forward-word arg)
+           (point))))
+       (t
+        (push-mark
+         (save-excursion
+           (forward-word arg)
+           (point))
+         nil t))))
 
 (defun kill-word (arg)
   "Kill characters forward until encountering the end of a word.
@@ -2816,7 +2908,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."
   :type '(choice (const :tag "None" nil)
@@ -2876,9 +2968,7 @@ Setting this variable automatically makes it local to the current buffer.")
        ;; Determine where to split the line.
        (let* (after-prefix
               (fill-point
-               (let ((opoint (point))
-                     bounce
-                     (first t))
+               (let ((opoint (point)))
                  (save-excursion
                    (beginning-of-line)
                    (setq after-prefix (point))
@@ -2886,87 +2976,50 @@ Setting this variable automatically makes it local to the current buffer.")
                         (looking-at (regexp-quote fill-prefix))
                         (setq after-prefix (match-end 0)))
                    (move-to-column (1+ fc))
-                   ;; Move back to the point where we can break the line.
-                   ;; We break the line between word or
-                   ;; after/before the character which has character
-                   ;; category `|'.  We search space, \c| followed by
-                   ;; a character, or \c| following a character.  If
-                   ;; not found, place the point at beginning of line.
-                   (while (or first
-                              (and (not (bobp))
-                                   (not bounce)
-                                   (fill-nobreak-p)))
-                     (setq first nil)
-                     (re-search-backward "[ \t]\\|\\c|.\\|.\\c|\\|^")
-                     ;; If we find nowhere on the line to break it,
-                     ;; break after one word.  Set bounce to t
-                     ;; so we will not keep going in this while loop.
-                     (if (<= (point) after-prefix)
-                         (progn
-                           (goto-char after-prefix)
-                           (re-search-forward "[ \t]" opoint t)
-                           (setq bounce t))
-                       (if (looking-at "[ \t]")
-                           ;; Break the line at word boundary.
-                           (skip-chars-backward " \t")
-                         ;; Break the line after/before \c|.
-                         (forward-char 1))))
-                   (if enable-multibyte-characters
-                       ;; If we are going to break the line after or
-                       ;; before a non-ascii character, we may have
-                       ;; to run a special function for the charset
-                       ;; of the character to find the correct break
-                       ;; point.
-                       (if (not (and (eq (charset-after (1- (point))) 'ascii)
-                                     (eq (charset-after (point)) 'ascii)))
-                           (fill-find-break-point after-prefix)))
-
-                   ;; Let fill-point be set to the place where we end up.
-                   ;; But move back before any whitespace here.
-                   (skip-chars-backward " \t")
+                   (fill-move-to-break-point after-prefix)
                    (point)))))
 
          ;; See whether the place we found is any good.
          (if (save-excursion
                (goto-char fill-point)
-               (and (not (bolp))
-                    ;; There is no use breaking at end of line.
-                    (not (save-excursion (skip-chars-forward " ") (eolp)))
-                    ;; It is futile to split at the end of the prefix
-                    ;; since we would just insert the prefix again.
-                    (not (and after-prefix (<= (point) after-prefix)))
-                    ;; Don't split right after a comment starter
-                    ;; since we would just make another comment starter.
-                    (not (and comment-start-skip
-                              (let ((limit (point)))
-                                (beginning-of-line)
-                                (and (re-search-forward comment-start-skip
-                                                        limit t)
-                                     (eq (point) limit)))))))
-             ;; Ok, we have a useful place to break the line.  Do it.
-             (let ((prev-column (current-column)))
-               ;; If point is at the fill-point, do not `save-excursion'.
-               ;; Otherwise, if a comment prefix or fill-prefix is inserted,
-               ;; point will end up before it rather than after it.
-               (if (save-excursion
-                     (skip-chars-backward " \t")
-                     (= (point) fill-point))
-                   (funcall comment-line-break-function t)
+               (or (bolp)
+                   ;; There is no use breaking at end of line.
+                   (save-excursion (skip-chars-forward " ") (eolp))
+                   ;; It is futile to split at the end of the prefix
+                   ;; since we would just insert the prefix again.
+                   (and after-prefix (<= (point) after-prefix))
+                   ;; Don't split right after a comment starter
+                   ;; since we would just make another comment starter.
+                   (and comment-start-skip
+                        (let ((limit (point)))
+                          (beginning-of-line)
+                          (and (re-search-forward comment-start-skip
+                                                  limit t)
+                               (eq (point) limit))))))
+             ;; No good place to break => stop trying.
+             (setq give-up t)
+           ;; Ok, we have a useful place to break the line.  Do it.
+           (let ((prev-column (current-column)))
+             ;; If point is at the fill-point, do not `save-excursion'.
+             ;; Otherwise, if a comment prefix or fill-prefix is inserted,
+             ;; point will end up before it rather than after it.
+             (if (save-excursion
+                   (skip-chars-backward " \t")
+                   (= (point) fill-point))
+                 (funcall comment-line-break-function t)
+               (save-excursion
+                 (goto-char fill-point)
+                 (funcall comment-line-break-function t)))
+             ;; Now do justification, if required
+             (if (not (eq justify 'left))
                  (save-excursion
-                   (goto-char fill-point)
-                   (funcall comment-line-break-function t)))
-               ;; Now do justification, if required
-               (if (not (eq justify 'left))
-                   (save-excursion
                    (end-of-line 0)
                    (justify-current-line justify nil t)))
-               ;; If making the new line didn't reduce the hpos of
-               ;; the end of the line, then give up now;
-               ;; trying again will not help.
-               (if (>= (current-column) prev-column)
-                   (setq give-up t)))
-           ;; No good place to break => stop trying.
-           (setq give-up t))))
+             ;; If making the new line didn't reduce the hpos of
+             ;; the end of the line, then give up now;
+             ;; trying again will not help.
+             (if (>= (current-column) prev-column)
+                 (setq give-up t))))))
       ;; Justify last line.
       (justify-current-line justify t t)
       t)))
@@ -3019,7 +3072,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
 (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,
@@ -3119,7 +3172,7 @@ in the mode line."
        (if (null arg) (not column-number-mode)
          (> (prefix-numeric-value arg) 0)))
   (force-mode-line-update))
-
+\f
 (defgroup paren-blinking nil
   "Blinking matching of parens and expressions."
   :prefix "blink-matching-"
@@ -3234,7 +3287,7 @@ when it is off screen)."
 
 ;Turned off because it makes dbx bomb out.
 (setq blink-paren-function 'blink-matching-open)
-
+\f
 ;; This executes C-g typed while Emacs is waiting for a command.
 ;; Quitting out of a program does not go through here;
 ;; that happens in the QUIT macro at the C code level.
@@ -3278,6 +3331,19 @@ or go back to just one window (by deleting all but the selected window)."
        ((string-match "^ \\*" (buffer-name (current-buffer)))
         (bury-buffer))))
 
+(defun play-sound-file (file &optional volume device)
+  "Play sound stored in FILE.
+VOLUME and DEVICE correspond to the keywords of the sound
+specification for `play-sound'."
+  (interactive "fPlay sound file: ")
+  (let ((sound (list :file file)))
+    (if volume
+       (plist-put sound :volume volume))
+    (if device
+       (plist-put sound :device device))
+    (push 'sound sound)
+    (play-sound sound)))
+
 (define-key global-map "\e\e\e" 'keyboard-escape-quit)
 
 (defcustom read-mail-command 'rmail
@@ -3870,24 +3936,25 @@ Returns nil if PROCESS has already terminated."
       (setq newname (substring newname 0 (match-beginning 0))))
   (when (memq (process-status process) '(run stop open))
     (let* ((process-connection-type (process-tty-name process))
-          (old-kwoq (process-kill-without-query process nil))
           (new-process
            (if (memq (process-status process) '(open))
-               (apply 'open-network-stream newname
-                      (if (process-buffer process) (current-buffer))
-                      (process-contact process))
+               (let ((args (process-contact process t)))
+                 (setq args (plist-put args :name newname))
+                 (setq args (plist-put args :buffer
+                                       (if (process-buffer process) (current-buffer))))
+                 (apply 'make-network-process args))
              (apply 'start-process newname
                     (if (process-buffer process) (current-buffer))
                     (process-command process)))))
-      (process-kill-without-query new-process old-kwoq)
-      (process-kill-without-query process old-kwoq)
+      (set-process-query-on-exit-flag
+       new-process (process-query-on-exit-flag process))
       (set-process-inherit-coding-system-flag
        new-process (process-inherit-coding-system-flag process))
       (set-process-filter new-process (process-filter process))
       (set-process-sentinel new-process (process-sentinel process))
       new-process)))
 
-;; things to maybe add (currently partly covered by `funcall mode':
+;; things to maybe add (currently partly covered by `funcall mode'):
 ;; - syntax-table
 ;; - overlays
 (defun clone-buffer (&optional newname display-flag)
@@ -4001,34 +4068,6 @@ the front of the list of recently selected ones."
 (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 normal-erase-is-backspace nil
@@ -4141,6 +4180,88 @@ See also `normal-erase-is-backspace'."
               (if normal-erase-is-backspace "forward" "backward"))))
 
 
+;;; make-network-process wrappers
+
+(if (featurep 'make-network-process)
+    (progn
+
+(defun open-network-stream (name buffer host service)
+  "Open a TCP connection for a service to a host.
+Returns a subprocess-object to represent the connection.
+Input and output work as for subprocesses; `delete-process' closes it.
+Args are NAME BUFFER HOST SERVICE.
+NAME is name for process.  It is modified if necessary to make it unique.
+BUFFER is the buffer (or buffer-name) to associate with the process.
+ Process output goes at end of that buffer, unless you specify
+ an output stream or filter function to handle the output.
+ BUFFER may be also nil, meaning that this process is not associated
+ with any buffer
+Third arg is name of the host to connect to, or its IP address.
+Fourth arg SERVICE is name of the service desired, or an integer
+specifying a port number to connect to."
+  (make-network-process :name name :buffer buffer
+                       :host host :service service))
+
+(defun open-network-stream-nowait (name buffer host service &optional sentinel filter)
+  "Initiate connection to a TCP connection for a service to a host.
+It returns nil if non-blocking connects are not supported; otherwise,
+it returns a subprocess-object to represent the connection.
+
+This function is similar to `open-network-stream', except that this
+function returns before the connection is established.  When the
+connection is completed, the sentinel function will be called with
+second arg matching `open' (if successful) or `failed' (on error).
+
+Args are NAME BUFFER HOST SERVICE SENTINEL FILTER.
+NAME, BUFFER, HOST, and SERVICE are as for `open-network-stream'.
+Optional args, SENTINEL and FILTER specifies the sentinel and filter
+functions to be used for this network stream."
+  (if (featurep 'make-network-process  '(:nowait t))
+      (make-network-process :name name :buffer buffer :nowait t
+                           :host host :service service
+                           :filter filter :sentinel sentinel)))
+
+(defun open-network-stream-server (name buffer service &optional sentinel filter)
+  "Create a network server process for a TCP service.
+It returns nil if server processes are not supported; otherwise,
+it returns a subprocess-object to represent the server.
+
+When a client connects to the specified service, a new subprocess
+is created to handle the new connection, and the sentinel function
+is called for the new process.
+
+Args are NAME BUFFER SERVICE SENTINEL FILTER.
+NAME is name for the server process.  Client processes are named by
+appending the ip-address and port number of the client to NAME.
+BUFFER is the buffer (or buffer-name) to associate with the server
+process.  Client processes will not get a buffer if a process filter
+is specified or BUFFER is nil; otherwise, a new buffer is created for
+the client process.  The name is similar to the process name.
+Third arg SERVICE is name of the service desired, or an integer
+specifying a port number to connect to.  It may also be t to selected
+an unused port number for the server.
+Optional args, SENTINEL and FILTER specifies the sentinel and filter
+functions to be used for the client processes; the server process
+does not use these function."
+  (if (featurep 'make-network-process '(:server t))
+      (make-network-process :name name :buffer buffer
+                           :service service :server t :noquery t)))
+
+))  ;; (featurep 'make-network-process)
+
+
+;; compatibility
+
+(defun process-kill-without-query (process &optional flag)
+  "Say no query needed if PROCESS is running when Emacs is exited.
+Optional second argument if non-nil says to require a query.
+Value is t if a query was formerly required.  
+New code should not use this function; use `process-query-on-exit-flag'
+or `set-process-query-on-exit-flag' instead."
+  (let ((old (process-query-on-exit-flag process)))
+    (set-process-query-on-exit-flag process nil)
+    old))
+
 ;;; Misc
 
 (defun byte-compiling-files-p ()