[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 2d876a4ca94 15/37: Convert ERC's Imenu integration into proper mo
From: |
F. Jason Park |
Subject: |
master 2d876a4ca94 15/37: Convert ERC's Imenu integration into proper module |
Date: |
Sat, 8 Apr 2023 17:31:29 -0400 (EDT) |
branch: master
commit 2d876a4ca94d7c74339eb18ca98528d017cab2a8
Author: F. Jason Park <jp@neverwas.me>
Commit: F. Jason Park <jp@neverwas.me>
Convert ERC's Imenu integration into proper module
* lisp/erc/erc-goodies.el: Don't add Imenu hooks to `erc-mode-hook' at
top level. Remove autoload for `erc-create-imenu-index' because it
already exists in the `erc-imenu' library.
(erc-imenu-setup): Move to the erc-imenu library.
* lisp/erc/erc-imenu.el (erc-unfill-notice): Allow modifications to
read-only text. Thanks to Yusef Aslam for reporting this bug.
(erc-imenu-setup): Move here from goodies.
(erc-imenu--create-index-function): New helper var to hold previous
local value of `imenu-create-index-function'. Perhaps advice should
be used instead, but a cursory search of the Emacs code base reveals
no such usage.
(erc-imenu-mode, erc-imenu-enable, erc-imenu-disable): Create "new"
ERC module for Imenu integration.
* lisp/erc/erc.el (erc-modules): Add `imenu' to default value and
create widget menu item. Update package-version.
* test/lisp/erc/erc-tests.el (erc-tests--modules): Add
`imenu'. (Bug#60954)
---
lisp/erc/erc-goodies.el | 6 ------
lisp/erc/erc-imenu.el | 23 ++++++++++++++++++++++-
lisp/erc/erc.el | 4 +++-
test/lisp/erc/erc-tests.el | 2 +-
4 files changed, 26 insertions(+), 9 deletions(-)
diff --git a/lisp/erc/erc-goodies.el b/lisp/erc/erc-goodies.el
index 5ddacb643fd..7ea6c42ec65 100644
--- a/lisp/erc/erc-goodies.el
+++ b/lisp/erc/erc-goodies.el
@@ -32,12 +32,6 @@
(eval-when-compile (require 'cl-lib))
(require 'erc)
-(defun erc-imenu-setup ()
- "Setup Imenu support in an ERC buffer."
- (setq-local imenu-create-index-function #'erc-create-imenu-index))
-
-(add-hook 'erc-mode-hook #'erc-imenu-setup)
-(autoload 'erc-create-imenu-index "erc-imenu" "Imenu index creation function")
;;; Automatically scroll to bottom
(defcustom erc-input-line-position nil
diff --git a/lisp/erc/erc-imenu.el b/lisp/erc/erc-imenu.el
index 6223cd3d06f..526afd32249 100644
--- a/lisp/erc/erc-imenu.el
+++ b/lisp/erc/erc-imenu.el
@@ -52,7 +52,8 @@ Don't rely on this function, read it first!"
(forward-line 1)
(looking-at " "))
(forward-line 1))
- (end-of-line) (point)))))
+ (end-of-line) (point))))
+ (inhibit-read-only t))
(with-temp-buffer
(insert str)
(goto-char (point-min))
@@ -124,6 +125,26 @@ Don't rely on this function, read it first!"
index-alist))
index-alist))
+(defvar-local erc-imenu--create-index-function nil
+ "Previous local value of `imenu-create-index-function', if any.")
+
+(defun erc-imenu-setup ()
+ "Wire up support for Imenu in an ERC buffer."
+ (when (and (local-variable-p 'imenu-create-index-function)
+ imenu-create-index-function)
+ (setq erc-imenu--create-index-function imenu-create-index-function))
+ (setq imenu-create-index-function #'erc-create-imenu-index))
+
+;;;###autoload(autoload 'erc-imenu-mode "erc-imenu" nil t)
+(define-erc-module imenu nil
+ "Simple Imenu integration for ERC."
+ ((add-hook 'erc-mode-hook #'erc-imenu-setup))
+ ((remove-hook 'erc-mode-hook #'erc-imenu-setup)
+ (erc-with-all-buffers-of-server erc-server-process nil
+ (when erc-imenu--create-index-function
+ (setq imenu-create-index-function erc-imenu--create-index-function)
+ (kill-local-variable 'erc-imenu--create-index-function)))))
+
(provide 'erc-imenu)
;;; erc-imenu.el ends here
diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el
index 60fe0480412..cc5cac87da8 100644
--- a/lisp/erc/erc.el
+++ b/lisp/erc/erc.el
@@ -1852,7 +1852,7 @@ buffer rather than a server buffer.")
;; each item is in the format '(old . new)
(delete-dups (mapcar #'erc--normalize-module-symbol mods)))
-(defcustom erc-modules '( autojoin button completion fill irccontrols
+(defcustom erc-modules '( autojoin button completion fill imenu irccontrols
list match menu move-to-prompt netsplit
networks noncommands readonly ring stamp track)
"A list of modules which ERC should enable.
@@ -1912,6 +1912,7 @@ removed from the list will be disabled."
(const :tag "dcc: Provide Direct Client-to-Client support" dcc)
(const :tag "fill: Wrap long lines" fill)
(const :tag "identd: Launch an identd server on port 8113" identd)
+ (const :tag "imenu: A simple Imenu integration" imenu)
(const :tag "irccontrols: Highlight or remove IRC control characters"
irccontrols)
(const :tag "keep-place: Leave point above un-viewed text" keep-place)
@@ -1949,6 +1950,7 @@ removed from the list will be disabled."
(const :tag "unmorse: Translate morse code in messages" unmorse)
(const :tag "xdcc: Act as an XDCC file-server" xdcc)
(repeat :tag "Others" :inline t symbol))
+ :package-version '(ERC . "5.6") ; FIXME sync on release
:group 'erc)
(defun erc-update-modules ()
diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el
index 0c7b06da436..acd470a1e17 100644
--- a/test/lisp/erc/erc-tests.el
+++ b/test/lisp/erc/erc-tests.el
@@ -1270,7 +1270,7 @@
(defconst erc-tests--modules
'( autoaway autojoin button capab-identify completion dcc fill identd
- irccontrols keep-place list log match menu move-to-prompt netsplit
+ imenu irccontrols keep-place list log match menu move-to-prompt netsplit
networks noncommands notifications notify page readonly
replace ring sasl scrolltobottom services smiley sound
spelling stamp track truncate unmorse xdcc))
- master 0f7fc5cfdf9 20/37: Be smarter about switching to TLS from M-x erc, (continued)
- master 0f7fc5cfdf9 20/37: Be smarter about switching to TLS from M-x erc, F. Jason Park, 2023/04/08
- master ad3dc74e074 27/37: Expose insertion time as text prop in erc-stamp, F. Jason Park, 2023/04/08
- master ba7fe88b782 22/37: Optionally prompt for more ERC entry-point params, F. Jason Park, 2023/04/08
- master 39d4f32fc9b 18/37: Fill doc strings for ERC modules, F. Jason Park, 2023/04/08
- master 22104de5daa 14/37: Add missing colors to erc-irccontrols-mode, F. Jason Park, 2023/04/08
- master 0d3ccdbde44 16/37: Don't associate ERC modules with undefined groups, F. Jason Park, 2023/04/08
- master 3a012d1db24 21/37: Add display option for interactive ERC invocations, F. Jason Park, 2023/04/08
- master dfaeeba97cc 01/37: Change ERC version to 5.6-git, F. Jason Park, 2023/04/08
- master 03eddc99242 07/37: Add probing erc-server-reconnect-function variant, F. Jason Park, 2023/04/08
- master b1007516cdf 02/37: Add subcommand dispatch facility to erc-cmd-HELP, F. Jason Park, 2023/04/08
- master 2d876a4ca94 15/37: Convert ERC's Imenu integration into proper module,
F. Jason Park <=
- master 61ed0b43cdb 05/37: Split overlong outgoing messages in erc-sasl, F. Jason Park, 2023/04/08
- master 8184a815aff 34/37: Add erc-button helper for substituting command keys, F. Jason Park, 2023/04/08
- master 379d35695b1 28/37: Make some erc-stamp functions more limber, F. Jason Park, 2023/04/08
- master 1f1cd467c6a 33/37: Replace Info-goto-node with info in erc-button-alist, F. Jason Park, 2023/04/08
- master e69bd59ec59 09/37: Honor arbitrary CHANTYPES in ERC, F. Jason Park, 2023/04/08
- master d5435a0d822 25/37: Refactor marker initialization in erc-open, F. Jason Park, 2023/04/08
- master 5011554529b 12/37: Don't require erc-goodies in erc.el, F. Jason Park, 2023/04/08
- master 0e4c07dc744 36/37: Allow erc-reuse-frames to favor connections, F. Jason Park, 2023/04/08
- master 89815631f24 10/37: Copy over upstream Compat macros to erc-compat, F. Jason Park, 2023/04/08
- master 9aa2806fdc3 13/37: Modify erc-mode-map in module definitions, F. Jason Park, 2023/04/08