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