1 ;;; erc-imenu.el -- Imenu support for ERC
3 ;; Copyright (C) 2001-2002, 2004, 2006-2014 Free Software Foundation,
6 ;; Author: Mario Lang <mlang@delysid.org>
7 ;; Maintainer: emacs-devel@gnu.org
9 ;; URL: http://www.emacswiki.org/cgi-bin/wiki.pl?ErcImenu
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
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
36 ;; This package defines the function `erc-create-imenu-index'. ERC
37 ;; uses this for `imenu-create-index-function', and autoloads it.
38 ;; Therefore, nothing needs to be done to use this package.
45 (defun erc-unfill-notice ()
46 "Return text from point to a computed end as a string unfilled.
47 Don't rely on this function, read it first!"
48 (let ((str (buffer-substring
50 (re-search-forward (regexp-quote erc-notice-prefix
)))
52 (while (save-excursion
56 (end-of-line) (point)))))
59 (goto-char (point-min))
60 (while (re-search-forward "\n +" nil t
)
62 (buffer-substring (point-min) (point-max)))))
65 (defun erc-create-imenu-index ()
66 (let ((index-alist '())
72 (mode-change-alist '())
73 (topic-change-alist '())
75 (goto-char (point-max))
76 (imenu-progress-message prev-pos
0)
80 (progn (forward-line 0)
82 (imenu-progress-message prev-pos nil t
)
84 (when (looking-at (concat (regexp-quote erc-notice-prefix
)
86 (let ((notice-text ;; Ugly hack, but seems to work.
87 (save-excursion (erc-unfill-notice)))
89 (push (cons notice-text pos
) notice-alist
)
91 (when (string-match "^\\(.*\\) has joined channel" notice-text
)
92 (push (cons (match-string 1 notice-text
) pos
) join-alist
))
93 (when (string-match "^\\(.+\\) has left channel" notice-text
)
94 (push (cons (match-string 1 notice-text
) pos
) left-alist
))
95 (when (string-match "^\\(.+\\) has quit\\(.*\\)$" notice-text
)
96 (push (cons (concat (match-string 1 notice-text
)
97 (match-string 2 notice-text
))
101 "^\\(\\S-+\\) (.+) has changed mode for \\S-+ to \\(.*\\)$"
103 (push (cons (concat (match-string 1 notice-text
) ": "
104 (match-string 2 notice-text
))
108 "^\\(\\S-+\\) (.+) has set the topic for \\S-+: \\(.*\\)$"
110 (push (cons (concat (match-string 1 notice-text
) ": "
111 (match-string 2 notice-text
)) pos
)
112 topic-change-alist
)))))
113 (when (looking-at "<\\(\\S-+\\)> \\(.+\\)$")
114 (let ((from (match-string 1))
115 (message-text (match-string 2)))
116 (push (cons (concat from
": " message-text
) (point))
118 (and notice-alist
(push (cons "notices" notice-alist
) index-alist
))
119 (and join-alist
(push (cons "joined" join-alist
) index-alist
))
120 (and left-alist
(push (cons "parted" left-alist
) index-alist
))
121 (and quit-alist
(push (cons "quit" quit-alist
) index-alist
))
122 (and mode-change-alist
(push (cons "mode-change" mode-change-alist
)
124 (and message-alist
(push (cons "messages" message-alist
) index-alist
))
125 (and topic-change-alist
(push (cons "topic-change" topic-change-alist
)
131 ;;; erc-imenu.el ends here
134 ;; indent-tabs-mode: t