]> code.delx.au - gnu-emacs/blobdiff - lisp/simple.el
entered into RCS
[gnu-emacs] / lisp / simple.el
index c607a9d1a3293d26dc702b8bfad57c7fbba18dc8..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,26 +358,6 @@ the minibuffer, then read and evaluate the result."
        (setq command-history (cons command command-history)))
     (eval command)))
 
-;; (defvar repeat-complex-command nil)
-
-(defvar minibuffer-history nil)
-(defvar minibuffer-history-variable 'minibuffer-history)
-(defvar minibuffer-history-position nil)
-
-(define-key minibuffer-local-map "\en" 'next-history-element)
-(define-key minibuffer-local-ns-map "\en" 'next-history-element)
-(define-key minibuffer-local-ns-map "\en" 'next-history-element)
-(define-key minibuffer-local-completion-map "\en" 'next-history-element)
-(define-key minibuffer-local-completion-map "\en" 'next-history-element)
-(define-key minibuffer-local-must-match-map "\en" 'next-history-element)
-
-(define-key minibuffer-local-map "\ep" 'previous-history-element)
-(define-key minibuffer-local-ns-map "\ep" 'previous-history-element)
-(define-key minibuffer-local-ns-map "\ep" 'previous-history-element)
-(define-key minibuffer-local-completion-map "\ep" 'previous-history-element)
-(define-key minibuffer-local-completion-map "\ep" 'previous-history-element)
-(define-key minibuffer-local-must-match-map "\ep" 'previous-history-element)
-
 (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.
@@ -377,25 +365,79 @@ 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))
+  (let ((elt (nth (1- arg) command-history))
        (minibuffer-history-position arg)
-       (repeat-complex-command-flag t)
+       (minibuffer-history-sexp-flag t)
        newcmd)
     (if elt
        (let ((minibuffer-history-variable ' command-history))
          (setq newcmd (read-from-minibuffer "Redo: "
                                             (prin1-to-string elt)
                                             minibuffer-local-map
-                                            t))
+                                            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))))
+\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."
@@ -404,21 +446,23 @@ Whilst editing the command, the following commands are available:
                   (length (symbol-value minibuffer-history-variable)))))
     (if (= minibuffer-history-position narg)
        (error (if (= minibuffer-history-position 1)
-                  "No following item in minibuffer history"
-                "No preceding item in minibuffer history"))
+                  "End of history; no next item"
+                "Beginning of history; no preceding item"))
       (erase-buffer)
       (setq minibuffer-history-position narg)
-      (insert (prin1-to-string (nth (1- minibuffer-history-position)
-                                   (symbol-value minibuffer-history-variable))))
+      (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-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: ")
@@ -810,10 +854,6 @@ yanking point; just return the Nth kill forward."
   (let ((interprogram-paste (and (= n 0)
                                 interprogram-paste-function
                                 (funcall interprogram-paste-function))))
-;;; RMS: Turn off the interprogram paste feature 
-;;; because currently it is wedged: it is always
-;;; giving a null string.
-    (setq interprogram-paste nil)
     (if interprogram-paste
        (progn
          ;; Disable the interprogram cut function when we add the new