Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Emacs Lisp function to "underline" the current line.
;; a la Graham's "On Lisp"
(defmacro nonzero-bind (var exp &rest body)
`(let ((,var ,exp))
(unless (zerop ,var)
(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: "
(nonzero-bind len (current-column)
(let* ((str (or str "="))
(slen (length str)))
((zerop slen)
(error "Underline string must be at least one character."))
((= 1 slen)
(insert-char (aref str 0) len))
(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