emacs: pad justified string with character
Is there an emacs command to pad a justified string with a character? Specifically, I'd like to be able开发者_JS百科 to take
;; Foobar
and get
;; ===================================Foobar====================================
where Foobar is centered in a field of width 77. For clarity, I produced the output above via the python code ";; {:=^77}".format("Foobar")
.
I don't know of any existing function to do that, but it's easy to write one:
(defun center-string-in-char (str len char)
(store-substring (make-string len char) (/ (- len (length str)) 2) str))
Now (center-string-in-char "Foobar" 77 ?=)
produces your example string (minus the leading ";; "
which you can add yourself).
精彩评论