Commit | Line | Data |
---|---|---|
597993cf MB |
1 | ;;; erc-ibuffer.el --- ibuffer integration with ERC |
2 | ||
114f9c96 | 3 | ;; Copyright (C) 2002, 2004, 2006, 2007, 2008, 2009, 2010 |
07da87e9 | 4 | ;; Free Software Foundation, Inc. |
597993cf MB |
5 | |
6 | ;; Author: Mario Lang <mlang@delysid.org> | |
7 | ;; Keywords: comm | |
8 | ;; URL: http://www.emacswiki.org/cgi-bin/wiki.pl?ErcIbuffer | |
9 | ||
10 | ;; This file is part of GNU Emacs. | |
11 | ||
4ee57b2a | 12 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
597993cf | 13 | ;; it under the terms of the GNU General Public License as published by |
4ee57b2a GM |
14 | ;; the Free Software Foundation, either version 3 of the License, or |
15 | ;; (at your option) any later version. | |
597993cf MB |
16 | |
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. | |
21 | ||
22 | ;; You should have received a copy of the GNU General Public License | |
4ee57b2a | 23 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
597993cf MB |
24 | |
25 | ;;; Commentary: | |
26 | ||
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 | |
30 | ||
31 | ;;; Code: | |
32 | ||
33 | (require 'ibuffer) | |
059e26cf | 34 | (require 'ibuf-ext) |
597993cf MB |
35 | (require 'erc) |
36 | ||
37 | (defgroup erc-ibuffer nil | |
38 | "The Ibuffer group for ERC." | |
39 | :group 'erc) | |
40 | ||
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 | |
059e26cf MB |
54 | "Char used to indicate a channel which had dangerous-host traffic lately |
55 | \(hidden)." | |
597993cf MB |
56 | :group 'erc-ibuffer |
57 | :type 'character) | |
58 | ||
059e26cf MB |
59 | (define-ibuffer-filter erc-server |
60 | "Toggle current view to buffers which are related to ERC servers." | |
61 | (:description "erc servers" | |
597993cf | 62 | :reader |
059e26cf MB |
63 | (let ((regexp |
64 | (read-from-minibuffer "Limit by server (regexp) (RET for all): "))) | |
597993cf MB |
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))))) | |
72 | ||
b6675b2d | 73 | ;; Silence the byte-compiler |
07da87e9 | 74 | (defvar erc-modified-channels-alist) |
0bde6a03 | 75 | |
059e26cf | 76 | (define-ibuffer-column erc-modified (:name "M") |
597993cf MB |
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 | " ")) | |
94 | ||
059e26cf | 95 | (define-ibuffer-column erc-server-name (:name "Server") |
83dc6995 | 96 | (if (and erc-server-process (processp erc-server-process)) |
597993cf MB |
97 | (with-current-buffer (process-buffer erc-server-process) |
98 | (or erc-server-announced-name erc-session-server)) | |
99 | "")) | |
100 | ||
059e26cf | 101 | (define-ibuffer-column erc-target (:name "Target") |
597993cf | 102 | (if (eq major-mode 'erc-mode) |
83dc6995 | 103 | (cond ((and erc-server-process (processp erc-server-process) |
597993cf MB |
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))) | |
113 | ||
059e26cf | 114 | (define-ibuffer-column erc-topic (:name "Topic") |
597993cf MB |
115 | (if (and (eq major-mode 'erc-mode) |
116 | erc-channel-topic) | |
117 | (erc-controls-interpret erc-channel-topic) | |
118 | "")) | |
119 | ||
059e26cf | 120 | (define-ibuffer-column |
597993cf MB |
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 | "")) | |
128 | ||
059e26cf | 129 | (define-ibuffer-column erc-away (:name "A") |
83dc6995 | 130 | (if (and erc-server-process |
597993cf | 131 | (processp erc-server-process) |
ff59d266 | 132 | (erc-away-time)) |
597993cf MB |
133 | "A" |
134 | " ")) | |
135 | ||
059e26cf | 136 | (define-ibuffer-column |
597993cf MB |
137 | erc-op (:name "O") |
138 | (if (and (eq major-mode 'erc-mode) | |
139 | (erc-channel-user-op-p (erc-current-nick))) | |
140 | "@" | |
141 | " ")) | |
142 | ||
059e26cf | 143 | (define-ibuffer-column erc-voice (:name "V") |
597993cf MB |
144 | (if (and (eq major-mode 'erc-mode) |
145 | (erc-channel-user-voice-p (erc-current-nick))) | |
146 | "+" | |
147 | " ")) | |
148 | ||
059e26cf | 149 | (define-ibuffer-column erc-channel-modes (:name "Mode") |
597993cf MB |
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) | |
157 | "") | |
158 | ")") | |
48d33090 SM |
159 | (if (not (derived-mode-p 'erc-mode)) |
160 | (format-mode-line mode-name nil nil (current-buffer)) | |
597993cf MB |
161 | ""))) |
162 | ||
059e26cf | 163 | (define-ibuffer-column erc-nick (:name "Nick") |
597993cf MB |
164 | (if (eq major-mode 'erc-mode) |
165 | (erc-current-nick) | |
166 | "")) | |
167 | ||
059e26cf MB |
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)))) | |
597993cf MB |
176 | (setq ibuffer-formats (append ibuffer-formats erc-ibuffer-formats)) |
177 | ||
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) | |
183 | ||
184 | (provide 'erc-ibuffer) | |
185 | ||
186 | ;;; erc-ibuffer.el ends here | |
187 | ;; | |
188 | ;; Local Variables: | |
189 | ;; indent-tabs-mode: t | |
190 | ;; tab-width: 8 | |
191 | ;; End: | |
192 | ||
193 | ;; arch-tag: fbad56a5-8595-45e0-a8c8-d8bb91e26944 |