Automatically run ctags command on save

This commit is contained in:
Maciej 2019-07-11 23:20:16 +03:00
parent cebb82f39e
commit b16f9bbd22
Signed by: maciej
GPG key ID: 41D62D42D3B0D765
4 changed files with 42 additions and 16 deletions

View file

@ -1,9 +1,14 @@
;; Do not mix ctags between folders
(provide 'my-ctags-config)
(setq tags-add-tables nil)
(setq ctags/refresh-command
(format "ctags -e -R -f %sTAGS %s."
default-directory default-directory))
;; Sentinel function for capturing ctags
(defun ctags-process-callback (process event)
"Show status of asynchronous ctags-process after it finishes."
(defun ctags/process-callback (process event)
"Show status of asynchronous ctags/process after it finishes."
(cond
((string-equal event "finished\n")
(message "Creating tag files...completed")
@ -14,17 +19,31 @@
(pop-to-buffer (get-buffer "*ctags*"))
)))
(setq ctags-refresh-command
(format "ctags -e -R -f %sTAGS %s."
default-directory default-directory))
(defun refresh-ctags ()
(cl-defun ctags/refresh-ctags (&key silent)
"Refresh ctags according to currently set command."
(interactive)
(message "Starting ctags process")
(start-process-shell-command "ctags" "*ctags*" ctags-refresh-command)
(set-process-sentinel (get-process "ctags") 'ctags-process-callback))
;; Print message if not silent
(when (not silent) (message "Starting ctags process..."))
;; Return if a version of the process is already running
(when (not (get-process "ctags"))
(start-process-shell-command "ctags" "*ctags*" ctags/refresh-command)
(set-process-sentinel (get-process "ctags") 'ctags/process-callback)))
;; Ctags bindings
(define-key prog-mode-map (kbd "C-c E") 'refresh-ctags)
(define-key prog-mode-map (kbd "C-c E") 'ctags/refresh-ctags)
;; Automatically update tags on save, but be silent about it.
(setq ctags/major-modes-to-update-on-save '())
(defun ctags/update-tags-on-save ()
"Update tags if current major mode is part of the list."
(interactive)
(when (member major-mode ctags/major-modes-to-update-on-save)
(ctags/refresh-ctags :silent t)))
(defun ctags/update-this-mode-on-save (mode)
"Update MODE on save."
(add-to-list (make-local-variable 'ctags/major-modes-to-update-on-save) mode))
(add-hook 'after-save-hook 'ctags/update-tags-on-save)

View file

@ -7,7 +7,7 @@
'(company-etags company-yasnippet))
(setq-local
ctags-refresh-command
ctags/refresh-command
(format
"ctags -e -R --languages=C -f %sTAGS %s."
(projectile-project-root) (projectile-project-root)

View file

@ -27,7 +27,7 @@
;; Set specific ctags command
(setq-local
ctags-refresh-command
ctags/refresh-command
(format
"ctags -e -R --languages=erlang -f %sTAGS %s. %slib/stdlib-* %slib/kernel-*"
(projectile-project-root) (projectile-project-root)
@ -44,4 +44,7 @@
(activate-erlang-mode)
;; Enable flycheck
(flycheck-select-checker 'erlang-otp))
(flycheck-select-checker 'erlang-otp)
;; Automatically update tags on save
(ctags/update-this-mode-on-save 'erlang-mode))

View file

@ -26,10 +26,14 @@
(setq ruby-insert-encoding-magic-comment nil)
;; Company list override
(add-to-list (make-local-variable 'company-backends) '(company-etags company-yasnippet))
(add-to-list (make-local-variable 'company-backends)
'(company-etags company-yasnippet))
;; Automatically update tags on save
(ctags/update-this-mode-on-save 'enh-ruby-mode)
;; Set specific ctags command
(setq-local ctags-refresh-command
(setq-local ctags/refresh-command
(format "ctags -e -R --languages=ruby -f %sTAGS %s. $(bundle list --paths)"
(projectile-project-root) (projectile-project-root))))