erc-ibuffer.el 5.9 KB

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