root/trunk/lisp/erc/erc-imenu.el

Revision 4220, 4.5 kB (checked in by miyoshi, 9 months ago)

Sync up with Emacs22.2.

Line 
1 ;;; erc-imenu.el -- Imenu support for ERC
2
3 ;; Copyright (C) 2001, 2002, 2004, 2006, 2007, 2008 Free Software Foundation, Inc.
4
5 ;; Author: Mario Lang <mlang@delysid.org>
6 ;; Keywords: comm
7 ;; URL: http://www.emacswiki.org/cgi-bin/wiki.pl?ErcImenu
8
9 ;; This file is part of GNU Emacs.
10
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, or (at your option)
14 ;; any later version.
15
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.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
25
26 ;;; Commentary:
27
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
30 ;; limiting commands
31
32 ;;; Code:
33
34 ;;; Commentary:
35
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.
39
40 ;;; Code:
41
42 (require 'erc)
43 (require 'imenu)
44
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
49               (save-excursion
50                 (re-search-forward (regexp-quote erc-notice-prefix)))
51               (progn
52                 (while (save-excursion
53                          (forward-line 1)
54                          (looking-at "    "))
55                   (forward-line 1))
56                 (end-of-line) (point)))))
57     (with-temp-buffer
58       (insert str)
59       (goto-char (point-min))
60       (while (re-search-forward "\n +" nil t)
61         (replace-match " "))
62       (buffer-substring (point-min) (point-max)))))
63
64 ;;;###autoload
65 (defun erc-create-imenu-index ()
66   (let ((index-alist '())
67         (notice-alist '())
68         (join-alist '())
69         (left-alist '())
70         (quit-alist '())
71         (message-alist '())
72         (mode-change-alist '())
73         (topic-change-alist '())
74         prev-pos)
75     (goto-char (point-max))
76     (imenu-progress-message prev-pos 0)
77     (while (if (bolp)
78                (> (forward-line -1)
79                   -1)
80              (progn (forward-line 0)
81                     t))
82       (imenu-progress-message prev-pos nil t)
83       (save-match-data
84         (when (looking-at (concat (regexp-quote erc-notice-prefix)
85                                   "\\(.+\\)$"))
86           (let ((notice-text  ;; Ugly hack, but seems to work.
87                  (save-excursion (erc-unfill-notice)))
88                 (pos (point)))
89             (push (cons notice-text pos) notice-alist)
90             (or
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))
98                            (point))
99                      quit-alist))
100              (when (string-match
101                     "^\\(\\S-+\\) (.+) has changed mode for \\S-+ to \\(.*\\)$"
102                     notice-text)
103                (push (cons (concat (match-string 1 notice-text) ": "
104                                    (match-string 2 notice-text))
105                            (point))
106                      mode-change-alist))
107              (when (string-match
108                     "^\\(\\S-+\\) (.+) has set the topic for \\S-+: \\(.*\\)$"
109                     notice-text)
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))
117                   message-alist)))))
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)
123                                  index-alist))
124     (and message-alist (push (cons "messages" message-alist) index-alist))
125     (and topic-change-alist (push (cons "topic-change" topic-change-alist)
126                                   index-alist))
127     index-alist))
128
129 (provide 'erc-imenu)
130
131 ;;; erc-imenu.el ends here
132 ;;
133 ;; Local Variables:
134 ;; indent-tabs-mode: t
135 ;; tab-width: 8
136 ;; End:
137
138 ;; arch-tag: 35c69082-ca29-43f7-a050-8da5f400de81
139
Note: See TracBrowser for help on using the browser.