(format-spec "su - %u %l"
`((?u . ,(user-login-name))
(?l . "ls")))
-=> "su - foo ls"
+ @result{} "su - foo ls"
@end example
In addition to allowing padding/limiting to a certain length, the
-following modifiers are can be used:
+following modifiers can be used:
@table @asis
@item @samp{0}
Same as previous, but remove characters from the right.
@end table
-If contradictory modifiers are used (for instance, both upper- and
+If contradictory modifiers are used (for instance, both upper and
lower case), then what happens is undefined.
As an example, @samp{"%<010b"} means ``insert the @samp{b} expansion,
;;; Code:
-(require 'subr-x)
+(eval-when-compile
+ (require 'subr-x))
(defun format-spec (format specification &optional only-present)
"Return a string based on FORMAT and SPECIFICATION.
(concat padding text)))))
(defun format-spec--parse-modifiers (modifiers)
- (let ((elems nil))
- (mapc (lambda (char)
+ (mapcan (lambda (char)
(when-let ((modifier
(pcase char
(?0 :zero-pad)
(?- :right-pad)
(?< :chop-left)
(?> :chop-right))))
- (push modifier elems)))
- modifiers)
- elems))
+ (list modifier)))
+ modifiers))
(defun format-spec-make (&rest pairs)
"Return an alist suitable for use in `format-spec' based on PAIRS.