]> git.eshelyaron.com Git - emacs.git/commitdiff
Decouple disparate escape-hatch concerns in erc-stamp
authorF. Jason Park <jp@neverwas.me>
Sat, 4 Nov 2023 20:48:11 +0000 (13:48 -0700)
committerF. Jason Park <jp@neverwas.me>
Sat, 4 Nov 2023 22:41:14 +0000 (15:41 -0700)
* lisp/erc/erc-stamp.el (erc-stamp--allow-unmanaged): Improve doc
string.
(erc-stamp--permanent-cursor-sensor-functions): New variable to take
over the formerly provided `cursor-sensor-functions' aspect of the
flag `erc-stamp--allow-unmanaged'.
(erc-add-timestamp): Use
`erc-stamp--permanent-cursor-sensor-functions' instead of
`erc-stamp--allow-unmanaged' in guard condition.
(erc-munge-invisibility-spec): Use dedicated compatibility flag
`erc-stamp--permanent-cursor-sensor-functions' and forgo unnecessary
setup when it's non-nil.  (Bug#60936)

lisp/erc/erc-stamp.el

index b65c7adf676d4ebcb2d0221a13e717bcdb02cd35..71036a9a8537e0d717737b45eaafc120ae8f3e75 100644 (file)
@@ -224,9 +224,19 @@ This becomes the message's `erc-ts' text property."
   "Non-nil means inhibit `erc-add-timestamp' completely.")
 
 (defvar erc-stamp--allow-unmanaged nil
-  "Non-nil means `erc-add-timestamp' runs unconditionally.
-Escape hatch for third-parties using lower-level API functions,
-such as `erc-display-line', directly.")
+  "Non-nil means run `erc-add-timestamp' almost unconditionally.
+This is an unofficial escape hatch for code wanting to use
+lower-level message-insertion functions, like `erc-insert-line',
+directly.  Third parties needing such functionality should
+petition for it via \\[erc-bug].")
+
+(defvar erc-stamp--permanent-cursor-sensor-functions nil
+  "Non-nil means add `cursor-sensor-functions' unconditionally.
+This is an unofficial escape hatch for code wanting the text
+property `cursor-sensor-functions' to always be present,
+regardless of the option `erc-echo-timestamps'.  Third parties
+needing such pre-5.6 behavior to stick around should make that
+known via \\[erc-bug].")
 
 (defun erc-add-timestamp ()
   "Add timestamp and text-properties to message.
@@ -256,8 +266,8 @@ or `erc-send-modify-hook'."
                  (erc-away-time))
        (funcall erc-insert-away-timestamp-function
                 (erc-format-timestamp ct erc-away-timestamp-format)))
-      (when erc-stamp--allow-unmanaged
-        (add-text-properties (point-min) (1- (point-max))
+      (when erc-stamp--permanent-cursor-sensor-functions
+        (add-text-properties (point-min) (max (point-min) (1- (point-max)))
                           ;; It's important for the function to
                           ;; be different on different entries (bug#22700).
                           (list 'cursor-sensor-functions
@@ -793,16 +803,18 @@ Return the empty string if FORMAT is nil."
       (cursor-intangible-mode -1)))
   (if erc-echo-timestamps
       (progn
-        (dolist (hook '(erc-insert-post-hook erc-send-post-hook))
-          (add-hook hook #'erc-stamp--add-csf-on-post-modify nil t))
-        (erc--restore-initialize-priors erc-stamp-mode
-          erc-stamp--csf-props-updated-p nil)
-        (unless (or erc-stamp--allow-unmanaged erc-stamp--csf-props-updated-p)
-          (setq erc-stamp--csf-props-updated-p t)
-          (let ((erc--msg-props (map-into '((erc-ts . t)) 'hash-table)))
-            (with-silent-modifications
-              (erc--traverse-inserted (point-min) erc-insert-marker
-                                      #'erc-stamp--add-csf-on-post-modify))))
+        (unless erc-stamp--permanent-cursor-sensor-functions
+          (dolist (hook '(erc-insert-post-hook erc-send-post-hook))
+            (add-hook hook #'erc-stamp--add-csf-on-post-modify nil t))
+          (erc--restore-initialize-priors erc-stamp-mode
+            erc-stamp--csf-props-updated-p nil)
+          (unless erc-stamp--csf-props-updated-p
+            (setq erc-stamp--csf-props-updated-p t)
+            (let ((erc--msg-props (map-into '((erc-ts . t)) 'hash-table)))
+              (with-silent-modifications
+                (erc--traverse-inserted
+                 (point-min) erc-insert-marker
+                 #'erc-stamp--add-csf-on-post-modify)))))
         (cursor-sensor-mode +1) ; idempotent
         (when (>= emacs-major-version 29)
           (add-function :before-until (local 'clear-message-function)