Mercurial > emacs
comparison lisp/erc/erc-track.el @ 84387:4ee03308c9b6
Sync ERC 5.3 (devel) from upstream
author | Michael Olson <mwolson@gnu.org> |
---|---|
date | Sat, 08 Sep 2007 03:07:09 +0000 |
parents | 85d67fae9a94 |
children | ffc87ddd4025 |
comparison
equal
deleted
inserted
replaced
84386:869c721b5469 | 84387:4ee03308c9b6 |
---|---|
92 | 92 |
93 (defcustom erc-track-exclude nil | 93 (defcustom erc-track-exclude nil |
94 "A list targets (channel names or query targets) which should not be tracked." | 94 "A list targets (channel names or query targets) which should not be tracked." |
95 :group 'erc-track | 95 :group 'erc-track |
96 :type '(repeat string)) | 96 :type '(repeat string)) |
97 | |
98 (defcustom erc-track-remove-disconnected-buffers nil | |
99 "*If true, remove buffers associated with a server that is | |
100 disconnected from `erc-modified-channels-alist'." | |
101 :group 'erc-track | |
102 :type 'boolean) | |
97 | 103 |
98 (defcustom erc-track-exclude-types '("NICK") | 104 (defcustom erc-track-exclude-types '("NICK") |
99 "*List of message types to be ignored. | 105 "*List of message types to be ignored. |
100 This list could look like '(\"JOIN\" \"PART\")." | 106 This list could look like '(\"JOIN\" \"PART\")." |
101 :group 'erc-track | 107 :group 'erc-track |
148 It should return a list of strings of the same number of elements. | 154 It should return a list of strings of the same number of elements. |
149 If nil instead of a function, shortening is disabled." | 155 If nil instead of a function, shortening is disabled." |
150 :group 'erc-track | 156 :group 'erc-track |
151 :type '(choice (const :tag "Disabled") | 157 :type '(choice (const :tag "Disabled") |
152 function)) | 158 function)) |
159 | |
160 (defcustom erc-track-list-changed-hook nil | |
161 "Hook that is run whenever the contents of | |
162 `erc-modified-channels-alist' changes. | |
163 | |
164 This is useful for people that don't use the default mode-line | |
165 notification but instead use a separate mechanism to provide | |
166 notification of channel activity." | |
167 :group 'erc-track | |
168 :type 'hook) | |
153 | 169 |
154 (defcustom erc-track-use-faces t | 170 (defcustom erc-track-use-faces t |
155 "*Use faces in the mode-line. | 171 "*Use faces in the mode-line. |
156 The faces used are the same as used for text in the buffers. | 172 The faces used are the same as used for text in the buffers. |
157 \(e.g. `erc-pal-face' is used if a pal sent a message to that channel.)" | 173 \(e.g. `erc-pal-face' is used if a pal sent a message to that channel.)" |
190 Setting this variable only has effects in GNU Emacs versions above 21.3. | 206 Setting this variable only has effects in GNU Emacs versions above 21.3. |
191 | 207 |
192 Choices are: | 208 Choices are: |
193 'before-modes - add to the beginning of `mode-line-modes' | 209 'before-modes - add to the beginning of `mode-line-modes' |
194 'after-modes - add to the end of `mode-line-modes' | 210 'after-modes - add to the end of `mode-line-modes' |
195 | 211 t - add to the end of `global-mode-string'. |
196 Any other value means add to the end of `global-mode-string'." | 212 nil - don't add to mode line |
213 " | |
197 :group 'erc-track | 214 :group 'erc-track |
198 :type '(choice (const :tag "Just before mode information" before-modes) | 215 :type '(choice (const :tag "Just before mode information" before-modes) |
199 (const :tag "Just after mode information" after-modes) | 216 (const :tag "Just after mode information" after-modes) |
200 (const :tag "After all other information" nil)) | 217 (const :tag "After all other information" t) |
218 (const :tag "Don't display in mode line" nil)) | |
201 :set (lambda (sym val) | 219 :set (lambda (sym val) |
202 (set sym val) | 220 (set sym val) |
203 (when (and (boundp 'erc-track-mode) | 221 (when (and (boundp 'erc-track-mode) |
204 erc-track-mode) | 222 erc-track-mode) |
205 (erc-track-remove-from-mode-line) | 223 (erc-track-remove-from-mode-line) |
261 :group 'erc-track) | 279 :group 'erc-track) |
262 | 280 |
263 (defcustom erc-track-switch-direction 'oldest | 281 (defcustom erc-track-switch-direction 'oldest |
264 "Direction `erc-track-switch-buffer' should switch. | 282 "Direction `erc-track-switch-buffer' should switch. |
265 | 283 |
284 importance - find buffer with the most important message | |
266 oldest - find oldest active buffer | 285 oldest - find oldest active buffer |
267 newest - find newest active buffer | 286 newest - find newest active buffer |
268 leastactive - find buffer with least unseen messages | 287 leastactive - find buffer with least unseen messages |
269 mostactive - find buffer with most unseen messages." | 288 mostactive - find buffer with most unseen messages." |
270 :group 'erc-track | 289 :group 'erc-track |
271 :type '(choice (const oldest) | 290 :type '(choice (const importance) |
291 (const oldest) | |
272 (const newest) | 292 (const newest) |
273 (const leastactive) | 293 (const leastactive) |
274 (const mostactive))) | 294 (const mostactive))) |
275 | 295 |
276 | 296 |
294 '(t erc-modified-channels-object))) | 314 '(t erc-modified-channels-object))) |
295 ((and (eq position 'after-modes) | 315 ((and (eq position 'after-modes) |
296 (boundp 'mode-line-modes)) | 316 (boundp 'mode-line-modes)) |
297 (add-to-list 'mode-line-modes | 317 (add-to-list 'mode-line-modes |
298 '(t erc-modified-channels-object) t)) | 318 '(t erc-modified-channels-object) t)) |
299 (t | 319 ((eq position t) |
300 (when (not global-mode-string) | 320 (when (not global-mode-string) |
301 (setq global-mode-string '(""))) ; Padding for mode-line wart | 321 (setq global-mode-string '(""))) ; Padding for mode-line wart |
302 (add-to-list 'global-mode-string | 322 (add-to-list 'global-mode-string |
303 'erc-modified-channels-object | 323 'erc-modified-channels-object |
304 t)))) | 324 t)))) |
642 (defun erc-user-is-active (&rest ignore) | 662 (defun erc-user-is-active (&rest ignore) |
643 "Set `erc-buffer-activity'." | 663 "Set `erc-buffer-activity'." |
644 (setq erc-buffer-activity (erc-current-time)) | 664 (setq erc-buffer-activity (erc-current-time)) |
645 (erc-track-modified-channels)) | 665 (erc-track-modified-channels)) |
646 | 666 |
667 (defun erc-track-get-buffer-window (buffer frame-param) | |
668 (if (eq frame-param 'selected-visible) | |
669 (if (eq (frame-visible-p (selected-frame)) t) | |
670 (get-buffer-window buffer nil) | |
671 nil) | |
672 (get-buffer-window buffer frame-param))) | |
673 | |
647 (defun erc-buffer-visible (buffer) | 674 (defun erc-buffer-visible (buffer) |
648 "Return non-nil when the buffer is visible." | 675 "Return non-nil when the buffer is visible." |
649 (if erc-track-when-inactive | 676 (if erc-track-when-inactive |
650 (when erc-buffer-activity; could be nil | 677 (when erc-buffer-activity; could be nil |
651 (and (get-buffer-window buffer erc-track-visibility) | 678 (and (erc-track-get-buffer-window buffer erc-track-visibility) |
652 (<= (erc-time-diff erc-buffer-activity (erc-current-time)) | 679 (<= (erc-time-diff erc-buffer-activity (erc-current-time)) |
653 erc-buffer-activity-timeout))) | 680 erc-buffer-activity-timeout))) |
654 (get-buffer-window buffer erc-track-visibility))) | 681 (erc-track-get-buffer-window buffer erc-track-visibility))) |
655 | 682 |
656 ;;; Tracking the channel modifications | 683 ;;; Tracking the channel modifications |
657 | 684 |
658 (defvar erc-modified-channels-update-inside nil | 685 (defvar erc-modified-channels-update-inside nil |
659 "Variable to prevent running `erc-modified-channels-update' multiple | 686 "Variable to prevent running `erc-modified-channels-update' multiple |
666 `erc-modified-channels-display' at the end. This should usually be | 693 `erc-modified-channels-display' at the end. This should usually be |
667 called via `window-configuration-change-hook'. | 694 called via `window-configuration-change-hook'. |
668 ARGS are ignored." | 695 ARGS are ignored." |
669 (interactive) | 696 (interactive) |
670 (unless erc-modified-channels-update-inside | 697 (unless erc-modified-channels-update-inside |
671 (let ((erc-modified-channels-update-inside t)) | 698 (let ((erc-modified-channels-update-inside t) |
699 (removed-channel nil)) | |
672 (mapcar (lambda (elt) | 700 (mapcar (lambda (elt) |
673 (let ((buffer (car elt))) | 701 (let ((buffer (car elt))) |
674 (when (or (not (bufferp buffer)) | 702 (when (or (not (bufferp buffer)) |
675 (not (buffer-live-p buffer)) | 703 (not (buffer-live-p buffer)) |
676 (erc-buffer-visible buffer) | 704 (erc-buffer-visible buffer) |
705 (and erc-track-remove-disconnected-buffers | |
677 (not (with-current-buffer buffer | 706 (not (with-current-buffer buffer |
678 erc-server-connected))) | 707 erc-server-connected)))) |
708 (setq removed-channel t) | |
679 (erc-modified-channels-remove-buffer buffer)))) | 709 (erc-modified-channels-remove-buffer buffer)))) |
680 erc-modified-channels-alist) | 710 erc-modified-channels-alist) |
711 (when removed-channel | |
681 (erc-modified-channels-display) | 712 (erc-modified-channels-display) |
682 (force-mode-line-update t)))) | 713 (force-mode-line-update t))))) |
683 | 714 |
684 (defvar erc-track-mouse-face (if (featurep 'xemacs) | 715 (defvar erc-track-mouse-face (if (featurep 'xemacs) |
685 'modeline-mousable | 716 'modeline-mousable |
686 'mode-line-highlight) | 717 'mode-line-highlight) |
687 "The face to use when mouse is over channel names in the mode line.") | 718 "The face to use when mouse is over channel names in the mode line.") |
727 | 758 |
728 (defun erc-modified-channels-display () | 759 (defun erc-modified-channels-display () |
729 "Set `erc-modified-channels-object' | 760 "Set `erc-modified-channels-object' |
730 according to `erc-modified-channels-alist'. | 761 according to `erc-modified-channels-alist'. |
731 Use `erc-make-mode-line-buffer-name' to create buttons." | 762 Use `erc-make-mode-line-buffer-name' to create buttons." |
732 (if (or | 763 (cond ((or (eq 'mostactive erc-track-switch-direction) |
733 (eq 'mostactive erc-track-switch-direction) | 764 (eq 'leastactive erc-track-switch-direction)) |
734 (eq 'leastactive erc-track-switch-direction)) | 765 (erc-track-sort-by-activest)) |
735 (erc-track-sort-by-activest)) | 766 ((eq 'importance erc-track-switch-direction) |
767 (erc-track-sort-by-importance))) | |
768 (run-hooks 'erc-track-list-changed-hook) | |
769 (unless (eq erc-track-position-in-mode-line nil) | |
736 (if (null erc-modified-channels-alist) | 770 (if (null erc-modified-channels-alist) |
737 (setq erc-modified-channels-object (erc-modified-channels-object nil)) | 771 (setq erc-modified-channels-object (erc-modified-channels-object nil)) |
738 ;; erc-modified-channels-alist contains all the data we need. To | 772 ;; erc-modified-channels-alist contains all the data we need. To |
739 ;; better understand what is going on, we split things up into | 773 ;; better understand what is going on, we split things up into |
740 ;; four lists: BUFFERS, COUNTS, SHORT-NAMES, and FACES. These | 774 ;; four lists: BUFFERS, COUNTS, SHORT-NAMES, and FACES. These |
766 counts (cdr counts) | 800 counts (cdr counts) |
767 faces (cdr faces))) | 801 faces (cdr faces))) |
768 (when (featurep 'xemacs) | 802 (when (featurep 'xemacs) |
769 (erc-modified-channels-object nil)) | 803 (erc-modified-channels-object nil)) |
770 (setq erc-modified-channels-object | 804 (setq erc-modified-channels-object |
771 (erc-modified-channels-object strings))))) | 805 (erc-modified-channels-object strings)))))) |
772 | 806 |
773 (defun erc-modified-channels-remove-buffer (buffer) | 807 (defun erc-modified-channels-remove-buffer (buffer) |
774 "Remove BUFFER from `erc-modified-channels-alist'." | 808 "Remove BUFFER from `erc-modified-channels-alist'." |
775 (interactive "bBuffer: ") | 809 (interactive "bBuffer: ") |
776 (setq erc-modified-channels-alist | 810 (setq erc-modified-channels-alist |
800 (let ((this-channel (or (erc-default-target) | 834 (let ((this-channel (or (erc-default-target) |
801 (buffer-name (current-buffer))))) | 835 (buffer-name (current-buffer))))) |
802 (if (and (not (erc-buffer-visible (current-buffer))) | 836 (if (and (not (erc-buffer-visible (current-buffer))) |
803 (not (member this-channel erc-track-exclude)) | 837 (not (member this-channel erc-track-exclude)) |
804 (not (and erc-track-exclude-server-buffer | 838 (not (and erc-track-exclude-server-buffer |
805 (string= this-channel | 839 (erc-server-buffer-p))) |
806 (buffer-name (erc-server-buffer))))) | |
807 (not (erc-message-type-member | 840 (not (erc-message-type-member |
808 (or (erc-find-parsed-property) | 841 (or (erc-find-parsed-property) |
809 (point-min)) | 842 (point-min)) |
810 erc-track-exclude-types))) | 843 erc-track-exclude-types))) |
811 ;; If the active buffer is not visible (not shown in a | 844 ;; If the active buffer is not visible (not shown in a |
845 (setcdr cell (cons (1+ (cadr cell)) new-face))))) | 878 (setcdr cell (cons (1+ (cadr cell)) new-face))))) |
846 ;; And display it | 879 ;; And display it |
847 (erc-modified-channels-display))) | 880 (erc-modified-channels-display))) |
848 ;; Else if the active buffer is the current buffer, remove it | 881 ;; Else if the active buffer is the current buffer, remove it |
849 ;; from our list. | 882 ;; from our list. |
850 (when (or (erc-buffer-visible (current-buffer)) | 883 (when (and (or (erc-buffer-visible (current-buffer)) |
851 (and this-channel | 884 (and this-channel |
852 (assq (current-buffer) erc-modified-channels-alist) | |
853 (member this-channel erc-track-exclude))) | 885 (member this-channel erc-track-exclude))) |
886 (assq (current-buffer) erc-modified-channels-alist)) | |
854 ;; Remove it from mode-line if buffer is visible or | 887 ;; Remove it from mode-line if buffer is visible or |
855 ;; channel was added to erc-track-exclude recently. | 888 ;; channel was added to erc-track-exclude recently. |
856 (erc-modified-channels-remove-buffer (current-buffer)) | 889 (erc-modified-channels-remove-buffer (current-buffer)) |
857 (erc-modified-channels-display))))) | 890 (erc-modified-channels-display))))) |
858 | 891 |
884 "Sort erc-modified-channels-alist by activity. | 917 "Sort erc-modified-channels-alist by activity. |
885 That means the number of unseen messages in a channel." | 918 That means the number of unseen messages in a channel." |
886 (setq erc-modified-channels-alist | 919 (setq erc-modified-channels-alist |
887 (sort erc-modified-channels-alist | 920 (sort erc-modified-channels-alist |
888 (lambda (a b) (> (nth 1 a) (nth 1 b)))))) | 921 (lambda (a b) (> (nth 1 a) (nth 1 b)))))) |
922 | |
923 (defun erc-track-face-priority (face) | |
924 "Return a number indicating the priority of FACE in | |
925 `erc-track-faces-priority-list'. Lower number means higher | |
926 priority. | |
927 | |
928 If face is not in `erc-track-faces-priority-list', it will have a | |
929 higher number than any other face in that list." | |
930 (let ((count 0)) | |
931 (catch 'done | |
932 (dolist (item erc-track-faces-priority-list) | |
933 (if (eq item face) | |
934 (throw 'done t) | |
935 (setq count (1+ count))))) | |
936 count)) | |
937 | |
938 (defun erc-track-sort-by-importance () | |
939 "Sort erc-modified-channels-alist by importance. | |
940 That means the position of the face in `erc-track-faces-priority-list'." | |
941 (setq erc-modified-channels-alist | |
942 (sort erc-modified-channels-alist | |
943 (lambda (a b) (< (erc-track-face-priority (cddr a)) | |
944 (erc-track-face-priority (cddr b))))))) | |
889 | 945 |
890 (defun erc-track-get-active-buffer (arg) | 946 (defun erc-track-get-active-buffer (arg) |
891 "Return the buffer name of ARG in `erc-modified-channels-alist'. | 947 "Return the buffer name of ARG in `erc-modified-channels-alist'. |
892 Negative arguments index in the opposite direction. This direction is | 948 Negative arguments index in the opposite direction. This direction is |
893 relative to `erc-track-switch-direction'" | 949 relative to `erc-track-switch-direction'" |
896 (when (< arg 0) | 952 (when (< arg 0) |
897 (setq dir (case dir | 953 (setq dir (case dir |
898 (oldest 'newest) | 954 (oldest 'newest) |
899 (newest 'oldest) | 955 (newest 'oldest) |
900 (mostactive 'leastactive) | 956 (mostactive 'leastactive) |
901 (leastactive 'mostactive))) | 957 (leastactive 'mostactive) |
958 (importance 'oldest))) | |
902 (setq arg (- arg))) | 959 (setq arg (- arg))) |
903 (setq offset (case dir | 960 (setq offset (case dir |
904 ((oldest leastactive) | 961 ((oldest leastactive) |
905 (- (length erc-modified-channels-alist) arg)) | 962 (- (length erc-modified-channels-alist) arg)) |
906 (t (1- arg)))) | 963 (t (1- arg)))) |