如何将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)