enh-ruby-mode & anaconda-mode + better company support
This commit is contained in:
parent
dc97746803
commit
7d8c577f7c
3 changed files with 111 additions and 57 deletions
|
@ -41,21 +41,15 @@
|
||||||
(setq-default company-backends '(company-capf (company-yasnippet company-keywords)))
|
(setq-default company-backends '(company-capf (company-yasnippet company-keywords)))
|
||||||
(make-variable-buffer-local 'company-backends)
|
(make-variable-buffer-local 'company-backends)
|
||||||
|
|
||||||
(defun company--backend-on (hook backends)
|
(defun company--backend-on (hook &rest backends)
|
||||||
(add-hook hook `(lambda() (setq company-backends (append '((,backends company-yasnippet company-capf)) company-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 '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 '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
|
;; Rewrite evil-complete to use company-dabbrev
|
||||||
(setq company-dabbrev-code-other-buffers t)
|
(setq company-dabbrev-code-other-buffers t)
|
||||||
(setq company-dabbrev-code-buffers nil)
|
(setq company-dabbrev-code-buffers nil)
|
||||||
|
|
|
@ -9,19 +9,76 @@
|
||||||
(setq python-environment-directory my-tmp-dir)
|
(setq python-environment-directory my-tmp-dir)
|
||||||
(setq python-shell-interpreter "ipython")
|
(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
|
;; Interferes with smartparens
|
||||||
(bind python-mode-map (kbd "DEL") nil)
|
(bind python-mode-map (kbd "DEL") nil)
|
||||||
(bind 'motion python-mode-map "gd" 'jedi:goto-definition)
|
|
||||||
|
|
||||||
(require 'jedi)
|
(use-package anaconda-mode
|
||||||
(unless (file-directory-p python-environment-directory)
|
:init
|
||||||
(jedi:install-server))
|
(progn
|
||||||
(add-hook 'python-mode-hook 'jedi:ac-setup)
|
(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
|
(use-package nose
|
||||||
:commands nose-mode
|
:commands nose-mode
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
(provide 'init-ruby)
|
(provide 'init-ruby)
|
||||||
|
|
||||||
(use-package ruby-mode
|
(use-package enh-ruby-mode
|
||||||
:mode (("\\.rb$" . ruby-mode)
|
:mode (("\\.rb$" . enh-ruby-mode)
|
||||||
("\\.ru$" . ruby-mode)
|
("\\.ru$" . enh-ruby-mode)
|
||||||
("\\.rake$" . ruby-mode)
|
("\\.rake$" . enh-ruby-mode)
|
||||||
("\\.gemspec$" . ruby-mode)
|
("\\.gemspec$" . enh-ruby-mode)
|
||||||
("\\.?pryrc$" . ruby-mode)
|
("\\.?pryrc$" . enh-ruby-mode)
|
||||||
("Gemfile$" . ruby-mode)
|
("Gemfile$" . enh-ruby-mode)
|
||||||
("Capfile$" . ruby-mode)
|
("Capfile$" . enh-ruby-mode)
|
||||||
("Vagrantfile$" . ruby-mode)
|
("Vagrantfile$" . enh-ruby-mode)
|
||||||
("Rakefile$" . ruby-mode))
|
("Rakefile$" . enh-ruby-mode))
|
||||||
:interpreter "ruby"
|
:interpreter "ruby"
|
||||||
:config
|
:config
|
||||||
(progn
|
(progn
|
||||||
|
@ -17,7 +17,9 @@
|
||||||
(setq ruby-indent-level 2)
|
(setq ruby-indent-level 2)
|
||||||
(setq ruby-deep-indent-paren t)
|
(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
|
(define-minor-mode rake-mode
|
||||||
"Buffer local minor mode for rake files"
|
"Buffer local minor mode for rake files"
|
||||||
|
@ -30,25 +32,28 @@
|
||||||
(evil-set-initial-state 'inf-ruby-mode 'insert)
|
(evil-set-initial-state 'inf-ruby-mode 'insert)
|
||||||
(push '(inf-ruby-mode :position bottom :stick t) popwin:special-display-config)
|
(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
|
(use-package rspec-mode
|
||||||
:defer t
|
:defer t
|
||||||
:pre-load
|
:pre-load
|
||||||
(progn (defvar rspec-mode-verifiable-map (make-sparse-keymap))
|
(progn
|
||||||
(defvar evilmi-ruby-match-tags
|
(defvar rspec-mode-verifiable-map (make-sparse-keymap))
|
||||||
'((("unless" "if") ("elsif" "else") "end")
|
(defvar evilmi-ruby-match-tags
|
||||||
("begin" ("rescue" "ensure") "end")
|
'((("unless" "if") ("elsif" "else") "end")
|
||||||
("case" ("when" "else") "end")
|
("begin" ("rescue" "ensure") "end")
|
||||||
(("class" "def" "while" "do" "module" "for" "until") () "end")
|
("case" ("when" "else") "end")
|
||||||
;; Rake
|
(("class" "def" "while" "do" "module" "for" "until") () "end")
|
||||||
(("task" "namespace") () "end"))))
|
;; Rake
|
||||||
|
(("task" "namespace") () "end"))))
|
||||||
:init
|
:init
|
||||||
(progn (associate-minor-mode "\\(/spec_helper\\|_spec\\)\\.rb$" 'rspec-mode)
|
(progn
|
||||||
(associate-minor-mode "/\\.rspec$" 'rspec-mode)
|
(associate-minor-mode "\\(/spec_helper\\|_spec\\)\\.rb$" 'rspec-mode)
|
||||||
(associate-minor-mode "/\\.rake$" 'rake-mode)
|
(associate-minor-mode "/\\.rspec$" 'rspec-mode)
|
||||||
(associate-mode "/\\.rspec$" 'text-mode))
|
(associate-minor-mode "/\\.rake$" 'rake-mode)
|
||||||
|
(associate-mode "/\\.rspec$" 'text-mode))
|
||||||
:config
|
:config
|
||||||
(bind 'normal
|
(bind 'normal
|
||||||
",tr" 'rspec-rerun
|
",tr" 'rspec-rerun
|
||||||
|
@ -59,22 +64,20 @@
|
||||||
(use-package robe
|
(use-package robe
|
||||||
:config
|
:config
|
||||||
(progn
|
(progn
|
||||||
(after "company" (require 'company-robe))
|
(after "company"
|
||||||
(add-hook! 'ruby-mode-hook
|
(use-package company-robe
|
||||||
|
:config (company--backend-on 'enh-ruby-mode-hook 'company-robe)))
|
||||||
|
|
||||||
|
(add-hook! 'enh-ruby-mode-hook
|
||||||
(robe-mode 1)
|
(robe-mode 1)
|
||||||
(after "auto-complete" (ac-robe-setup))
|
(after "auto-complete" (ac-robe-setup))
|
||||||
(after "company" (add-to-list 'company-backends 'company-robe))
|
|
||||||
(unless robe-running (robe-start 1))
|
(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
|
(defun my--ruby-load-file (&optional file)
|
||||||
my-send-region-to-repl-func 'ruby-send-region
|
|
||||||
my-run-code-interpreter "ruby"))
|
|
||||||
|
|
||||||
(defun my/ruby-load-file (&optional file)
|
|
||||||
(let ((file (or file buffer-file-name)))
|
(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)
|
(bound-and-true-p robe-running)
|
||||||
(file-exists-p buffer-file-name))
|
(file-exists-p buffer-file-name))
|
||||||
(ruby-load-file file))))
|
(ruby-load-file file))))
|
||||||
(add-hook 'after-save-hook 'my/ruby-load-file)))))
|
(add-hook 'after-save-hook 'my--ruby-load-file)))))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue