changeset 874:b945f592b94d

*** empty log message ***
author Richard M. Stallman <rms@gnu.org>
date Sun, 26 Jul 1992 19:54:20 +0000
parents 0abaf590e0ca
children 29b360fea58e
files lisp/mail/rmail.el lisp/simple.el
diffstat 2 files changed, 124 insertions(+), 49 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/mail/rmail.el	Sun Jul 26 19:36:03 1992 +0000
+++ b/lisp/mail/rmail.el	Sun Jul 26 19:54:20 1992 +0000
@@ -261,6 +261,7 @@
   (define-key rmail-mode-map "\e\C-m" 'rmail-retry-failure)
   (define-key rmail-mode-map "c" 'rmail-continue)
   (define-key rmail-mode-map "f" 'rmail-forward)
+  (define-key rmail-mode-map "\er" 'rmail-search-backwards)
   (define-key rmail-mode-map "\es" 'rmail-search)
   (define-key rmail-mode-map "<" 'rmail-first-message)
   (define-key rmail-mode-map ">" 'rmail-last-message)
@@ -1108,11 +1109,11 @@
     (if (>= where (rmail-msgbeg high)) high low)))
 
 (defvar rmail-search-last-regexp nil)
-(defun rmail-search (regexp &optional reversep)
+(defun rmail-search (regexp &optional n)
   "Show message containing next match for REGEXP.
-Search in reverse (earlier messages) with non-nil second arg REVERSEP.
-Interactively, empty argument means use same regexp used last time,
-and reverse search is specified by a negative numeric arg."
+Prefix argument gives repeat count; negative argument means search
+backwards (through earlier messages).
+Interactively, empty argument means use same regexp used last time."
   (interactive
     (let* ((reversep (< (prefix-numeric-value current-prefix-arg) 0))
 	   (prompt
@@ -1128,7 +1129,9 @@
 	     (setq rmail-search-last-regexp regexp))
 	    ((not rmail-search-last-regexp)
 	     (error "No previous Rmail search string")))
-      (list rmail-search-last-regexp reversep)))
+      (list rmail-search-last-regexp
+	    (prefix-numeric-value current-prefix-arg))))
+  (or n (setq n 1))
   (message "%sRmail search for %s..."
 	   (if reversep "Reverse " "")
 	   regexp)
@@ -1137,20 +1140,23 @@
 	(omax (point-max))
 	(opoint (point))
 	win
+	(reversep (< n 0))
 	(msg rmail-current-message))
     (unwind-protect
 	(progn
 	  (widen)
-	  ;; Check messages one by one, advancing message number up or down
-	  ;; but searching forward through each message.
-	  (if reversep
-	      (while (and (null win) (> msg 1))
-		(goto-char (rmail-msgbeg (setq msg (1- msg))))
-		(setq win (re-search-forward
-			   regexp (rmail-msgend msg) t)))
-	    (while (and (null win) (< msg rmail-total-messages))
-	      (goto-char (rmail-msgbeg (setq msg (1+ msg))))
-	      (setq win (re-search-forward regexp (rmail-msgend msg) t)))))
+	  (while (/= n 0)
+	    ;; Check messages one by one, advancing message number up or down
+	    ;; but searching forward through each message.
+	    (if reversep
+		(while (and (null win) (> msg 1))
+		  (goto-char (rmail-msgbeg (setq msg (1- msg))))
+		  (setq win (re-search-forward
+			     regexp (rmail-msgend msg) t)))
+	      (while (and (null win) (< msg rmail-total-messages))
+		(goto-char (rmail-msgbeg (setq msg (1+ msg))))
+		(setq win (re-search-forward regexp (rmail-msgend msg) t))))
+	    (setq n (+ n (if (< n 0) -1 1)))))
       (if win
 	  (progn
 	    ;; If this is a reverse search and we found a message,
@@ -1171,6 +1177,30 @@
 	(ding)
 	(message "Search failed: %s" regexp)))))
 
+(defun rmail-search-backwards (regexp &optional n)
+  "Show message containing previous match for REGEXP.
+Prefix argument gives repeat count; negative argument means search
+forward (through later messages).
+Interactively, empty argument means use same regexp used last time."
+  (interactive
+    (let* ((reversep (< (prefix-numeric-value current-prefix-arg) 0))
+	   (prompt
+	    (concat (if reversep "Reverse " "") "Rmail search (regexp): "))
+	   regexp)
+      (if rmail-search-last-regexp
+	  (setq prompt (concat prompt
+			       "(default "
+			       rmail-search-last-regexp
+			       ") ")))
+      (setq regexp (read-string prompt))
+      (cond ((not (equal regexp ""))
+	     (setq rmail-search-last-regexp regexp))
+	    ((not rmail-search-last-regexp)
+	     (error "No previous Rmail search string")))
+      (list rmail-search-last-regexp
+	    (prefix-numeric-value current-prefix-arg))))
+  (rmail-search regexp (- (or n -1))))
+
 ;; Show the first message which has the `unseen' attribute.
 (defun rmail-first-unseen-message ()
   (let ((current 1)
--- a/lisp/simple.el	Sun Jul 26 19:36:03 1992 +0000
+++ b/lisp/simple.el	Sun Jul 26 19:54:20 1992 +0000
@@ -350,8 +350,35 @@
 	(setq command-history (cons command command-history)))
     (eval command)))
 
-;; (defvar repeat-complex-command nil)
-
+(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.
+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- arg) command-history))
+	(minibuffer-history-position arg)
+	(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
+					     (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))))
+
 (defvar minibuffer-history nil)
 (defvar minibuffer-history-sexp-flag nil)
 (setq minibuffer-history-variable 'minibuffer-history)
@@ -371,35 +398,55 @@
 (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.
-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.
-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- arg) command-history))
-	(minibuffer-history-position arg)
-	(minibuffer-history-sexp-flag t)
-	(repeat-complex-command-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
-					     (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))))
+(define-key minibuffer-local-map "\er" 'previous-matching-history-element)
+(define-key minibuffer-local-ns-map "\er" 'previous-matching-history-element)
+(define-key minibuffer-local-ns-map "\er" 'previous-matching-history-element)
+(define-key minibuffer-local-completion-map "\er"
+  'previous-matching-history-element)
+(define-key minibuffer-local-completion-map "\er"
+  'previous-matching-history-element)
+(define-key minibuffer-local-must-match-map "\er"
+  'previous-matching-history-element)
+
+(define-key minibuffer-local-map "\es" 'next-matching-history-element)
+(define-key minibuffer-local-ns-map "\es" 'next-matching-history-element)
+(define-key minibuffer-local-ns-map "\es" 'next-matching-history-element)
+(define-key minibuffer-local-completion-map "\es"
+  'next-matching-history-element)
+(define-key minibuffer-local-completion-map "\es"
+  'next-matching-history-element)
+(define-key minibuffer-local-must-match-map "\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))
+	(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 following item in minibuffer history"
+		   "No preceding item in minibuffer history")))
+      (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."
@@ -423,10 +470,8 @@
 (defun previous-history-element (n)
   "Inserts the previous element of `command-history' into the minibuffer."
   (interactive "p")
-;;  (if repeat-complex-command-flag
   (next-history-element (- n)))
-;;    (repeat-complex-command 1)))
-
+
 (defun goto-line (arg)
   "Goto line ARG, counting from line 1 at beginning of buffer."
   (interactive "NGoto line: ")