Last active
July 18, 2021 16:51
-
-
Save agumonkey/fd5cf9f876bfd369164423f788b964bc to your computer and use it in GitHub Desktop.
zap-to-over
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" | |
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