Created
October 20, 2013 18:12
-
-
Save seh/7073195 to your computer and use it in GitHub Desktop.
Emacs Lisp function to "underline" the current line.
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
;; a la Graham's "On Lisp" | |
(defmacro nonzero-bind (var exp &rest body) | |
`(let ((,var ,exp)) | |
(unless (zerop ,var) | |
,@body))) | |
(defun underline-current (&optional str) | |
"Insert multiple copies of STR under and of same width as current line. | |
The default underline string is =. | |
With a prefix argument, prompt for the underline string." | |
(interactive (list (if current-prefix-arg | |
(read-string "Underline string: " | |
"=")))) | |
(save-excursion | |
(end-of-line) | |
(nonzero-bind len (current-column) | |
(newline) | |
(let* ((str (or str "=")) | |
(slen (length str))) | |
(cond | |
((zerop slen) | |
(error "Underline string must be at least one character.")) | |
((= 1 slen) | |
(insert-char (aref str 0) len)) | |
(t | |
(dotimes (i (/ len slen)) | |
(insert str)) | |
(nonzero-bind rem (mod len slen) | |
(insert-string (substring str 0 rem))))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment