0

我的配置是从http://www.emacswiki.org/emacs/GnuGlobal#toc4复制的。目的是在我保存源文件后更新现有的标签文件。但是结果和预期的一样。

完整的配置是:

(gtags-mode 1)
(defun gtags-root-dir ()
  "Returns GTAGS root directory or nil if doesn't exist."
  (with-temp-buffer
    (if (zerop (call-process "global" nil t nil "-pr"))
    (buffer-substring (point-min) (1- (point-max)))
      nil)))

(defun gtags-update-single(filename)  
  "Update Gtags database for changes in a single file"
  (interactive)
  (start-process "update-gtags" "update-gtags" "bash" "-c" (concat "cd " (gtags-root-dir) " ; gtags --single-update " filename )))

(defun gtags-update-current-file()
  (interactive)
  (defvar filename)
  (setq filename (replace-regexp-in-string (gtags-root-dir) "." (buffer-file-name (current-buffer))))
  (gtags-update-single filename)
  (message "Gtags updated for %s" filename))

(defun gtags-update-hook()
      "Update GTAGS file (insert )ncrementally upon saving a file"
      (when gtags-mode     ;;It is copy past error..
        (when (gtags-root-dir)
          (gtags-update-current-file))))
(add-hook 'after-save-hook 'gtags-update-hook)

更新

我的理解是标签将通过命令更新

  (gtags-update-single filename)
  (message "Gtags updated for %s" filename))

一旦缓冲区中的文件被保存。这意味着新添加或重命名或删除的功能将更新到标记文件。在我的测试中,我确实看到了输出消息(标签位于 ededemo 目录中):

 Wrote /other/projectbase/cplusproject/ededemo/src/main.cpp
 Gtags updated for ./src/main.cpp

每次函数在 cx cs 之后重命名或添加。但是 Mx gtags-find-tag 找不到我新添加的功能。理解有没有错误?

4

1 回答 1

1

这条线显然是负责任的/坏的:

(when gtags-;-*- mode: ${1:mode} -*-

查看 Wiki 页面,我无法理解您是如何做到的。

文档字符串注释也已损坏。只需再次复制整个功能。

于 2014-06-21T13:44:35.660 回答