]> code.delx.au - gnu-emacs/blobdiff - lisp/simple.el
Merge from emacs--devo--0
[gnu-emacs] / lisp / simple.el
index 7faa05476876fb27646532f6d8bf8c74de5e88bd..27d7abfc8e75d8c798f37a6a851a4ccf9e464525 100644 (file)
@@ -10,7 +10,7 @@
 
 ;; GNU Emacs is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
 
 ;; GNU Emacs is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
+;; the Free Software Foundation; either version 3, or (at your option)
 ;; any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
@@ -156,6 +156,15 @@ If `fringe-arrow', indicate the locus by the fringe arrow."
   :group 'next-error
   :version "22.1")
 
   :group 'next-error
   :version "22.1")
 
+(defcustom next-error-recenter nil
+  "*Display the line in the visited source file recentered as specified.
+If non-nil, the value is passed directly to `recenter'."
+  :type '(choice (integer :tag "Line to recenter to")
+                 (const :tag "Center of window" (4))
+                 (const :tag "No recentering" nil))
+  :group 'next-error
+  :version "23.1")
+
 (defcustom next-error-hook nil
   "*List of hook functions run by `next-error' after visiting source file."
   :type 'hook
 (defcustom next-error-hook nil
   "*List of hook functions run by `next-error' after visiting source file."
   :type 'hook
@@ -305,6 +314,8 @@ See variables `compilation-parse-errors-function' and
     ;; we know here that next-error-function is a valid symbol we can funcall
     (with-current-buffer next-error-last-buffer
       (funcall next-error-function (prefix-numeric-value arg) reset)
     ;; we know here that next-error-function is a valid symbol we can funcall
     (with-current-buffer next-error-last-buffer
       (funcall next-error-function (prefix-numeric-value arg) reset)
+      (when next-error-recenter
+        (recenter next-error-recenter))
       (run-hooks 'next-error-hook))))
 
 (defun next-error-internal ()
       (run-hooks 'next-error-hook))))
 
 (defun next-error-internal ()
@@ -313,6 +324,8 @@ See variables `compilation-parse-errors-function' and
   ;; we know here that next-error-function is a valid symbol we can funcall
   (with-current-buffer next-error-last-buffer
     (funcall next-error-function 0 nil)
   ;; we know here that next-error-function is a valid symbol we can funcall
   (with-current-buffer next-error-last-buffer
     (funcall next-error-function 0 nil)
+    (when next-error-recenter
+      (recenter next-error-recenter))
     (run-hooks 'next-error-hook)))
 
 (defalias 'goto-next-locus 'next-error)
     (run-hooks 'next-error-hook)))
 
 (defalias 'goto-next-locus 'next-error)
@@ -950,9 +963,9 @@ in *Help* buffer.  See also the command `describe-char'."
        (if (or (not coding)
                (eq (coding-system-type coding) t))
            (setq coding default-buffer-file-coding-system))
        (if (or (not coding)
                (eq (coding-system-type coding) t))
            (setq coding default-buffer-file-coding-system))
-       (if (not (char-valid-p char))
+       (if (eq (char-charset char) 'eight-bit)
            (setq encoding-msg
            (setq encoding-msg
-                 (format "(%d, #o%o, #x%x, invalid)" char char char))
+                 (format "(%d, #o%o, #x%x, raw-byte)" char char char))
          ;; Check if the character is displayed with some `display'
          ;; text property.  In that case, set under-display to the
          ;; buffer substring covered by that property.
          ;; Check if the character is displayed with some `display'
          ;; text property.  In that case, set under-display to the
          ;; buffer substring covered by that property.
@@ -1287,55 +1300,61 @@ makes the search case-sensitive."
 
 (defvar minibuffer-temporary-goal-position nil)
 
 
 (defvar minibuffer-temporary-goal-position nil)
 
+(defun goto-history-element (nabs)
+  "Puts element of the minibuffer history in the minibuffer.
+The argument NABS specifies the absolute history position."
+  (interactive "p")
+  (let ((minimum (if minibuffer-default -1 0))
+       elt minibuffer-returned-to-present)
+    (if (and (zerop minibuffer-history-position)
+            (null minibuffer-text-before-history))
+       (setq minibuffer-text-before-history
+             (minibuffer-contents-no-properties)))
+    (if (< nabs minimum)
+       (if minibuffer-default
+           (error "End of history; no next item")
+         (error "End of history; no default available")))
+    (if (> nabs (length (symbol-value minibuffer-history-variable)))
+       (error "Beginning of history; no preceding item"))
+    (unless (memq last-command '(next-history-element
+                                previous-history-element))
+      (let ((prompt-end (minibuffer-prompt-end)))
+       (set (make-local-variable 'minibuffer-temporary-goal-position)
+            (cond ((<= (point) prompt-end) prompt-end)
+                  ((eobp) nil)
+                  (t (point))))))
+    (goto-char (point-max))
+    (delete-minibuffer-contents)
+    (setq minibuffer-history-position nabs)
+    (cond ((= nabs -1)
+          (setq elt minibuffer-default))
+         ((= nabs 0)
+          (setq elt (or minibuffer-text-before-history ""))
+          (setq minibuffer-returned-to-present t)
+          (setq minibuffer-text-before-history nil))
+         (t (setq elt (nth (1- minibuffer-history-position)
+                           (symbol-value minibuffer-history-variable)))))
+    (insert
+     (if (and (eq minibuffer-history-sexp-flag (minibuffer-depth))
+             (not minibuffer-returned-to-present))
+        (let ((print-level nil))
+          (prin1-to-string elt))
+       elt))
+    (goto-char (or minibuffer-temporary-goal-position (point-max)))))
+
 (defun next-history-element (n)
   "Puts next element of the minibuffer history in the minibuffer.
 With argument N, it uses the Nth following element."
   (interactive "p")
   (or (zerop n)
 (defun next-history-element (n)
   "Puts next element of the minibuffer history in the minibuffer.
 With argument N, it uses the Nth following element."
   (interactive "p")
   (or (zerop n)
-      (let ((narg (- minibuffer-history-position n))
-           (minimum (if minibuffer-default -1 0))
-           elt minibuffer-returned-to-present)
-       (if (and (zerop minibuffer-history-position)
-                (null minibuffer-text-before-history))
-           (setq minibuffer-text-before-history
-                 (minibuffer-contents-no-properties)))
-       (if (< narg minimum)
-           (if minibuffer-default
-               (error "End of history; no next item")
-             (error "End of history; no default available")))
-       (if (> narg (length (symbol-value minibuffer-history-variable)))
-           (error "Beginning of history; no preceding item"))
-       (unless (memq last-command '(next-history-element
-                                    previous-history-element))
-         (let ((prompt-end (minibuffer-prompt-end)))
-           (set (make-local-variable 'minibuffer-temporary-goal-position)
-                (cond ((<= (point) prompt-end) prompt-end)
-                      ((eobp) nil)
-                      (t (point))))))
-       (goto-char (point-max))
-       (delete-minibuffer-contents)
-       (setq minibuffer-history-position narg)
-       (cond ((= narg -1)
-              (setq elt minibuffer-default))
-             ((= narg 0)
-              (setq elt (or minibuffer-text-before-history ""))
-              (setq minibuffer-returned-to-present t)
-              (setq minibuffer-text-before-history nil))
-             (t (setq elt (nth (1- minibuffer-history-position)
-                               (symbol-value minibuffer-history-variable)))))
-       (insert
-        (if (and (eq minibuffer-history-sexp-flag (minibuffer-depth))
-                 (not minibuffer-returned-to-present))
-            (let ((print-level nil))
-              (prin1-to-string elt))
-          elt))
-       (goto-char (or minibuffer-temporary-goal-position (point-max))))))
+      (goto-history-element (- minibuffer-history-position n))))
 
 (defun previous-history-element (n)
   "Puts previous element of the minibuffer history in the minibuffer.
 With argument N, it uses the Nth previous element."
   (interactive "p")
 
 (defun previous-history-element (n)
   "Puts previous element of the minibuffer history in the minibuffer.
 With argument N, it uses the Nth previous element."
   (interactive "p")
-  (next-history-element (- n)))
+  (or (zerop n)
+      (goto-history-element (+ minibuffer-history-position n))))
 
 (defun next-complete-history-element (n)
   "Get next history element which completes the minibuffer before the point.
 
 (defun next-complete-history-element (n)
   "Get next history element which completes the minibuffer before the point.
@@ -1368,6 +1387,137 @@ Return 0 if current buffer is not a minibuffer."
   ;; the buffer; this should be 0 for normal buffers.
   (1- (minibuffer-prompt-end)))
 \f
   ;; the buffer; this should be 0 for normal buffers.
   (1- (minibuffer-prompt-end)))
 \f
+;; isearch minibuffer history
+(add-hook 'minibuffer-setup-hook 'minibuffer-history-isearch-setup)
+
+(defvar minibuffer-history-isearch-message-overlay)
+(make-variable-buffer-local 'minibuffer-history-isearch-message-overlay)
+
+(defun minibuffer-history-isearch-setup ()
+  "Set up a minibuffer for using isearch to search the minibuffer history.
+Intended to be added to `minibuffer-setup-hook'."
+  (set (make-local-variable 'isearch-search-fun-function)
+       'minibuffer-history-isearch-search)
+  (set (make-local-variable 'isearch-message-function)
+       'minibuffer-history-isearch-message)
+  (set (make-local-variable 'isearch-wrap-function)
+       'minibuffer-history-isearch-wrap)
+  (set (make-local-variable 'isearch-push-state-function)
+       'minibuffer-history-isearch-push-state)
+  (add-hook 'isearch-mode-end-hook 'minibuffer-history-isearch-end nil t))
+
+(defun minibuffer-history-isearch-end ()
+  "Clean up the minibuffer after terminating isearch in the minibuffer."
+  (if minibuffer-history-isearch-message-overlay
+      (delete-overlay minibuffer-history-isearch-message-overlay)))
+
+(defun minibuffer-history-isearch-search ()
+  "Return the proper search function, for isearch in minibuffer history."
+  (cond
+   (isearch-word
+    (if isearch-forward 'word-search-forward 'word-search-backward))
+   (t
+    (lambda (string bound noerror)
+      (let ((search-fun
+            ;; Use standard functions to search within minibuffer text
+             (cond
+              (isearch-regexp
+               (if isearch-forward 're-search-forward 're-search-backward))
+              (t
+               (if isearch-forward 'search-forward 'search-backward))))
+           found)
+       ;; Avoid lazy-highlighting matches in the minibuffer prompt when
+       ;; searching forward.  Lazy-highlight calls this lambda with the
+       ;; bound arg, so skip the minibuffer prompt.
+       (if (and bound isearch-forward (< (point) (minibuffer-prompt-end)))
+           (goto-char (minibuffer-prompt-end)))
+        (or
+        ;; 1. First try searching in the initial minibuffer text
+        (funcall search-fun string
+                 (if isearch-forward bound (minibuffer-prompt-end))
+                 noerror)
+        ;; 2. If the above search fails, start putting next/prev history
+        ;; elements in the minibuffer successively, and search the string
+        ;; in them.  Do this only when bound is nil (i.e. not while
+        ;; lazy-highlighting search strings in the current minibuffer text).
+        (unless bound
+          (condition-case nil
+              (progn
+                (while (not found)
+                  (cond (isearch-forward
+                         (next-history-element 1)
+                         (goto-char (minibuffer-prompt-end)))
+                        (t
+                         (previous-history-element 1)
+                         (goto-char (point-max))))
+                  (setq isearch-barrier (point) isearch-opoint (point))
+                  ;; After putting the next/prev history element, search
+                  ;; the string in them again, until next-history-element
+                  ;; or previous-history-element raises an error at the
+                  ;; beginning/end of history.
+                  (setq found (funcall search-fun string
+                                       (unless isearch-forward
+                                         ;; For backward search, don't search
+                                         ;; in the minibuffer prompt
+                                         (minibuffer-prompt-end))
+                                       noerror)))
+                ;; Return point of the new search result
+                (point))
+            ;; Return nil when next(prev)-history-element fails
+            (error nil)))))))))
+
+(defun minibuffer-history-isearch-message (&optional c-q-hack ellipsis)
+  "Display the minibuffer history search prompt.
+If there are no search errors, this function displays an overlay with
+the isearch prompt which replaces the original minibuffer prompt.
+Otherwise, it displays the standard isearch message returned from
+`isearch-message'."
+  (if (not (and (minibufferp) isearch-success (not isearch-error)))
+      ;; Use standard function `isearch-message' when not in the minibuffer,
+      ;; or search fails, or has an error (like incomplete regexp).
+      ;; This function overwrites minibuffer text with isearch message,
+      ;; so it's possible to see what is wrong in the search string.
+      (isearch-message c-q-hack ellipsis)
+    ;; Otherwise, put the overlay with the standard isearch prompt over
+    ;; the initial minibuffer prompt.
+    (if (overlayp minibuffer-history-isearch-message-overlay)
+       (move-overlay minibuffer-history-isearch-message-overlay
+                     (point-min) (minibuffer-prompt-end))
+      (setq minibuffer-history-isearch-message-overlay
+           (make-overlay (point-min) (minibuffer-prompt-end)))
+      (overlay-put minibuffer-history-isearch-message-overlay 'evaporate t))
+    (overlay-put minibuffer-history-isearch-message-overlay
+                'display (isearch-message-prefix c-q-hack ellipsis))
+    ;; And clear any previous isearch message.
+    (message "")))
+
+(defun minibuffer-history-isearch-wrap ()
+  "Wrap the minibuffer history search when search is failed.
+Move point to the first history element for a forward search,
+or to the last history element for a backward search."
+  (unless isearch-word
+    ;; When `minibuffer-history-isearch-search' fails on reaching the
+    ;; beginning/end of the history, wrap the search to the first/last
+    ;; minibuffer history element.
+    (if isearch-forward
+       (goto-history-element (length (symbol-value minibuffer-history-variable)))
+      (goto-history-element 0))
+    (setq isearch-success t))
+  (goto-char (if isearch-forward (minibuffer-prompt-end) (point-max))))
+
+(defun minibuffer-history-isearch-push-state ()
+  "Save a function restoring the state of minibuffer history search.
+Save `minibuffer-history-position' to the additional state parameter
+in the search status stack."
+  `(lambda (cmd)
+     (minibuffer-history-isearch-pop-state cmd ,minibuffer-history-position)))
+
+(defun minibuffer-history-isearch-pop-state (cmd hist-pos)
+  "Restore the minibuffer history search state.
+Go to the history element by the absolute history position `hist-pos'."
+  (goto-history-element hist-pos))
+
+\f
 ;Put this on C-x u, so we can force that rather than C-_ into startup msg
 (defalias 'advertised-undo 'undo)
 
 ;Put this on C-x u, so we can force that rather than C-_ into startup msg
 (defalias 'advertised-undo 'undo)
 
@@ -2189,6 +2339,18 @@ value passed."
       (when stderr-file (delete-file stderr-file))
       (when lc (delete-file lc)))))
 
       (when stderr-file (delete-file stderr-file))
       (when lc (delete-file lc)))))
 
+(defun start-file-process (name buffer program &rest program-args)
+  "Start a program in a subprocess.  Return the process object for it.
+Similar to `start-process', but may invoke a file handler based on
+`default-directory'.  The current working directory of the
+subprocess is `default-directory'.
+
+PROGRAM and PROGRAM-ARGS might be file names.  They are not
+objects of file handler invocation."
+  (let ((fh (find-file-name-handler default-directory 'start-file-process)))
+    (if fh (apply fh 'start-file-process name buffer program program-args)
+      (apply 'start-process name buffer program program-args))))
+
 
 \f
 (defvar universal-argument-map
 
 \f
 (defvar universal-argument-map
@@ -3271,12 +3433,11 @@ purposes.  See the documentation of `set-mark' for more information."
 If the last global mark pushed was not in the current buffer,
 also push LOCATION on the global mark ring.
 Display `Mark set' unless the optional second arg NOMSG is non-nil.
 If the last global mark pushed was not in the current buffer,
 also push LOCATION on the global mark ring.
 Display `Mark set' unless the optional second arg NOMSG is non-nil.
-In Transient Mark mode, activate mark if optional third arg ACTIVATE non-nil.
 
 Novice Emacs Lisp programmers often try to use the mark for the wrong
 purposes.  See the documentation of `set-mark' for more information.
 
 
 Novice Emacs Lisp programmers often try to use the mark for the wrong
 purposes.  See the documentation of `set-mark' for more information.
 
-In Transient Mark mode, this does not activate the mark."
+In Transient Mark mode, activate mark if optional third arg ACTIVATE non-nil."
   (unless (null (mark t))
     (setq mark-ring (cons (copy-marker (mark-marker)) mark-ring))
     (when (> (length mark-ring) mark-ring-max)
   (unless (null (mark t))
     (setq mark-ring (cons (copy-marker (mark-marker)) mark-ring))
     (when (> (length mark-ring) mark-ring-max)
@@ -3478,15 +3639,6 @@ Outline mode sets this."
   :type 'boolean
   :group 'editing-basics)
 
   :type 'boolean
   :group 'editing-basics)
 
-(defun line-move-invisible-p (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)))))
-
 ;; Returns non-nil if partial move was done.
 (defun line-move-partial (arg noerror to-end)
   (if (< arg 0)
 ;; Returns non-nil if partial move was done.
 (defun line-move-partial (arg noerror to-end)
   (if (< arg 0)
@@ -3606,7 +3758,7 @@ Outline mode sets this."
              (while (and (> arg 0) (not done))
                ;; If the following character is currently invisible,
                ;; skip all characters with that same `invisible' property value.
              (while (and (> arg 0) (not done))
                ;; If the following character is currently invisible,
                ;; skip all characters with that same `invisible' property value.
-               (while (and (not (eobp)) (line-move-invisible-p (point)))
+               (while (and (not (eobp)) (invisible-p (point)))
                  (goto-char (next-char-property-change (point))))
                ;; Move a line.
                ;; We don't use `end-of-line', since we want to escape
                  (goto-char (next-char-property-change (point))))
                ;; Move a line.
                ;; We don't use `end-of-line', since we want to escape
@@ -3624,7 +3776,7 @@ Outline mode sets this."
                    (setq done t)))
                 ((and (> arg 1)  ;; Use vertical-motion for last move
                       (not (integerp selective-display))
                    (setq done t)))
                 ((and (> arg 1)  ;; Use vertical-motion for last move
                       (not (integerp selective-display))
-                      (not (line-move-invisible-p (point))))
+                      (not (invisible-p (point))))
                  ;; We avoid vertical-motion when possible
                  ;; because that has to fontify.
                  (forward-line 1))
                  ;; We avoid vertical-motion when possible
                  ;; because that has to fontify.
                  (forward-line 1))
@@ -3653,7 +3805,7 @@ Outline mode sets this."
                    (setq done t)))
                 ((and (< arg -1) ;; Use vertical-motion for last move
                       (not (integerp selective-display))
                    (setq done t)))
                 ((and (< arg -1) ;; Use vertical-motion for last move
                       (not (integerp selective-display))
-                      (not (line-move-invisible-p (1- (point)))))
+                      (not (invisible-p (1- (point)))))
                  (forward-line -1))
                 ((zerop (vertical-motion -1))
                  (if (not noerror)
                  (forward-line -1))
                 ((zerop (vertical-motion -1))
                  (if (not noerror)
@@ -3665,7 +3817,7 @@ Outline mode sets this."
                          ;; if our target is the middle of this line.
                          (or (zerop (or goal-column temporary-goal-column))
                              (< arg 0))
                          ;; if our target is the middle of this line.
                          (or (zerop (or goal-column temporary-goal-column))
                              (< arg 0))
-                         (not (bobp)) (line-move-invisible-p (1- (point))))
+                         (not (bobp)) (invisible-p (1- (point))))
                    (goto-char (previous-char-property-change (point))))))))
          ;; This is the value the function returns.
          (= arg 0))
                    (goto-char (previous-char-property-change (point))))))))
          ;; This is the value the function returns.
          (= arg 0))
@@ -3697,7 +3849,7 @@ Outline mode sets this."
             (save-excursion
               ;; Like end-of-line but ignores fields.
               (skip-chars-forward "^\n")
             (save-excursion
               ;; Like end-of-line but ignores fields.
               (skip-chars-forward "^\n")
-              (while (and (not (eobp)) (line-move-invisible-p (point)))
+              (while (and (not (eobp)) (invisible-p (point)))
                 (goto-char (next-char-property-change (point)))
                 (skip-chars-forward "^\n"))
               (point))))
                 (goto-char (next-char-property-change (point)))
                 (skip-chars-forward "^\n"))
               (point))))
@@ -3780,13 +3932,13 @@ and `current-column' to be able to ignore invisible text."
     (move-to-column col))
 
   (when (and line-move-ignore-invisible
     (move-to-column col))
 
   (when (and line-move-ignore-invisible
-            (not (bolp)) (line-move-invisible-p (1- (point))))
+            (not (bolp)) (invisible-p (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))
     (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-p (point)))
+                 (invisible-p (point)))
        (goto-char (next-char-property-change (point))))
       ;; Have we advanced to a larger column position?
       (if (> (current-column) normal-column)
        (goto-char (next-char-property-change (point))))
       ;; Have we advanced to a larger column position?
       (if (> (current-column) normal-column)
@@ -3799,7 +3951,7 @@ and `current-column' to be able to ignore invisible text."
        ;; but with a more reasonable buffer position.
        (goto-char normal-location)
        (let ((line-beg (save-excursion (beginning-of-line) (point))))
        ;; 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-p (1- (point))))
+         (while (and (not (bolp)) (invisible-p (1- (point))))
            (goto-char (previous-char-property-change (point) line-beg))))))))
 
 (defun move-end-of-line (arg)
            (goto-char (previous-char-property-change (point) line-beg))))))))
 
 (defun move-end-of-line (arg)
@@ -3820,7 +3972,7 @@ To ignore intangibility, bind `inhibit-point-motion-hooks' to t."
                 (and (line-move arg t)
                      (not (bobp))
                      (progn
                 (and (line-move arg t)
                      (not (bobp))
                      (progn
-                       (while (and (not (bobp)) (line-move-invisible-p (1- (point))))
+                       (while (and (not (bobp)) (invisible-p (1- (point))))
                          (goto-char (previous-char-property-change (point))))
                        (backward-char 1)))
                 (point)))))
                          (goto-char (previous-char-property-change (point))))
                        (backward-char 1)))
                 (point)))))
@@ -3856,13 +4008,13 @@ To ignore intangibility, bind `inhibit-point-motion-hooks' to t."
 
     ;; Move to beginning-of-line, ignoring fields and invisibles.
     (skip-chars-backward "^\n")
 
     ;; Move to beginning-of-line, ignoring fields and invisibles.
     (skip-chars-backward "^\n")
-    (while (and (not (bobp)) (line-move-invisible-p (1- (point))))
+    (while (and (not (bobp)) (invisible-p (1- (point))))
       (goto-char (previous-char-property-change (point)))
       (skip-chars-backward "^\n"))
     (setq start (point))
 
     ;; Now find first visible char in the line
       (goto-char (previous-char-property-change (point)))
       (skip-chars-backward "^\n"))
     (setq start (point))
 
     ;; Now find first visible char in the line
-    (while (and (not (eobp)) (line-move-invisible-p (point)))
+    (while (and (not (eobp)) (invisible-p (point)))
       (goto-char (next-char-property-change (point))))
     (setq first-vis (point))
 
       (goto-char (next-char-property-change (point))))
     (setq first-vis (point))
 
@@ -4168,13 +4320,6 @@ If optional arg REALLY-WORD is non-nil, it finds just a word."
                 regexp)
   :group 'fill)
 
                 regexp)
   :group 'fill)
 
-(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.
-The function should take a single optional argument, which is a flag
-indicating whether it should use soft newlines.")
-
 ;; This function is used as the auto-fill-function of a buffer
 ;; when Auto-Fill mode is enabled.
 ;; It returns t if it really did any work.
 ;; This function is used as the auto-fill-function of a buffer
 ;; when Auto-Fill mode is enabled.
 ;; It returns t if it really did any work.
@@ -4248,10 +4393,10 @@ indicating whether it should use soft newlines.")
              (if (save-excursion
                    (skip-chars-backward " \t")
                    (= (point) fill-point))
              (if (save-excursion
                    (skip-chars-backward " \t")
                    (= (point) fill-point))
-                 (funcall comment-line-break-function t)
+                 (default-indent-new-line t)
                (save-excursion
                  (goto-char fill-point)
                (save-excursion
                  (goto-char fill-point)
-                 (funcall comment-line-break-function t)))
+                 (default-indent-new-line t)))
              ;; Now do justification, if required
              (if (not (eq justify 'left))
                  (save-excursion
              ;; Now do justification, if required
              (if (not (eq justify 'left))
                  (save-excursion
@@ -4266,6 +4411,43 @@ indicating whether it should use soft newlines.")
       (justify-current-line justify t t)
       t)))
 
       (justify-current-line justify t t)
       t)))
 
+(defvar comment-line-break-function 'comment-indent-new-line
+  "*Mode-specific function which line breaks and continues a comment.
+This function is called during auto-filling when a comment syntax
+is defined.
+The function should take a single optional argument, which is a flag
+indicating whether it should use soft newlines.")
+
+(defun default-indent-new-line (&optional soft)
+  "Break line at point and indent.
+If a comment syntax is defined, call `comment-indent-new-line'.
+
+The inserted newline is marked hard if variable `use-hard-newlines' is true,
+unless optional argument SOFT is non-nil."
+  (interactive)
+  (if comment-start
+      (funcall comment-line-break-function soft)
+    ;; Insert the newline before removing empty space so that markers
+    ;; get preserved better.
+    (if soft (insert-and-inherit ?\n) (newline 1))
+    (save-excursion (forward-char -1) (delete-horizontal-space))
+    (delete-horizontal-space)
+
+    (if (and fill-prefix (not adaptive-fill-mode))
+       ;; Blindly trust a non-adaptive fill-prefix.
+       (progn
+         (indent-to-left-margin)
+         (insert-before-markers-and-inherit fill-prefix))
+
+      (cond
+       ;; If there's an adaptive prefix, use it unless we're inside
+       ;; a comment and the prefix is not a comment starter.
+       (fill-prefix
+       (indent-to-left-margin)
+       (insert-and-inherit fill-prefix))
+       ;; If we're not inside a comment, just try to indent.
+       (t (indent-according-to-mode))))))
+
 (defvar normal-auto-fill-function 'do-auto-fill
   "The function to use for `auto-fill-function' if Auto Fill mode is turned on.
 Some major modes set this.")
 (defvar normal-auto-fill-function 'do-auto-fill
   "The function to use for `auto-fill-function' if Auto Fill mode is turned on.
 Some major modes set this.")
@@ -4344,8 +4526,9 @@ The variable `selective-display' has a separate value for each buffer."
 
 (defun toggle-truncate-lines (&optional arg)
   "Toggle whether to fold or truncate long lines for the current buffer.
 
 (defun toggle-truncate-lines (&optional arg)
   "Toggle whether to fold or truncate long lines for the current buffer.
-With arg, truncate long lines iff arg is positive.
-Note that in side-by-side windows, truncation is always enabled."
+With prefix argument ARG, truncate long lines if ARG is positive,
+otherwise don't truncate them.  Note that in side-by-side
+windows, truncation is always enabled."
   (interactive "P")
   (setq truncate-lines
        (if (null arg)
   (interactive "P")
   (setq truncate-lines
        (if (null arg)
@@ -4368,11 +4551,11 @@ Note that in side-by-side windows, truncation is always enabled."
 
 (defun overwrite-mode (arg)
   "Toggle overwrite mode.
 
 (defun overwrite-mode (arg)
   "Toggle overwrite mode.
-With arg, turn overwrite mode on iff arg is positive.
-In overwrite mode, printing characters typed in replace existing text
-on a one-for-one basis, rather than pushing it to the right.  At the
-end of a line, such characters extend the line.  Before a tab,
-such characters insert until the tab is filled in.
+With prefix argument ARG, turn overwrite mode on if ARG is positive,
+otherwise turn it off.  In overwrite mode, printing characters typed
+in replace existing text on a one-for-one basis, rather than pushing
+it to the right.  At the end of a line, such characters extend the line.
+Before a tab, such characters insert until the tab is filled in.
 \\[quoted-insert] still inserts characters in overwrite mode; this
 is supposed to make it easier to insert characters when necessary."
   (interactive "P")
 \\[quoted-insert] still inserts characters in overwrite mode; this
 is supposed to make it easier to insert characters when necessary."
   (interactive "P")
@@ -4384,14 +4567,13 @@ is supposed to make it easier to insert characters when necessary."
 
 (defun binary-overwrite-mode (arg)
   "Toggle binary overwrite mode.
 
 (defun binary-overwrite-mode (arg)
   "Toggle binary overwrite mode.
-With arg, turn binary overwrite mode on iff arg is positive.
-In binary overwrite mode, printing characters typed in replace
-existing text.  Newlines are not treated specially, so typing at the
-end of a line joins the line to the next, with the typed character
-between them.  Typing before a tab character simply replaces the tab
-with the character typed.
-\\[quoted-insert] replaces the text at the cursor, just as ordinary
-typing characters do.
+With prefix argument ARG, turn binary overwrite mode on if ARG is
+positive, otherwise turn it off.  In binary overwrite mode, printing
+characters typed in replace existing text.  Newlines are not treated
+specially, so typing at the end of a line joins the line to the next,
+with the typed character between them.  Typing before a tab character
+simply replaces the tab with the character typed.  \\[quoted-insert]
+replaces the text at the cursor, just as ordinary typing characters do.
 
 Note that binary overwrite mode is not its own minor mode; it is a
 specialization of overwrite mode, entered by setting the
 
 Note that binary overwrite mode is not its own minor mode; it is a
 specialization of overwrite mode, entered by setting the
@@ -4406,9 +4588,9 @@ specialization of overwrite mode, entered by setting the
 
 (define-minor-mode line-number-mode
   "Toggle Line Number mode.
 
 (define-minor-mode line-number-mode
   "Toggle Line Number mode.
-With arg, turn Line Number mode on iff arg is positive.
-When Line Number mode is enabled, the line number appears
-in the mode line.
+With arg, turn Line Number mode on if arg is positive, otherwise
+turn it off.  When Line Number mode is enabled, the line number
+appears in the mode line.
 
 Line numbers do not appear for very large buffers and buffers
 with very long lines; see variables `line-number-display-limit'
 
 Line numbers do not appear for very large buffers and buffers
 with very long lines; see variables `line-number-display-limit'
@@ -4417,16 +4599,16 @@ and `line-number-display-limit-width'."
 
 (define-minor-mode column-number-mode
   "Toggle Column Number mode.
 
 (define-minor-mode column-number-mode
   "Toggle Column Number mode.
-With arg, turn Column Number mode on iff arg is positive.
-When Column Number mode is enabled, the column number appears
-in the mode line."
+With arg, turn Column Number mode on if arg is positive,
+otherwise turn it off.  When Column Number mode is enabled, the
+column number appears in the mode line."
   :global t :group 'mode-line)
 
 (define-minor-mode size-indication-mode
   "Toggle Size Indication mode.
   :global t :group 'mode-line)
 
 (define-minor-mode size-indication-mode
   "Toggle Size Indication mode.
-With arg, turn Size Indication mode on iff arg is positive.  When
-Size Indication mode is enabled, the size of the accessible part
-of the buffer appears in the mode line."
+With arg, turn Size Indication mode on if arg is positive,
+otherwise turn it off.  When Size Indication mode is enabled, the
+size of the accessible part of the buffer appears in the mode line."
   :global t :group 'mode-line)
 \f
 (defgroup paren-blinking nil
   :global t :group 'mode-line)
 \f
 (defgroup paren-blinking nil
@@ -4961,7 +5143,7 @@ With prefix argument N, move N items (negative N means move backward)."
 These functions are called in order with four arguments:
 CHOICE - the string to insert in the buffer,
 BUFFER - the buffer in which the choice should be inserted,
 These functions are called in order with four arguments:
 CHOICE - the string to insert in the buffer,
 BUFFER - the buffer in which the choice should be inserted,
-MINI-P - non-nil iff BUFFER is a minibuffer, and
+MINI-P - non-nil if BUFFER is a minibuffer, and
 BASE-SIZE - the number of characters in BUFFER before
 the string being completed.
 
 BASE-SIZE - the number of characters in BUFFER before
 the string being completed.
 
@@ -5247,10 +5429,10 @@ PREFIX is the string that represents this modifier in an event type symbol."
 \f
 ;;;; Keypad support.
 
 \f
 ;;;; Keypad support.
 
-;;; Make the keypad keys act like ordinary typing keys.  If people add
-;;; bindings for the function key symbols, then those bindings will
-;;; override these, so this shouldn't interfere with any existing
-;;; bindings.
+;; Make the keypad keys act like ordinary typing keys.  If people add
+;; bindings for the function key symbols, then those bindings will
+;; override these, so this shouldn't interfere with any existing
+;; bindings.
 
 ;; Also tell read-char how to handle these keys.
 (mapc
 
 ;; Also tell read-char how to handle these keys.
 (mapc
@@ -5569,7 +5751,8 @@ See also `normal-erase-is-backspace'."
 
 (define-minor-mode visible-mode
   "Toggle Visible mode.
 
 (define-minor-mode visible-mode
   "Toggle Visible mode.
-With argument ARG turn Visible mode on iff ARG is positive.
+With argument ARG turn Visible mode on if ARG is positive, otherwise
+turn it off.
 
 Enabling Visible mode makes all invisible text temporarily visible.
 Disabling Visible mode turns off that effect.  Visible mode
 
 Enabling Visible mode makes all invisible text temporarily visible.
 Disabling Visible mode turns off that effect.  Visible mode
@@ -5605,6 +5788,57 @@ works by saving the value of `buffer-invisibility-spec' and setting it to nil."
 ;      'insert-in-front-hooks '(minibuffer-prompt-insertion)))
 ;
 
 ;      'insert-in-front-hooks '(minibuffer-prompt-insertion)))
 ;
 
+\f
+;;;; Problematic external packages.
+
+;; rms says this should be done by specifying symbols that define
+;; versions together with bad values.  This is therefore not as
+;; flexible as it could be.  See the thread:
+;; http://lists.gnu.org/archive/html/emacs-devel/2007-08/msg00300.html
+(defconst bad-packages-alist
+  ;; Not sure exactly which semantic versions have problems.
+  ;; Definitely 2.0pre3, probably all 2.0pre's before this.
+  '((semantic semantic-version "2\\.0pre[1-3]"
+              "The version of `semantic' loaded does not work in Emacs 22.
+It can cause constant high CPU load.  Upgrade to at least 2.0pre4.")
+    ;; CUA-mode does not work with GNU Emacs version 22.1 and newer.
+    ;; Except for version 1.2, all of the 1.x and 2.x version of cua-mode
+    ;; provided the `CUA-mode' feature.  Since this is no longer true,
+    ;; we can warn the user if the `CUA-mode' feature is ever provided.
+    (CUA-mode t nil
+"CUA-mode is now part of the standard GNU Emacs distribution,
+so you can now enable CUA via the Options menu or by customizing `cua-mode'.
+
+You have loaded an older version of CUA-mode which does not work
+correctly with this version of Emacs.  You should remove the old
+version and use the one distributed with Emacs."))
+  "Alist of packages known to cause problems in this version of Emacs.
+Each element has the form (PACKAGE SYMBOL REGEXP STRING).
+PACKAGE is either a regular expression to match file names, or a
+symbol (a feature name); see the documentation of
+`after-load-alist', to which this variable adds functions.
+SYMBOL is either the name of a string variable, or `t'.  Upon
+loading PACKAGE, if SYMBOL is t or matches REGEXP, display a
+warning using STRING as the message.")
+
+(defun bad-package-check (package)
+  "Run a check using the element from `bad-packages-alist' matching PACKAGE."
+  (condition-case nil
+      (let* ((list (assoc package bad-packages-alist))
+             (symbol (nth 1 list)))
+        (and list
+             (boundp symbol)
+             (or (eq symbol t)
+                 (and (stringp (setq symbol (eval symbol)))
+                      (string-match (nth 2 list) symbol)))
+             (display-warning :warning (nth 3 list))))
+    (error nil)))
+
+(mapc (lambda (elem)
+        (eval-after-load (car elem) `(bad-package-check ',(car elem))))
+      bad-packages-alist)
+
+
 (provide 'simple)
 
 ;; arch-tag: 24af67c0-2a49-44f6-b3b1-312d8b570dfd
 (provide 'simple)
 
 ;; arch-tag: 24af67c0-2a49-44f6-b3b1-312d8b570dfd