summaryrefslogtreecommitdiffstats
path: root/emacs/.emacs.d/init.org
diff options
context:
space:
mode:
authorGravatar Tom Willemse2015-04-21 21:51:32 +0200
committerGravatar Tom Willemse2015-04-21 21:51:32 +0200
commitd49ecc62a751e4bcfea82d2743b2dc26f4f46614 (patch)
treedca3f72efee9e12087e2ebc3ddc5e395a61cc679 /emacs/.emacs.d/init.org
parent4e6871d7cab0ec63b54386a50ff841b47e1c846d (diff)
downloaddotfiles-d49ecc62a751e4bcfea82d2743b2dc26f4f46614.tar.gz
dotfiles-d49ecc62a751e4bcfea82d2743b2dc26f4f46614.zip
Move and expand the switching newline keys section
Diffstat (limited to 'emacs/.emacs.d/init.org')
-rw-r--r--emacs/.emacs.d/init.org52
1 files 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