cscope layer: Make it agnostic of c-c++ and python modes

This commit is contained in:
syl20bnr 2015-07-23 22:20:25 -04:00
parent bf47c76535
commit 15d90743f7
3 changed files with 48 additions and 23 deletions

View file

@ -20,11 +20,13 @@
company-ycmd
flycheck
gdb-mi
helm-cscope
helm-gtags
semantic
srefactor
stickyfunc-enhance
ycmd
xscope
))
(unless (version< emacs-version "24.4")
@ -148,3 +150,13 @@
(defun c-c++/post-init-company-ycmd ()
(push 'company-ycmd company-backends-c-mode-common))
(defun c-c++/pre-init-xcscope ()
(spacemacs|use-package-add-hook xcscope
:post-init
(evil-leader/set-key-for-mode 'c-mode-common "mgi" 'cscope-index-files)))
(defun c-c++/pre-init-helm-cscope ()
(spacemacs|use-package-add-hook xcscope
:post-init
(spacemacs/setup-helm-cscope 'c-mode-common)))

View file

@ -19,6 +19,7 @@
eldoc
evil-jumper
flycheck
helm-cscope
helm-pydoc
hy-mode
pip-requirements
@ -29,6 +30,7 @@
semantic
smartparens
stickyfunc-enhance
xcscope
))
(defun python/init-anaconda-mode ()
@ -285,3 +287,13 @@ fix this issue."
(defun python/post-init-stickyfunc-enhance ()
(add-hook 'python-mode-hook 'spacemacs/lazy-load-stickyfunc-enhance))
(defun python/pre-init-xcscope ()
(spacemacs|use-package-add-hook xcscope
:post-init
(evil-leader/set-key-for-mode 'python-mode "mgi" 'cscope/run-pycscope)))
(defun python/pre-init-helm-cscope ()
(spacemacs|use-package-add-hook xcscope
:post-init
(spacemacs/setup-helm-cscope 'python-mode)))

View file

@ -22,34 +22,35 @@
(defun cscope/init-xcscope ()
(use-package xcscope
:config
;; for python projects, we don't want xcscope to rebuild the databse,
;; because it uses cscope instead of pycscope
(setq-default cscope-option-do-not-update-database t)
(setq-default cscope-display-cscope-buffer nil)
:commands (cscope-index-files cscope/run-pycscope)
:init
(progn
;; for python projects, we don't want xcscope to rebuild the databse,
;; because it uses cscope instead of pycscope
(setq cscope-option-do-not-update-database t
cscope-display-cscope-buffer nil)
(defun cscope//safe-project-root ()
"Return project's root, or nil if not in a project."
(and (fboundp 'projectile-project-root)
(projectile-project-p)
(projectile-project-root)))
(defun cscope//safe-project-root ()
"Return project's root, or nil if not in a project."
(and (fboundp 'projectile-project-root)
(projectile-project-p)
(projectile-project-root)))
(defun cscope/run-pycscope (directory)
(interactive (list (file-name-as-directory
(read-directory-name "Run pycscope in directory: "
(cscope//safe-project-root)))))
(let ((default-directory directory))
(shell-command (format "pycscope -R -f '%s'"
(expand-file-name "cscope.out" directory)))))
(evil-leader/set-key-for-mode 'python-mode "mgi" 'cscope/run-pycscope)
(evil-leader/set-key-for-mode 'c-mode "mgi" 'cscope-index-files)
(evil-leader/set-key-for-mode 'c++-mode "mgi" 'cscope-index-files)))
(defun cscope/run-pycscope (directory)
(interactive (list (file-name-as-directory
(read-directory-name "Run pycscope in directory: "
(cscope//safe-project-root)))))
(let ((default-directory directory))
(shell-command
(format "pycscope -R -f '%s'"
(expand-file-name "cscope.out" directory))))))))
(defun cscope/init-helm-cscope ()
(use-package helm-cscope
:config
(dolist (mode '(python-mode c-mode c++-mode))
:defer t
:init
(defun spacemacs/setup-helm-cscope (mode)
"Setup `helm-cscope' for MODE"
(evil-leader/set-key-for-mode mode
"mgc" 'helm-cscope-find-called-function
"mgC" 'helm-cscope-find-calling-this-funtcion