Fix typos.
[emacs.git] / lisp / erc / erc-imenu.el
blob3e6e853ff7051580fdd38e0b7423b2cdecdf63df
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>
6 ;; Keywords: comm
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/>.
24 ;;; Commentary:
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
28 ;; limiting commands
30 ;;; Code:
32 ;;; Commentary:
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.
38 ;;; Code:
40 (require 'erc)
41 (require 'imenu)
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
47 (save-excursion
48 (re-search-forward (regexp-quote erc-notice-prefix)))
49 (progn
50 (while (save-excursion
51 (forward-line 1)
52 (looking-at " "))
53 (forward-line 1))
54 (end-of-line) (point)))))
55 (with-temp-buffer
56 (insert str)
57 (goto-char (point-min))
58 (while (re-search-forward "\n +" nil t)
59 (replace-match " "))
60 (buffer-substring (point-min) (point-max)))))
62 ;;;###autoload
63 (defun erc-create-imenu-index ()
64 (let ((index-alist '())
65 (notice-alist '())
66 (join-alist '())
67 (left-alist '())
68 (quit-alist '())
69 (message-alist '())
70 (mode-change-alist '())
71 (topic-change-alist '())
72 prev-pos)
73 (goto-char (point-max))
74 (imenu-progress-message prev-pos 0)
75 (while (if (bolp)
76 (> (forward-line -1)
77 -1)
78 (progn (forward-line 0)
79 t))
80 (imenu-progress-message prev-pos nil t)
81 (save-match-data
82 (when (looking-at (concat (regexp-quote erc-notice-prefix)
83 "\\(.+\\)$"))
84 (let ((notice-text ;; Ugly hack, but seems to work.
85 (save-excursion (erc-unfill-notice)))
86 (pos (point)))
87 (push (cons notice-text pos) notice-alist)
88 (or
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))
96 (point))
97 quit-alist))
98 (when (string-match
99 "^\\(\\S-+\\) (.+) has changed mode for \\S-+ to \\(.*\\)$"
100 notice-text)
101 (push (cons (concat (match-string 1 notice-text) ": "
102 (match-string 2 notice-text))
103 (point))
104 mode-change-alist))
105 (when (string-match
106 "^\\(\\S-+\\) (.+) has set the topic for \\S-+: \\(.*\\)$"
107 notice-text)
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))
115 message-alist)))))
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)
121 index-alist))
122 (and message-alist (push (cons "messages" message-alist) index-alist))
123 (and topic-change-alist (push (cons "topic-change" topic-change-alist)
124 index-alist))
125 index-alist))
127 (provide 'erc-imenu)
129 ;;; erc-imenu.el ends here
131 ;; Local Variables:
132 ;; indent-tabs-mode: t
133 ;; tab-width: 8
134 ;; End: