General lang refactor; new refactor, help, build & test menus

This commit is contained in:
Henrik Lissner 2017-10-03 02:49:49 +02:00
parent d0fcb23314
commit ed76cfda99
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
4 changed files with 87 additions and 67 deletions

View file

@ -4,45 +4,64 @@
:mode "\\.go$"
:interpreter "go"
:config
(setq gofmt-command "goimports")
(add-hook 'go-mode-hook #'flycheck-mode)
(setq gofmt-command "goimports")
(if (not (executable-find "goimports"))
(warn "go-mode: couldn't find goimports; no code formatting/fixed imports on save")
(add-hook! go-mode (add-hook 'before-save-hook #'gofmt-before-save nil t)))
(set! :build 'go-build 'go-mode #'+go/build)
(set! :repl 'go-mode #'gorepl-run)
(set! :jump 'go-mode
:definition #'go-guru-definition
:references #'go-guru-referrers
:documentation #'godoc-at-point)
(def-menu! +go/refactor-menu
"Refactoring commands for `go-mode' buffers."
'(("Add import" :exec go-import-add :region nil)
("Remove unused imports" :exec go-remove-unused-imports :region nil)
("Format buffer (gofmt)" :exec go-gofmt))
:prompt "Refactor: ")
(def-menu! +go/build-menu
"Build/compilation commands for `go-mode' buffers."
'(("Build project" :exec "go build")
("Build & run project" :exec "go run")
("Clean files" :exec "go clean"))
:prompt "Run test: ")
(def-menu! +go/test-menu
"Test commands for `go-mode' buffers."
'(("Last test" :exec +go/test-rerun)
("All tests" :exec +go/test-all)
("Single test" :exec +go/test-single)
("Nested test" :exec +go/test-nested))
:prompt "Run test: ")
(def-menu! +go/help-menu
"Help and information commands for `go-mode' buffers."
'(("Go to imports" :exec go-goto-imports)
("Lookup in godoc" :exec godoc-at-point)
("Describe this" :exec go-guru-describe)
("List free variables" :exec go-guru-freevars)
("What does this point to" :exec go-guru-pointsto)
("Implements relations for package types" :exec go-guru-implements :region nil)
("List peers for channel" :exec go-guru-peers)
("List references to object" :exec go-guru-referrers)
("Which errors" :exec go-guru-whicerrs)
("What query" :exec go-guru-what)
("Show callers of this function" :exec go-guru-callers :region nil)
("Show callees of this function" :exec go-guru-callees :region nil)))
(map! :map go-mode-map
:n "gd" #'go-guru-definition
:n "gD" #'go-guru-referrers
(:localleader
:localleader
"r" #'+go/refactor-menu
"b" #'+go/build-menu
"h" #'+go/help-menu
"t" #'+go/test-menu
:n "gr" #'go-play-buffer
:v "gr" #'go-play-region
(:prefix "f"
:n "i" #'go-goto-imports
:n "h" #'godoc-at-point
:n "d" #'go-guru-describe
:n "v" #'go-guru-freevars
:n "I" #'go-guru-implements
:n "p" #'go-guru-peers
:n "r" #'go-guru-referrers
:n "t" #'go-guru-pointsto
:n "s" #'go-guru-callstack
:n "e" #'go-guru-whicherrs
:n "c" #'go-guru-callers
:n "C" #'go-guru-callees)
(:prefix "r"
:n "a" #'go-import-add
:n "i" #'go-remove-unused-imports
:nv "f" #'gofmt)
(:prefix "t"
:n "r" #'+go/test-rerun
:n "a" #'+go/test-all
:n "s" #'+go/test-single
:n "n" #'+go/test-nested))))
:v "gr" #'go-play-region))
(def-package! go-eldoc

View file

@ -18,6 +18,9 @@
;; Conform switch-case indentation to editorconfig's config
(set! :editorconfig :add '(js2-mode js2-basic-offset js-switch-indent-offset))
(sp-with-modes '(js2-mode rjsx-mode)
(sp-local-pair "/* " " */" :post-handlers '(("| " "SPC"))))
;; Favor local eslint over global, if available
(defun +javascript|init-flycheck-elint ()
(when (derived-mode-p 'js-mode)
@ -28,40 +31,10 @@
(setq-local flycheck-javascript-eslint-executable eslint))))
(add-hook 'flycheck-mode-hook #'+javascript|init-flycheck-elint)
(sp-with-modes '(js2-mode rjsx-mode)
(sp-local-pair "/* " " */" :post-handlers '(("| " "SPC"))))
(map! :map js2-mode-map
:localleader
:n "S" #'+javascript/skewer-this-buffer
:prefix "r"
:n "g" #'js2r-add-to-globals-annotation
:n "ca" #'js2r-arguments-to-object
:n "Xa" #'js2r-contract-array
:n "Xf" #'js2r-contract-function
:n "Xo" #'js2r-contract-object
:nv "d" #'js2r-debug-this
:n "xa" #'js2r-expand-array
:n "xf" #'js2r-expand-function
:n "xo" #'js2r-expand-object
:v "ef" #'js2r-extract-function
:v "em" #'js2r-extract-method
:v "ev" #'js2r-extract-var
:n "F" #'js2r-forward-barf
:n "f" #'js2r-forward-slurp
:v "ii" #'js2r-inject-global-in-iife
:v "iv" #'js2r-inline-var
:v "p" #'js2r-introduce-parameter
:n "p" #'js2r-localize-parameter
:nv "l" #'js2r-log-this
:n "r" #'js2r-rename-var
:n "ss" #'js2r-split-string
:n "sv" #'js2r-split-var-declaration
:n "ct" #'js2r-ternary-to-if
:v "u" #'js2r-unwrap
:n "t" #'js2r-var-to-this
:n "ii" #'js2r-wrap-buffer-in-iife))
"r" #'+javascript/refactor
"S" #'+javascript/skewer-this-buffer))
;; A find-{definition,references} backend for js2-mode. NOTE The xref API is
@ -81,7 +54,35 @@
js2r-add-to-globals-annotation js2r-extract-var js2r-inline-var
js2r-rename-var js2r-var-to-this js2r-arguments-to-object js2r-ternary-to-if
js2r-split-var-declaration js2r-split-string js2r-unwrap js2r-log-this
js2r-debug-this js2r-forward-slurp js2r-forward-barf))
js2r-debug-this js2r-forward-slurp js2r-forward-barf)
:init
(def-menu! +javascript/refactor
"Refactoring commands for `js2-mode' buffers."
'(("Extract into function" :exec js2r-extract-function :region t)
("Extract into method" :exec js2r-extract-method :region t)
("Introduce parameter to function" :exec js2r-introduce-parameter :region t)
("Localize parameter" :exec js2r-localize-parameter :region nil)
("Expand object" :exec js2r-expand-object :region nil)
("Expand function" :exec js2r-expand-function :region nil)
("Expand array" :exec js2r-expand-array :region nil)
("Contract object" :exec js2r-contract-object :region nil)
("Contract function" :exec js2r-contract-function :region nil)
("Contract array" :exec js2r-contract-array :region nil)
("Wrap buffer in IIFE" :exec js2r-wrap-buffer-in-iife :region nil)
("Inject global into IIFE" :exec js2r-inject-global-in-iife :region t)
("Add to globals annotation" :exec js2r-add-to-globals-annotation :region nil)
("Extract variable" :exec js2r-extract-var :region t)
("Inline variable" :exec js2r-inline-var :region t)
("Rename variable" :exec js2r-rename-var :region nil)
("Replace var with this" :exec js2r-var-to-this :region nil)
("Arguments to object" :exec js2r-arguments-to-object :region nil)
("Ternary to if" :exec js2r-ternary-to-if :region nil)
("Split var declaration" :exec js2r-split-var-declaration :region nil)
("Split string" :exec js2r-split-string :region nil)
("Unwrap" :exec js2r-unwrap :region t)
("Log this" :exec js2r-log-this)
("Debug this" :exec js2r-debug-this))
:prompt "Refactor: "))
(def-package! tern

View file

@ -27,11 +27,10 @@
(setq racer-cmd (expand-file-name "racer/target/release/racer" +rust-src-dir)
racer-rust-src-path (expand-file-name "rust/src/" +rust-src-dir))
(unless (file-exists-p racer-cmd)
(warn "rust-mode: racer binary can't be found; auto-completion is disabled"))
(set! :jump 'rust-mode :definition #'racer-find-definition)
;; TODO Unit test keybinds
(map! :map rust-mode-map :m "gd" #'racer-find-definition))
(unless (file-exists-p racer-cmd)
(warn "rust-mode: racer binary can't be found; auto-completion is disabled")))
(def-package! company-racer

View file

@ -13,6 +13,7 @@
(:localleader
:n "rb" #'+css/toggle-inline-or-block))
;;
;; Packages
;;