An assortment of emacs hacks

I use emacs as my editor, in the sense of "the binary I run is called emacs". I do not use it in anything resembling the intended way, and my init.el would horrify both emacs and vim people equally.

It's not really worth sharing in full, because it's kind of a conglomeration of my own muscle memory from all the other editors I've used, but these are some of the interesting parts.

Automatic wrapping for isearch

; ... on isearch-repeat-{forward,reverse}
(setq isearch-wrap-pause 'no-ding)

; ... while typing
(defvar in-isearch-wrapping-bodge nil)
(defun isearch-wrapping-bodge ()
    (if (and (not isearch-success) (not in-isearch-wrapping-bodge))
        (progn
          (setq in-isearch-wrapping-bodge t)
          (isearch-repeat (if isearch-forward 'forward))
          (setq in-isearch-wrapping-bodge nil))))
(advice-add 'isearch-search-and-update :after #'isearch-wrapping-bodge)

; bug fix for backspace in isearch caused by ^
(define-key isearch-mode-map [remap isearch-delete-char] 'isearch-del-char)

Muscle memory compatibility for people who used vim a lot but never got, like, really into vim

; Obviously, this only works if you're using some sort of modal editing thing, or don't ever need to type :.
(bind ":" #'execute-extended-command)
(defun w () (interactive) (save-buffer))
(defun q () (interactive) (kill-this-buffer))
(defun wq () (interactive) (w) (q))

Stop indenting text to word boundaries

; This is the thing where if you have some text and indent the next line
;      it indents up to the second word, even if
;         that's not a multiple of the tab width, and then
;                continues indenting to weird and inconsistent levels
;                          as if anyone writes English text
;                             like this.
; This probably breaks something somewhere. I don't care, it's a bad feature and should not exist.
(defalias 'indent-relative 'tab-to-tab-stop)

Single-file editing mode

In emacs:

(setq kill-buffer-hook nil)
(add-hook 'kill-buffer-hook (lambda ()
                              (if (and (getenv "EMACS_SINGLE_FILE_EDIT") (buffer-file-name))
                                  (kill-emacs))))

In a script somewhere in $PATH, named emacs1 (aliasing this won't work, because things that aren't the shell trying to exec $EDITOR won't know about the alias):

#!/bin/sh
EMACS_SINGLE_FILE_EDIT=1 emacs $*

And in your environment:

export EDITOR=emacs1

This makes e.g. git commit open an emacs instance that automatically goes away when you :wq.