annotate lisp/erc/erc-track.el @ 91305:b919d16b3066

Add unidata.txt.
author Andreas Schwab <schwab@suse.de>
date Thu, 03 Jan 2008 17:45:29 +0000
parents 11b4896b439a
children 107ccd98fa12
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
1 ;;; erc-track.el --- Track modified channel buffers
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
2
76856
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
3 ;; Copyright (C) 2002, 2003, 2004, 2005, 2006,
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
4 ;; 2007 Free Software Foundation, Inc.
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
5
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
6 ;; Author: Mario Lang <mlang@delysid.org>
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
7 ;; Keywords: comm, faces
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
8 ;; URL: http://www.emacswiki.org/cgi-bin/wiki.pl?ErcChannelTracking
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
9
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
10 ;; This file is part of GNU Emacs.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
11
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
13 ;; it under the terms of the GNU General Public License as published by
78219
85d67fae9a94 Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents: 76856
diff changeset
14 ;; the Free Software Foundation; either version 3, or (at your option)
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
15 ;; any later version.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
16
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
17 ;; GNU Emacs is distributed in the hope that it will be useful,
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
20 ;; GNU General Public License for more details.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
21
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
25 ;; Boston, MA 02110-1301, USA.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
26
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
27 ;;; Commentary:
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
28
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
29 ;; Highlights keywords and pals (friends), and hides or highlights fools
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
30 ;; (using a dark color). Add to your ~/.emacs:
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
31
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
32 ;; (require 'erc-track)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
33 ;; (erc-track-mode 1)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
34
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
35 ;; Todo:
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
36 ;; * Add extensibility so that custom functions can track
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
37 ;; custom modification types.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
38
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
39 (eval-when-compile (require 'cl))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
40 (require 'erc)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
41 (require 'erc-compat)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
42 (require 'erc-match)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
43
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
44 ;;; Code:
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
45
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
46 (defgroup erc-track nil
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
47 "Track active buffers and show activity in the modeline."
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
48 :group 'erc)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
49
76856
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
50 (defcustom erc-track-enable-keybindings 'ask
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
51 "Whether to enable the ERC track keybindings, namely:
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
52 `C-c C-SPC' and `C-c C-@', which both do the same thing.
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
53
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
54 The default is to check to see whether these keys are used
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
55 already: if not, then enable the ERC track minor mode, which
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
56 provides these keys. Otherwise, do not touch the keys.
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
57
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
58 This can alternatively be set to either t or nil, which indicate
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
59 respectively always to enable ERC track minor mode or never to
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
60 enable ERC track minor mode.
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
61
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
62 The reason for using this default value is to both (1) adhere to
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
63 the Emacs development guidelines which say not to touch keys of
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
64 the form C-c C-<something> and also (2) to meet the expectations
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
65 of long-time ERC users, many of whom rely on these keybindings."
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
66 :group 'erc-track
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
67 :type '(choice (const :tag "Ask, if used already" ask)
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
68 (const :tag "Enable" t)
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
69 (const :tag "Disable" nil)))
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
70
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
71 (defcustom erc-track-visibility t
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
72 "Where do we look for buffers to determine their visibility?
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
73 The value of this variable determines, when a buffer is considered
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
74 visible or invisible. New messages in invisible buffers are tracked,
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
75 while switching to visible buffers when they are tracked removes them
76856
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
76 from the list. See also `erc-track-when-inactive'.
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
77
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
78 Possible values are:
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
79
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
80 t - all frames
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
81 visible - all visible frames
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
82 nil - only the selected frame
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
83 selected-visible - only the selected frame if it is visible
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
84
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
85 Activity means that there was no user input in the last 10 seconds."
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
86 :group 'erc-track
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
87 :type '(choice (const :tag "All frames" t)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
88 (const :tag "All visible frames" visible)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
89 (const :tag "Only the selected frame" nil)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
90 (const :tag "Only the selected frame if it was active"
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
91 active)))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
92
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
93 (defcustom erc-track-exclude nil
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
94 "A list targets (channel names or query targets) which should not be tracked."
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
95 :group 'erc-track
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
96 :type '(repeat string))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
97
84387
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
98 (defcustom erc-track-remove-disconnected-buffers nil
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
99 "*If true, remove buffers associated with a server that is
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
100 disconnected from `erc-modified-channels-alist'."
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
101 :group 'erc-track
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
102 :type 'boolean)
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
103
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
104 (defcustom erc-track-exclude-types '("NICK")
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
105 "*List of message types to be ignored.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
106 This list could look like '(\"JOIN\" \"PART\")."
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
107 :group 'erc-track
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
108 :type 'erc-message-type)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
109
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
110 (defcustom erc-track-exclude-server-buffer nil
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
111 "*If true, don't perform tracking on the server buffer; this is
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
112 useful for excluding all the things like MOTDs from the server and
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
113 other miscellaneous functions."
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
114 :group 'erc-track
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
115 :type 'boolean)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
116
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
117 (defcustom erc-track-shorten-start 1
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
118 "This number specifies the minimum number of characters a channel name in
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
119 the mode-line should be reduced to."
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
120 :group 'erc-track
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
121 :type 'number)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
122
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
123 (defcustom erc-track-shorten-cutoff 4
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
124 "All channel names longer than this value will be shortened."
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
125 :group 'erc-track
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
126 :type 'number)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
127
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
128 (defcustom erc-track-shorten-aggressively nil
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
129 "*If non-nil, channel names will be shortened more aggressively.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
130 Usually, names are not shortened if this will save only one character.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
131 Example: If there are two channels, #linux-de and #linux-fr, then
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
132 normally these will not be shortened. When shortening aggressively,
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
133 however, these will be shortened to #linux-d and #linux-f.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
134
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
135 If this variable is set to `max', then channel names will be shortened
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
136 to the max. Usually, shortened channel names will remain unique for a
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
137 given set of existing channels. When shortening to the max, the shortened
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
138 channel names will be unique for the set of active channels only.
71883
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
139 Example: If there are two active channels #emacs and #vi, and two inactive
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
140 channels #electronica and #folk, then usually the active channels are
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
141 shortened to #em and #v. When shortening to the max, however, #emacs is
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
142 not compared to #electronica -- only to #vi, therefore it can be shortened
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
143 even more and the result is #e and #v.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
144
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
145 This setting is used by `erc-track-shorten-names'."
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
146 :group 'erc-track
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
147 :type '(choice (const :tag "No" nil)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
148 (const :tag "Yes" t)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
149 (const :tag "Max" max)))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
150
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
151 (defcustom erc-track-shorten-function 'erc-track-shorten-names
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
152 "*This function will be used to reduce the channel names before display.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
153 It takes one argument, CHANNEL-NAMES which is a list of strings.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
154 It should return a list of strings of the same number of elements.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
155 If nil instead of a function, shortening is disabled."
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
156 :group 'erc-track
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
157 :type '(choice (const :tag "Disabled")
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
158 function))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
159
84387
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
160 (defcustom erc-track-list-changed-hook nil
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
161 "Hook that is run whenever the contents of
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
162 `erc-modified-channels-alist' changes.
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
163
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
164 This is useful for people that don't use the default mode-line
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
165 notification but instead use a separate mechanism to provide
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
166 notification of channel activity."
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
167 :group 'erc-track
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
168 :type 'hook)
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
169
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
170 (defcustom erc-track-use-faces t
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
171 "*Use faces in the mode-line.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
172 The faces used are the same as used for text in the buffers.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
173 \(e.g. `erc-pal-face' is used if a pal sent a message to that channel.)"
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
174 :group 'erc-track
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
175 :type 'boolean)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
176
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
177 (defcustom erc-track-faces-priority-list
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
178 '(erc-error-face erc-current-nick-face erc-keyword-face erc-pal-face
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
179 erc-nick-msg-face erc-direct-msg-face erc-button erc-dangerous-host-face
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
180 erc-default-face erc-action-face erc-nick-default-face erc-fool-face
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
181 erc-notice-face erc-input-face erc-prompt-face)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
182 "A list of faces used to highlight active buffer names in the modeline.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
183 If a message contains one of the faces in this list, the buffer name will
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
184 be highlighted using that face. The first matching face is used."
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
185 :group 'erc-track
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
186 :type '(repeat face))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
187
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
188 (defcustom erc-track-priority-faces-only nil
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
189 "Only track text highlighted with a priority face.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
190 If you would like to ignore changes in certain channels where there
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
191 are no faces corresponding to your `erc-track-faces-priority-list', set
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
192 this variable. You can set a list of channel name strings, so those
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
193 will be ignored while all other channels will be tracked as normal.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
194 Other options are 'all, to apply this to all channels or nil, to disable
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
195 this feature.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
196 Note: If you have a lot of faces listed in `erc-track-faces-priority-list',
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
197 setting this variable might not be very useful."
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
198 :group 'erc-track
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
199 :type '(choice (const nil)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
200 (repeat string)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
201 (const all)))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
202
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
203 (defcustom erc-track-position-in-mode-line 'before-modes
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
204 "Where to show modified channel information in the mode-line.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
205
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
206 Setting this variable only has effects in GNU Emacs versions above 21.3.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
207
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
208 Choices are:
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
209 'before-modes - add to the beginning of `mode-line-modes'
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
210 'after-modes - add to the end of `mode-line-modes'
84387
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
211 t - add to the end of `global-mode-string'.
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
212 nil - don't add to mode line
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
213 "
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
214 :group 'erc-track
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
215 :type '(choice (const :tag "Just before mode information" before-modes)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
216 (const :tag "Just after mode information" after-modes)
84387
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
217 (const :tag "After all other information" t)
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
218 (const :tag "Don't display in mode line" nil))
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
219 :set (lambda (sym val)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
220 (set sym val)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
221 (when (and (boundp 'erc-track-mode)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
222 erc-track-mode)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
223 (erc-track-remove-from-mode-line)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
224 (erc-track-add-to-mode-line val))))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
225
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
226 (defun erc-modified-channels-object (strings)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
227 "Generate a new `erc-modified-channels-object' based on STRINGS.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
228 If STRINGS is nil, we initialize `erc-modified-channels-object' to
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
229 an appropriate initial value for this flavor of Emacs."
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
230 (if strings
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
231 (if (featurep 'xemacs)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
232 (let ((e-m-c-s '("[")))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
233 (push (cons (extent-at 0 (car strings)) (car strings))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
234 e-m-c-s)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
235 (dolist (string (cdr strings))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
236 (push "," e-m-c-s)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
237 (push (cons (extent-at 0 string) string)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
238 e-m-c-s))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
239 (push "] " e-m-c-s)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
240 (reverse e-m-c-s))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
241 (concat (if (eq erc-track-position-in-mode-line 'after-modes)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
242 "[" " [")
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
243 (mapconcat 'identity (nreverse strings) ",")
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
244 (if (eq erc-track-position-in-mode-line 'before-modes)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
245 "] " "]")))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
246 (if (featurep 'xemacs) '() "")))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
247
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
248 (defvar erc-modified-channels-object (erc-modified-channels-object nil)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
249 "Internal object used for displaying modified channels in the mode line.")
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
250
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
251 (put 'erc-modified-channels-object 'risky-local-variable t); allow properties
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
252
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
253 (defvar erc-modified-channels-alist nil
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
254 "An ALIST used for tracking channel modification activity.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
255 Each element looks like (BUFFER COUNT FACE) where BUFFER is a buffer
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
256 object of the channel the entry corresponds to, COUNT is a number
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
257 indicating how often activity was noticed, and FACE is the face to use
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
258 when displaying the buffer's name. See `erc-track-faces-priority-list',
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
259 and `erc-track-showcount'.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
260
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
261 Entries in this list should only happen for buffers where activity occurred
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
262 while the buffer was not visible.")
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
263
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
264 (defcustom erc-track-showcount nil
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
265 "If non-nil, count of unseen messages will be shown for each channel."
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
266 :type 'boolean
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
267 :group 'erc-track)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
268
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
269 (defcustom erc-track-showcount-string ":"
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
270 "The string to display between buffer name and the count in the mode line.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
271 The default is a colon, resulting in \"#emacs:9\"."
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
272 :type 'string
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
273 :group 'erc-track)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
274
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
275 (defcustom erc-track-switch-from-erc t
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
276 "If non-nil, `erc-track-switch-buffer' will return to the last non-erc buffer
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
277 when there are no more active channels."
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
278 :type 'boolean
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
279 :group 'erc-track)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
280
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
281 (defcustom erc-track-switch-direction 'oldest
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
282 "Direction `erc-track-switch-buffer' should switch.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
283
84387
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
284 importance - find buffer with the most important message
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
285 oldest - find oldest active buffer
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
286 newest - find newest active buffer
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
287 leastactive - find buffer with least unseen messages
84636
ffc87ddd4025 Sync changes from upstream ERC
Michael Olson <mwolson@gnu.org>
parents: 84387
diff changeset
288 mostactive - find buffer with most unseen messages.
ffc87ddd4025 Sync changes from upstream ERC
Michael Olson <mwolson@gnu.org>
parents: 84387
diff changeset
289
ffc87ddd4025 Sync changes from upstream ERC
Michael Olson <mwolson@gnu.org>
parents: 84387
diff changeset
290 If set to 'importance, the importance is determined by position
ffc87ddd4025 Sync changes from upstream ERC
Michael Olson <mwolson@gnu.org>
parents: 84387
diff changeset
291 in `erc-track-faces-priority-list', where first is most
ffc87ddd4025 Sync changes from upstream ERC
Michael Olson <mwolson@gnu.org>
parents: 84387
diff changeset
292 important."
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
293 :group 'erc-track
84387
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
294 :type '(choice (const importance)
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
295 (const oldest)
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
296 (const newest)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
297 (const leastactive)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
298 (const mostactive)))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
299
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
300
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
301 (defun erc-track-remove-from-mode-line ()
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
302 "Remove `erc-track-modified-channels' from the mode-line"
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
303 (when (boundp 'mode-line-modes)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
304 (setq mode-line-modes
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
305 (remove '(t erc-modified-channels-object) mode-line-modes)))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
306 (when (consp global-mode-string)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
307 (setq global-mode-string
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
308 (delq 'erc-modified-channels-object global-mode-string))))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
309
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
310 (defun erc-track-add-to-mode-line (position)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
311 "Add `erc-track-modified-channels' to POSITION in the mode-line.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
312 See `erc-track-position-in-mode-line' for possible values."
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
313 ;; CVS Emacs has a new format string, and global-mode-string
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
314 ;; is very far to the right.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
315 (cond ((and (eq position 'before-modes)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
316 (boundp 'mode-line-modes))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
317 (add-to-list 'mode-line-modes
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
318 '(t erc-modified-channels-object)))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
319 ((and (eq position 'after-modes)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
320 (boundp 'mode-line-modes))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
321 (add-to-list 'mode-line-modes
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
322 '(t erc-modified-channels-object) t))
84387
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
323 ((eq position t)
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
324 (when (not global-mode-string)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
325 (setq global-mode-string '(""))) ; Padding for mode-line wart
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
326 (add-to-list 'global-mode-string
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
327 'erc-modified-channels-object
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
328 t))))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
329
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
330 ;;; Shortening of names
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
331
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
332 (defun erc-track-shorten-names (channel-names)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
333 "Call `erc-unique-channel-names' with the correct parameters.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
334 This function is a good value for `erc-track-shorten-function'.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
335 The list of all channels is returned by `erc-all-buffer-names'.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
336 CHANNEL-NAMES is the list of active channel names.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
337 Only channel names longer than `erc-track-shorten-cutoff' are
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
338 actually shortened, and they are only shortened to a minimum
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
339 of `erc-track-shorten-start' characters."
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
340 (erc-unique-channel-names
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
341 (erc-all-buffer-names)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
342 channel-names
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
343 (lambda (s)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
344 (> (length s) erc-track-shorten-cutoff))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
345 erc-track-shorten-start))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
346
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
347 (defvar erc-default-recipients)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
348
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
349 (defun erc-all-buffer-names ()
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
350 "Return all channel or query buffer names.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
351 Note that we cannot use `erc-channel-list' with a nil argument,
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
352 because that does not return query buffers."
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
353 (save-excursion
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
354 (let (result)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
355 (dolist (buf (buffer-list))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
356 (set-buffer buf)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
357 (when (or (eq major-mode 'erc-mode) (eq major-mode 'erc-dcc-chat-mode))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
358 (setq result (cons (buffer-name) result))))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
359 result)))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
360
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
361 (defun erc-unique-channel-names (all active &optional predicate start)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
362 "Return a list of unique channel names.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
363 ALL is the list of all channel and query buffer names.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
364 ACTIVE is the list of active buffer names.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
365 PREDICATE is a predicate that should return non-nil if a name needs
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
366 no shortening.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
367 START is the minimum length of the name used."
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
368 (if (eq 'max erc-track-shorten-aggressively)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
369 ;; Return the unique substrings of all active channels.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
370 (erc-unique-substrings active predicate start)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
371 ;; Otherwise, determine the unique substrings of all channels, and
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
372 ;; for every active channel, return the corresponding substring.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
373 ;; Given the names of the active channels, we now need to find the
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
374 ;; corresponding short name from the list of all substrings. To
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
375 ;; avoid problems when there are two channels and one is a
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
376 ;; substring of the other (notorious examples are #hurd and
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
377 ;; #hurd-bunny), every candidate gets the longest possible
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
378 ;; substring.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
379 (let ((all-substrings (sort
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
380 (erc-unique-substrings all predicate start)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
381 (lambda (a b) (> (length a) (length b)))))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
382 result)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
383 (dolist (channel active)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
384 (let ((substrings all-substrings)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
385 candidate
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
386 winner)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
387 (while (and substrings (not winner))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
388 (setq candidate (car substrings)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
389 substrings (cdr substrings))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
390 (when (and (string= candidate
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
391 (substring channel
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
392 0
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
393 (min (length candidate)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
394 (length channel))))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
395 (not (member candidate result)))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
396 (setq winner candidate)))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
397 (setq result (cons winner result))))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
398 (nreverse result))))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
399
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
400 (defun erc-unique-substrings (strings &optional predicate start)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
401 "Return a list of unique substrings of STRINGS."
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
402 (if (or (not (numberp start))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
403 (< start 0))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
404 (setq start 2))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
405 (mapcar
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
406 (lambda (str)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
407 (let* ((others (delete str (copy-sequence strings)))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
408 (maxlen (length str))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
409 (i (min start
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
410 (length str)))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
411 candidate
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
412 done)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
413 (if (and (functionp predicate) (not (funcall predicate str)))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
414 ;; do not shorten if a predicate exists and it returns nil
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
415 str
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
416 ;; Start with smallest substring candidate, ie. length 1.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
417 ;; Then check all the others and see whether any of them starts
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
418 ;; with the same substring. While there is such another
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
419 ;; element in the list, increase the length of the candidate.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
420 (while (not done)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
421 (if (> i maxlen)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
422 (setq done t)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
423 (setq candidate (substring str 0 i)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
424 done (not (erc-unique-substring-1 candidate others))))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
425 (setq i (1+ i)))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
426 (if (and (= (length candidate) (1- maxlen))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
427 (not erc-track-shorten-aggressively))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
428 str
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
429 candidate))))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
430 strings))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
431
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
432 (defun erc-unique-substring-1 (candidate others)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
433 "Return non-nil when any string in OTHERS starts with CANDIDATE."
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
434 (let (result other (maxlen (length candidate)))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
435 (while (and others
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
436 (not result))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
437 (setq other (car others)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
438 others (cdr others))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
439 (when (and (>= (length other) maxlen)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
440 (string= candidate (substring other 0 maxlen)))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
441 (setq result other)))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
442 result))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
443
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
444 ;;; Test:
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
445
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
446 (erc-assert
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
447 (and
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
448 ;; verify examples from the doc strings
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
449 (equal (let ((erc-track-shorten-aggressively nil))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
450 (erc-unique-channel-names
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
451 '("#emacs" "#vi" "#electronica" "#folk")
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
452 '("#emacs" "#vi")))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
453 '("#em" "#vi")) ; emacs is different from electronica
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
454 (equal (let ((erc-track-shorten-aggressively t))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
455 (erc-unique-channel-names
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
456 '("#emacs" "#vi" "#electronica" "#folk")
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
457 '("#emacs" "#vi")))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
458 '("#em" "#v")) ; vi is shortened by one letter
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
459 (equal (let ((erc-track-shorten-aggressively 'max))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
460 (erc-unique-channel-names
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
461 '("#emacs" "#vi" "#electronica" "#folk")
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
462 '("#emacs" "#vi")))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
463 '("#e" "#v")) ; emacs need not be different from electronica
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
464 (equal (let ((erc-track-shorten-aggressively nil))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
465 (erc-unique-channel-names
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
466 '("#linux-de" "#linux-fr")
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
467 '("#linux-de" "#linux-fr")))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
468 '("#linux-de" "#linux-fr")) ; shortening by one letter is too aggressive
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
469 (equal (let ((erc-track-shorten-aggressively t))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
470 (erc-unique-channel-names
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
471 '("#linux-de" "#linux-fr")
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
472 '("#linux-de" "#linux-fr")))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
473 '("#linux-d" "#linux-f")); now we want to be aggressive
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
474 ;; specific problems
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
475 (equal (let ((erc-track-shorten-aggressively nil))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
476 (erc-unique-channel-names
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
477 '("#dunnet" "#lisp" "#sawfish" "#fsf" "#guile"
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
478 "#testgnome" "#gnu" "#fsbot" "#hurd" "#hurd-bunny"
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
479 "#emacs")
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
480 '("#hurd-bunny" "#hurd" "#sawfish" "#lisp")))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
481 '("#hurd-" "#hurd" "#s" "#l"))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
482 (equal (let ((erc-track-shorten-aggressively nil))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
483 (erc-unique-substrings
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
484 '("#emacs" "#vi" "#electronica" "#folk")))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
485 '("#em" "#vi" "#el" "#f"))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
486 (equal (let ((erc-track-shorten-aggressively t))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
487 (erc-unique-substrings
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
488 '("#emacs" "#vi" "#electronica" "#folk")))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
489 '("#em" "#v" "#el" "#f"))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
490 (equal (let ((erc-track-shorten-aggressively nil))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
491 (erc-unique-channel-names
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
492 '("#emacs" "#burse" "+linux.de" "#starwars"
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
493 "#bitlbee" "+burse" "#ratpoison")
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
494 '("+linux.de" "#starwars" "#burse")))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
495 '("+l" "#s" "#bu"))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
496 (equal (let ((erc-track-shorten-aggressively nil))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
497 (erc-unique-channel-names
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
498 '("fsbot" "#emacs" "deego")
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
499 '("fsbot")))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
500 '("fs"))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
501 (equal (let ((erc-track-shorten-aggressively nil))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
502 (erc-unique-channel-names
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
503 '("fsbot" "#emacs" "deego")
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
504 '("fsbot")
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
505 (lambda (s)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
506 (> (length s) 4))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
507 1))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
508 '("f"))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
509 (equal (let ((erc-track-shorten-aggressively nil))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
510 (erc-unique-channel-names
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
511 '("fsbot" "#emacs" "deego")
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
512 '("fsbot")
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
513 (lambda (s)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
514 (> (length s) 4))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
515 2))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
516 '("fs"))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
517 (let ((erc-track-shorten-aggressively nil))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
518 (equal (erc-unique-channel-names '("deego" "#hurd" "#hurd-bunny" "#emacs")
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
519 '("#hurd" "#hurd-bunny"))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
520 '("#hurd" "#hurd-")))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
521 ;; general examples
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
522 (let ((erc-track-shorten-aggressively t))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
523 (and (equal (erc-unique-substring-1 "abc" '("ab" "abcd")) "abcd")
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
524 (not (erc-unique-substring-1 "a" '("xyz" "xab")))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
525 (equal (erc-unique-substrings '("abc" "xyz" "xab"))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
526 '("ab" "xy" "xa"))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
527 (equal (erc-unique-substrings '("abc" "abcdefg"))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
528 '("abc" "abcd"))))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
529 (let ((erc-track-shorten-aggressively nil))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
530 (and (equal (erc-unique-substring-1 "abc" '("ab" "abcd")) "abcd")
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
531 (not (erc-unique-substring-1 "a" '("xyz" "xab")))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
532 (equal (erc-unique-substrings '("abc" "xyz" "xab"))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
533 '("abc" "xyz" "xab"))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
534 (equal (erc-unique-substrings '("abc" "abcdefg"))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
535 '("abc" "abcd"))))))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
536
76856
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
537 ;;; Minor mode
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
538
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
539 ;; Play nice with other IRC clients (and Emacs development rules) by
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
540 ;; making this a minor mode
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
541
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
542 (defvar erc-track-minor-mode-map (make-sparse-keymap)
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
543 "Keymap for rcirc track minor mode.")
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
544
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
545 (define-key erc-track-minor-mode-map (kbd "C-c C-@") 'erc-track-switch-buffer)
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
546 (define-key erc-track-minor-mode-map (kbd "C-c C-SPC")
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
547 'erc-track-switch-buffer)
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
548
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
549 ;;;###autoload
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
550 (define-minor-mode erc-track-minor-mode
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
551 "Global minor mode for tracking ERC buffers and showing activity in the
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
552 mode line.
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
553
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
554 This exists for the sole purpose of providing the C-c C-SPC and
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
555 C-c C-@ keybindings. Make sure that you have enabled the track
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
556 module, otherwise the keybindings will not do anything useful."
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
557 :init-value nil
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
558 :lighter ""
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
559 :keymap erc-track-minor-mode-map
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
560 :global t
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
561 :group 'erc-track)
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
562
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
563 (defun erc-track-minor-mode-maybe ()
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
564 "Enable `erc-track-minor-mode', depending on `erc-track-enable-keybindings'."
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
565 (unless (or erc-track-minor-mode
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
566 ;; don't start the minor mode until we have an ERC
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
567 ;; process running, because we don't want to prompt the
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
568 ;; user while starting Emacs
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
569 (null (erc-buffer-list)))
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
570 (cond ((eq erc-track-enable-keybindings 'ask)
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
571 (let ((key (or (and (key-binding (kbd "C-c C-SPC")) "C-SPC")
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
572 (and (key-binding (kbd "C-c C-@")) "C-@"))))
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
573 (if key
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
574 (if (y-or-n-p
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
575 (concat "The C-c " key " binding is in use;"
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
576 " override it for tracking? "))
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
577 (progn
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
578 (message (concat "Will change it; set"
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
579 " `erc-track-enable-keybindings'"
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
580 " to disable this message"))
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
581 (sleep-for 3)
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
582 (erc-track-minor-mode 1))
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
583 (message (concat "Not changing it; set"
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
584 " `erc-track-enable-keybindings'"
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
585 " to disable this message"))
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
586 (sleep-for 3))
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
587 (erc-track-minor-mode 1))))
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
588 ((eq erc-track-enable-keybindings t)
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
589 (erc-track-minor-mode 1))
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
590 (t nil))))
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
591
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
592 ;;; Module
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
593
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
594 ;;;###autoload (autoload 'erc-track-mode "erc-track" nil t)
76856
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
595 (define-erc-module track nil
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
596 "This mode tracks ERC channel buffers with activity."
76856
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
597 ;; Enable:
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
598 ((when (boundp 'erc-track-when-inactive)
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
599 (if erc-track-when-inactive
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
600 (progn
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
601 (if (featurep 'xemacs)
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
602 (defadvice switch-to-buffer (after erc-update-when-inactive
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
603 (&rest args) activate)
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
604 (erc-user-is-active))
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
605 (add-hook 'window-configuration-change-hook 'erc-user-is-active))
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
606 (add-hook 'erc-send-completed-hook 'erc-user-is-active)
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
607 (add-hook 'erc-server-001-functions 'erc-user-is-active))
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
608 (erc-track-add-to-mode-line erc-track-position-in-mode-line)
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
609 (setq erc-modified-channels-object (erc-modified-channels-object nil))
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
610 (erc-update-mode-line)
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
611 (if (featurep 'xemacs)
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
612 (defadvice switch-to-buffer (after erc-update (&rest args) activate)
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
613 (erc-modified-channels-update))
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
614 (add-hook 'window-configuration-change-hook
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
615 'erc-modified-channels-update))
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
616 (add-hook 'erc-insert-post-hook 'erc-track-modified-channels)
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
617 (add-hook 'erc-disconnected-hook 'erc-modified-channels-update))
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
618 ;; enable the tracking keybindings
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
619 (erc-track-minor-mode-maybe)))
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
620 ;; Disable:
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
621 ((when (boundp 'erc-track-when-inactive)
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
622 (erc-track-remove-from-mode-line)
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
623 (if erc-track-when-inactive
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
624 (progn
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
625 (if (featurep 'xemacs)
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
626 (ad-disable-advice 'switch-to-buffer 'after
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
627 'erc-update-when-inactive)
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
628 (remove-hook 'window-configuration-change-hook
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
629 'erc-user-is-active))
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
630 (remove-hook 'erc-send-completed-hook 'erc-user-is-active)
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
631 (remove-hook 'erc-server-001-functions 'erc-user-is-active)
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
632 (remove-hook 'erc-timer-hook 'erc-user-is-active))
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
633 (if (featurep 'xemacs)
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
634 (ad-disable-advice 'switch-to-buffer 'after 'erc-update)
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
635 (remove-hook 'window-configuration-change-hook
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
636 'erc-modified-channels-update))
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
637 (remove-hook 'erc-disconnected-hook 'erc-modified-channels-update)
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
638 (remove-hook 'erc-insert-post-hook 'erc-track-modified-channels))
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
639 ;; disable the tracking keybindings
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
640 (when erc-track-minor-mode
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
641 (erc-track-minor-mode -1)))))
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
642
76856
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
643 (defcustom erc-track-when-inactive nil
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
644 "Enable channel tracking even for visible buffers, if you are
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
645 inactive."
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
646 :group 'erc-track
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
647 :type 'boolean
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
648 :set (lambda (sym val)
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
649 (if erc-track-mode
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
650 (progn
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
651 (erc-track-disable)
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
652 (set sym val)
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
653 (erc-track-enable))
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
654 (set sym val))))
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
655
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
656 ;;; Visibility
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
657
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
658 (defvar erc-buffer-activity nil
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
659 "Last time the user sent something.")
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
660
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
661 (defvar erc-buffer-activity-timeout 10
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
662 "How many seconds of inactivity by the user
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
663 to consider when `erc-track-visibility' is set to
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
664 only consider active buffers visible.")
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
665
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
666 (defun erc-user-is-active (&rest ignore)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
667 "Set `erc-buffer-activity'."
86836
11b4896b439a Sync from upstream ERC
Michael Olson <mwolson@gnu.org>
parents: 85771
diff changeset
668 (when erc-server-connected
11b4896b439a Sync from upstream ERC
Michael Olson <mwolson@gnu.org>
parents: 85771
diff changeset
669 (setq erc-buffer-activity (erc-current-time))
11b4896b439a Sync from upstream ERC
Michael Olson <mwolson@gnu.org>
parents: 85771
diff changeset
670 (erc-track-modified-channels)))
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
671
84387
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
672 (defun erc-track-get-buffer-window (buffer frame-param)
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
673 (if (eq frame-param 'selected-visible)
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
674 (if (eq (frame-visible-p (selected-frame)) t)
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
675 (get-buffer-window buffer nil)
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
676 nil)
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
677 (get-buffer-window buffer frame-param)))
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
678
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
679 (defun erc-buffer-visible (buffer)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
680 "Return non-nil when the buffer is visible."
76856
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
681 (if erc-track-when-inactive
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
682 (when erc-buffer-activity; could be nil
84387
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
683 (and (erc-track-get-buffer-window buffer erc-track-visibility)
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
684 (<= (erc-time-diff erc-buffer-activity (erc-current-time))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
685 erc-buffer-activity-timeout)))
84387
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
686 (erc-track-get-buffer-window buffer erc-track-visibility)))
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
687
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
688 ;;; Tracking the channel modifications
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
689
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
690 (defvar erc-modified-channels-update-inside nil
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
691 "Variable to prevent running `erc-modified-channels-update' multiple
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
692 times. Without it, you cannot debug `erc-modified-channels-display',
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
693 because the debugger also cases changes to the window-configuration.")
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
694
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
695 (defun erc-modified-channels-update (&rest args)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
696 "This function updates the information in `erc-modified-channels-alist'
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
697 according to buffer visibility. It calls
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
698 `erc-modified-channels-display' at the end. This should usually be
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
699 called via `window-configuration-change-hook'.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
700 ARGS are ignored."
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
701 (interactive)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
702 (unless erc-modified-channels-update-inside
84387
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
703 (let ((erc-modified-channels-update-inside t)
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
704 (removed-channel nil))
85233
977fdc85afd3 (erc-modified-channels-update): Use mapc rather than mapcar.
Glenn Morris <rgm@gnu.org>
parents: 84636
diff changeset
705 (mapc (lambda (elt)
977fdc85afd3 (erc-modified-channels-update): Use mapc rather than mapcar.
Glenn Morris <rgm@gnu.org>
parents: 84636
diff changeset
706 (let ((buffer (car elt)))
977fdc85afd3 (erc-modified-channels-update): Use mapc rather than mapcar.
Glenn Morris <rgm@gnu.org>
parents: 84636
diff changeset
707 (when (or (not (bufferp buffer))
977fdc85afd3 (erc-modified-channels-update): Use mapc rather than mapcar.
Glenn Morris <rgm@gnu.org>
parents: 84636
diff changeset
708 (not (buffer-live-p buffer))
977fdc85afd3 (erc-modified-channels-update): Use mapc rather than mapcar.
Glenn Morris <rgm@gnu.org>
parents: 84636
diff changeset
709 (erc-buffer-visible buffer)
977fdc85afd3 (erc-modified-channels-update): Use mapc rather than mapcar.
Glenn Morris <rgm@gnu.org>
parents: 84636
diff changeset
710 (and erc-track-remove-disconnected-buffers
977fdc85afd3 (erc-modified-channels-update): Use mapc rather than mapcar.
Glenn Morris <rgm@gnu.org>
parents: 84636
diff changeset
711 (not (with-current-buffer buffer
977fdc85afd3 (erc-modified-channels-update): Use mapc rather than mapcar.
Glenn Morris <rgm@gnu.org>
parents: 84636
diff changeset
712 erc-server-connected))))
977fdc85afd3 (erc-modified-channels-update): Use mapc rather than mapcar.
Glenn Morris <rgm@gnu.org>
parents: 84636
diff changeset
713 (setq removed-channel t)
977fdc85afd3 (erc-modified-channels-update): Use mapc rather than mapcar.
Glenn Morris <rgm@gnu.org>
parents: 84636
diff changeset
714 (erc-modified-channels-remove-buffer buffer))))
977fdc85afd3 (erc-modified-channels-update): Use mapc rather than mapcar.
Glenn Morris <rgm@gnu.org>
parents: 84636
diff changeset
715 erc-modified-channels-alist)
84387
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
716 (when removed-channel
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
717 (erc-modified-channels-display)
84387
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
718 (force-mode-line-update t)))))
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
719
74093
bc5d69739d5e Merge from erc--emacs--22
Miles Bader <miles@gnu.org>
parents: 71883
diff changeset
720 (defvar erc-track-mouse-face (if (featurep 'xemacs)
bc5d69739d5e Merge from erc--emacs--22
Miles Bader <miles@gnu.org>
parents: 71883
diff changeset
721 'modeline-mousable
bc5d69739d5e Merge from erc--emacs--22
Miles Bader <miles@gnu.org>
parents: 71883
diff changeset
722 'mode-line-highlight)
bc5d69739d5e Merge from erc--emacs--22
Miles Bader <miles@gnu.org>
parents: 71883
diff changeset
723 "The face to use when mouse is over channel names in the mode line.")
bc5d69739d5e Merge from erc--emacs--22
Miles Bader <miles@gnu.org>
parents: 71883
diff changeset
724
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
725 (defun erc-make-mode-line-buffer-name (string buffer &optional faces count)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
726 "Return STRING as a button that switches to BUFFER when clicked.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
727 If FACES are provided, color STRING with them."
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
728 ;; We define a new sparse keymap every time, because 1. this data
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
729 ;; structure is very small, the alternative would require us to
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
730 ;; defvar a keymap, 2. the user is not interested in customizing it
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
731 ;; (really?), 3. the defun needs to switch to BUFFER, so we would
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
732 ;; need to save that value somewhere.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
733 (let ((map (make-sparse-keymap))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
734 (name (if erc-track-showcount
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
735 (concat string
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
736 erc-track-showcount-string
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
737 (int-to-string count))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
738 (copy-sequence string))))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
739 (define-key map (vector 'mode-line 'mouse-2)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
740 `(lambda (e)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
741 (interactive "e")
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
742 (save-selected-window
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
743 (select-window
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
744 (posn-window (event-start e)))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
745 (switch-to-buffer ,buffer))))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
746 (define-key map (vector 'mode-line 'mouse-3)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
747 `(lambda (e)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
748 (interactive "e")
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
749 (save-selected-window
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
750 (select-window
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
751 (posn-window (event-start e)))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
752 (switch-to-buffer-other-window ,buffer))))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
753 (put-text-property 0 (length name) 'local-map map name)
74093
bc5d69739d5e Merge from erc--emacs--22
Miles Bader <miles@gnu.org>
parents: 71883
diff changeset
754 (put-text-property
bc5d69739d5e Merge from erc--emacs--22
Miles Bader <miles@gnu.org>
parents: 71883
diff changeset
755 0 (length name)
bc5d69739d5e Merge from erc--emacs--22
Miles Bader <miles@gnu.org>
parents: 71883
diff changeset
756 'help-echo (concat "mouse-2: switch to buffer, "
bc5d69739d5e Merge from erc--emacs--22
Miles Bader <miles@gnu.org>
parents: 71883
diff changeset
757 "mouse-3: switch to buffer in other window")
bc5d69739d5e Merge from erc--emacs--22
Miles Bader <miles@gnu.org>
parents: 71883
diff changeset
758 name)
bc5d69739d5e Merge from erc--emacs--22
Miles Bader <miles@gnu.org>
parents: 71883
diff changeset
759 (put-text-property 0 (length name) 'mouse-face erc-track-mouse-face name)
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
760 (when (and faces erc-track-use-faces)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
761 (put-text-property 0 (length name) 'face faces name))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
762 name))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
763
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
764 (defun erc-modified-channels-display ()
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
765 "Set `erc-modified-channels-object'
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
766 according to `erc-modified-channels-alist'.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
767 Use `erc-make-mode-line-buffer-name' to create buttons."
84387
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
768 (cond ((or (eq 'mostactive erc-track-switch-direction)
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
769 (eq 'leastactive erc-track-switch-direction))
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
770 (erc-track-sort-by-activest))
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
771 ((eq 'importance erc-track-switch-direction)
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
772 (erc-track-sort-by-importance)))
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
773 (run-hooks 'erc-track-list-changed-hook)
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
774 (unless (eq erc-track-position-in-mode-line nil)
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
775 (if (null erc-modified-channels-alist)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
776 (setq erc-modified-channels-object (erc-modified-channels-object nil))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
777 ;; erc-modified-channels-alist contains all the data we need. To
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
778 ;; better understand what is going on, we split things up into
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
779 ;; four lists: BUFFERS, COUNTS, SHORT-NAMES, and FACES. These
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
780 ;; four lists we use to create a new
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
781 ;; `erc-modified-channels-object' using
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
782 ;; `erc-make-mode-line-buffer-name'.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
783 (let* ((buffers (mapcar 'car erc-modified-channels-alist))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
784 (counts (mapcar 'cadr erc-modified-channels-alist))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
785 (faces (mapcar 'cddr erc-modified-channels-alist))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
786 (long-names (mapcar #'(lambda (buf)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
787 (or (buffer-name buf)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
788 ""))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
789 buffers))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
790 (short-names (if (functionp erc-track-shorten-function)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
791 (funcall erc-track-shorten-function
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
792 long-names)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
793 long-names))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
794 strings)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
795 (while buffers
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
796 (when (car short-names)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
797 (setq strings (cons (erc-make-mode-line-buffer-name
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
798 (car short-names)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
799 (car buffers)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
800 (car faces)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
801 (car counts))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
802 strings)))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
803 (setq short-names (cdr short-names)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
804 buffers (cdr buffers)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
805 counts (cdr counts)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
806 faces (cdr faces)))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
807 (when (featurep 'xemacs)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
808 (erc-modified-channels-object nil))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
809 (setq erc-modified-channels-object
84387
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
810 (erc-modified-channels-object strings))))))
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
811
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
812 (defun erc-modified-channels-remove-buffer (buffer)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
813 "Remove BUFFER from `erc-modified-channels-alist'."
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
814 (interactive "bBuffer: ")
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
815 (setq erc-modified-channels-alist
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
816 (delete (assq buffer erc-modified-channels-alist)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
817 erc-modified-channels-alist))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
818 (when (interactive-p)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
819 (erc-modified-channels-display)))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
820
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
821 (defun erc-track-find-face (faces)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
822 "Return the face to use in the modeline from the faces in FACES.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
823 If `erc-track-faces-priority-list' is set, the one from FACES who is
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
824 first in that list will be used."
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
825 (let ((candidates erc-track-faces-priority-list)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
826 candidate face)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
827 (while (and candidates (not face))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
828 (setq candidate (car candidates)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
829 candidates (cdr candidates))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
830 (when (memq candidate faces)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
831 (setq face candidate)))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
832 face))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
833
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
834 (defun erc-track-modified-channels ()
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
835 "Hook function for `erc-insert-post-hook' to check if the current
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
836 buffer should be added to the modeline as a hidden, modified
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
837 channel. Assumes it will only be called when current-buffer
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
838 is in `erc-mode'."
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
839 (let ((this-channel (or (erc-default-target)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
840 (buffer-name (current-buffer)))))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
841 (if (and (not (erc-buffer-visible (current-buffer)))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
842 (not (member this-channel erc-track-exclude))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
843 (not (and erc-track-exclude-server-buffer
84387
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
844 (erc-server-buffer-p)))
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
845 (not (erc-message-type-member
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
846 (or (erc-find-parsed-property)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
847 (point-min))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
848 erc-track-exclude-types)))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
849 ;; If the active buffer is not visible (not shown in a
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
850 ;; window), and not to be excluded, determine the kinds of
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
851 ;; faces used in the current message, and unless the user
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
852 ;; wants to ignore changes in certain channels where there
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
853 ;; are no faces corresponding to `erc-track-faces-priority-list',
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
854 ;; and the faces in the current message are found in said
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
855 ;; priority list, add the buffer to the erc-modified-channels-alist,
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
856 ;; if it is not already there. If the buffer is already on the list
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
857 ;; (in the car), change its face attribute (in the cddr) if
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
858 ;; necessary. See `erc-modified-channels-alist' for the
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
859 ;; exact data structure used.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
860 (let ((faces (erc-faces-in (buffer-string))))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
861 (unless (and
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
862 (or (eq erc-track-priority-faces-only 'all)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
863 (member this-channel erc-track-priority-faces-only))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
864 (not (catch 'found
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
865 (dolist (f faces)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
866 (when (member f erc-track-faces-priority-list)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
867 (throw 'found t))))))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
868 (if (not (assq (current-buffer) erc-modified-channels-alist))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
869 ;; Add buffer, faces and counts
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
870 (setq erc-modified-channels-alist
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
871 (cons (cons (current-buffer)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
872 (cons 1 (erc-track-find-face faces)))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
873 erc-modified-channels-alist))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
874 ;; Else modify the face for the buffer, if necessary.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
875 (when faces
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
876 (let* ((cell (assq (current-buffer)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
877 erc-modified-channels-alist))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
878 (old-face (cddr cell))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
879 (new-face (erc-track-find-face
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
880 (if old-face
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
881 (cons old-face faces)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
882 faces))))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
883 (setcdr cell (cons (1+ (cadr cell)) new-face)))))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
884 ;; And display it
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
885 (erc-modified-channels-display)))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
886 ;; Else if the active buffer is the current buffer, remove it
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
887 ;; from our list.
84387
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
888 (when (and (or (erc-buffer-visible (current-buffer))
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
889 (and this-channel
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
890 (member this-channel erc-track-exclude)))
84387
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
891 (assq (current-buffer) erc-modified-channels-alist))
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
892 ;; Remove it from mode-line if buffer is visible or
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
893 ;; channel was added to erc-track-exclude recently.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
894 (erc-modified-channels-remove-buffer (current-buffer))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
895 (erc-modified-channels-display)))))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
896
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
897 (defun erc-faces-in (str)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
898 "Return a list of all faces used in STR."
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
899 (let ((i 0)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
900 (m (length str))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
901 (faces (erc-list (get-text-property 0 'face str))))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
902 (while (and (setq i (next-single-property-change i 'face str m))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
903 (not (= i m)))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
904 (dolist (face (erc-list (get-text-property i 'face str)))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
905 (add-to-list 'faces face)))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
906 faces))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
907
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
908 (erc-assert
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
909 (let ((str "is bold"))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
910 (put-text-property 3 (length str)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
911 'face '(bold erc-current-nick-face)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
912 str)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
913 (erc-faces-in str)))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
914
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
915 ;;; Buffer switching
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
916
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
917 (defvar erc-track-last-non-erc-buffer nil
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
918 "Stores the name of the last buffer you were in before activating
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
919 `erc-track-switch-buffers'")
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
920
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
921 (defun erc-track-sort-by-activest ()
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
922 "Sort erc-modified-channels-alist by activity.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
923 That means the number of unseen messages in a channel."
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
924 (setq erc-modified-channels-alist
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
925 (sort erc-modified-channels-alist
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
926 (lambda (a b) (> (nth 1 a) (nth 1 b))))))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
927
84387
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
928 (defun erc-track-face-priority (face)
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
929 "Return a number indicating the priority of FACE in
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
930 `erc-track-faces-priority-list'. Lower number means higher
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
931 priority.
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
932
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
933 If face is not in `erc-track-faces-priority-list', it will have a
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
934 higher number than any other face in that list."
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
935 (let ((count 0))
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
936 (catch 'done
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
937 (dolist (item erc-track-faces-priority-list)
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
938 (if (eq item face)
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
939 (throw 'done t)
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
940 (setq count (1+ count)))))
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
941 count))
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
942
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
943 (defun erc-track-sort-by-importance ()
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
944 "Sort erc-modified-channels-alist by importance.
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
945 That means the position of the face in `erc-track-faces-priority-list'."
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
946 (setq erc-modified-channels-alist
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
947 (sort erc-modified-channels-alist
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
948 (lambda (a b) (< (erc-track-face-priority (cddr a))
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
949 (erc-track-face-priority (cddr b)))))))
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
950
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
951 (defun erc-track-get-active-buffer (arg)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
952 "Return the buffer name of ARG in `erc-modified-channels-alist'.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
953 Negative arguments index in the opposite direction. This direction is
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
954 relative to `erc-track-switch-direction'"
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
955 (let ((dir erc-track-switch-direction)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
956 offset)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
957 (when (< arg 0)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
958 (setq dir (case dir
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
959 (oldest 'newest)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
960 (newest 'oldest)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
961 (mostactive 'leastactive)
84387
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
962 (leastactive 'mostactive)
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78219
diff changeset
963 (importance 'oldest)))
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
964 (setq arg (- arg)))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
965 (setq offset (case dir
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
966 ((oldest leastactive)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
967 (- (length erc-modified-channels-alist) arg))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
968 (t (1- arg))))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
969 ;; normalise out of range user input
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
970 (cond ((>= offset (length erc-modified-channels-alist))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
971 (setq offset (1- (length erc-modified-channels-alist))))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
972 ((< offset 0)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
973 (setq offset 0)))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
974 (car (nth offset erc-modified-channels-alist))))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
975
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
976 (defun erc-track-switch-buffer (arg)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
977 "Switch to the next active ERC buffer, or if there are no active buffers,
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
978 switch back to the last non-ERC buffer visited. Next is defined by
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
979 `erc-track-switch-direction', a negative argument will reverse this."
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
980 (interactive "p")
76856
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
981 (if (not erc-track-mode)
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
982 (message (concat "Enable the ERC track module if you want to use the"
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
983 " tracking minor mode"))
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
984 (cond (erc-modified-channels-alist
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
985 ;; if we're not in erc-mode, set this buffer to return to
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
986 (unless (eq major-mode 'erc-mode)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
987 (setq erc-track-last-non-erc-buffer (current-buffer)))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
988 ;; and jump to the next active channel
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
989 (switch-to-buffer (erc-track-get-active-buffer arg)))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
990 ;; if no active channels, switch back to what we were doing before
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
991 ((and erc-track-last-non-erc-buffer
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
992 erc-track-switch-from-erc
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
993 (buffer-live-p erc-track-last-non-erc-buffer))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
994 (switch-to-buffer erc-track-last-non-erc-buffer)))))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
995
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
996 (provide 'erc-track)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
997
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
998 ;;; erc-track.el ends here
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
999 ;;
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
1000 ;; Local Variables:
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
1001 ;; indent-tabs-mode: t
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
1002 ;; tab-width: 8
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
1003 ;; End:
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
1004
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
1005 ;; arch-tag: 11b439f5-e5d7-4c6c-bb3f-eda98f9b0ac1