]> code.delx.au - gnu-emacs/blob - lisp/erc/erc-ibuffer.el
9d658eec2f003854154bc570eabb84456d824faa
[gnu-emacs] / lisp / erc / erc-ibuffer.el
1 ;;; erc-ibuffer.el --- ibuffer integration with ERC
2
3 ;; Copyright (C) 2002, 2004, 2006-2011 Free Software Foundation, Inc.
4
5 ;; Author: Mario Lang <mlang@delysid.org>
6 ;; Keywords: comm
7 ;; URL: http://www.emacswiki.org/cgi-bin/wiki.pl?ErcIbuffer
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23
24 ;;; Commentary:
25
26 ;; This file contains code related to Ibuffer and ERC. Totally alpha,
27 ;; needs work. Usage: Type / C-e C-h when in Ibuffer-mode to see new
28 ;; limiting commands
29
30 ;;; Code:
31
32 (require 'ibuffer)
33 (require 'ibuf-ext)
34 (require 'erc)
35
36 (defgroup erc-ibuffer nil
37 "The Ibuffer group for ERC."
38 :group 'erc)
39
40 (defcustom erc-ibuffer-keyword-char ?k
41 "Char used to indicate a channel which had keyword traffic lately (hidden)."
42 :group 'erc-ibuffer
43 :type 'character)
44 (defcustom erc-ibuffer-pal-char ?p
45 "Char used to indicate a channel which had pal traffic lately (hidden)."
46 :group 'erc-ibuffer
47 :type 'character)
48 (defcustom erc-ibuffer-fool-char ?f
49 "Char used to indicate a channel which had fool traffic lately (hidden)."
50 :group 'erc-ibuffer
51 :type 'character)
52 (defcustom erc-ibuffer-dangerous-host-char ?d
53 "Char used to indicate a channel which had dangerous-host traffic lately
54 \(hidden)."
55 :group 'erc-ibuffer
56 :type 'character)
57
58 (define-ibuffer-filter erc-server
59 "Toggle current view to buffers which are related to ERC servers."
60 (:description "erc servers"
61 :reader
62 (let ((regexp
63 (read-from-minibuffer "Limit by server (regexp) (RET for all): ")))
64 (if (string= regexp "")
65 ".*"
66 regexp)))
67 (with-current-buffer buf
68 (and (eq major-mode 'erc-mode)
69 (string-match qualifier (or erc-server-announced-name
70 erc-session-server)))))
71
72 ;; Silence the byte-compiler
73 (defvar erc-modified-channels-alist)
74
75 (define-ibuffer-column erc-modified (:name "M")
76 (if (and (boundp 'erc-track-mode)
77 erc-track-mode)
78 (let ((entry (assq (current-buffer) erc-modified-channels-alist)))
79 (if entry
80 (if (> (length entry) 1)
81 (cond ((eq 'pal (nth 1 entry))
82 (string erc-ibuffer-pal-char))
83 ((eq 'fool (nth 1 entry))
84 (string erc-ibuffer-fool-char))
85 ((eq 'keyword (nth 1 entry))
86 (string erc-ibuffer-keyword-char))
87 ((eq 'dangerous-host (nth 1 entry))
88 (string erc-ibuffer-dangerous-host-char))
89 (t "$"))
90 (string ibuffer-modified-char))
91 " "))
92 " "))
93
94 (define-ibuffer-column erc-server-name (:name "Server")
95 (if (and erc-server-process (processp erc-server-process))
96 (with-current-buffer (process-buffer erc-server-process)
97 (or erc-server-announced-name erc-session-server))
98 ""))
99
100 (define-ibuffer-column erc-target (:name "Target")
101 (if (eq major-mode 'erc-mode)
102 (cond ((and erc-server-process (processp erc-server-process)
103 (eq (current-buffer) (process-buffer erc-server-process)))
104 (concat "Server " erc-session-server ":"
105 (erc-port-to-string erc-session-port)))
106 ((erc-channel-p (erc-default-target))
107 (concat (erc-default-target)))
108 ((erc-default-target)
109 (concat "Query: " (erc-default-target)))
110 (t "(parted)"))
111 (buffer-name)))
112
113 (define-ibuffer-column erc-topic (:name "Topic")
114 (if (and (eq major-mode 'erc-mode)
115 erc-channel-topic)
116 (erc-controls-interpret erc-channel-topic)
117 ""))
118
119 (define-ibuffer-column
120 erc-members (:name "Users")
121 (if (and (eq major-mode 'erc-mode)
122 (boundp 'erc-channel-users)
123 (hash-table-p erc-channel-users)
124 (> (hash-table-size erc-channel-users) 0))
125 (number-to-string (hash-table-size erc-channel-users))
126 ""))
127
128 (define-ibuffer-column erc-away (:name "A")
129 (if (and erc-server-process
130 (processp erc-server-process)
131 (erc-away-time))
132 "A"
133 " "))
134
135 (define-ibuffer-column
136 erc-op (:name "O")
137 (if (and (eq major-mode 'erc-mode)
138 (erc-channel-user-op-p (erc-current-nick)))
139 "@"
140 " "))
141
142 (define-ibuffer-column erc-voice (:name "V")
143 (if (and (eq major-mode 'erc-mode)
144 (erc-channel-user-voice-p (erc-current-nick)))
145 "+"
146 " "))
147
148 (define-ibuffer-column erc-channel-modes (:name "Mode")
149 (if (and (eq major-mode 'erc-mode)
150 (or (> (length erc-channel-modes) 0)
151 erc-channel-user-limit))
152 (concat (apply 'concat
153 "(+" erc-channel-modes)
154 (if erc-channel-user-limit
155 (format "l %d" erc-channel-user-limit)
156 "")
157 ")")
158 (if (not (derived-mode-p 'erc-mode))
159 (format-mode-line mode-name nil nil (current-buffer))
160 "")))
161
162 (define-ibuffer-column erc-nick (:name "Nick")
163 (if (eq major-mode 'erc-mode)
164 (erc-current-nick)
165 ""))
166
167 (defvar erc-ibuffer-formats
168 '((mark erc-modified erc-away erc-op erc-voice " " (erc-nick 8 8) " "
169 (erc-target 18 40) (erc-members 5 5 :center)
170 (erc-channel-modes 6 16 :center) " " (erc-server-name 20 30) " "
171 (erc-topic 10 -1))
172 (mark erc-modified erc-away erc-op erc-voice " " (erc-target 18 40)
173 (erc-members 5 5 :center) (erc-channel-modes 9 20 :center) " "
174 (erc-topic 10 -1))))
175 (setq ibuffer-formats (append ibuffer-formats erc-ibuffer-formats))
176
177 (defvar erc-ibuffer-limit-map nil
178 "Prefix keymap to use for ERC related limiting.")
179 (define-prefix-command 'erc-ibuffer-limit-map)
180 (define-key 'erc-ibuffer-limit-map (kbd "s") 'ibuffer-limit-by-erc-server)
181 (define-key ibuffer-mode-map (kbd "/ \C-e") 'erc-ibuffer-limit-map)
182
183 (provide 'erc-ibuffer)
184
185 ;;; erc-ibuffer.el ends here
186 ;;
187 ;; Local Variables:
188 ;; indent-tabs-mode: t
189 ;; tab-width: 8
190 ;; End:
191