Skip to content

Instantly share code, notes, and snippets.

@agumonkey
Last active July 18, 2021 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agumonkey/fd5cf9f876bfd369164423f788b964bc to your computer and use it in GitHub Desktop.
Save agumonkey/fd5cf9f876bfd369164423f788b964bc to your computer and use it in GitHub Desktop.
zap-to-over
"
Bline lineM line lineE
K C D
D = C + BM - KC
asks for a template
finds M and yields M - C as offset
TODO: only moves to the first match.
TODO: iron out error cases
"
(defvar DEBUG t)
(defun debug (fmt &rest args)
(when DEBUG (apply #'message (cons fmt args))))
(defun zap-to-over (s &optional space)
(interactive "s> ")
(let* ((space (or space ?\s))
(c (point))
(b (line-beginning-position 0))
(k (line-beginning-position 1))
(m (save-excursion
(goto-char b)
(when (re-search-forward s nil t)
(- (point) (length s))))))
(if m
(let* ((bm (- m b))
(kc (- c k))
(np (+ c (- bm kc))))
(progn
(debug "< %s (c:%d bm:%d kc:%d np:%d)" s c bm kc np)
(insert (make-string (- np (point)) space))))
(message "no match"))))
(defalias 'align-to #'zap-to-over)
(defalias 'align-below #'zap-to-over)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment