Commit a1b49f3b authored by Basil L. Contovounesios's avatar Basil L. Contovounesios
Browse files

Fix last change to format-spec

* doc/lispref/text.texi (Interpolated Strings): Use @result and fix
typos.
* lisp/format-spec.el: Avoid loading subr-x at runtime.
(format-spec--parse-modifiers): Optimize slightly.
parent b728620a
Pipeline #2500 passed with stage
in 67 minutes and 50 seconds
......@@ -4655,11 +4655,11 @@ Here's a trivial example:
(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}
......@@ -4684,7 +4684,7 @@ If the length needs to limited, remove characters from the left.
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,
......
......@@ -24,7 +24,8 @@
;;; 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.
......@@ -118,8 +119,7 @@ where they are, including \"%%\" strings."
(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)
......@@ -129,9 +129,8 @@ where they are, including \"%%\" strings."
(?- :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.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment