Jump to function definition in Emacs by mouse-click

邮差的信 提交于 2019-12-13 01:25:16

问题


Using Emacs + Common Lisp (SBCL) + Slime, is there a quick way to jump to the definition of a function (defun ...) without typing (find-function) the name of the function? I am looking for an similar solution as often provided in Eclipse: Strg + (left-mouse-click on function call).


回答1:


In Emacs:

With point on the function whose definition you want to visit, hit C-x 5 F (find-function-other-frame).

You can also bind find-function, find-function-other-window, or find-function-other-frame to a mouse button action.

You mention Strg + (left-mouse-click on function call), for instance. Dunno what Strg is here, but you can easily bind [mouse-1] or [down-mouse-1] to a command that checks the symbol at the click position, and if it is a defined function calls find-function for it, and if it is not has the usual [mouse-1] or [down-mouse-1] behavior.

Personally, I wouldn't want such behavior, but it is easy to achieve in Emacs. For example:

(defun my-find-func-mouse (event)
  (interactive "e")
  (let ((fn  (save-excursion
               (goto-char (posn-point (event-end event)))
               (function-called-at-point))))
    (unless (fboundp fn) (error "No function here"))
    (find-function-do-it fn nil 'switch-to-buffer-other-window)))

(global-set-key [C-down-mouse-1] nil)
(global-set-key [C-mouse-1] #'my-find-func-mouse)



回答2:


You can use the keyboard. Usually 'm-.' or 'esc-.' in Emacs. The cursor must be on the symbol.




回答3:


The usual way is to create a TAGS file using etags:

$ find . -type f -iname "*.lisp*" | etags -

Then, do M-x visit-tags-table and navigate to the TAGS file. After the tags are loaded, you can simply do M-. with point on function and it will open in the current buffer.

Also, you can use M-* to go back to where you were before.

If you're using projectile, you can simply keep your TAGS file in the project root and you won't need to run M-x visit-tags-table. Projectile will load the tags table automatically when you first press M-.



来源:https://stackoverflow.com/questions/30802346/jump-to-function-definition-in-emacs-by-mouse-click

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!