From a1b49f3bff5e104581b43ac5a9093a576f87f04b Mon Sep 17 00:00:00 2001 From: "Basil L. Contovounesios" Date: Sat, 20 Jul 2019 16:46:04 +0100 Subject: [PATCH] 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. --- doc/lispref/text.texi | 6 +++--- lisp/format-spec.el | 11 +++++------ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/doc/lispref/text.texi b/doc/lispref/text.texi index df9fce066f0..e73141faf4c 100644 --- a/doc/lispref/text.texi +++ b/doc/lispref/text.texi @@ -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, diff --git a/lisp/format-spec.el b/lisp/format-spec.el index 220cecd9b05..fec93ce83d9 100644 --- a/lisp/format-spec.el +++ b/lisp/format-spec.el @@ -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. -- 2.39.2