emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 3df279a 1/2: ERC: Track: Rewrite 'erc-track-find-face' as 'erc-tr


From: Amin Bandali
Subject: master 3df279a 1/2: ERC: Track: Rewrite 'erc-track-find-face' as 'erc-track-select-mode-line-face'
Date: Sun, 12 Sep 2021 01:21:18 -0400 (EDT)

branch: master
commit 3df279aae2a1f0c8dc5acee59dd48840f6695866
Author: Olivier Certner <olce.emacs@certner.fr>
Commit: Amin Bandali <bandali@gnu.org>

    ERC: Track: Rewrite 'erc-track-find-face' as 
'erc-track-select-mode-line-face'
    
    * lisp/erc/erc-track.el (erc-track-find-face): Declare obsolete and
    rewrite as 'erc-track-select-mode-line-face', changing the function
    arguments, so that it is very clear what the current algorithm is.
    No functional changes.  Performance improvements.  Clarify the
    documentation and remove the part on some faces being lists, which
    clearly does not apply.
    (erc-track-modified-channels): Replace calls to 'erc-track-find-face'
    with calls to 'erc-track-select-mode-line-face', preserving the
    existing behavior.
    (erc-modified-channels-alist): Change the reference to
    'erc-track-select-mode-line-face' in the documentation following the
    rename.
    * etc/NEWS: Announce the change.
    
    Co-authored-by: Amin Bandali <bandali@gnu.org>
---
 etc/NEWS              |  7 ++++
 lisp/erc/erc-track.el | 91 ++++++++++++++++++++++++++++++---------------------
 2 files changed, 60 insertions(+), 38 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index 50cf074..406a73b 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2653,6 +2653,13 @@ node "(erc) Connecting" in the ERC manual for more 
details and
 examples on how to specify and use TLS client certificates with
 'erc-tls'.
 
+---
+*** Add 'erc-track-select-mode-line-face' (obsoletes 'erc-track-find-face').
+The 'erc-track-find-face' function of the erc-track module has been
+declared obsolete and rewritten as 'erc-track-select-mode-line-face',
+with different expected arguments (the current and old faces are now
+separated) and clearer documentation.
+
 ** xwidget-webkit mode
 
 *** New xwidget commands.
diff --git a/lisp/erc/erc-track.el b/lisp/erc/erc-track.el
index 7cdddbf..7b9a2e9 100644
--- a/lisp/erc/erc-track.el
+++ b/lisp/erc/erc-track.el
@@ -275,9 +275,9 @@ is disconnected, provided 
`erc-track-remove-disconnected-buffers'
 is true).
 
 For how the face is chosen for a buffer, see
-`erc-track-find-face' and `erc-track-priority-faces-only'.  For
-how buffers are then displayed in the mode line, see
-`erc-modified-channels-display'.")
+`erc-track-select-mode-line-face' and
+`erc-track-priority-faces-only'.  For how buffers are then
+displayed in the mode line, see `erc-modified-channels-display'.")
 
 (defcustom erc-track-showcount nil
   "If non-nil, count of unseen messages will be shown for each channel."
@@ -734,37 +734,49 @@ Use `erc-make-mode-line-buffer-name' to create buttons."
     (erc-modified-channels-display)))
 
 (defun erc-track-find-face (faces)
-  "Return the face to use in the mode line from the faces in FACES.
-If `erc-track-faces-priority-list' is set, the one from FACES who
-is first in that list will be used.  If nothing matches or if
-`erc-track-faces-priority-list' is not set, the default mode-line
-faces will be used.
-
-If `erc-track-faces-normal-list' is non-nil, use it to produce a
-blinking effect that indicates channel activity when the first
-element in FACES and the highest-ranking face among the rest of
-FACES are both members of `erc-track-faces-normal-list'.
-
-If one of the faces is a list, then it will be ranked according
-to its highest-tanking face member.  A list of faces including
-that member will take priority over just the single member
-element."
+  "Return the face to use in the mode line."
+  (declare (obsolete erc-track-select-mode-line-face "28.1"))
+  (erc-track-select-mode-line-face (car faces) (cdr faces)))
+
+(defun erc-track-select-mode-line-face (cur-face new-faces)
+  "Return the face to use in the mode line.
+
+CUR-FACE is the face currently used in the mode line (for the
+current buffer).  NEW-FACES is the list of new faces that have
+just been seen (in the current buffer).
+
+Initially, the selected face is the one with highest priority in
+`erc-track-faces-priority-list' (i.e., the one closest to the
+front of the list) among CUR-FACE and NEW-FACES.  If nothing
+matches (including if `erc-track-faces-priority-list' is not
+set), the default mode-line faces will be used (NIL is returned).
+
+If the selected face is still CUR-FACE (highest priority), and
+the highest priority face in NEW-FACES alone is different (which
+necessarily means it has lower priority than CUR-FACE), and both
+are in `erc-track-faces-normal-list', then the latter is selected
+instead.  This has the effect of allowing the current mode line
+face, if a member of `erc-track-faces-normal-list', to be
+replaced with another with lower priority face from NEW-FACES, if
+that face with highest priority in NEW-FACES is also a member of
+`erc-track-faces-normal-list'."
   (let ((choice (catch 'face
-                 (dolist (candidate erc-track-faces-priority-list)
-                   (when (member candidate faces)
-                     (throw 'face candidate)))))
-       (no-first (and erc-track-faces-normal-list
-                      (catch 'face
-                        (dolist (candidate erc-track-faces-priority-list)
-                          (when (member candidate (cdr faces))
-                            (throw 'face candidate)))))))
-    (cond ((null choice)
-          nil)
-         ((and (member choice erc-track-faces-normal-list)
-               (member no-first erc-track-faces-normal-list))
-          no-first)
-         (t
-          choice))))
+                  (dolist (candidate erc-track-faces-priority-list)
+                    (when (or (equal candidate cur-face)
+                              (member candidate new-faces))
+                      (throw 'face candidate))))))
+    (when choice
+      (if (and (equal choice cur-face)
+               (member choice erc-track-faces-normal-list))
+          (let ((only-in-new
+                 (catch 'face
+                   (dolist (candidate erc-track-faces-priority-list)
+                     (when (member candidate new-faces)
+                       (throw 'face candidate))))))
+            (if (member only-in-new erc-track-faces-normal-list)
+                only-in-new
+              choice))
+        choice))))
 
 (defun erc-track-modified-channels ()
   "Hook function for `erc-insert-post-hook' to check if the current
@@ -804,17 +816,20 @@ is in `erc-mode'."
                ;; Add buffer, faces and counts
                (setq erc-modified-channels-alist
                      (cons (cons (current-buffer)
-                                 (cons 1 (erc-track-find-face faces)))
+                                 (cons
+                                   1 (erc-track-select-mode-line-face
+                                      (car faces) (cdr faces))))
                            erc-modified-channels-alist))
              ;; Else modify the face for the buffer, if necessary.
              (when faces
                (let* ((cell (assq (current-buffer)
                                   erc-modified-channels-alist))
                       (old-face (cddr cell))
-                      (new-face (erc-track-find-face
-                                 (if old-face
-                                     (cons old-face faces)
-                                   faces))))
+                      (new-face (if old-face
+                                     (erc-track-select-mode-line-face
+                                      old-face faces)
+                                   (erc-track-select-mode-line-face
+                                    (car faces) (cdr faces)))))
                  (setcdr cell (cons (1+ (cadr cell)) new-face)))))
            ;; And display it
            (erc-modified-channels-display)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]