]> code.delx.au - gnu-emacs/blobdiff - lisp/simple.el
entered into RCS
[gnu-emacs] / lisp / simple.el
index 840bd77a4b0a03cc83888b48b4b83c0006a5f848..982bd78047d8ff08e2be4db7c20bfaee840bc0f2 100644 (file)
@@ -56,6 +56,7 @@ You may also type up to 3 octal digits, to insert a character with that code"
 
 (defun delete-indentation (&optional arg)
   "Join this line to previous and fix up whitespace at join.
+If there is a fill prefix, delete it from the beginning of this line.
 With argument, join this line to following line."
   (interactive "*P")
   (beginning-of-line)
@@ -63,6 +64,13 @@ With argument, join this line to following line."
   (if (eq (preceding-char) ?\n)
       (progn
        (delete-region (point) (1- (point)))
+       ;; If the second line started with the fill prefix,
+       ;; delete the prefix.
+       (if (and fill-prefix
+                (string= fill-prefix
+                         (buffer-substring (point)
+                                           (+ (point) (length fill-prefix)))))
+           (delete-region (point) (+ (point) (length fill-prefix))))
        (fixup-whitespace))))
 
 (defun fixup-whitespace ()
@@ -334,7 +342,7 @@ Other major modes are defined by comparison with this one."
 ;; for the sake of completion of names like eval-region, eval-current-buffer.
 (defun eval-expression (expression)
   "Evaluate EXPRESSION and print value in minibuffer.
-Value is also consed on to front of variable  values  's value."
+Value is also consed on to front of the variable `values'."
   (interactive "xEval: ")
   (setq values (cons (eval expression) values))
   (prin1 (car values) t))
@@ -350,59 +358,111 @@ the minibuffer, then read and evaluate the result."
        (setq command-history (cons command command-history)))
     (eval command)))
 
-;; (defvar repeat-complex-command nil)
-
-(defvar repeat-complex-command-map (copy-keymap minibuffer-local-map))
-(define-key repeat-complex-command-map "\ep" 'previous-complex-command)
-(define-key repeat-complex-command-map "\en" 'next-complex-command)
-(defun repeat-complex-command (repeat-complex-command-arg)
+(defun repeat-complex-command (arg)
   "Edit and re-evaluate last complex command, or ARGth from last.
 A complex command is one which used the minibuffer.
 The command is placed in the minibuffer as a Lisp form for editing.
 The result is executed, repeating the command as changed.
 If the command has been changed or is not the most recent previous command
 it is added to the front of the command history.
-Whilst editing the command, the following commands are available:
-\\{repeat-complex-command-map}"
+You can use the minibuffer history commands \\<minibuffer-local-map>\\[next-history-element] and \\[previous-history-element]
+to get different commands to edit and resubmit."
   (interactive "p")
-  (let ((elt (nth (1- repeat-complex-command-arg) command-history))
-       (repeat-complex-command-flag t)
+  (let ((elt (nth (1- arg) command-history))
+       (minibuffer-history-position arg)
+       (minibuffer-history-sexp-flag t)
        newcmd)
     (if elt
-       (progn
+       (let ((minibuffer-history-variable ' command-history))
          (setq newcmd (read-from-minibuffer "Redo: "
                                             (prin1-to-string elt)
-                                            repeat-complex-command-map
-                                            t))
+                                            minibuffer-local-map
+                                            t
+                                            (cons 'command-history
+                                                  arg)))
          ;; If command to be redone does not match front of history,
          ;; add it to the history.
          (or (equal newcmd (car command-history))
              (setq command-history (cons newcmd command-history)))
          (eval newcmd))
       (ding))))
-
-(defun next-complex-command (n)
-  "Inserts the next element of `command-history' into the minibuffer."
+\f
+(defvar minibuffer-history nil)
+(defvar minibuffer-history-sexp-flag nil)
+(setq minibuffer-history-variable 'minibuffer-history)
+(setq minibuffer-history-position nil)
+
+(mapcar
+ (function (lambda (key-and-command)
+            (mapcar
+             (function (lambda (keymap)
+                         (define-key (symbol-value keymap)
+                           (car key-and-command)
+                           (cdr key-and-command))))
+             '(minibuffer-local-map
+               minibuffer-local-ns-map
+               minibuffer-local-completion-map
+               minibuffer-local-must-match-map))))
+ '(("\en" . next-history-element) ([next] . next-history-element)
+   ("\ep" . previous-history-element) ([prior] . previous-history-element)
+   ("\er" . previous-matching-history-element)
+   ("\es" . next-matching-history-element)))
+
+(put 'previous-matching-history-element 'enable-recursive-minibuffers t)
+(defun previous-matching-history-element (regexp n)
+  (interactive "sPrevious element matching (regexp): \np")
+  (let ((history (symbol-value minibuffer-history-variable))
+       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)
+         (error (if (= pos 1)
+                    "No later matching history item"
+                  "No earlier matching history item")))
+      (if (string-match regexp
+                       (if minibuffer-history-sexp-flag
+                           (prin1-to-string (nth (1- pos) history))
+                         (nth (1- pos) history)))
+         (setq n (+ n (if (< n 0) -1 1)))))
+    (setq minibuffer-history-position pos)
+    (erase-buffer)
+    (let ((elt (nth (1- pos) history)))
+      (insert (if minibuffer-history-sexp-flag
+                 (prin1-to-string elt)
+               elt)))
+      (goto-char (point-min))))
+
+(put 'next-matching-history-element 'enable-recursive-minibuffers t)
+(defun next-matching-history-element (regexp n)
+  (interactive "sNext element matching (regexp): \np")
+  (previous-matching-history-element regexp (- n)))
+
+(defun next-history-element (n)
+  "Insert the next element of the minibuffer history into the minibuffer."
   (interactive "p")
-  (let ((narg (min (max 1 (- repeat-complex-command-arg n))
-                  (length command-history))))
-    (if (= repeat-complex-command-arg narg)
-       (error (if (= repeat-complex-command-arg 1)
-                  "No following item in command history"
-                "No preceding item in command history"))
+  (let ((narg (min (max 1 (- minibuffer-history-position n))
+                  (length (symbol-value minibuffer-history-variable)))))
+    (if (= minibuffer-history-position narg)
+       (error (if (= minibuffer-history-position 1)
+                  "End of history; no next item"
+                "Beginning of history; no preceding item"))
       (erase-buffer)
-      (setq repeat-complex-command-arg narg)
-      (insert (prin1-to-string (nth (1- repeat-complex-command-arg)
-                                   command-history)))
+      (setq minibuffer-history-position narg)
+      (let ((elt (nth (1- minibuffer-history-position)
+                     (symbol-value minibuffer-history-variable))))
+       (insert
+        (if minibuffer-history-sexp-flag
+            (prin1-to-string elt)
+          elt)))
       (goto-char (point-min)))))
 
-(defun previous-complex-command (n)
+(defun previous-history-element (n)
   "Inserts the previous element of `command-history' into the minibuffer."
   (interactive "p")
-  (if repeat-complex-command-flag
-      (next-complex-command (- n))
-    (repeat-complex-command 1)))
-
+  (next-history-element (- n)))
+\f
 (defun goto-line (arg)
   "Goto line ARG, counting from line 1 at beginning of buffer."
   (interactive "NGoto line: ")