Automatically run ctags command on save
This commit is contained in:
parent
cebb82f39e
commit
b16f9bbd22
4 changed files with 42 additions and 16 deletions
41
08ctags.el
41
08ctags.el
|
|
@ -1,9 +1,14 @@
|
||||||
;; Do not mix ctags between folders
|
;; Do not mix ctags between folders
|
||||||
|
(provide 'my-ctags-config)
|
||||||
|
|
||||||
(setq tags-add-tables nil)
|
(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
|
;; Sentinel function for capturing ctags
|
||||||
(defun ctags-process-callback (process event)
|
(defun ctags/process-callback (process event)
|
||||||
"Show status of asynchronous ctags-process after it finishes."
|
"Show status of asynchronous ctags/process after it finishes."
|
||||||
(cond
|
(cond
|
||||||
((string-equal event "finished\n")
|
((string-equal event "finished\n")
|
||||||
(message "Creating tag files...completed")
|
(message "Creating tag files...completed")
|
||||||
|
|
@ -14,17 +19,31 @@
|
||||||
(pop-to-buffer (get-buffer "*ctags*"))
|
(pop-to-buffer (get-buffer "*ctags*"))
|
||||||
)))
|
)))
|
||||||
|
|
||||||
(setq ctags-refresh-command
|
(cl-defun ctags/refresh-ctags (&key silent)
|
||||||
(format "ctags -e -R -f %sTAGS %s."
|
|
||||||
default-directory default-directory))
|
|
||||||
|
|
||||||
(defun refresh-ctags ()
|
|
||||||
"Refresh ctags according to currently set command."
|
"Refresh ctags according to currently set command."
|
||||||
(interactive)
|
(interactive)
|
||||||
|
|
||||||
(message "Starting ctags process")
|
;; Print message if not silent
|
||||||
(start-process-shell-command "ctags" "*ctags*" ctags-refresh-command)
|
(when (not silent) (message "Starting ctags process..."))
|
||||||
(set-process-sentinel (get-process "ctags") 'ctags-process-callback))
|
|
||||||
|
;; 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
|
;; 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)
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
'(company-etags company-yasnippet))
|
'(company-etags company-yasnippet))
|
||||||
|
|
||||||
(setq-local
|
(setq-local
|
||||||
ctags-refresh-command
|
ctags/refresh-command
|
||||||
(format
|
(format
|
||||||
"ctags -e -R --languages=C -f %sTAGS %s."
|
"ctags -e -R --languages=C -f %sTAGS %s."
|
||||||
(projectile-project-root) (projectile-project-root)
|
(projectile-project-root) (projectile-project-root)
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@
|
||||||
|
|
||||||
;; Set specific ctags command
|
;; Set specific ctags command
|
||||||
(setq-local
|
(setq-local
|
||||||
ctags-refresh-command
|
ctags/refresh-command
|
||||||
(format
|
(format
|
||||||
"ctags -e -R --languages=erlang -f %sTAGS %s. %slib/stdlib-* %slib/kernel-*"
|
"ctags -e -R --languages=erlang -f %sTAGS %s. %slib/stdlib-* %slib/kernel-*"
|
||||||
(projectile-project-root) (projectile-project-root)
|
(projectile-project-root) (projectile-project-root)
|
||||||
|
|
@ -44,4 +44,7 @@
|
||||||
|
|
||||||
(activate-erlang-mode)
|
(activate-erlang-mode)
|
||||||
;; Enable flycheck
|
;; 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))
|
||||||
|
|
|
||||||
|
|
@ -26,10 +26,14 @@
|
||||||
(setq ruby-insert-encoding-magic-comment nil)
|
(setq ruby-insert-encoding-magic-comment nil)
|
||||||
|
|
||||||
;; Company list override
|
;; 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
|
;; 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)"
|
(format "ctags -e -R --languages=ruby -f %sTAGS %s. $(bundle list --paths)"
|
||||||
(projectile-project-root) (projectile-project-root))))
|
(projectile-project-root) (projectile-project-root))))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue