root/trunk/lisp/erc/erc-ibuffer.el

Revision 4220, 5.9 kB (checked in by miyoshi, 9 months ago)

Sync up with Emacs22.2.

Line 
1 ;;; erc-ibuffer.el --- ibuffer integration with ERC
2
3 ;; Copyright (C) 2002, 2004, 2006, 2007, 2008 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, or (at your option)
14 ;; 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; see the file COPYING.  If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
25
26 ;;; Commentary:
27
28 ;; This file contains code related to Ibuffer and ERC.  Totally alpha,
29 ;; needs work.  Usage:  Type / C-e C-h when in Ibuffer-mode to see new
30 ;; limiting commands
31
32 ;;; Code:
33
34 (require 'ibuffer)
35 (require 'ibuf-ext)
36 (require 'erc)
37
38 (defgroup erc-ibuffer nil
39   "The Ibuffer group for ERC."
40   :group 'erc)
41
42 (defcustom erc-ibuffer-keyword-char ?k
43   "Char used to indicate a channel which had keyword traffic lately (hidden)."
44   :group 'erc-ibuffer
45   :type 'character)
46 (defcustom erc-ibuffer-pal-char ?p
47   "Char used to indicate a channel which had pal traffic lately (hidden)."
48   :group 'erc-ibuffer
49   :type 'character)
50 (defcustom erc-ibuffer-fool-char ?f
51   "Char used to indicate a channel which had fool traffic lately (hidden)."
52   :group 'erc-ibuffer
53   :type 'character)
54 (defcustom erc-ibuffer-dangerous-host-char ?d
55   "Char used to indicate a channel which had dangerous-host traffic lately
56 \(hidden)."
57   :group 'erc-ibuffer
58   :type 'character)
59
60 (define-ibuffer-filter erc-server
61   "Toggle current view to buffers which are related to ERC servers."
62   (:description "erc servers"
63    :reader
64    (let ((regexp
65           (read-from-minibuffer "Limit by server (regexp) (RET for all): ")))
66      (if (string= regexp "")
67          ".*"
68        regexp)))
69   (with-current-buffer buf
70     (and (eq major-mode 'erc-mode)
71          (string-match qualifier (or erc-server-announced-name
72                                      erc-session-server)))))
73
74 (define-ibuffer-column erc-modified (:name "M")
75   (if (and (boundp 'erc-track-mode)
76            erc-track-mode)
77       (let ((entry (assq (current-buffer) erc-modified-channels-alist)))
78         (if entry
79             (if (> (length entry) 1)
80                 (cond ((eq 'pal (nth 1 entry))
81                        (string erc-ibuffer-pal-char))
82                       ((eq 'fool (nth 1 entry))
83                        (string erc-ibuffer-fool-char))
84                       ((eq 'keyword (nth 1 entry))
85                        (string erc-ibuffer-keyword-char))
86                       ((eq 'dangerous-host (nth 1 entry))
87                        (string erc-ibuffer-dangerous-host-char))
88                       (t "$"))
89               (string ibuffer-modified-char))
90           " "))
91     " "))
92
93 (define-ibuffer-column erc-server-name (:name "Server")
94   (if (and erc-server-process (processp erc-server-process))
95       (with-current-buffer (process-buffer erc-server-process)
96         (or erc-server-announced-name erc-session-server))
97     ""))
98
99 (define-ibuffer-column erc-target (:name "Target")
100   (if (eq major-mode 'erc-mode)
101       (cond ((and erc-server-process (processp erc-server-process)
102                   (eq (current-buffer) (process-buffer erc-server-process)))
103              (concat "Server " erc-session-server ":"
104                      (erc-port-to-string erc-session-port)))
105             ((erc-channel-p (erc-default-target))
106              (concat (erc-default-target)))
107             ((erc-default-target)
108              (concat "Query: " (erc-default-target)))
109             (t "(parted)"))
110     (buffer-name)))
111
112 (define-ibuffer-column erc-topic (:name "Topic")
113   (if (and (eq major-mode 'erc-mode)
114            erc-channel-topic)
115       (erc-controls-interpret erc-channel-topic)
116     ""))
117
118 (define-ibuffer-column
119  erc-members (:name "Users")
120   (if (and (eq major-mode 'erc-mode)
121            (boundp 'erc-channel-users)
122            (hash-table-p erc-channel-users)
123            (> (hash-table-size erc-channel-users) 0))
124      (number-to-string (hash-table-size erc-channel-users))
125     ""))
126
127 (define-ibuffer-column erc-away (:name "A")
128   (if (and erc-server-process
129            (processp erc-server-process)
130            (erc-away-time))
131       "A"
132     " "))
133
134 (define-ibuffer-column
135  erc-op (:name "O")
136   (if (and (eq major-mode 'erc-mode)
137            (erc-channel-user-op-p (erc-current-nick)))
138       "@"
139     " "))
140
141 (define-ibuffer-column erc-voice (:name "V")
142   (if (and (eq major-mode 'erc-mode)
143            (erc-channel-user-voice-p (erc-current-nick)))
144       "+"
145     " "))
146
147 (define-ibuffer-column erc-channel-modes (:name "Mode")
148   (if (and (eq major-mode 'erc-mode)
149            (or (> (length erc-channel-modes) 0)
150                erc-channel-user-limit))
151       (concat (apply 'concat
152                      "(+" erc-channel-modes)
153               (if erc-channel-user-limit
154                   (format "l %d" erc-channel-user-limit)
155                 "")
156               ")")
157     (if (not (eq major-mode 'erc-mode))
158         mode-name
159       "")))
160
161 (define-ibuffer-column erc-nick (:name "Nick")
162   (if (eq major-mode 'erc-mode)
163       (erc-current-nick)
164     ""))
165
166 (defvar erc-ibuffer-formats
167   '((mark erc-modified erc-away erc-op erc-voice " " (erc-nick 8 8) " "
168           (erc-target 18 40) (erc-members 5 5 :center)
169           (erc-channel-modes 6 16 :center) " " (erc-server-name 20 30) " "
170           (erc-topic 10 -1))
171     (mark erc-modified erc-away erc-op erc-voice " " (erc-target 18 40)
172           (erc-members 5 5 :center) (erc-channel-modes 9 20 :center) " "
173           (erc-topic 10 -1))))
174 (setq ibuffer-formats (append ibuffer-formats erc-ibuffer-formats))
175
176 (defvar erc-ibuffer-limit-map nil
177   "Prefix keymap to use for ERC related limiting.")
178 (define-prefix-command 'erc-ibuffer-limit-map)
179 (define-key 'erc-ibuffer-limit-map (kbd "s") 'ibuffer-limit-by-erc-server)
180 (define-key ibuffer-mode-map (kbd "/ \C-e") 'erc-ibuffer-limit-map)
181
182 (provide 'erc-ibuffer)
183
184 ;;; erc-ibuffer.el ends here
185 ;;
186 ;; Local Variables:
187 ;; indent-tabs-mode: t
188 ;; tab-width: 8
189 ;; End:
190
191 ;; arch-tag: fbad56a5-8595-45e0-a8c8-d8bb91e26944
192
Note: See TracBrowser for help on using the browser.