Function: erc-track-modified-channels

erc-track-modified-channels is a byte-compiled function defined in erc-track.el.gz.

Signature

(erc-track-modified-channels)

Documentation

Hook function for erc-insert-post-hook.

Check if the current buffer should be added to the mode line as a hidden, modified channel. Assumes it will only be called when the current buffer is in erc-mode.

Source Code

;; Defined in /usr/src/emacs/lisp/erc/erc-track.el.gz
(defun erc-track-modified-channels ()
  "Hook function for `erc-insert-post-hook'.
Check if the current buffer should be added to the mode line as a
hidden, modified channel.  Assumes it will only be called when
the current buffer is in `erc-mode'."
  (let ((this-channel (or (erc-default-target)
			  (buffer-name (current-buffer)))))
    (if (and (not (erc-buffer-visible (current-buffer)))
	     (not (member this-channel erc-track-exclude))
	     (not (and erc-track-exclude-server-buffer
                       ;; FIXME either use `erc--server-buffer-p' or
                       ;; explain why that's unwise.
                       (erc-server-or-unjoined-channel-buffer-p)))
             (not (let ((parsed (erc-find-parsed-property)))
                    (or (erc-message-type-member (or parsed (point-min))
                                                 erc-track-exclude-types)
                        ;; Skip certain non-server-sent messages.
                        (and (not parsed)
                             (erc--memq-msg-prop 'erc--skip 'track))))))
	;; If the active buffer is not visible (not shown in a
	;; window), and not to be excluded, determine the kinds of
	;; faces used in the current message, and unless the user
	;; wants to ignore changes in certain channels where there
	;; are no faces corresponding to `erc-track-faces-priority-list',
	;; and the faces in the current message are found in said
	;; priority list, add the buffer to the erc-modified-channels-alist,
	;; if it is not already there.  If the buffer is already on the list
	;; (in the car), change its face attribute (in the cddr) if
	;; necessary.  See `erc-modified-channels-alist' for the
	;; exact data structure used.
        (when-let*
            ((faces (if erc-track-ignore-normal-contenders-p
                        (erc-faces-in (buffer-string))
                      (erc-track--collect-faces-in)))
             (normals erc-track--normal-faces)
             (erc-track-faces-priority-list
              `(,@erc-track--attn-faces ,@erc-track-faces-priority-list))
             (ranks (cons erc-track--priority-faces
                          erc-track-faces-priority-list))
             ((not (and
                    (or (eq erc-track-priority-faces-only 'all)
                        (member this-channel erc-track-priority-faces-only))
                    ;; Iterate over the shorter of `ranks' and `faces'.
                    (let* ((r>fp (or erc-track-ignore-normal-contenders-p
                                     (> (hash-table-count (car ranks))
                                        (hash-table-count (car faces)))))
                           (elems (cond ((not r>fp) (cdr ranks)) ; f>=r
                                        (erc-track-ignore-normal-contenders-p
                                         faces)
                                        ((cdr faces))))
                           (table (if r>fp (car ranks) (car faces))))
                      (not (catch 'found
                             (dolist (f elems)
                               (when (gethash f table)
                                 (throw 'found t))))))))))
          (progn ; FIXME remove `progn' on next major edit
	    (if (not (assq (current-buffer) erc-modified-channels-alist))
		;; Add buffer, faces and counts
		(setq erc-modified-channels-alist
		      (cons (cons (current-buffer)
				  (cons
                                   1 (if erc-track-ignore-normal-contenders-p
                                         (erc-track-select-mode-line-face
                                          nil faces)
                                       (erc-track--select-mode-line-face
                                        nil faces ranks normals))))
			    erc-modified-channels-alist))
	      ;; Else modify the face for the buffer, if necessary.
              (when (or erc-track-ignore-normal-contenders-p (cdr faces))
		(let* ((cell (assq (current-buffer)
				   erc-modified-channels-alist))
		       (old-face (cddr cell))
                       (new-face (if erc-track-ignore-normal-contenders-p
                                     (erc-track-select-mode-line-face
                                      old-face faces)
                                   (erc-track--select-mode-line-face
                                    old-face faces ranks normals))))
		  (setcdr cell (cons (1+ (cadr cell)) new-face)))))
	    ;; And display it
	    (erc-modified-channels-display)))
      ;; Else if the active buffer is the current buffer, remove it
      ;; from our list.
      (when (and (or (erc-buffer-visible (current-buffer))
		(and this-channel
		     (member this-channel erc-track-exclude)))
		 (assq (current-buffer) erc-modified-channels-alist))
	;; Remove it from mode-line if buffer is visible or
	;; channel was added to erc-track-exclude recently.
	(erc-modified-channels-remove-buffer (current-buffer))
	(erc-modified-channels-display)))))