emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] lisp/org-agenda.el: Fix void-function string-pad in Emacs <28.1
@ 2023-01-24  2:52 Aaron L. Zeng
  2023-01-24  9:23 ` Ihor Radchenko
  0 siblings, 1 reply; 6+ messages in thread
From: Aaron L. Zeng @ 2023-01-24  2:52 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: Aaron L. Zeng

* 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



^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-01-24 18:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-24  2:52 [PATCH] lisp/org-agenda.el: Fix void-function string-pad in Emacs <28.1 Aaron L. Zeng
2023-01-24  9:23 ` Ihor Radchenko
2023-01-24 16:30   ` Aaron Zeng
2023-01-24 17:47     ` Aaron Zeng
2023-01-24 18:21       ` Ihor Radchenko
2023-01-24 18:35         ` Aaron Zeng

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).