With the folks from Nextjournal we’ve been getting really excited about Spacemacs lately. There are a few Cursive users and one Atom user holding out, but the rest of us have all moved to Spacemacs. This includes old vim hands and people who had been using Emacs for years.
It’s super nice how polished and complete Spacemacs is, but still anything that is based on Emacs is meant to be tweaked. This thread is for sharing those tweaks.
The rules
one tweak per post
share up to 10 lines of emacs lisp code (we’re looking for tweaks, not for new packages)
explain what it does, how you use it, and why you like it
This way files will show line numbers relative to the position of the cursor, e.g. here I’m on line 32, so lines above and below 32 show how far away they are from 32.
I know it’s a weird mix of smartparens and built-in Emacs commands. I don’t like the SPC k transient state for navigation, though I can’t articulate why.
One more tweak. I never really understood how the system clipboard interacts with Vim’s y or p operations, never mind Emacs’s kill-ring. simpleclip simplifies things, by allowing you to copy/paste/cut using Cmd-C/V/X (Super on Linux), like most other editors. With simpclip, the kill ring isn’t by touched by operations involving the system clipboard — both clipboards are kept separate.
dotspacemacs-additional-packages '(simpleclip)
; ... in dotspacemacs/user-config
(require 'simpleclip)
(simpleclip-mode 1)
Assume the point is on a paren. v % will highlight the form you want to comment. Then in command mode you can use this binding (eg fd SPC ocv) to comment that form without needing to manually manage any enclosing forms.
Here’s a tweak I’d like to make, but I’m not sure what the right way is.
In lisp-mode (SPC k .) comman isn’t being used, I’d like to bind it to the major mode leader, as in normal mode, so that I can e.g. evaluate a form without having to switch modes.
Anyone know how you would do that? I guess it’s using evil-global-set-key as @pesterhazy demonstrated, but how do I figure out which keymap , is bound to? describe-key doesn’t really help since it’s a prefix key.
Does anyone have a shortcut which sends a (reset) expression to the repl.
I’m currently using integrant.repl and every time I make a change I have to switch to the REPL and type (reset) to reload the system. It would be nice if I had a keyboard shortcut to do that.
I don’t remember where I first saw this tip, but as a simple way to globally redefine keys, create a custom minor-mode with its own keymap.
For example, I like to have <esc> remapped to <ctrl-s>everywhere. I tried to do this before by picking out each keymap and adding the new binding, but even after something like 10 custom keymap bindings, there was always still more that were missing (there was always one of the company-mode maps I couldn’t seem to figure out).
This custom minor-mode hack fixed all of them in less lines, and is (or should be) guaranteed to work for whatever new keymaps any new layers bring along (and also makes sure that <ctrl-h> sends a backspace, as is right and proper):
(defvar custom-keys-minor-mode-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "C-s") (kbd "<escape>"))
(define-key map (kbd "C-h") (kbd "DEL"))
map)
"Minor mode for custom keymap.")
(define-minor-mode custom-keys-minor-mode
"A minor mode to allow for global keymap overrides."
:init-value t
:lighter nil)
(custom-keys-minor-mode 1)
The exact stop/start or suspend/resume functions depend on your setup. If you’re using Component with reloaded.repl then use reloaded.repl/suspend and reloaded.repl/resume. For integrant you might have to define your own wrappers in user.clj.