开发者

emacs: pad justified string with character

开发者 https://www.devze.com 2023-03-15 20:29 出处:网络
Is there an emacs command to pad a justified string with a character? Specifically, I\'d like to be able开发者_JS百科 to take

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

精彩评论

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