[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 5e2be1e0ba6 09/12: Swap hook positions of erc-fill and erc-match-
From: |
F. Jason Park |
Subject: |
master 5e2be1e0ba6 09/12: Swap hook positions of erc-fill and erc-match-message |
Date: |
Fri, 13 Oct 2023 10:49:37 -0400 (EDT) |
branch: master
commit 5e2be1e0ba64f030b8493d3e7b93b69caba3a254
Author: F. Jason Park <jp@neverwas.me>
Commit: F. Jason Park <jp@neverwas.me>
Swap hook positions of erc-fill and erc-match-message
* etc/ERC-NEWS: Fix new order of reserved modify-hook members.
* lisp/erc/erc-fill.el: Increase depth of `erc-fill' in both modify
hooks from 40 to 60.
* lisp/erc/erc-match.el (erc-match-mode, erc-match-enable,
erc-match-disable): Use general module setup function
`erc-match--setup' for buffer-local modifications instead of calling
`erc-match--modify-invisibility-spec' directly. Add and remove new
post-modify hook `erc-match--on-insert-post'.
(erc-hide-fools): Use `erc--msg-props' for communicating to
post-processing step for applying invisible props instead of doing so
immediately.
(erc-match--on-insert-post): New function to apply module-specific
`invisible' props. Will likely be replaced by a general service to do
the same, perhaps provided by a future "erc-ignore"-like module.
(erc-match--modify-invisibility-spec, erc-match--setup): Rename former
to latter and only operate on current buffer.
* test/lisp/erc/erc-scenarios-match.el
(erc-scenarios-match--stamp-left-fools-invisible,
erc-scenarios-match--stamp-right-fools-invisible,
erc-scenarios-match--stamp-right-invisible-fill-wrap,
erc-scenarios-match--stamp-both-invisible-fill-static): Update
expected order of ERC-owned `invisible' prop members `match-fools' and
`timestamp'.
* test/lisp/erc/erc-tests.el (erc--essential-hook-ordering): Swap
expected order of `erc-fill' and `erc-add-timestamp' in both hooks.
(Bug#64301)
---
etc/ERC-NEWS | 13 ++++++-------
lisp/erc/erc-fill.el | 4 ++--
lisp/erc/erc-match.el | 31 ++++++++++++++++++++++---------
test/lisp/erc/erc-scenarios-match.el | 14 +++++++-------
test/lisp/erc/erc-tests.el | 6 +++---
5 files changed, 40 insertions(+), 28 deletions(-)
diff --git a/etc/ERC-NEWS b/etc/ERC-NEWS
index 1861e488288..2e56539f210 100644
--- a/etc/ERC-NEWS
+++ b/etc/ERC-NEWS
@@ -276,13 +276,12 @@ essential members of important hooks.
Luckily, ERC now leverages a feature introduced in Emacs 27, "hook
depth," to secure the positions of a few key members of
'erc-insert-modify-hook' and 'erc-send-modify-hook'. So far, this
-includes the functions 'erc-button-add-buttons', 'erc-fill',
-'erc-match-message', and 'erc-add-timestamp', which now appear in that
-order, when present, at depths beginning at 20 and ending below 80.
-Of most interest to module authors is the new relative positioning of
-the first two, 'erc-button-add-buttons' and 'erc-fill', which have
-been swapped with respect to their previous places in recent ERC
-versions.
+includes the functions 'erc-button-add-buttons', 'erc-match-message',
+'erc-fill', and 'erc-add-timestamp', which now appear in that order,
+when present, at depths beginning at 20 and ending below 80. Of most
+interest to module authors is the new relative positioning of the
+first three, which have been rotated leftward with respect to their
+previous places in recent ERC versions (fill, button, match ,stamp).
ERC also provisionally reserves the same depth interval for
'erc-insert-pre-hook' and possibly other, similar hooks, but will
diff --git a/lisp/erc/erc-fill.el b/lisp/erc/erc-fill.el
index 5ab5d73d9f2..4ec58fcb96f 100644
--- a/lisp/erc/erc-fill.el
+++ b/lisp/erc/erc-fill.el
@@ -49,8 +49,8 @@ the channel buffers are filled."
;; other modules. Ideally, this module's processing should happen
;; after "morphological" modifications to a message's text but
;; before superficial decorations.
- ((add-hook 'erc-insert-modify-hook #'erc-fill 40)
- (add-hook 'erc-send-modify-hook #'erc-fill 40))
+ ((add-hook 'erc-insert-modify-hook #'erc-fill 60)
+ (add-hook 'erc-send-modify-hook #'erc-fill 60))
((remove-hook 'erc-insert-modify-hook #'erc-fill)
(remove-hook 'erc-send-modify-hook #'erc-fill)))
diff --git a/lisp/erc/erc-match.el b/lisp/erc/erc-match.el
index 50db8a132ec..186717579d7 100644
--- a/lisp/erc/erc-match.el
+++ b/lisp/erc/erc-match.el
@@ -53,13 +53,14 @@ they are hidden or highlighted. This is controlled via the
variables
you can decide whether the entire message or only the sending nick is
highlighted."
((add-hook 'erc-insert-modify-hook #'erc-match-message 50)
- (add-hook 'erc-mode-hook #'erc-match--modify-invisibility-spec)
- (unless erc--updating-modules-p
- (erc-buffer-do #'erc-match--modify-invisibility-spec))
+ (add-hook 'erc-mode-hook #'erc-match--setup)
+ (unless erc--updating-modules-p (erc-buffer-do #'erc-match--setup))
+ (add-hook 'erc-insert-post-hook #'erc-match--on-insert-post 50)
(erc--modify-local-map t "C-c C-k" #'erc-go-to-log-matches-buffer))
((remove-hook 'erc-insert-modify-hook #'erc-match-message)
- (remove-hook 'erc-mode-hook #'erc-match--modify-invisibility-spec)
- (erc-match--modify-invisibility-spec)
+ (remove-hook 'erc-insert-post-hook #'erc-match--on-insert-post)
+ (remove-hook 'erc-mode-hook #'erc-match--setup)
+ (erc-buffer-do #'erc-match--setup)
(erc--modify-local-map nil "C-c C-k" #'erc-go-to-log-matches-buffer)))
;; Remaining customizations
@@ -657,7 +658,20 @@ See `erc-log-match-format'."
(defun erc-hide-fools (match-type _nickuserhost _message)
"Hide comments from designated fools."
- (when (eq match-type 'fool)
+ (when (and erc--msg-props (eq match-type 'fool))
+ (puthash 'erc--invisible 'erc-match-fool erc--msg-props)))
+
+;; FIXME remove, make public, or only add locally.
+;;
+;; ERC modules typically don't add internal functions to public hooks
+;; globally. However, ERC 5.6 will likely include a general
+;; (internal) facility for adding invisible props, which will obviate
+;; the need for this function. IOW, leaving this internal for now is
+;; an attempt to avoid the hassle of the deprecation process.
+(defun erc-match--on-insert-post ()
+ "Hide messages marked with the `erc--invisible' prop."
+ (when (erc--check-msg-prop 'erc--invisible 'erc-match-fool)
+ (remhash 'erc--invisible erc--msg-props)
(erc--hide-message 'match-fools)))
(defun erc-beep-on-match (match-type _nickuserhost _message)
@@ -666,14 +680,13 @@ This function is meant to be called from
`erc-text-matched-hook'."
(when (member match-type erc-beep-match-types)
(beep)))
-(defun erc-match--modify-invisibility-spec ()
+(defun erc-match--setup ()
"Add an `erc-match' property to the local spec."
;; Hopefully, this will be extended to do the same for other
;; invisible properties managed by this module.
(if erc-match-mode
(erc-match-toggle-hidden-fools +1)
- (erc-with-all-buffers-of-server nil nil
- (erc-match-toggle-hidden-fools -1))))
+ (erc-match-toggle-hidden-fools -1)))
(defun erc-match-toggle-hidden-fools (arg)
"Toggle fool visibility.
diff --git a/test/lisp/erc/erc-scenarios-match.el
b/test/lisp/erc/erc-scenarios-match.el
index 3da55572cf7..17f7649566e 100644
--- a/test/lisp/erc/erc-scenarios-match.el
+++ b/test/lisp/erc/erc-scenarios-match.el
@@ -134,7 +134,7 @@
;; Leading stamp has combined `invisible' property value.
(should (equal (get-text-property (pos-bol) 'invisible)
- '(timestamp match-fools)))
+ '(match-fools timestamp)))
;; Message proper has the `invisible' property `match-fools'.
(let ((msg-beg (next-single-property-change (pos-bol) 'invisible)))
@@ -168,7 +168,7 @@
;; Stamps have a combined `invisible' property value.
(should (equal (get-text-property (1- end) 'invisible)
- '(timestamp match-fools)))
+ '(match-fools timestamp)))
;; The final newline is hidden by `match', not `stamps'
(with-suppressed-warnings ((obsolete erc-legacy-invisible-bounds-p))
@@ -184,7 +184,7 @@
;; It ends just before the timestamp.
(let ((msg-end (next-single-property-change (pos-bol) 'invisible)))
(should (equal (get-text-property msg-end 'invisible)
- '(timestamp match-fools)))
+ '(match-fools timestamp)))
;; Stamp's `invisible' property extends throughout the stamp
;; and ends before the trailing newline.
@@ -230,7 +230,7 @@
;; Stamps have a combined `invisible' property value.
(should (equal (get-text-property (1- (pos-eol)) 'invisible)
- '(timestamp match-fools)))
+ '(match-fools timestamp)))
;; The message proper has the `invisible' property `match-fools',
;; which starts at the preceding newline...
@@ -239,7 +239,7 @@
;; ... and ends just before the timestamp.
(let ((msgend (next-single-property-change (1- (pos-bol)) 'invisible)))
(should (equal (get-text-property msgend 'invisible)
- '(timestamp match-fools)))
+ '(match-fools timestamp)))
;; The newline before `erc-insert-marker' is still visible.
(should-not (get-text-property (pos-eol) 'invisible))
@@ -350,7 +350,7 @@
(let ((msgend (next-single-property-change (pos-bol) 'invisible)))
;; Stamp has a combined `invisible' property value.
(should (equal (get-text-property msgend 'invisible)
- '(timestamp match-fools)))
+ '(match-fools timestamp)))
;; Combined `invisible' property spans entire timestamp.
(should (= (next-single-property-change msgend 'invisible)
@@ -492,7 +492,7 @@
(let ((msgend (next-single-property-change (pos-bol) 'invisible)))
;; Stamp has a combined `invisible' property value.
(should (equal (get-text-property msgend 'invisible)
- '(timestamp match-fools)))
+ '(match-fools timestamp)))
;; Combined `invisible' property spans entire timestamp.
(should (= (next-single-property-change msgend 'invisible)
diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el
index 39135a8c2df..4f4662f5075 100644
--- a/test/lisp/erc/erc-tests.el
+++ b/test/lisp/erc/erc-tests.el
@@ -2455,14 +2455,14 @@
'( :erc-insert-modify-hook (erc-controls-highlight ; 0
erc-button-add-buttons ; 30
- erc-fill ; 40
erc-match-message ; 50
- erc-add-timestamp) ; 60
+ erc-fill ; 60
+ erc-add-timestamp) ; 70
:erc-send-modify-hook ( erc-controls-highlight ; 0
erc-button-add-buttons ; 30
erc-fill ; 40
- erc-add-timestamp)))) ; 50
+ erc-add-timestamp)))) ; 70
(ert-deftest erc-migrate-modules ()
(should (equal (erc-migrate-modules '(autojoin timestamp button))
- master updated (bd297132016 -> baf778c7caa), F. Jason Park, 2023/10/13
- master 328a985651a 01/12: Skip post-minibuffer restore in erc-scrolltobottom-all, F. Jason Park, 2023/10/13
- master 9120d7a32ea 02/12: Honor nil values in erc--restore-initialize-priors, F. Jason Park, 2023/10/13
- master d46c016fbd0 03/12: Sort and dedupe when loading modules in erc-open, F. Jason Park, 2023/10/13
- master a4bae965e06 07/12: Easily excise list-valued text prop members in ERC, F. Jason Park, 2023/10/13
- master c68dc7786fc 08/12: Manage some text props for ERC insertion-hook members, F. Jason Park, 2023/10/13
- master f8af241192b 10/12: Treat previous/next-line specially in erc-fill-wrap, F. Jason Park, 2023/10/13
- master 5e2be1e0ba6 09/12: Swap hook positions of erc-fill and erc-match-message,
F. Jason Park <=
- master 1950ddebacb 04/12: Allow spoofing process marker in erc-display-line-1, F. Jason Park, 2023/10/13
- master 9c2f99b7d73 05/12: Use erc-display-message instead of erc-make-notice, F. Jason Park, 2023/10/13
- master baf778c7caa 12/12: More defcustom fixes in ERC (Bug#66520), F. Jason Park, 2023/10/13
- master f97fdf5e50e 06/12: Deprecate option erc-remove-parsed-property, F. Jason Park, 2023/10/13
- master 52af0a5fb97 11/12: Add command to refill buffer in erc-fill-wrap-mode, F. Jason Park, 2023/10/13