* 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)
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
;; 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)))
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
(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)
(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.
;; 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)))
;; 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))
;; 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.
;; 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...
;; ... 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))
(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)
(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)
'( :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))