Avoid 64-bit compilation warnings in unexw32.c
[emacs.git] / lisp / erc / erc-imenu.el
blob9440cb10e74393e387bc32fd485aa5beee2fda0c
1 ;;; erc-imenu.el -- Imenu support for ERC
3 ;; Copyright (C) 2001-2002, 2004, 2006-2017 Free Software Foundation,
4 ;; Inc.
6 ;; Author: Mario Lang <mlang@delysid.org>
7 ;; Maintainer: emacs-devel@gnu.org
8 ;; Keywords: comm
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 <https://www.gnu.org/licenses/>.
26 ;;; Commentary:
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
32 ;;; Code:
34 ;;; Commentary:
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.
40 ;;; Code:
42 (require 'erc)
43 (require 'imenu)
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)))))
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))
129 (provide 'erc-imenu)
131 ;;; erc-imenu.el ends here
133 ;; Local Variables:
134 ;; indent-tabs-mode: t
135 ;; tab-width: 8
136 ;; End: