1 ;;; erc-ibuffer.el --- ibuffer integration with ERC
3 ;; Copyright (C) 2002, 2004, 2006-2016 Free Software Foundation, Inc.
5 ;; Author: Mario Lang <mlang@delysid.org>
6 ;; Maintainer: emacs-devel@gnu.org
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/>.
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
37 (defgroup erc-ibuffer nil
38 "The Ibuffer group for ERC."
41 (defcustom erc-ibuffer-keyword-char ?k
42 "Char used to indicate a channel which had keyword traffic lately (hidden)."
45 (defcustom erc-ibuffer-pal-char ?p
46 "Char used to indicate a channel which had pal traffic lately (hidden)."
49 (defcustom erc-ibuffer-fool-char ?f
50 "Char used to indicate a channel which had fool traffic lately (hidden)."
53 (defcustom erc-ibuffer-dangerous-host-char ?d
54 "Char used to indicate a channel which had dangerous-host traffic lately
59 (define-ibuffer-filter erc-server
60 "Toggle current view to buffers which are related to ERC servers."
61 (:description
"erc servers"
64 (read-from-minibuffer "Limit by server (regexp) (RET for all): ")))
65 (if (string= 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
)
79 (let ((entry (assq (current-buffer) erc-modified-channels-alist
)))
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
))
91 (string ibuffer-modified-char
))
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
))
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)))
114 (define-ibuffer-column erc-topic
(:name
"Topic")
115 (if (and (eq major-mode
'erc-mode
)
117 (erc-controls-interpret erc-channel-topic
)
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
))
129 (define-ibuffer-column erc-away
(:name
"A")
130 (if (and erc-server-process
131 (processp erc-server-process
)
136 (define-ibuffer-column
138 (if (and (eq major-mode
'erc-mode
)
139 (erc-channel-user-op-p (erc-current-nick)))
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)))
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
)
159 (if (not (derived-mode-p 'erc-mode
))
160 (format-mode-line mode-name nil nil
(current-buffer))
163 (define-ibuffer-column erc-nick
(:name
"Nick")
164 (if (eq major-mode
'erc-mode
)
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) " "
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
) " "
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
189 ;; indent-tabs-mode: t