Set maintainer of most lisp/erc/*.el files to FSF
[bpt/emacs.git] / lisp / erc / erc-imenu.el
CommitLineData
597993cf
MB
1;;; erc-imenu.el -- Imenu support for ERC
2
acaf905b 3;; Copyright (C) 2001-2002, 2004, 2006-2012 Free Software Foundation, Inc.
597993cf
MB
4
5;; Author: Mario Lang <mlang@delysid.org>
df5d5f59 6;; Maintainer: FSF
597993cf
MB
7;; Keywords: comm
8;; URL: http://www.emacswiki.org/cgi-bin/wiki.pl?ErcImenu
9
10;; This file is part of GNU Emacs.
11
4ee57b2a 12;; GNU Emacs is free software: you can redistribute it and/or modify
597993cf 13;; it under the terms of the GNU General Public License as published by
4ee57b2a
GM
14;; the Free Software Foundation, either version 3 of the License, or
15;; (at your option) any later version.
597993cf
MB
16
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.
21
22;; You should have received a copy of the GNU General Public License
4ee57b2a 23;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
597993cf
MB
24
25;;; Commentary:
26
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
29;; limiting commands
30
31;;; Code:
32
597993cf
MB
33;;; Commentary:
34
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.
38
39;;; Code:
40
41(require 'erc)
42(require 'imenu)
43
44(defun erc-unfill-notice ()
45 "Return text from point to a computed end as a string unfilled.
46Don't rely on this function, read it first!"
47 (let ((str (buffer-substring
48 (save-excursion
49 (re-search-forward (regexp-quote erc-notice-prefix)))
50 (progn
51 (while (save-excursion
52 (forward-line 1)
53 (looking-at " "))
54 (forward-line 1))
55 (end-of-line) (point)))))
56 (with-temp-buffer
57 (insert str)
58 (goto-char (point-min))
59 (while (re-search-forward "\n +" nil t)
60 (replace-match " "))
61 (buffer-substring (point-min) (point-max)))))
62
63;;;###autoload
64(defun erc-create-imenu-index ()
65 (let ((index-alist '())
66 (notice-alist '())
67 (join-alist '())
68 (left-alist '())
69 (quit-alist '())
70 (message-alist '())
71 (mode-change-alist '())
72 (topic-change-alist '())
73 prev-pos)
74 (goto-char (point-max))
75 (imenu-progress-message prev-pos 0)
76 (while (if (bolp)
77 (> (forward-line -1)
78 -1)
79 (progn (forward-line 0)
80 t))
81 (imenu-progress-message prev-pos nil t)
82 (save-match-data
83 (when (looking-at (concat (regexp-quote erc-notice-prefix)
84 "\\(.+\\)$"))
85 (let ((notice-text ;; Ugly hack, but seems to work.
86 (save-excursion (erc-unfill-notice)))
87 (pos (point)))
88 (push (cons notice-text pos) notice-alist)
89 (or
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))
97 (point))
98 quit-alist))
99 (when (string-match
100 "^\\(\\S-+\\) (.+) has changed mode for \\S-+ to \\(.*\\)$"
101 notice-text)
102 (push (cons (concat (match-string 1 notice-text) ": "
103 (match-string 2 notice-text))
104 (point))
105 mode-change-alist))
106 (when (string-match
107 "^\\(\\S-+\\) (.+) has set the topic for \\S-+: \\(.*\\)$"
108 notice-text)
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))
116 message-alist)))))
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)
122 index-alist))
123 (and message-alist (push (cons "messages" message-alist) index-alist))
124 (and topic-change-alist (push (cons "topic-change" topic-change-alist)
125 index-alist))
126 index-alist))
127
128(provide 'erc-imenu)
129
130;;; erc-imenu.el ends here
131;;
132;; Local Variables:
133;; indent-tabs-mode: t
134;; tab-width: 8
135;; End:
136