1 ;;; erc-imenu.el -- Imenu support for ERC
3 ;; Copyright (C) 2001-2002, 2004, 2006-2011 Free Software Foundation, Inc.
5 ;; Author: Mario Lang <mlang@delysid.org>
7 ;; URL: http://www.emacswiki.org/cgi-bin/wiki.pl?ErcImenu
9 ;; This file is part of GNU Emacs.
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 of the License, or
14 ;; (at your option) any later version.
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.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 ;; This file contains code related to Ibuffer and ERC. Totally alpha,
27 ;; needs work. Usage: Type / C-e C-h when in Ibuffer-mode to see new
34 ;; This package defines the function `erc-create-imenu-index'. ERC
35 ;; uses this for `imenu-create-index-function', and autoloads it.
36 ;; Therefore, nothing needs to be done to use this package.
43 (defun erc-unfill-notice ()
44 "Return text from point to a computed end as a string unfilled.
45 Don't rely on this function, read it first!"
46 (let ((str (buffer-substring
48 (re-search-forward (regexp-quote erc-notice-prefix
)))
50 (while (save-excursion
54 (end-of-line) (point)))))
57 (goto-char (point-min))
58 (while (re-search-forward "\n +" nil t
)
60 (buffer-substring (point-min) (point-max)))))
63 (defun erc-create-imenu-index ()
64 (let ((index-alist '())
70 (mode-change-alist '())
71 (topic-change-alist '())
73 (goto-char (point-max))
74 (imenu-progress-message prev-pos
0)
78 (progn (forward-line 0)
80 (imenu-progress-message prev-pos nil t
)
82 (when (looking-at (concat (regexp-quote erc-notice-prefix
)
84 (let ((notice-text ;; Ugly hack, but seems to work.
85 (save-excursion (erc-unfill-notice)))
87 (push (cons notice-text pos
) notice-alist
)
89 (when (string-match "^\\(.*\\) has joined channel" notice-text
)
90 (push (cons (match-string 1 notice-text
) pos
) join-alist
))
91 (when (string-match "^\\(.+\\) has left channel" notice-text
)
92 (push (cons (match-string 1 notice-text
) pos
) left-alist
))
93 (when (string-match "^\\(.+\\) has quit\\(.*\\)$" notice-text
)
94 (push (cons (concat (match-string 1 notice-text
)
95 (match-string 2 notice-text
))
99 "^\\(\\S-+\\) (.+) has changed mode for \\S-+ to \\(.*\\)$"
101 (push (cons (concat (match-string 1 notice-text
) ": "
102 (match-string 2 notice-text
))
106 "^\\(\\S-+\\) (.+) has set the topic for \\S-+: \\(.*\\)$"
108 (push (cons (concat (match-string 1 notice-text
) ": "
109 (match-string 2 notice-text
)) pos
)
110 topic-change-alist
)))))
111 (when (looking-at "<\\(\\S-+\\)> \\(.+\\)$")
112 (let ((from (match-string 1))
113 (message-text (match-string 2)))
114 (push (cons (concat from
": " message-text
) (point))
116 (and notice-alist
(push (cons "notices" notice-alist
) index-alist
))
117 (and join-alist
(push (cons "joined" join-alist
) index-alist
))
118 (and left-alist
(push (cons "parted" left-alist
) index-alist
))
119 (and quit-alist
(push (cons "quit" quit-alist
) index-alist
))
120 (and mode-change-alist
(push (cons "mode-change" mode-change-alist
)
122 (and message-alist
(push (cons "messages" message-alist
) index-alist
))
123 (and topic-change-alist
(push (cons "topic-change" topic-change-alist
)
129 ;;; erc-imenu.el ends here
132 ;; indent-tabs-mode: t