]> code.delx.au - gnu-emacs/blobdiff - lisp/erc/erc-track.el
Update copyright year to 2016
[gnu-emacs] / lisp / erc / erc-track.el
index 054c135fa67ba7e0034822f4eccf88f1d23f1b03..1750cb7784530e7b3fc746c2ba7ebc817c7f4e7b 100644 (file)
@@ -1,9 +1,9 @@
-;;; erc-track.el --- Track modified channel buffers
+;;; erc-track.el --- Track modified channel buffers  -*- lexical-binding:t -*-
 
-;; Copyright (C) 2002-2013 Free Software Foundation, Inc.
+;; Copyright (C) 2002-2016 Free Software Foundation, Inc.
 
 ;; Author: Mario Lang <mlang@delysid.org>
-;; Maintainer: FSF
+;; Maintainer: emacs-devel@gnu.org
 ;; Keywords: comm, faces
 ;; URL: http://www.emacswiki.org/cgi-bin/wiki.pl?ErcChannelTracking
 
@@ -101,7 +101,7 @@ disconnected from `erc-modified-channels-alist'."
 
 (defcustom erc-track-exclude-types '("NICK" "333" "353")
   "List of message types to be ignored.
-This list could look like '(\"JOIN\" \"PART\").
+This list could look like (\"JOIN\" \"PART\").
 
 By default, exclude changes of nicknames (NICK), display of who
 set the channel topic (333), and listing of users on the current
@@ -210,7 +210,7 @@ If you would like to ignore changes in certain channels where there
 are no faces corresponding to your `erc-track-faces-priority-list', set
 this variable.  You can set a list of channel name strings, so those
 will be ignored while all other channels will be tracked as normal.
-Other options are 'all, to apply this to all channels or nil, to disable
+Other options are `all', to apply this to all channels or nil, to disable
 this feature.
 
 Note: If you have a lot of faces listed in `erc-track-faces-priority-list',
@@ -248,10 +248,10 @@ The effect may be disabled by setting this variable to nil."
 Setting this variable only has effects in GNU Emacs versions above 21.3.
 
 Choices are:
-'before-modes - add to the beginning of `mode-line-modes',
-'after-modes  - add to the end of `mode-line-modes',
-t             - add to the end of `global-mode-string',
-nil           - don't add to mode line."
+`before-modes' - add to the beginning of `mode-line-modes',
+`after-modes'  - add to the end of `mode-line-modes',
+t              - add to the end of `global-mode-string',
+nil            - don't add to mode line."
   :group 'erc-track
   :type '(choice (const :tag "Just before mode information" before-modes)
                 (const :tag "Just after mode information" after-modes)
@@ -265,9 +265,7 @@ nil           - don't add to mode line."
           (erc-track-add-to-mode-line val))))
 
 (defun erc-modified-channels-object (strings)
-  "Generate a new `erc-modified-channels-object' based on STRINGS.
-If STRINGS is nil, we initialize `erc-modified-channels-object' to
-an appropriate initial value for this flavor of Emacs."
+  "Generate a new `erc-modified-channels-object' based on STRINGS."
   (if strings
       (if (featurep 'xemacs)
          (let ((e-m-c-s '("[")))
@@ -328,7 +326,7 @@ when there are no more active channels."
   leastactive -  find buffer with least unseen messages
   mostactive  -  find buffer with most unseen messages.
 
-If set to 'importance, the importance is determined by position
+If set to `importance', the importance is determined by position
 in `erc-track-faces-priority-list', where first is most
 important."
   :group 'erc-track
@@ -710,7 +708,7 @@ inactive."
 to consider when `erc-track-visibility' is set to
 only consider active buffers visible.")
 
-(defun erc-user-is-active (&rest ignore)
+(defun erc-user-is-active (&rest _ignore)
   "Set `erc-buffer-activity'."
   (when erc-server-connected
     (setq erc-buffer-activity (erc-current-time))
@@ -743,9 +741,9 @@ only consider active buffers visible.")
 (defvar erc-modified-channels-update-inside nil
   "Variable to prevent running `erc-modified-channels-update' multiple
 times.  Without it, you cannot debug `erc-modified-channels-display',
-because the debugger also cases changes to the window-configuration.")
+because the debugger also causes changes to the window-configuration.")
 
-(defun erc-modified-channels-update (&rest args)
+(defun erc-modified-channels-update (&rest _args)
   "This function updates the information in `erc-modified-channels-alist'
 according to buffer visibility.  It calls
 `erc-modified-channels-display' at the end. This should usually be
@@ -767,8 +765,7 @@ ARGS are ignored."
                  (erc-modified-channels-remove-buffer buffer))))
            erc-modified-channels-alist)
       (when removed-channel
-       (erc-modified-channels-display)
-       (force-mode-line-update t)))
+       (erc-modified-channels-display)))
     (remove-hook 'post-command-hook 'erc-modified-channels-update)))
 
 (defvar erc-track-mouse-face (if (featurep 'xemacs)
@@ -791,19 +788,19 @@ If FACES are provided, color STRING with them."
                          (int-to-string count))
                (copy-sequence string))))
     (define-key map (vector 'mode-line 'mouse-2)
-      `(lambda (e)
-        (interactive "e")
-        (save-selected-window
-          (select-window
-           (posn-window (event-start e)))
-          (switch-to-buffer ,buffer))))
+      (lambda (e)
+       (interactive "e")
+       (save-selected-window
+         (select-window
+          (posn-window (event-start e)))
+         (switch-to-buffer buffer))))
     (define-key map (vector 'mode-line 'mouse-3)
-      `(lambda (e)
-        (interactive "e")
-        (save-selected-window
-          (select-window
-           (posn-window (event-start e)))
-          (switch-to-buffer-other-window ,buffer))))
+      (lambda (e)
+       (interactive "e")
+       (save-selected-window
+         (select-window
+          (posn-window (event-start e)))
+         (switch-to-buffer-other-window buffer))))
     (put-text-property 0 (length name) 'local-map map name)
     (put-text-property
      0 (length name)
@@ -825,43 +822,45 @@ Use `erc-make-mode-line-buffer-name' to create buttons."
        ((eq 'importance erc-track-switch-direction)
         (erc-track-sort-by-importance)))
   (run-hooks 'erc-track-list-changed-hook)
-  (unless (eq erc-track-position-in-mode-line nil)
-  (if (null erc-modified-channels-alist)
-      (setq erc-modified-channels-object (erc-modified-channels-object nil))
-    ;; erc-modified-channels-alist contains all the data we need.  To
-    ;; better understand what is going on, we split things up into
-    ;; four lists: BUFFERS, COUNTS, SHORT-NAMES, and FACES.  These
-    ;; four lists we use to create a new
-    ;; `erc-modified-channels-object' using
-    ;; `erc-make-mode-line-buffer-name'.
-    (let* ((buffers (mapcar 'car erc-modified-channels-alist))
-          (counts (mapcar 'cadr erc-modified-channels-alist))
-          (faces (mapcar 'cddr erc-modified-channels-alist))
-          (long-names (mapcar #'(lambda (buf)
-                                  (or (buffer-name buf)
-                                      ""))
-                              buffers))
-          (short-names (if (functionp erc-track-shorten-function)
-                           (funcall erc-track-shorten-function
-                                    long-names)
-                         long-names))
-          strings)
-      (while buffers
-       (when (car short-names)
-         (setq strings (cons (erc-make-mode-line-buffer-name
-                              (car short-names)
-                              (car buffers)
-                              (car faces)
-                              (car counts))
-                             strings)))
-       (setq short-names (cdr short-names)
-             buffers (cdr buffers)
-             counts (cdr counts)
-             faces (cdr faces)))
-      (when (featurep 'xemacs)
-       (erc-modified-channels-object nil))
-      (setq erc-modified-channels-object
-           (erc-modified-channels-object strings))))))
+  (when erc-track-position-in-mode-line
+    (let* ((oldobject erc-modified-channels-object)
+          (strings
+           (when erc-modified-channels-alist
+             ;; erc-modified-channels-alist contains all the data we need.  To
+             ;; better understand what is going on, we split things up into
+             ;; four lists: BUFFERS, COUNTS, SHORT-NAMES, and FACES.  These
+             ;; four lists we use to create a new
+             ;; `erc-modified-channels-object' using
+             ;; `erc-make-mode-line-buffer-name'.
+             (let* ((buffers (mapcar 'car erc-modified-channels-alist))
+                    (counts (mapcar 'cadr erc-modified-channels-alist))
+                    (faces (mapcar 'cddr erc-modified-channels-alist))
+                    (long-names (mapcar #'(lambda (buf)
+                                            (or (buffer-name buf)
+                                                ""))
+                                        buffers))
+                    (short-names (if (functionp erc-track-shorten-function)
+                                     (funcall erc-track-shorten-function
+                                              long-names)
+                                   long-names))
+                    strings)
+               (while buffers
+                 (when (car short-names)
+                   (setq strings (cons (erc-make-mode-line-buffer-name
+                                        (car short-names)
+                                        (car buffers)
+                                        (car faces)
+                                        (car counts))
+                                       strings)))
+                 (setq short-names (cdr short-names)
+                       buffers (cdr buffers)
+                       counts (cdr counts)
+                       faces (cdr faces)))
+               strings)))
+          (newobject (erc-modified-channels-object strings)))
+      (unless (equal-including-properties oldobject newobject)
+       (setq erc-modified-channels-object newobject)
+       (force-mode-line-update t)))))
 
 (defun erc-modified-channels-remove-buffer (buffer)
   "Remove BUFFER from `erc-modified-channels-alist'."
@@ -976,8 +975,9 @@ is in `erc-mode'."
        cur)
     (while (and (setq i (next-single-property-change i 'face str m))
                (not (= i m)))
-      (when (setq cur (get-text-property i 'face str))
-       (add-to-list 'faces cur)))
+      (and (setq cur (get-text-property i 'face str))
+          (not (member cur faces))
+          (push cur faces)))
     faces))
 
 (cl-assert