簡體   English   中英

保存后,將emacs中的gtag文件更新為單個文件

[英]Update gtag file in emacs for a single file once on saving

我的配置是從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找不到我新添加的功能。 理解上有什么錯誤嗎?

該行顯然是負責任/中斷的:

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

在Wiki頁面上,我無法理解您最終如何做到這一點。

文檔字符串注釋也已損壞。 只需再次復制整個功能。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM