Mercurial > emacs
comparison lisp/erc/erc-track.el @ 76856:2fae574a2382
Release ERC 5.2.
I have updated the version of ERC to 5.2, since it fixes a bug with C-c
C-SPC being bound globally by default. For the full list of changes in
this version, see etc/ERC-NEWS.
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-687
Creator: Michael Olson <mwolson@gnu.org>
author | Miles Bader <miles@gnu.org> |
---|---|
date | Sun, 01 Apr 2007 13:36:38 +0000 |
parents | 7a3f13e2dd57 |
children | 85d67fae9a94 |
comparison
equal
deleted
inserted
replaced
76855:e6686c0a3d45 | 76856:2fae574a2382 |
---|---|
1 ;;; erc-track.el --- Track modified channel buffers | 1 ;;; erc-track.el --- Track modified channel buffers |
2 | 2 |
3 ;; Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc. | 3 ;; Copyright (C) 2002, 2003, 2004, 2005, 2006, |
4 ;; 2007 Free Software Foundation, Inc. | |
4 | 5 |
5 ;; Author: Mario Lang <mlang@delysid.org> | 6 ;; Author: Mario Lang <mlang@delysid.org> |
6 ;; Keywords: comm, faces | 7 ;; Keywords: comm, faces |
7 ;; URL: http://www.emacswiki.org/cgi-bin/wiki.pl?ErcChannelTracking | 8 ;; URL: http://www.emacswiki.org/cgi-bin/wiki.pl?ErcChannelTracking |
8 | 9 |
43 ;;; Code: | 44 ;;; Code: |
44 | 45 |
45 (defgroup erc-track nil | 46 (defgroup erc-track nil |
46 "Track active buffers and show activity in the modeline." | 47 "Track active buffers and show activity in the modeline." |
47 :group 'erc) | 48 :group 'erc) |
49 | |
50 (defcustom erc-track-enable-keybindings 'ask | |
51 "Whether to enable the ERC track keybindings, namely: | |
52 `C-c C-SPC' and `C-c C-@', which both do the same thing. | |
53 | |
54 The default is to check to see whether these keys are used | |
55 already: if not, then enable the ERC track minor mode, which | |
56 provides these keys. Otherwise, do not touch the keys. | |
57 | |
58 This can alternatively be set to either t or nil, which indicate | |
59 respectively always to enable ERC track minor mode or never to | |
60 enable ERC track minor mode. | |
61 | |
62 The reason for using this default value is to both (1) adhere to | |
63 the Emacs development guidelines which say not to touch keys of | |
64 the form C-c C-<something> and also (2) to meet the expectations | |
65 of long-time ERC users, many of whom rely on these keybindings." | |
66 :group 'erc-track | |
67 :type '(choice (const :tag "Ask, if used already" ask) | |
68 (const :tag "Enable" t) | |
69 (const :tag "Disable" nil))) | |
48 | 70 |
49 (defcustom erc-track-visibility t | 71 (defcustom erc-track-visibility t |
50 "Where do we look for buffers to determine their visibility? | 72 "Where do we look for buffers to determine their visibility? |
51 The value of this variable determines, when a buffer is considered | 73 The value of this variable determines, when a buffer is considered |
52 visible or invisible. New messages in invisible buffers are tracked, | 74 visible or invisible. New messages in invisible buffers are tracked, |
53 while switching to visible buffers when they are tracked removes them | 75 while switching to visible buffers when they are tracked removes them |
54 from the list. See also `erc-track-when-inactive-mode'. | 76 from the list. See also `erc-track-when-inactive'. |
55 | 77 |
56 Possible values are: | 78 Possible values are: |
57 | 79 |
58 t - all frames | 80 t - all frames |
59 visible - all visible frames | 81 visible - all visible frames |
486 (equal (erc-unique-substrings '("abc" "xyz" "xab")) | 508 (equal (erc-unique-substrings '("abc" "xyz" "xab")) |
487 '("abc" "xyz" "xab")) | 509 '("abc" "xyz" "xab")) |
488 (equal (erc-unique-substrings '("abc" "abcdefg")) | 510 (equal (erc-unique-substrings '("abc" "abcdefg")) |
489 '("abc" "abcd")))))) | 511 '("abc" "abcd")))))) |
490 | 512 |
513 ;;; Minor mode | |
514 | |
515 ;; Play nice with other IRC clients (and Emacs development rules) by | |
516 ;; making this a minor mode | |
517 | |
518 (defvar erc-track-minor-mode-map (make-sparse-keymap) | |
519 "Keymap for rcirc track minor mode.") | |
520 | |
521 (define-key erc-track-minor-mode-map (kbd "C-c C-@") 'erc-track-switch-buffer) | |
522 (define-key erc-track-minor-mode-map (kbd "C-c C-SPC") | |
523 'erc-track-switch-buffer) | |
524 | |
525 ;;;###autoload | |
526 (define-minor-mode erc-track-minor-mode | |
527 "Global minor mode for tracking ERC buffers and showing activity in the | |
528 mode line. | |
529 | |
530 This exists for the sole purpose of providing the C-c C-SPC and | |
531 C-c C-@ keybindings. Make sure that you have enabled the track | |
532 module, otherwise the keybindings will not do anything useful." | |
533 :init-value nil | |
534 :lighter "" | |
535 :keymap erc-track-minor-mode-map | |
536 :global t | |
537 :group 'erc-track) | |
538 | |
539 (defun erc-track-minor-mode-maybe () | |
540 "Enable `erc-track-minor-mode', depending on `erc-track-enable-keybindings'." | |
541 (unless (or erc-track-minor-mode | |
542 ;; don't start the minor mode until we have an ERC | |
543 ;; process running, because we don't want to prompt the | |
544 ;; user while starting Emacs | |
545 (null (erc-buffer-list))) | |
546 (cond ((eq erc-track-enable-keybindings 'ask) | |
547 (let ((key (or (and (key-binding (kbd "C-c C-SPC")) "C-SPC") | |
548 (and (key-binding (kbd "C-c C-@")) "C-@")))) | |
549 (if key | |
550 (if (y-or-n-p | |
551 (concat "The C-c " key " binding is in use;" | |
552 " override it for tracking? ")) | |
553 (progn | |
554 (message (concat "Will change it; set" | |
555 " `erc-track-enable-keybindings'" | |
556 " to disable this message")) | |
557 (sleep-for 3) | |
558 (erc-track-minor-mode 1)) | |
559 (message (concat "Not changing it; set" | |
560 " `erc-track-enable-keybindings'" | |
561 " to disable this message")) | |
562 (sleep-for 3)) | |
563 (erc-track-minor-mode 1)))) | |
564 ((eq erc-track-enable-keybindings t) | |
565 (erc-track-minor-mode 1)) | |
566 (t nil)))) | |
567 | |
491 ;;; Module | 568 ;;; Module |
492 | 569 |
493 ;;;###autoload (autoload 'erc-track-mode "erc-track" nil t) | 570 ;;;###autoload (autoload 'erc-track-mode "erc-track" nil t) |
494 (define-erc-module track track-modified-channels | 571 (define-erc-module track nil |
495 "This mode tracks ERC channel buffers with activity." | 572 "This mode tracks ERC channel buffers with activity." |
496 ((erc-track-add-to-mode-line erc-track-position-in-mode-line) | 573 ;; Enable: |
497 (setq erc-modified-channels-object (erc-modified-channels-object nil)) | 574 ((when (boundp 'erc-track-when-inactive) |
498 (erc-update-mode-line) | 575 (if erc-track-when-inactive |
499 (if (featurep 'xemacs) | 576 (progn |
500 (defadvice switch-to-buffer (after erc-update (&rest args) activate) | 577 (if (featurep 'xemacs) |
501 (erc-modified-channels-update)) | 578 (defadvice switch-to-buffer (after erc-update-when-inactive |
502 (add-hook 'window-configuration-change-hook 'erc-modified-channels-update)) | 579 (&rest args) activate) |
503 (add-hook 'erc-insert-post-hook 'erc-track-modified-channels) | 580 (erc-user-is-active)) |
504 (add-hook 'erc-disconnected-hook 'erc-modified-channels-update)) | 581 (add-hook 'window-configuration-change-hook 'erc-user-is-active)) |
505 ((erc-track-remove-from-mode-line) | 582 (add-hook 'erc-send-completed-hook 'erc-user-is-active) |
506 (if (featurep 'xemacs) | 583 (add-hook 'erc-server-001-functions 'erc-user-is-active)) |
507 (ad-disable-advice 'switch-to-buffer 'after 'erc-update) | 584 (erc-track-add-to-mode-line erc-track-position-in-mode-line) |
508 (remove-hook 'window-configuration-change-hook | 585 (setq erc-modified-channels-object (erc-modified-channels-object nil)) |
509 'erc-modified-channels-update)) | 586 (erc-update-mode-line) |
510 (remove-hook 'erc-disconnected-hook 'erc-modified-channels-update) | 587 (if (featurep 'xemacs) |
511 (remove-hook 'erc-insert-post-hook 'erc-track-modified-channels))) | 588 (defadvice switch-to-buffer (after erc-update (&rest args) activate) |
512 | 589 (erc-modified-channels-update)) |
513 ;;;###autoload (autoload 'erc-track-when-inactive-mode "erc-track" nil t) | 590 (add-hook 'window-configuration-change-hook |
514 (define-erc-module track-when-inactive nil | 591 'erc-modified-channels-update)) |
515 "This mode enables channel tracking even for visible buffers, | 592 (add-hook 'erc-insert-post-hook 'erc-track-modified-channels) |
516 if you are inactivity." | 593 (add-hook 'erc-disconnected-hook 'erc-modified-channels-update)) |
517 ((if (featurep 'xemacs) | 594 ;; enable the tracking keybindings |
518 (defadvice switch-to-buffer (after erc-update-when-inactive (&rest args) activate) | 595 (erc-track-minor-mode-maybe))) |
519 (erc-user-is-active)) | 596 ;; Disable: |
520 (add-hook 'window-configuration-change-hook 'erc-user-is-active)) | 597 ((when (boundp 'erc-track-when-inactive) |
521 (add-hook 'erc-send-completed-hook 'erc-user-is-active) | 598 (erc-track-remove-from-mode-line) |
522 (add-hook 'erc-server-001-functions 'erc-user-is-active)) | 599 (if erc-track-when-inactive |
523 ((erc-track-remove-from-mode-line) | 600 (progn |
524 (if (featurep 'xemacs) | 601 (if (featurep 'xemacs) |
525 (ad-disable-advice 'switch-to-buffer 'after 'erc-update-when-inactive) | 602 (ad-disable-advice 'switch-to-buffer 'after |
526 (remove-hook 'window-configuration-change-hook 'erc-user-is-active)) | 603 'erc-update-when-inactive) |
527 (remove-hook 'erc-send-completed-hook 'erc-user-is-active) | 604 (remove-hook 'window-configuration-change-hook |
528 (remove-hook 'erc-server-001-functions 'erc-user-is-active) | 605 'erc-user-is-active)) |
529 (remove-hook 'erc-timer-hook 'erc-user-is-active))) | 606 (remove-hook 'erc-send-completed-hook 'erc-user-is-active) |
607 (remove-hook 'erc-server-001-functions 'erc-user-is-active) | |
608 (remove-hook 'erc-timer-hook 'erc-user-is-active)) | |
609 (if (featurep 'xemacs) | |
610 (ad-disable-advice 'switch-to-buffer 'after 'erc-update) | |
611 (remove-hook 'window-configuration-change-hook | |
612 'erc-modified-channels-update)) | |
613 (remove-hook 'erc-disconnected-hook 'erc-modified-channels-update) | |
614 (remove-hook 'erc-insert-post-hook 'erc-track-modified-channels)) | |
615 ;; disable the tracking keybindings | |
616 (when erc-track-minor-mode | |
617 (erc-track-minor-mode -1))))) | |
618 | |
619 (defcustom erc-track-when-inactive nil | |
620 "Enable channel tracking even for visible buffers, if you are | |
621 inactive." | |
622 :group 'erc-track | |
623 :type 'boolean | |
624 :set (lambda (sym val) | |
625 (if erc-track-mode | |
626 (progn | |
627 (erc-track-disable) | |
628 (set sym val) | |
629 (erc-track-enable)) | |
630 (set sym val)))) | |
530 | 631 |
531 ;;; Visibility | 632 ;;; Visibility |
532 | 633 |
533 (defvar erc-buffer-activity nil | 634 (defvar erc-buffer-activity nil |
534 "Last time the user sent something.") | 635 "Last time the user sent something.") |
543 (setq erc-buffer-activity (erc-current-time)) | 644 (setq erc-buffer-activity (erc-current-time)) |
544 (erc-track-modified-channels)) | 645 (erc-track-modified-channels)) |
545 | 646 |
546 (defun erc-buffer-visible (buffer) | 647 (defun erc-buffer-visible (buffer) |
547 "Return non-nil when the buffer is visible." | 648 "Return non-nil when the buffer is visible." |
548 (if erc-track-when-inactive-mode | 649 (if erc-track-when-inactive |
549 (when erc-buffer-activity; could be nil | 650 (when erc-buffer-activity; could be nil |
550 (and (get-buffer-window buffer erc-track-visibility) | 651 (and (get-buffer-window buffer erc-track-visibility) |
551 (<= (erc-time-diff erc-buffer-activity (erc-current-time)) | 652 (<= (erc-time-diff erc-buffer-activity (erc-current-time)) |
552 erc-buffer-activity-timeout))) | 653 erc-buffer-activity-timeout))) |
553 (get-buffer-window buffer erc-track-visibility))) | 654 (get-buffer-window buffer erc-track-visibility))) |
813 (defun erc-track-switch-buffer (arg) | 914 (defun erc-track-switch-buffer (arg) |
814 "Switch to the next active ERC buffer, or if there are no active buffers, | 915 "Switch to the next active ERC buffer, or if there are no active buffers, |
815 switch back to the last non-ERC buffer visited. Next is defined by | 916 switch back to the last non-ERC buffer visited. Next is defined by |
816 `erc-track-switch-direction', a negative argument will reverse this." | 917 `erc-track-switch-direction', a negative argument will reverse this." |
817 (interactive "p") | 918 (interactive "p") |
818 (when erc-track-mode | 919 (if (not erc-track-mode) |
920 (message (concat "Enable the ERC track module if you want to use the" | |
921 " tracking minor mode")) | |
819 (cond (erc-modified-channels-alist | 922 (cond (erc-modified-channels-alist |
820 ;; if we're not in erc-mode, set this buffer to return to | 923 ;; if we're not in erc-mode, set this buffer to return to |
821 (unless (eq major-mode 'erc-mode) | 924 (unless (eq major-mode 'erc-mode) |
822 (setq erc-track-last-non-erc-buffer (current-buffer))) | 925 (setq erc-track-last-non-erc-buffer (current-buffer))) |
823 ;; and jump to the next active channel | 926 ;; and jump to the next active channel |
826 ((and erc-track-last-non-erc-buffer | 929 ((and erc-track-last-non-erc-buffer |
827 erc-track-switch-from-erc | 930 erc-track-switch-from-erc |
828 (buffer-live-p erc-track-last-non-erc-buffer)) | 931 (buffer-live-p erc-track-last-non-erc-buffer)) |
829 (switch-to-buffer erc-track-last-non-erc-buffer))))) | 932 (switch-to-buffer erc-track-last-non-erc-buffer))))) |
830 | 933 |
831 ;; These bindings are global, because they pop us from any other | |
832 ;; buffer to an active ERC buffer! | |
833 | |
834 (global-set-key (kbd "C-c C-@") 'erc-track-switch-buffer) | |
835 (global-set-key (kbd "C-c C-SPC") 'erc-track-switch-buffer) | |
836 | |
837 (provide 'erc-track) | 934 (provide 'erc-track) |
838 | 935 |
839 ;;; erc-track.el ends here | 936 ;;; erc-track.el ends here |
840 ;; | 937 ;; |
841 ;; Local Variables: | 938 ;; Local Variables: |