universal-ctags / citre

A superior code reading & auto-completion tool with pluggable backends.
GNU General Public License v3.0
326 stars 26 forks source link

add citre-mode-map, so user can define key to override global keybindings #81

Closed jiacai2050 closed 3 years ago

jiacai2050 commented 3 years ago
  (defvar my/citre-mode-map
    (let ((map (make-sparse-keymap)))
      (define-key map (kbd "M-.") 'citre-jump)
      (define-key map (kbd "M-,") 'citre-jump-back)
      map))
  (require 'citre)
  (require 'citre-config)
  (add-to-list 'minor-mode-map-alist (cons 'citre-mode my/citre-mode-map))

Currently, I hack minor-mode-map-alist to do this, it would be great if this package provide it out of box.

AmaiKinono commented 3 years ago

If you think this is necessary, I can give citre-mode a map, but I think I wouldn't put any keybinding in it. You'll have to customize it yourself.

The point is, citre-mode is for capf/xref/imenu integration, and citre-peek/jump is separate from citre-mode. You don't have to enable citre-mode to use them. So conceptually they shouldn't appear in citre-mode-map.

If all you want is "If there's a tags file, use citre-jump, otherwise use xref", you can try citre-jump+ command in the wiki.

So, what's your choice?

jiacai2050 commented 3 years ago

Hi,I try citre-jump+, it works fine, but have one issue for jump elisp functions, it will prompt symbols of all elisp functions instead of go to definition of current symbol, do you have any ideas to fix this? image

AmaiKinono commented 3 years ago

This didn't happen to me. Does it happen in vanilla Emacs? I suspect your configuration causes this problem.

jiacai2050 commented 3 years ago

I can reproduce this with emacs -Q, which emacs version are you using? mine is

AmaiKinono commented 3 years ago

Ah, yes, you are right.

Try this:

(call-interactively #'xref-find-definitions)|xref-push-marker-stack

| is the cursor. Call eval-last-sexp (C-x C-e) here, and it behaves like you described. But directly type M-x xref-find-definitions on the symbol doesn't.

I think it has something to do with the "interactive spec", but I've never managed to understand it. Do you have any idea?

jiacai2050 commented 3 years ago
(defun citre-jump+ ()
    (interactive)
    (condition-case _
        (citre-jump)
      (error (let* ((xref-prompt-for-identifier nil))
               (call-interactively #'xref-find-definitions)))))

After dig into this, I find when xref-prompt-for-identifier is nil, prompt will be gone. Although root cause is still unclear, but it works.

I think about this issue again, it makes no harm to provide a (empty) keymap, and users can customize what they like. Please think again whether provide it or not.

AmaiKinono commented 3 years ago

I find when xref-prompt-for-identifier is nil, prompt will be gone.

Thanks! This is good enough.

it makes no harm to provide a (empty) keymap, and users can customize what they like.

Yes. I'll do it.

AmaiKinono commented 3 years ago

I've put your citre-peek+ in the wiki, and added a citre-mode-map.