开发者

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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜