>From 0e8a8d030117022b6e3beaf7ab76c8bf70ff29a7 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Wed, 6 Jul 2022 20:53:41 -0700 Subject: [PATCH 2/2] Add command to jump to erc-match keywords * lisp/erc/erc-match.el (erc-match-next-keyword, erc-match-previous-keyword): Add new commands. * tests/lisp/erc/erc-match-tests.el: New file. --- lisp/erc/erc-match.el | 31 +++++++++++++- test/lisp/erc/erc-match-tests.el | 72 ++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+), 1 deletion(-) diff --git a/lisp/erc/erc-match.el b/lisp/erc/erc-match.el index 20fe640225..76bda8c467 100644 --- a/lisp/erc/erc-match.el +++ b/lisp/erc/erc-match.el @@ -520,7 +520,7 @@ erc-match-message (face match-face)) (when (consp regex) (setq regex (car elt) - face (cdr elt))) + face (list (cadr elt) 'erc-keyword-face))) (goto-char (+ 2 (or nick-end (point-min)))) (while (re-search-forward regex nil t) @@ -647,6 +647,35 @@ erc-beep-on-match (when (member match-type erc-beep-match-types) (beep))) +(declare-function text-property-search-forward "text-property-search" + (property &optional value predicate not-current)) +(declare-function text-property-search-backward "text-property-search" + (property &optional value predicate not-current)) + +(defun erc-match-next-keyword (arg) + "Jump to the ARGth next keyword, if any." + (interactive "p") + (require 'text-property-search) + (let* ((f (if (< arg 0) + #'text-property-search-backward + #'text-property-search-forward)) + (i (1+ (abs arg))) + (test (lambda (a b) (if (consp b) (memq a b) (eq a b)))) + (args `(font-lock-face erc-keyword-face ,test t)) + (opoint (and (> (point) erc-insert-marker) (point))) + m) + (when opoint + (goto-char erc-insert-marker)) + (while (and (not (zerop (cl-decf i))) (setq m (apply f args))) + (goto-char (prop-match-beginning m))) + (unless (or m (not opoint)) + (goto-char opoint)))) + +(defun erc-match-previous-keyword (arg) + "Jump to the ARGth previous keyword, if any" + (interactive "p") + (erc-match-next-keyword (- arg))) + (provide 'erc-match) ;;; erc-match.el ends here diff --git a/test/lisp/erc/erc-match-tests.el b/test/lisp/erc/erc-match-tests.el index aed23e665d..7f0159544f 100644 --- a/test/lisp/erc/erc-match-tests.el +++ b/test/lisp/erc/erc-match-tests.el @@ -118,4 +118,76 @@ erc-dangerous-hosts (should (equal (cadr (pop calls)) '(("example\\.net")))) (should-not erc-dangerous-hosts))))) +(defun erc-match-tests--populate () + (let ((erc-keywords `("five" ("six" font-lock-string-face) "\\