Function: next-matching-history-element

next-matching-history-element is an interactive and byte-compiled function defined in simple.el.gz.

Signature

(next-matching-history-element REGEXP N)

Documentation

Find the next history element that matches REGEXP.

(The next history element refers to a more recent action.)
With prefix argument N, search for Nth next match. If N is negative, find the previous or Nth previous match. Normally, history elements are matched case-insensitively if case-fold-search is non-nil, but an uppercase letter in REGEXP makes the search case-sensitive.

View in manual

Probably introduced at or before Emacs version 31.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/simple.el.gz
(defun next-matching-history-element (regexp n)
  "Find the next history element that matches REGEXP.
\(The next history element refers to a more recent action.)
With prefix argument N, search for Nth next match.
If N is negative, find the previous or Nth previous match.
Normally, history elements are matched case-insensitively if
`case-fold-search' is non-nil, but an uppercase letter in REGEXP
makes the search case-sensitive."
  (interactive
   (let* ((n (prefix-numeric-value current-prefix-arg))
          (enable-recursive-minibuffers t)
          (regexp (read-from-minibuffer
                   (format-prompt "%s element matching regexp"
                                  (and minibuffer-history-search-history
                                       (car minibuffer-history-search-history))
                                  (if (>= n 0) "Next" "Previous"))
                   nil minibuffer-local-map nil
                   'minibuffer-history-search-history
                   (car minibuffer-history-search-history))))
     ;; Use the last regexp specified, by default, if input is empty.
     (list (if (string= regexp "")
	       (if minibuffer-history-search-history
		   (car minibuffer-history-search-history)
                 (user-error "No history search regexp"))
	     regexp)
           n)))
  (previous-matching-history-element regexp (- n)))