From d49ecc62a751e4bcfea82d2743b2dc26f4f46614 Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Tue, 21 Apr 2015 21:51:32 +0200 Subject: [PATCH] Move and expand the switching newline keys section --- emacs/.emacs.d/init.org | 52 +++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/emacs/.emacs.d/init.org b/emacs/.emacs.d/init.org index 7a9eb08..0f2913e 100644 --- a/emacs/.emacs.d/init.org +++ b/emacs/.emacs.d/init.org @@ -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