summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp/subr-x.el
diff options
context:
space:
mode:
authorLars Ingebrigtsen <larsi@gnus.org>2020-12-22 06:59:25 +0100
committerLars Ingebrigtsen <larsi@gnus.org>2020-12-22 06:59:25 +0100
commit051d8f75350e54009180cc2fa5e5f86c92db1e13 (patch)
tree152ba517b0220a4f6fb0d6716a25991e9d119cb1 /lisp/emacs-lisp/subr-x.el
parent9480169f1b8a27ed61db0913989c9a81339ccd9d (diff)
downloademacs-051d8f75350e54009180cc2fa5e5f86c92db1e13.tar.gz
emacs-051d8f75350e54009180cc2fa5e5f86c92db1e13.tar.bz2
emacs-051d8f75350e54009180cc2fa5e5f86c92db1e13.zip
Make string-pad take an optional START parameter
* lisp/emacs-lisp/subr-x.el (string-pad): Alter the calling convention.
Diffstat (limited to 'lisp/emacs-lisp/subr-x.el')
-rw-r--r--lisp/emacs-lisp/subr-x.el14
1 files changed, 8 insertions, 6 deletions
diff --git a/lisp/emacs-lisp/subr-x.el b/lisp/emacs-lisp/subr-x.el
index b79482fd4b3..dc046c3d76a 100644
--- a/lisp/emacs-lisp/subr-x.el
+++ b/lisp/emacs-lisp/subr-x.el
@@ -322,7 +322,7 @@ The boundaries that match REGEXP are included in the result."
(push (substring string start-substring) result)
(nreverse result))))
-(defun string-pad (string length &optional padding)
+(defun string-pad (string length &optional padding start)
"Pad STRING to LENGTH using PADDING.
If PADDING is nil, the space character is used. If not nil, it
should be a character.
@@ -330,16 +330,18 @@ should be a character.
If STRING is longer than the absolute value of LENGTH, no padding
is done.
-If LENGTH is positive, the padding is done to the end of the
-string, and if it's negative, padding is done to the start of the
+If START is nil (or not present), the padding is done to the end
+of the string, and non-nil, padding is done to the start of the
string."
- (let ((pad-length (- (abs length) (length string))))
+ (unless (natnump length)
+ (signal 'wrong-type-argument (list 'natnump length)))
+ (let ((pad-length (- length (length string))))
(if (< pad-length 0)
string
- (concat (and (< length 0)
+ (concat (and start
(make-string pad-length (or padding ?\s)))
string
- (and (> length 0)
+ (and (not start)
(make-string pad-length (or padding ?\s)))))))
(defun string-chop-newline (string)