How to programmatically create/update a TAGS file with emacs?

后端 未结 7 1092
我在风中等你
我在风中等你 2021-01-31 11:20

Is there any plugin for emacs to automatically update the TAGS file in my C project (for example on buffer save or access) or create a new one if there is no TAGS file present?

7条回答
  •  深忆病人
    2021-01-31 11:38

    Install find-and-ctags (https://github.com/redguardtoo/find-and-ctags), then insert below code into ~/.emacs,

    (defun my-setup-develop-environment ()
      (interactive)
    
      ;; you can use `find-and-ctags-current-full-filename-match-pattern-p' instead
      (when (find-and-ctags-current-path-match-pattern-p "/MYPROJ")
        (setq-local tags-table-list
                    (list (find-and-ctags-run-ctags-if-needed "~/workspace/MYPROJ" ; project directory
                   '(("-not -size +64k" "--exclude=*.min.js") ; (find-opts ctags-opts)
                                                                ;; you may add more find-opts ctags-opts pair HERE to run find&ctags again to APPEND to same TAGS file
                                                                ;; ctags-opts must contain "-a" to append
                                                                ;; (find-opts "-a")
                                                                )))))
    
      ;; for other projects
      ;; insert NEW `when' statements here
      )
    (add-hook 'prog-mode-hook 'my-setup-develop-environment) ; prog-mode require emacs24+
    (add-hook 'lua-mode-hook 'my-setup-develop-environment) ; lua-mode does NOT inherit from prog-mode
    
    ;; OPTIONAL
    (add-hook 'after-save-hook 'find-and-ctags-auto-update-tags)
    

    It works on windows, all you need is replace "~/workspace/MYPROJ" with "C:/workspace/MYPROJ". CTags executable could be any version, because produced TAGS contains only relative path.

提交回复
热议问题