erc-ibuffer.el 5.9 KB

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