diff --git a/init/init-company.el b/init/init-company.el index 4a1e3f953..68be4a615 100644 --- a/init/init-company.el +++ b/init/init-company.el @@ -41,21 +41,15 @@ (setq-default company-backends '(company-capf (company-yasnippet company-keywords))) (make-variable-buffer-local 'company-backends) - (defun company--backend-on (hook backends) - (add-hook hook `(lambda() (setq company-backends (append '((,backends company-yasnippet company-capf)) company-backends))))) + (defun company--backend-on (hook &rest backends) + (add-hook hook + `(lambda() + (setq company-backends + (append '((,@backends company-yasnippet)) company-backends))))) - (company--backend-on 'scss-mode-hook 'company-css) (company--backend-on 'nxml-mode-hook 'company-nxml) - (company--backend-on 'js2-mode-hook 'company-tern) (company--backend-on 'emacs-lisp-mode-hook 'company-elisp) - (company--backend-on 'ruby-mode-hook 'company-robe) - (company--backend-on 'inf-ruby-mode-hook 'company-inf-ruby) - - (company--backend-on 'python-mode-hook 'company-anaconda) - (add-hook 'python-mode-hook 'anaconda-mode) - (add-hook 'python-mode-hook 'eldoc-mode) - ;; Rewrite evil-complete to use company-dabbrev (setq company-dabbrev-code-other-buffers t) (setq company-dabbrev-code-buffers nil) diff --git a/init/init-python.el b/init/init-python.el index 15962c14e..7a87a1b07 100644 --- a/init/init-python.el +++ b/init/init-python.el @@ -9,19 +9,76 @@ (setq python-environment-directory my-tmp-dir) (setq python-shell-interpreter "ipython") - (add-hook! 'python-mode-hook - (setq my-switch-to-repl-func 'python-shell-switch-to-shell - my-send-region-to-repl-func 'python-shell-send-region - my-run-code-interpreter "python")) - ;; Interferes with smartparens (bind python-mode-map (kbd "DEL") nil) - (bind 'motion python-mode-map "gd" 'jedi:goto-definition) - (require 'jedi) - (unless (file-directory-p python-environment-directory) - (jedi:install-server)) - (add-hook 'python-mode-hook 'jedi:ac-setup) + (use-package anaconda-mode + :init + (progn + (add-hook 'python-mode-hook 'anaconda-mode) + (add-hook 'python-mode-hook 'eldoc-mode) + (add-hook! 'anaconda-mode-hook + (process-buffer (python-shell-get-or-create-process python-shell-interpreter t nil)))) + :config + (progn + (bind 'motion anaconda-mode-map "gd" 'anaconda-mode-goto-definitions) + (bind 'normal anaconda-nav-mode-map [escape] 'anaconda-nav-quit) + + (push '("*anaconda-doc*" :position bottom :height 15 :noselect t) popwin:special-display-config) + (push '("*anaconda-nav*" :position bottom :height 15 :stick t) popwin:special-display-config) + (push '("^\\*Python.+\\*$" :regexp t :position bottom :height 20 :noselect t) popwin:special-display-config) + + ;; Delete the window on escape or C-g + (defadvice anaconda-mode-doc-buffer (after anaconda-doc-buffer-escape-to-close activate) + (with-current-buffer (get-buffer "*anaconda-doc*") + (local-set-key [escape] 'anaconda-nav-quit) + (local-set-key [?\C-g] 'anaconda-nav-quit))) + + (after "emr" + (emr-declare-command 'anaconda-mode-view-doc + :title "view documentation" + :modes 'python-mode + :predicate (lambda () (and (anaconda-mode-running-p) + (not (use-region-p)) + (not (sp-point-in-string-or-comment))))) + (emr-declare-command 'anaconda-mode-goto-assignments + :title "go to assignments" + :modes 'python-mode + :predicate (lambda () (and (anaconda-mode-running-p) + (not (use-region-p)) + (not (sp-point-in-string-or-comment))))) + + (emr-declare-command 'anaconda-mode-goto-definitions + :title "go to definition" + :modes 'python-mode + :predicate (lambda () (and (anaconda-mode-running-p) + (not (use-region-p)) + (not (sp-point-in-string-or-comment))))) + + (emr-declare-command 'anaconda-mode-usages + :title "show usages" + :modes 'python-mode + :predicate (lambda () (and (anaconda-mode-running-p) + (not (use-region-p)) + (not (sp-point-in-string-or-comment)))))) + + (after "auto-complete" + (use-package ac-anaconda + :init (add-hook 'python-mode-hook 'ac-anaconda-setup))) + + (after "company" + (use-package company-anaconda + :config (company--backend-on 'python-mode-hook 'company-anaconda))))) + + (use-package jedi + :disabled t + :config + (progn + (unless (file-directory-p python-environment-directory) + (jedi:install-server)) + (add-hook 'python-mode-hook 'jedi:ac-setup) + + (bind 'motion python-mode-map "gd" 'jedi:goto-definition))) (use-package nose :commands nose-mode diff --git a/init/init-ruby.el b/init/init-ruby.el index a9f7670a4..e541e79f9 100644 --- a/init/init-ruby.el +++ b/init/init-ruby.el @@ -1,15 +1,15 @@ (provide 'init-ruby) -(use-package ruby-mode - :mode (("\\.rb$" . ruby-mode) - ("\\.ru$" . ruby-mode) - ("\\.rake$" . ruby-mode) - ("\\.gemspec$" . ruby-mode) - ("\\.?pryrc$" . ruby-mode) - ("Gemfile$" . ruby-mode) - ("Capfile$" . ruby-mode) - ("Vagrantfile$" . ruby-mode) - ("Rakefile$" . ruby-mode)) +(use-package enh-ruby-mode + :mode (("\\.rb$" . enh-ruby-mode) + ("\\.ru$" . enh-ruby-mode) + ("\\.rake$" . enh-ruby-mode) + ("\\.gemspec$" . enh-ruby-mode) + ("\\.?pryrc$" . enh-ruby-mode) + ("Gemfile$" . enh-ruby-mode) + ("Capfile$" . enh-ruby-mode) + ("Vagrantfile$" . enh-ruby-mode) + ("Rakefile$" . enh-ruby-mode)) :interpreter "ruby" :config (progn @@ -17,7 +17,9 @@ (setq ruby-indent-level 2) (setq ruby-deep-indent-paren t) - (add-hook 'ruby-mode-hook 'enable-tab-width-2) + (add-hook 'enh-ruby-mode-hook 'enable-tab-width-2) + + (after "emr" (use-package ruby-refactor)) (define-minor-mode rake-mode "Buffer local minor mode for rake files" @@ -30,25 +32,28 @@ (evil-set-initial-state 'inf-ruby-mode 'insert) (push '(inf-ruby-mode :position bottom :stick t) popwin:special-display-config) - (use-package company-inf-ruby) - )) + (after "company" + (use-package company-inf-ruby + :config (company--backend-on 'inf-ruby-mode-hook 'company-inf-ruby))))) (use-package rspec-mode :defer t :pre-load - (progn (defvar rspec-mode-verifiable-map (make-sparse-keymap)) - (defvar evilmi-ruby-match-tags - '((("unless" "if") ("elsif" "else") "end") - ("begin" ("rescue" "ensure") "end") - ("case" ("when" "else") "end") - (("class" "def" "while" "do" "module" "for" "until") () "end") - ;; Rake - (("task" "namespace") () "end")))) + (progn + (defvar rspec-mode-verifiable-map (make-sparse-keymap)) + (defvar evilmi-ruby-match-tags + '((("unless" "if") ("elsif" "else") "end") + ("begin" ("rescue" "ensure") "end") + ("case" ("when" "else") "end") + (("class" "def" "while" "do" "module" "for" "until") () "end") + ;; Rake + (("task" "namespace") () "end")))) :init - (progn (associate-minor-mode "\\(/spec_helper\\|_spec\\)\\.rb$" 'rspec-mode) - (associate-minor-mode "/\\.rspec$" 'rspec-mode) - (associate-minor-mode "/\\.rake$" 'rake-mode) - (associate-mode "/\\.rspec$" 'text-mode)) + (progn + (associate-minor-mode "\\(/spec_helper\\|_spec\\)\\.rb$" 'rspec-mode) + (associate-minor-mode "/\\.rspec$" 'rspec-mode) + (associate-minor-mode "/\\.rake$" 'rake-mode) + (associate-mode "/\\.rspec$" 'text-mode)) :config (bind 'normal ",tr" 'rspec-rerun @@ -59,22 +64,20 @@ (use-package robe :config (progn - (after "company" (require 'company-robe)) - (add-hook! 'ruby-mode-hook + (after "company" + (use-package company-robe + :config (company--backend-on 'enh-ruby-mode-hook 'company-robe))) + + (add-hook! 'enh-ruby-mode-hook (robe-mode 1) (after "auto-complete" (ac-robe-setup)) - (after "company" (add-to-list 'company-backends 'company-robe)) (unless robe-running (robe-start 1)) - (my/ruby-load-file buffer-file-name) + (my--ruby-load-file buffer-file-name)) - (setq my-switch-to-repl-func 'ruby-switch-to-inf - my-send-region-to-repl-func 'ruby-send-region - my-run-code-interpreter "ruby")) - - (defun my/ruby-load-file (&optional file) + (defun my--ruby-load-file (&optional file) (let ((file (or file buffer-file-name))) - (when (and (eq major-mode 'ruby-mode) + (when (and (eq major-mode 'enh-ruby-mode) (bound-and-true-p robe-running) (file-exists-p buffer-file-name)) (ruby-load-file file)))) - (add-hook 'after-save-hook 'my/ruby-load-file))))) + (add-hook 'after-save-hook 'my--ruby-load-file)))))