Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better Imenu integration (integrate with other imenu backend instead of overwriting it) #182

Open
milanglacier opened this issue Oct 29, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@milanglacier
Copy link

milanglacier commented Oct 29, 2024

Citre mode will overwrite imenu-create-index-function when citre-enable-imenu-integration is t.

However, this might create problem if the user also has other imenu backend, e.g. eglot-imenu, or the imenu from the built-in xxxx-ts-mode since emacs 29. and want to use multiple imenu backends all at once.

Here is the piece of code of how eglot is handling the imenu:

    (unless (eglot--stay-out-of-p 'imenu)
      (add-function :before-until (local 'imenu-create-index-function)
                    #'eglot-imenu))

The takeaway is, instead of overwrite this function, it patches the imenu-create-index-function so that previous imenu backend does not remove.

This would be something like this and I think this way to use menu integration is a sensible default.

diff --git a/citre.el b/citre.el
index 4c3effb..0eed496 100644
--- a/citre.el
+++ b/citre.el
@@ -591,16 +591,15 @@ The returned value is a valid element of the return value of
       (add-hook 'completion-at-point-functions
                 #'citre-completion-at-point nil t))
     (when citre-enable-imenu-integration
-      (setq citre-imenu--create-index-function-orig
-            imenu-create-index-function)
-      (setq imenu-create-index-function #'citre-imenu-create-index-function)))
+      (add-function :before-until (local 'imenu-create-index-function)
+                    #'citre-imenu-create-index-function)
+      ))
    (t
     (remove-hook 'xref-backend-functions #'citre-xref-backend t)
     (remove-hook 'completion-at-point-functions
                  #'citre-completion-at-point t)
     (when citre-enable-imenu-integration
-      (setq imenu-create-index-function
-            citre-imenu--create-index-function-orig)))))
+      (remove-function (local 'imenu-create-index-function) #'citre-imenu-create-index-function)))))
 
 ;;;###autoload
 (defun citre-auto-enable-citre-mode ()
@milanglacier milanglacier added the bug Something isn't working label Oct 29, 2024
@AmaiKinono
Copy link
Member

Thanks for the report! Yes, it's a pretty neat technique and we should do this instead. Would you like to open a PR for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants