Skip to content

Commit

Permalink
evil: enter insert-state only from normal-state
Browse files Browse the repository at this point in the history
  • Loading branch information
AlejandroCatalina authored and TheBB committed Feb 23, 2016
1 parent 48d05d3 commit bdd702d
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 39 deletions.
6 changes: 6 additions & 0 deletions layers/+distribution/spacemacs-base/packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,12 @@
(defun evil-insert-state-cursor-hide ()
(setq evil-insert-state-cursor '((hbar . 0))))

(defun spacemacs/normal-to-insert-state ()
"Switches to evil-insert-state if the current state is
evil-normal state."
(when (evil-normal-state-p)
(evil-insert-state)))

(unless (eq dotspacemacs-editing-style 'emacs)
(evil-mode 1)))
:config
Expand Down
10 changes: 5 additions & 5 deletions layers/+lang/clojure/packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ the focus."
`insert state'."
(interactive)
(cider-insert-last-sexp-in-repl t)
(evil-insert-state))
(spacemacs/normal-to-insert-state))

(defun spacemacs/cider-send-region-to-repl (start end)
"Send region to REPL and evaluate it without changing
Expand All @@ -72,7 +72,7 @@ the focus."
(interactive "r")
(cider-insert-in-repl
(buffer-substring-no-properties start end) t)
(evil-insert-state))
(spacemacs/normal-to-insert-state))

(defun spacemacs/cider-send-function-to-repl ()
"Send current function to REPL and evaluate it without changing
Expand All @@ -85,7 +85,7 @@ the focus."
`insert state'."
(interactive)
(cider-insert-defun-in-repl t)
(evil-insert-state))
(spacemacs/normal-to-insert-state))

(defun spacemacs/cider-send-ns-form-to-repl ()
"Send buffer's ns form to REPL and evaluate it without changing
Expand All @@ -98,15 +98,15 @@ the focus."
`insert state'."
(interactive)
(cider-insert-ns-form-in-repl t)
(evil-insert-state))
(spacemacs/normal-to-insert-state))

(defun spacemacs/cider-send-buffer-in-repl-and-focus ()
"Send the current buffer in the REPL and switch to the REPL in
`insert state'."
(interactive)
(cider-load-buffer)
(cider-switch-to-repl-buffer)
(evil-insert-state))
(spacemacs/normal-to-insert-state))

(defun spacemacs/cider-test-run-focused-test ()
(interactive)
Expand Down
4 changes: 2 additions & 2 deletions layers/+lang/elm/packages-funcs.el
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
(interactive)
(elm-repl-push-decl)
(run-elm-interactive)
(evil-insert-state))
(spacemacs/normal-to-insert-state))

(defun spacemacs/elm-repl-push-focus ()
"Send current region to the REPL and focus it in insert state."
(elm-repl-push)
(run-elm-interactive)
(evil-insert-state))
(spacemacs/normal-to-insert-state))
6 changes: 3 additions & 3 deletions layers/+lang/fsharp/packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,23 @@
(interactive)
(fsharp-load-buffer-file)
(switch-to-buffer-other-window inferior-fsharp-buffer-name)
(evil-insert-state))
(spacemacs/normal-to-insert-state))

(defun spacemacs/fsharp-eval-phrase-focus ()
"Send the current phrase to REPL and switch to the REPL in
`insert state'."
(interactive)
(fsharp-eval-phrase)
(switch-to-buffer-other-window inferior-fsharp-buffer-name)
(evil-insert-state))
(spacemacs/normal-to-insert-state))

(defun spacemacs/fsharp-eval-region-focus (start end)
"Send the current phrase to REPL and switch to the REPL in
`insert state'."
(interactive "r")
(fsharp-eval-region start end)
(switch-to-buffer-other-window inferior-fsharp-buffer-name)
(evil-insert-state))
(spacemacs/normal-to-insert-state))

(spacemacs/set-leader-keys-for-major-mode 'fsharp-mode
;; Compile
Expand Down
6 changes: 3 additions & 3 deletions layers/+lang/idris/packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@
(interactive "p")
(idris-load-file set-line)
(idris-pop-to-repl)
(evil-insert-state))
(spacemacs/normal-to-insert-state))

(defun spacemacs/idris-load-forward-line-and-focus ()
"Pass the next line to REPL and switch to it in `insert state'."
(interactive)
(idris-load-forward-line)
(idris-pop-to-repl)
(evil-insert-state))
(spacemacs/normal-to-insert-state))

(defun spacemacs/idris-load-backward-line-and-focus ()
"Pass the previous line to REPL and switch to it in `insert state'."
(interactive)
(idris-load-backward-line)
(idris-pop-to-repl)
(evil-insert-state))
(spacemacs/normal-to-insert-state))

(spacemacs/set-leader-keys-for-major-mode 'idris-mode
;; Shorthands: rebind the standard evil-mode combinations to the local
Expand Down
6 changes: 3 additions & 3 deletions layers/+lang/javascript/packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,14 @@
(interactive)
(skewer-load-buffer)
(skewer-repl)
(evil-insert-state))
(spacemacs/normal-to-insert-state))

(defun spacemacs/skewer-eval-defun-and-focus ()
"Execute function at point in browser and switch to REPL in insert state."
(interactive)
(skewer-eval-defun)
(skewer-repl)
(evil-insert-state))
(spacemacs/normal-to-insert-state))

(defun spacemacs/skewer-eval-region (beg end)
"Execute the region as JavaScript code in the attached browser."
Expand All @@ -250,7 +250,7 @@
(interactive "r")
(spacemacs/skewer-eval-region beg end)
(skewer-repl)
(evil-insert-state))
(spacemacs/normal-to-insert-state))

(spacemacs/set-leader-keys-for-major-mode 'js2-mode
"'" 'spacemacs/skewer-start-repl
Expand Down
6 changes: 3 additions & 3 deletions layers/+lang/ocaml/packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -123,23 +123,23 @@
(interactive)
(utop-eval-phrase)
(utop)
(evil-insert-state))
(spacemacs/normal-to-insert-state))

(defun spacemacs/utop-eval-buffer-and-go ()
"Send buffer to REPL and evaluate it and switch to the REPL in
`insert state'"
(interactive)
(utop-eval-buffer)
(utop)
(evil-insert-state))
(spacemacs/normal-to-insert-state))

(defun spacemacs/utop-eval-region-and-go (start end)
"Send region to REPL and evaluate it and switch to the REPL in
`insert state'"
(interactive "r")
(utop-eval-region start end)
(utop)
(evil-insert-state))
(spacemacs/normal-to-insert-state))

(spacemacs/set-leader-keys-for-major-mode 'tuareg-mode
"'" 'utop
Expand Down
10 changes: 5 additions & 5 deletions layers/+lang/python/packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -271,27 +271,27 @@
(interactive)
(python-shell-send-buffer)
(python-shell-switch-to-shell)
(evil-insert-state))
(spacemacs/normal-to-insert-state))

(defun python-shell-send-defun-switch ()
"Send function content to shell and switch to it in insert mode."
(interactive)
(python-shell-send-defun nil)
(python-shell-switch-to-shell)
(evil-insert-state))
(spacemacs/normal-to-insert-state))

(defun python-shell-send-region-switch (start end)
"Send region content to shell and switch to it in insert mode."
(interactive "r")
(python-shell-send-region start end)
(python-shell-switch-to-shell)
(evil-insert-state))
(spacemacs/normal-to-insert-state))

(defun python-start-or-switch-repl ()
"Start and/or switch to the REPL."
(interactive)
(python-shell-switch-to-shell)
(evil-insert-state))
(spacemacs/normal-to-insert-state))

;; reset compile-command (by default it is `make -k')
(setq compile-command nil)
Expand All @@ -317,7 +317,7 @@
(spacemacs/python-execute-file arg)
(switch-to-buffer-other-window "*compilation*")
(end-of-buffer)
(evil-insert-state))
(spacemacs/normal-to-insert-state))

(spacemacs/declare-prefix-for-mode 'python-mode "mc" "execute")
(spacemacs/declare-prefix-for-mode 'python-mode "md" "debug")
Expand Down
8 changes: 4 additions & 4 deletions layers/+lang/racket/packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -43,31 +43,31 @@
`insert state'."
(interactive)
(racket-run-and-switch-to-repl)
(evil-insert-state))
(spacemacs/normal-to-insert-state))

(defun spacemacs/racket-send-last-sexp-focus ()
"Call `racket-send-last-sexp' and switch to REPL buffer in
`insert state'."
(interactive)
(racket-send-last-sexp)
(racket-repl)
(evil-insert-state))
(spacemacs/normal-to-insert-state))

(defun spacemacs/racket-send-definition-focus ()
"Call `racket-send-definition' and switch to REPL buffer in
`insert state'."
(interactive)
(racket-send-definition)
(racket-repl)
(evil-insert-state))
(spacemacs/normal-to-insert-state))

(defun spacemacs/racket-send-region-focus (start end)
"Call `racket-send-region' and switch to REPL buffer in
`insert state'."
(interactive "r")
(racket-send-region start end)
(racket-repl)
(evil-insert-state))
(spacemacs/normal-to-insert-state))

(spacemacs/set-leader-keys-for-major-mode 'racket-mode
;; navigation
Expand Down
4 changes: 2 additions & 2 deletions layers/+lang/scala/packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@
(interactive)
(ensime-inf-eval-buffer)
(ensime-inf-switch)
(evil-insert-state))
(spacemacs/normal-to-insert-state))

(defun ensime-inf-eval-region-switch (start end)
"Send region content to shell and switch to it in insert mode."
(interactive "r")
(ensime-inf-switch)
(ensime-inf-eval-region start end)
(evil-insert-state))
(spacemacs/normal-to-insert-state))

(dolist (prefix '(("mb" . "scala/build")
("mc" . "scala/check")
Expand Down
6 changes: 3 additions & 3 deletions layers/+lang/sml/packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@
"Send buffer to REPL and switch to it in `insert state'."
(interactive)
(sml-prog-proc-send-buffer t)
(evil-insert-state))
(spacemacs/normal-to-insert-state))

(defun spacemacs/sml-prog-proc-send-region-and-focus (start end)
"Send region to REPL and switch to it in `insert state'."
(interactive "r")
(sml-prog-proc-send-region start end t)
(evil-insert-state))
(spacemacs/normal-to-insert-state))

(defun spacemacs/sml-send-function-and-focus ()
"Send function at point to REPL and switch to it in `insert state'."
(interactive)
(sml-send-function t)
(evil-insert-state))
(spacemacs/normal-to-insert-state))

(spacemacs/set-leader-keys-for-major-mode 'sml-mode
;; REPL
Expand Down
8 changes: 4 additions & 4 deletions layers/+lang/sql/packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -55,28 +55,28 @@
(interactive)
(let ((sql-pop-to-buffer-after-send-region t))
(call-interactively 'sql-send-string)
(evil-insert-state)))
(spacemacs/normal-to-insert-state)))

(defun spacemacs/sql-send-buffer-and-focus ()
"Send the buffer to SQLi and switch to SQLi in `insert state'."
(interactive)
(let ((sql-pop-to-buffer-after-send-region t))
(sql-send-buffer)
(evil-insert-state)))
(spacemacs/normal-to-insert-state)))

(defun spacemacs/sql-send-paragraph-and-focus ()
"Send the paragraph to SQLi and switch to SQLi in `insert state'."
(interactive)
(let ((sql-pop-to-buffer-after-send-region t))
(sql-send-paragraph)
(evil-insert-state)))
(spacemacs/normal-to-insert-state)))

(defun spacemacs/sql-send-region-and-focus (start end)
"Send region to SQLi and switch to SQLi in `insert state'."
(interactive "r")
(let ((sql-pop-to-buffer-after-send-region t))
(sql-send-region start end)
(evil-insert-state)))
(spacemacs/normal-to-insert-state)))

(spacemacs/set-leader-keys-for-major-mode 'sql-mode
"'" 'spacemacs/sql-start
Expand Down
4 changes: 2 additions & 2 deletions layers/shell/packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,12 @@ is achieved by adding the relevant text properties."
"Correctly revert to insert state after selection."
(interactive)
(helm-eshell-history)
(evil-insert-state))
(spacemacs/normal-to-insert-state))
(defun spacemacs/helm-shell-history ()
"Correctly revert to insert state after selection."
(interactive)
(helm-comint-input-ring)
(evil-insert-state))
(spacemacs/normal-to-insert-state))
(defun spacemacs/init-helm-eshell ()
"Initialize helm-eshell."
;; this is buggy for now
Expand Down

0 comments on commit bdd702d

Please sign in to comment.