summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lisp/mail/rmail.el60
-rw-r--r--lisp/simple.el95
2 files changed, 115 insertions, 40 deletions
diff --git a/lisp/mail/rmail.el b/lisp/mail/rmail.el
index fa0c7db2d1c..ba2a9766411 100644
--- a/lisp/mail/rmail.el
+++ b/lisp/mail/rmail.el
@@ -261,6 +261,7 @@ Note: it means the file has no messages in it.\n\^_")))
(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 @@ or forward if N is negative."
(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 @@ and reverse search is specified by a negative numeric arg."
(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 @@ and reverse search is specified by a negative numeric arg."
(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 @@ and reverse search is specified by a negative numeric arg."
(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)
diff --git a/lisp/simple.el b/lisp/simple.el
index 0ed38887103..2da71888eda 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -350,27 +350,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-sexp-flag nil)
-(setq minibuffer-history-variable 'minibuffer-history)
-(setq 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.
@@ -384,7 +363,6 @@ to get different commands to edit and resubmit."
(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))
@@ -400,6 +378,75 @@ to get different commands to edit and resubmit."
(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)
+(setq 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)
+
+(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 @@ to get different commands to edit and resubmit."
(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: ")