【问题标题】:emacs lisp code to add files for monitoringemacs lisp 代码添加文件进行监控
【发布时间】:2011-05-15 13:09:45
【问题描述】:
我是 emacs lisp 编程的新手。我是一名开发人员,每天都在用 c 编程。我想使用标签来使用 emacs 进行代码浏览。但是,我的项目规模非常大,无法时不时地运行 etags。我想以这种方式在 emacs 中添加 lisp 函数或代码,我打开 emacs 的每个文件都必须写入一个文件(将其命名为 ~/project_files_opened.txt),我将 cron 作业,它只会对打开的文件进行 etags..有人可以帮我提供一些参考资料或现有代码吗?即使是一些例子也能帮助我理解...谢谢..
【问题讨论】:
标签:
file
emacs
elisp
monitor
【解决方案3】:
稍微不同的技巧怎么样?当您打开一个文件(您关心的)时,将其添加到 TAGS 文件中。您可以使用以下代码轻松做到这一点:
(setq tags-file-name "/scratch2/TAGS")
(setq tags-revert-without-query t)
(add-hook 'find-file-hooks 'add-opened-file-to-tags)
(defun add-opened-file-to-tags ()
"every time a file is opened, add it to the TAGS file (if not already present)
Note: only add it to the TAGS file when the major mode is one we care about"
(when (memq major-mode '(c-mode c++-mode))
(let ((opened-file (buffer-file-name)))
(save-excursion
(visit-tags-table-buffer)
(unless (member opened-file (tags-table-files))
(shell-command
(format "etags -a --output %s %s" tags-file-name opened-file)))))))
;; create an empty TAGS file if necessary
(unless (file-exists-p tags-file-name)
(shell-command (format "touch %s" tags-file-name)))
每隔一段时间,您需要删除 TAGS 文件以刷新内容。或者你可以使用类似下面的 M-x refresh-tags-table:
(defun refresh-tags-file ()
"rebuild the tags file"
(interactive)
(let ((tags-files
(save-excursion
(visit-tags-table-buffer)
(tags-table-files))))
(delete-file tags-file-name)
(dolist (file tags-files)
(shell-command (format "etags -a --output %s %s" tags-file-name file)))))