Move and expand the switching newline keys section

This commit is contained in:
Tom Willemse 2015-04-21 21:51:32 +02:00
parent 4e6871d7ca
commit d49ecc62a7

View file

@ -980,26 +980,6 @@
(add-hook 'eval-expression-minibuffer-setup-hook #'eldoc-mode)
#+END_SRC
* Return to {{{key(C-j)}}} in electric indent mode
When =electric-indent-mode= is enabled the default function bound to
{{{key(C-j)}}} (=electric-newline-and-maybe-indent=) stops indenting
after adding a newline, whilst {{{key(RET)}}} starts doing it. Since
I use {{{key(C-j)}}} almost exclusively and don't use {{{key(RET)}}}
at all, it's really not useful to me. So when =electric-indent-mode=
is enabled, switch the two.
#+BEGIN_SRC emacs-lisp
(add-hook 'electric-indent-local-mode-hook
(lambda ()
(if electric-indent-mode
(progn
(local-set-key (kbd "C-j") 'newline)
(local-set-key (kbd "RET") 'electric-newline-and-maybe-indent))
(local-unset-key (kbd "C-j"))
(local-unset-key (kbd "RET")))))
#+END_SRC
* Remove whitespace when closing delimiters
In =electric-pair-mode=, skip over and delete white space if it stands
@ -1180,6 +1160,38 @@
(add-hook 'scss-mode-hook #'electric-indent-local-mode)
#+END_SRC
*** Switch keys back
When =electric-indent-mode= is enabled the default function bound to
{{{key(C-j)}}} (=electric-newline-and-maybe-indent=) stops indenting
after adding a newline, whilst {{{key(RET)}}} starts doing it.
Since I use {{{key(C-j)}}} almost exclusively and don't use
{{{key(RET)}}} at all, it's really not useful to me. So I want to
switch the two when =electric-indent-mode= is enabled.
This is very simple. First I define a simple function that checks
if the =electric-indent-mode= variable is set (which it should be if
the mode is turned on) and if so I set the proper keys /locally/. If
=electric-indent-mode= is /not/ set, which happens when the mode is
turned off, I remove the local keybindings.
#+BEGIN_SRC emacs-lisp
(defun oni:switch-newline-keys ()
"Switch the `C-j' and `RET' keys in the local buffer."
(if electric-indent-mode
(progn
(local-set-key (kbd "C-j") 'newline)
(local-set-key (kbd "RET") 'electric-newline-and-maybe-indent))
(local-unset-key (kbd "C-j"))
(local-unset-key (kbd "RET"))))
#+END_SRC
And then I add it to the electric indent mode's hook.
#+BEGIN_SRC emacs-lisp
(add-hook 'electric-indent-local-mode-hook #'oni:switch-newline-keys)
#+END_SRC
** Electric pairing
Electric pairing of delimiters is one of those features that is