1 ;;; erc-imenu.el -- Imenu support for ERC
3 ;; Copyright (C) 2001-2002, 2004, 2006-2012 Free Software Foundation, Inc.
5 ;; Author: Mario Lang <mlang@delysid.org>
8 ;; URL: http://www.emacswiki.org/cgi-bin/wiki.pl?ErcImenu
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
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.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
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
35 ;; This package defines the function `erc-create-imenu-index'. ERC
36 ;; uses this for `imenu-create-index-function', and autoloads it.
37 ;; Therefore, nothing needs to be done to use this package.
44 (defun erc-unfill-notice ()
45 "Return text from point to a computed end as a string unfilled.
46 Don't rely on this function, read it first!"
47 (let ((str (buffer-substring
49 (re-search-forward (regexp-quote erc-notice-prefix
)))
51 (while (save-excursion
55 (end-of-line) (point)))))
58 (goto-char (point-min))
59 (while (re-search-forward "\n +" nil t
)
61 (buffer-substring (point-min) (point-max)))))
64 (defun erc-create-imenu-index ()
65 (let ((index-alist '())
71 (mode-change-alist '())
72 (topic-change-alist '())
74 (goto-char (point-max))
75 (imenu-progress-message prev-pos
0)
79 (progn (forward-line 0)
81 (imenu-progress-message prev-pos nil t
)
83 (when (looking-at (concat (regexp-quote erc-notice-prefix
)
85 (let ((notice-text ;; Ugly hack, but seems to work.
86 (save-excursion (erc-unfill-notice)))
88 (push (cons notice-text pos
) notice-alist
)
90 (when (string-match "^\\(.*\\) has joined channel" notice-text
)
91 (push (cons (match-string 1 notice-text
) pos
) join-alist
))
92 (when (string-match "^\\(.+\\) has left channel" notice-text
)
93 (push (cons (match-string 1 notice-text
) pos
) left-alist
))
94 (when (string-match "^\\(.+\\) has quit\\(.*\\)$" notice-text
)
95 (push (cons (concat (match-string 1 notice-text
)
96 (match-string 2 notice-text
))
100 "^\\(\\S-+\\) (.+) has changed mode for \\S-+ to \\(.*\\)$"
102 (push (cons (concat (match-string 1 notice-text
) ": "
103 (match-string 2 notice-text
))
107 "^\\(\\S-+\\) (.+) has set the topic for \\S-+: \\(.*\\)$"
109 (push (cons (concat (match-string 1 notice-text
) ": "
110 (match-string 2 notice-text
)) pos
)
111 topic-change-alist
)))))
112 (when (looking-at "<\\(\\S-+\\)> \\(.+\\)$")
113 (let ((from (match-string 1))
114 (message-text (match-string 2)))
115 (push (cons (concat from
": " message-text
) (point))
117 (and notice-alist
(push (cons "notices" notice-alist
) index-alist
))
118 (and join-alist
(push (cons "joined" join-alist
) index-alist
))
119 (and left-alist
(push (cons "parted" left-alist
) index-alist
))
120 (and quit-alist
(push (cons "quit" quit-alist
) index-alist
))
121 (and mode-change-alist
(push (cons "mode-change" mode-change-alist
)
123 (and message-alist
(push (cons "messages" message-alist
) index-alist
))
124 (and topic-change-alist
(push (cons "topic-change" topic-change-alist
)
130 ;;; erc-imenu.el ends here
133 ;; indent-tabs-mode: t