summaryrefslogtreecommitdiffstats
path: root/emacs/.emacs.d/init.org
diff options
context:
space:
mode:
authorGravatar Tom Willemse2014-10-23 16:38:45 +0200
committerGravatar Tom Willemse2014-10-23 16:38:45 +0200
commit4baea6bdac339d2b329b84eb40d22a11c66f818f (patch)
tree4fed1a0ae842542625090f72a5468ebceb058dd1 /emacs/.emacs.d/init.org
parent05c68a9e2e2597c3789e5c1529b9d14db07dc755 (diff)
downloaddotfiles-4baea6bdac339d2b329b84eb40d22a11c66f818f.tar.gz
dotfiles-4baea6bdac339d2b329b84eb40d22a11c66f818f.zip
Add electric-indent and electric pair modes to init.org
Diffstat (limited to 'emacs/.emacs.d/init.org')
-rw-r--r--emacs/.emacs.d/init.org59
1 files changed, 59 insertions, 0 deletions
diff --git a/emacs/.emacs.d/init.org b/emacs/.emacs.d/init.org
index 72128ce..8075ddc 100644
--- a/emacs/.emacs.d/init.org
+++ b/emacs/.emacs.d/init.org
@@ -955,6 +955,65 @@
(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
+
+* Automatically indent some modes
+
+ Some modes, not all, benefit from using =electric-indent-mode=. So
+ enable it locally for those modes.
+
+ #+BEGIN_SRC emacs-lisp
+ (add-hook 'scss-mode-hook #'electric-indent-local-mode)
+ #+END_SRC
+
+* Automatically pair in some modes
+
+ Almost all modes benefit from automatic delimiter pairing, but not
+ all modes are equal. =paredit= works awesomely for anything lisp-like,
+ but not so much for other modes, that's where =electric-pair-mode=
+ comes in. Unfortunately it has no local version, so I copied the
+ code from =electric-indent-local-mode= and changed it work with
+ =electric-pair-mode=.
+
+ #+BEGIN_SRC emacs-lisp
+ ;; Copied from electric.el, modified from `electric-indent-local-mode'.
+ (define-minor-mode oni:electric-pair-local-mode
+ "Toggle `electric-pair-mode' only in this buffer."
+ :variable (buffer-local-value 'electric-pair-mode (current-buffer))
+ (cond
+ ((eq electric-pair-mode (default-value 'electric-pair-mode))
+ (kill-local-variable 'electric-pair-mode))
+ ((not (default-value 'electric-pair-mode))
+ ;; Locally enabled, but globally disabled.
+ (electric-pair-mode 1) ; Setup the hooks.
+ (setq-default electric-pair-mode nil) ; But keep it globally disabled.
+ )))
+ #+END_SRC
+
+ And then we just enable it for the interesting modes.
+
+ #+BEGIN_SRC emacs-lisp
+ (add-hook 'scss-mode-hook #'oni:electric-pair-local-mode)
+ #+END_SRC
+
* Load custom file
I don't really use the Emacs customization interface much, but I