emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] lisp/org-agenda.el: Fix void-function string-pad in Emacs <28.1


From: Aaron L. Zeng
Subject: [PATCH] lisp/org-agenda.el: Fix void-function string-pad in Emacs <28.1
Date: Mon, 23 Jan 2023 21:52:59 -0500

* org-compat.el (org-string-pad): Add compatibility function
`org-string-pad' for `string-pad', introduced in Emacs 28.1.

* org-agenda.el (org-fix-agenda-info): Use `org-string-pad' rather
than `string-pad'.

Since this is more-or-less just copying string-pad's definition from
subr-x.el, I think this qualifies for TINYCHANGE.

TINYCHANGE
---
 lisp/org-agenda.el |  4 ++--
 lisp/org-compat.el | 21 +++++++++++++++++++++
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index 2d194ad34..4f0522086 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -3474,13 +3474,13 @@ This ensures the export commands can easily use it."
     (when (setq tmp (plist-get props 'date))
       (when (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
       (let ((calendar-date-display-form
-             '(year "-" (string-pad month 2 ?0 'left) "-" (string-pad day 2 ?0 
'left))))
+             '(year "-" (org-string-pad month 2 ?0 'left) "-" (org-string-pad 
day 2 ?0 'left))))
        (setq tmp (calendar-date-string tmp)))
       (setq props (plist-put props 'date tmp)))
     (when (setq tmp (plist-get props 'day))
       (when (integerp tmp) (setq tmp (calendar-gregorian-from-absolute tmp)))
       (let ((calendar-date-display-form
-             '(year "-" (string-pad month 2 ?0 'left) "-" (string-pad day 2 ?0 
'left))))
+             '(year "-" (org-string-pad month 2 ?0 'left) "-" (org-string-pad 
day 2 ?0 'left))))
        (setq tmp (calendar-date-string tmp)))
       (setq props (plist-put props 'day tmp))
       (setq props (plist-put props 'agenda-day tmp)))
diff --git a/lisp/org-compat.el b/lisp/org-compat.el
index 6c5085255..eb20d5baf 100644
--- a/lisp/org-compat.el
+++ b/lisp/org-compat.el
@@ -173,6 +173,27 @@ removed."
       (string-trim (replace-regexp-in-string blank " " string t t)
                    blank blank))))
 
+(if (fboundp 'string-pad)
+    (defalias 'org-string-pad #'string-pad)
+  ;; From Emacs subr-x.el.
+  (defun org-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.
+
+If STRING is longer than the absolute value of LENGTH, no padding
+is done.
+
+If START is nil (or not present), the padding is done to the end
+of the string, and if non-nil, padding is done to the start of
+the string."
+    (unless (natnump length)
+      (signal 'wrong-type-argument (list 'natnump length)))
+    (let ((pad-length (- length (length string))))
+      (cond ((<= pad-length 0) string)
+            (start (concat (make-string pad-length (or padding ?\s)) string))
+            (t (concat string (make-string pad-length (or padding ?\s))))))))
+
 (if (fboundp 'format-prompt)
     (defalias 'org-format-prompt #'format-prompt)
   ;; From Emacs minibuffer.el, inlining
-- 
2.38.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]