| | 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))) |
|---|
| | 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 | |
|---|
| 496 | | ((erc-track-add-to-mode-line erc-track-position-in-mode-line) |
|---|
| 497 | | (setq erc-modified-channels-object (erc-modified-channels-object nil)) |
|---|
| 498 | | (erc-update-mode-line) |
|---|
| 499 | | (if (featurep 'xemacs) |
|---|
| 500 | | (defadvice switch-to-buffer (after erc-update (&rest args) activate) |
|---|
| 501 | | (erc-modified-channels-update)) |
|---|
| 502 | | (add-hook 'window-configuration-change-hook 'erc-modified-channels-update)) |
|---|
| 503 | | (add-hook 'erc-insert-post-hook 'erc-track-modified-channels) |
|---|
| 504 | | (add-hook 'erc-disconnected-hook 'erc-modified-channels-update)) |
|---|
| 505 | | ((erc-track-remove-from-mode-line) |
|---|
| 506 | | (if (featurep 'xemacs) |
|---|
| 507 | | (ad-disable-advice 'switch-to-buffer 'after 'erc-update) |
|---|
| 508 | | (remove-hook 'window-configuration-change-hook |
|---|
| 509 | | 'erc-modified-channels-update)) |
|---|
| 510 | | (remove-hook 'erc-disconnected-hook 'erc-modified-channels-update) |
|---|
| 511 | | (remove-hook 'erc-insert-post-hook 'erc-track-modified-channels))) |
|---|
| 512 | | |
|---|
| 513 | | ;;;###autoload (autoload 'erc-track-when-inactive-mode "erc-track" nil t) |
|---|
| 514 | | (define-erc-module track-when-inactive nil |
|---|
| 515 | | "This mode enables channel tracking even for visible buffers, |
|---|
| 516 | | if you are inactivity." |
|---|
| 517 | | ((if (featurep 'xemacs) |
|---|
| 518 | | (defadvice switch-to-buffer (after erc-update-when-inactive (&rest args) activate) |
|---|
| 519 | | (erc-user-is-active)) |
|---|
| 520 | | (add-hook 'window-configuration-change-hook 'erc-user-is-active)) |
|---|
| 521 | | (add-hook 'erc-send-completed-hook 'erc-user-is-active) |
|---|
| 522 | | (add-hook 'erc-server-001-functions 'erc-user-is-active)) |
|---|
| 523 | | ((erc-track-remove-from-mode-line) |
|---|
| 524 | | (if (featurep 'xemacs) |
|---|
| 525 | | (ad-disable-advice 'switch-to-buffer 'after 'erc-update-when-inactive) |
|---|
| 526 | | (remove-hook 'window-configuration-change-hook 'erc-user-is-active)) |
|---|
| 527 | | (remove-hook 'erc-send-completed-hook 'erc-user-is-active) |
|---|
| 528 | | (remove-hook 'erc-server-001-functions 'erc-user-is-active) |
|---|
| 529 | | (remove-hook 'erc-timer-hook 'erc-user-is-active))) |
|---|
| | 573 | ;; Enable: |
|---|
| | 574 | ((when (boundp 'erc-track-when-inactive) |
|---|
| | 575 | (if erc-track-when-inactive |
|---|
| | 576 | (progn |
|---|
| | 577 | (if (featurep 'xemacs) |
|---|
| | 578 | (defadvice switch-to-buffer (after erc-update-when-inactive |
|---|
| | 579 | (&rest args) activate) |
|---|
| | 580 | (erc-user-is-active)) |
|---|
| | 581 | (add-hook 'window-configuration-change-hook 'erc-user-is-active)) |
|---|
| | 582 | (add-hook 'erc-send-completed-hook 'erc-user-is-active) |
|---|
| | 583 | (add-hook 'erc-server-001-functions 'erc-user-is-active)) |
|---|
| | 584 | (erc-track-add-to-mode-line erc-track-position-in-mode-line) |
|---|
| | 585 | (setq erc-modified-channels-object (erc-modified-channels-object nil)) |
|---|
| | 586 | (erc-update-mode-line) |
|---|
| | 587 | (if (featurep 'xemacs) |
|---|
| | 588 | (defadvice switch-to-buffer (after erc-update (&rest args) activate) |
|---|
| | 589 | (erc-modified-channels-update)) |
|---|
| | 590 | (add-hook 'window-configuration-change-hook |
|---|
| | 591 | 'erc-modified-channels-update)) |
|---|
| | 592 | (add-hook 'erc-insert-post-hook 'erc-track-modified-channels) |
|---|
| | 593 | (add-hook 'erc-disconnected-hook 'erc-modified-channels-update)) |
|---|
| | 594 | ;; enable the tracking keybindings |
|---|
| | 595 | (erc-track-minor-mode-maybe))) |
|---|
| | 596 | ;; Disable: |
|---|
| | 597 | ((when (boundp 'erc-track-when-inactive) |
|---|
| | 598 | (erc-track-remove-from-mode-line) |
|---|
| | 599 | (if erc-track-when-inactive |
|---|
| | 600 | (progn |
|---|
| | 601 | (if (featurep 'xemacs) |
|---|
| | 602 | (ad-disable-advice 'switch-to-buffer 'after |
|---|
| | 603 | 'erc-update-when-inactive) |
|---|
| | 604 | (remove-hook 'window-configuration-change-hook |
|---|
| | 605 | '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)))) |
|---|