(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)
(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
(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)
(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,
(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)
(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.
(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 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)
+
+(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."
(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)))
-
+\f
(defun goto-line (arg)
"Goto line ARG, counting from line 1 at beginning of buffer."
(interactive "NGoto line: ")