自动跳转到Emacs中的标记

时间:2012-08-22 14:03:32

标签: emacs ctags etag

我希望find-tag自动接受默认选项(即点上的单词)并跳转到标记位置而不提示。

这可能吗?

我也在使用Emacswiki的find-tag建议版本,如果匹配重新运行ctags。所以我想要这样的事情:

is current word a known tag?
-> yes: jump to it without further confirmation
-> no: rerun ctags
is it known now?
-> yes: jump to it without further confirmation
-> no: prompt user for input

谢谢!

5 个答案:

答案 0 :(得分:5)

这是谷歌“查找标签emacs没有提示”的热门歌曲之一。对于简单版本 - 没有海报提到的ctag-regeneration逻辑 - 似乎关键是:

(find-tag (find-tag-default))

所以,对我来说,这很有效:

(defun find-tag-no-prompt ()
  "Jump to the tag at point without prompting"
  (interactive)
  (find-tag (find-tag-default)))
;; don't prompt when finding a tag
(global-set-key (kbd "M-.") 'find-tag-no-prompt)

答案 1 :(得分:2)

这是我对ctags的设置,对我来说很棒。我从here借用它。

(require 'eproject)
(require 'etags-select)

(defun build-ctags ()
  (interactive)
  (message "building project tags")
  (let ((root (eproject-root)))
    (shell-command
     (concat "ctags-exuberant -e -R --extra=+fq --exclude=db --exclude=test --exclude=.git --exclude=public -f " root "TAGS " root)))
  (visit-project-tags)
  (message "tags built successfully"))

(defun visit-project-tags ()
  (interactive)
  (let ((tags-file (concat (eproject-root) "TAGS")))
    (visit-tags-table tags-file)
    (message (concat "Loaded " tags-file))))

(defun hbin-find-tag ()
  "Borrow from http://mattbriggs.net/blog/2012/03/18/awesome-emacs-plugins-ctags/"
  (interactive)
  (if (file-exists-p (concat (eproject-root) "TAGS"))
      (visit-project-tags)
    (build-ctags))
  (etags-select-find-tag-at-point))

(global-set-key (kbd "M-.") 'hbin-find-tag)

PS:你可能需要这些:

git://github.com/jrockway/eproject.git
git://github.com/emacsmirror/etags-select.git

答案 2 :(得分:2)

好吧,我找到了一个黑客解决方案:

;; auto jump
(global-set-key (kbd "C-x C-M->") 'find-tag) ; bind to some unused placeholder
(global-set-key (kbd "M-.") (kbd "C-x C-M-> <return>"))

首先将find-tag绑定到一些你永远不会使用的虚拟绑定(这一步是避免无限循环所必需的)。然后将M-.绑定到此新绑定+ <return>

丑陋,但有效...如果有人有更好的答案(包括处理原始问题中描述的失败搜索),我会留下问题。

答案 3 :(得分:0)

这是一个稍加修改的版本,可以加载相关的宝石(在轨道上的红宝石中很有用)

  (defun build-ctags ()
      (interactive)
      (message "building project tags")
      (let ((default-directory (eproject-root)))
        (shell-command (concat "exctags -e -R --extra=+fq --exclude=db --exclude=test --exclude=.git --exclude=public -f TAGS * " (trim-string (shell-command-to-string "rvm gemdir")) "/gems/*"))
        (visit-project-tags)
        (message "tags built successfully")))

答案 4 :(得分:0)

默认情况下,Emacs 25会这样做。 M-.xref-find-definitions)跳转到定义,M-,xref-pop-marker-stack)弹回。