diff options
| author | Olivier Certner | 2021-01-14 18:26:38 +0100 |
|---|---|---|
| committer | Amin Bandali | 2021-09-12 01:05:38 -0400 |
| commit | 3df279aae2a1f0c8dc5acee59dd48840f6695866 (patch) | |
| tree | f2e4abb07c89144bddcd572a5784e7d280ded348 /lisp/erc | |
| parent | e4b7fa05001ef48db28a77e1343ffb196de39609 (diff) | |
| download | emacs-3df279aae2a1f0c8dc5acee59dd48840f6695866.tar.gz emacs-3df279aae2a1f0c8dc5acee59dd48840f6695866.zip | |
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>
Diffstat (limited to 'lisp/erc')
| -rw-r--r-- | lisp/erc/erc-track.el | 91 |
1 files changed, 53 insertions, 38 deletions
diff --git a/lisp/erc/erc-track.el b/lisp/erc/erc-track.el index 7cdddbfd386..7b9a2e9cd5b 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' | |||
| 275 | is true). | 275 | is true). |
| 276 | 276 | ||
| 277 | For how the face is chosen for a buffer, see | 277 | For how the face is chosen for a buffer, see |
| 278 | `erc-track-find-face' and `erc-track-priority-faces-only'. For | 278 | `erc-track-select-mode-line-face' and |
| 279 | how buffers are then displayed in the mode line, see | 279 | `erc-track-priority-faces-only'. For how buffers are then |
| 280 | `erc-modified-channels-display'.") | 280 | displayed in the mode line, see `erc-modified-channels-display'.") |
| 281 | 281 | ||
| 282 | (defcustom erc-track-showcount nil | 282 | (defcustom erc-track-showcount nil |
| 283 | "If non-nil, count of unseen messages will be shown for each channel." | 283 | "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." | |||
| 734 | (erc-modified-channels-display))) | 734 | (erc-modified-channels-display))) |
| 735 | 735 | ||
| 736 | (defun erc-track-find-face (faces) | 736 | (defun erc-track-find-face (faces) |
| 737 | "Return the face to use in the mode line from the faces in FACES. | 737 | "Return the face to use in the mode line." |
| 738 | If `erc-track-faces-priority-list' is set, the one from FACES who | 738 | (declare (obsolete erc-track-select-mode-line-face "28.1")) |
| 739 | is first in that list will be used. If nothing matches or if | 739 | (erc-track-select-mode-line-face (car faces) (cdr faces))) |
| 740 | `erc-track-faces-priority-list' is not set, the default mode-line | 740 | |
| 741 | faces will be used. | 741 | (defun erc-track-select-mode-line-face (cur-face new-faces) |
| 742 | 742 | "Return the face to use in the mode line. | |
| 743 | If `erc-track-faces-normal-list' is non-nil, use it to produce a | 743 | |
| 744 | blinking effect that indicates channel activity when the first | 744 | CUR-FACE is the face currently used in the mode line (for the |
| 745 | element in FACES and the highest-ranking face among the rest of | 745 | current buffer). NEW-FACES is the list of new faces that have |
| 746 | FACES are both members of `erc-track-faces-normal-list'. | 746 | just been seen (in the current buffer). |
| 747 | 747 | ||
| 748 | If one of the faces is a list, then it will be ranked according | 748 | Initially, the selected face is the one with highest priority in |
| 749 | to its highest-tanking face member. A list of faces including | 749 | `erc-track-faces-priority-list' (i.e., the one closest to the |
| 750 | that member will take priority over just the single member | 750 | front of the list) among CUR-FACE and NEW-FACES. If nothing |
| 751 | element." | 751 | matches (including if `erc-track-faces-priority-list' is not |
| 752 | set), the default mode-line faces will be used (NIL is returned). | ||
| 753 | |||
| 754 | If the selected face is still CUR-FACE (highest priority), and | ||
| 755 | the highest priority face in NEW-FACES alone is different (which | ||
| 756 | necessarily means it has lower priority than CUR-FACE), and both | ||
| 757 | are in `erc-track-faces-normal-list', then the latter is selected | ||
| 758 | instead. This has the effect of allowing the current mode line | ||
| 759 | face, if a member of `erc-track-faces-normal-list', to be | ||
| 760 | replaced with another with lower priority face from NEW-FACES, if | ||
| 761 | that face with highest priority in NEW-FACES is also a member of | ||
| 762 | `erc-track-faces-normal-list'." | ||
| 752 | (let ((choice (catch 'face | 763 | (let ((choice (catch 'face |
| 753 | (dolist (candidate erc-track-faces-priority-list) | 764 | (dolist (candidate erc-track-faces-priority-list) |
| 754 | (when (member candidate faces) | 765 | (when (or (equal candidate cur-face) |
| 755 | (throw 'face candidate))))) | 766 | (member candidate new-faces)) |
| 756 | (no-first (and erc-track-faces-normal-list | 767 | (throw 'face candidate)))))) |
| 757 | (catch 'face | 768 | (when choice |
| 758 | (dolist (candidate erc-track-faces-priority-list) | 769 | (if (and (equal choice cur-face) |
| 759 | (when (member candidate (cdr faces)) | 770 | (member choice erc-track-faces-normal-list)) |
| 760 | (throw 'face candidate))))))) | 771 | (let ((only-in-new |
| 761 | (cond ((null choice) | 772 | (catch 'face |
| 762 | nil) | 773 | (dolist (candidate erc-track-faces-priority-list) |
| 763 | ((and (member choice erc-track-faces-normal-list) | 774 | (when (member candidate new-faces) |
| 764 | (member no-first erc-track-faces-normal-list)) | 775 | (throw 'face candidate)))))) |
| 765 | no-first) | 776 | (if (member only-in-new erc-track-faces-normal-list) |
| 766 | (t | 777 | only-in-new |
| 767 | choice)))) | 778 | choice)) |
| 779 | choice)))) | ||
| 768 | 780 | ||
| 769 | (defun erc-track-modified-channels () | 781 | (defun erc-track-modified-channels () |
| 770 | "Hook function for `erc-insert-post-hook' to check if the current | 782 | "Hook function for `erc-insert-post-hook' to check if the current |
| @@ -804,17 +816,20 @@ is in `erc-mode'." | |||
| 804 | ;; Add buffer, faces and counts | 816 | ;; Add buffer, faces and counts |
| 805 | (setq erc-modified-channels-alist | 817 | (setq erc-modified-channels-alist |
| 806 | (cons (cons (current-buffer) | 818 | (cons (cons (current-buffer) |
| 807 | (cons 1 (erc-track-find-face faces))) | 819 | (cons |
| 820 | 1 (erc-track-select-mode-line-face | ||
| 821 | (car faces) (cdr faces)))) | ||
| 808 | erc-modified-channels-alist)) | 822 | erc-modified-channels-alist)) |
| 809 | ;; Else modify the face for the buffer, if necessary. | 823 | ;; Else modify the face for the buffer, if necessary. |
| 810 | (when faces | 824 | (when faces |
| 811 | (let* ((cell (assq (current-buffer) | 825 | (let* ((cell (assq (current-buffer) |
| 812 | erc-modified-channels-alist)) | 826 | erc-modified-channels-alist)) |
| 813 | (old-face (cddr cell)) | 827 | (old-face (cddr cell)) |
| 814 | (new-face (erc-track-find-face | 828 | (new-face (if old-face |
| 815 | (if old-face | 829 | (erc-track-select-mode-line-face |
| 816 | (cons old-face faces) | 830 | old-face faces) |
| 817 | faces)))) | 831 | (erc-track-select-mode-line-face |
| 832 | (car faces) (cdr faces))))) | ||
| 818 | (setcdr cell (cons (1+ (cadr cell)) new-face))))) | 833 | (setcdr cell (cons (1+ (cadr cell)) new-face))))) |
| 819 | ;; And display it | 834 | ;; And display it |
| 820 | (erc-modified-channels-display))) | 835 | (erc-modified-channels-display))) |