在Emacs根项目中保存TAGS文件

时间:2018-06-05 04:54:51

标签: emacs tags etags

如何将TAGS文件保存在项目的根目录中?

当我更改文件时,我的emacs配置将在每个目录中保存TAGS文件。 例如,当我更改src/目录中的文件时,它会在此目录中保存TAGS文件,而不是将此文件保存在项目的根目录中:

project1:
  main.py
  TAGS          <<< correct.
  src/
      newlib.py
      TAGS      <<< incorrect. this file should be store in root directory (project1/TAGS)
  libs/
      something.py

这是我TAGS的emacs配置:

;; create tags
(defun create-tags (dir-name)
  "Create tags file."
  (interactive "DDirectory: ")
    (eshell-command
      (format "find . -type f -iname \"*.py\" -not -path \"*/venv/*\" | etags -" dir-name)))

;; refresh tags
(defun er-refresh-etags (&optional extension)
  "Run etags on all peer files in current dir and reload them silently."
  (interactive)
    (shell-command (format "find . -type f -iname \"*.py\" -not -path \"*/venv/*\" | etags -" '.))
    (let ((tags-revert-without-query t))  ; don't query, revert silently          
      (visit-tags-table default-directory nil)))

;; hooks for tags
(create-tags '.)
(add-hook 'after-save-hook (create-tags '.))
(add-hook 'after-save-hook #'er-refresh-etags)

0 个答案:

没有答案