emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Aaron L. Zeng" <me@bcc32.com>
To: emacs-orgmode@gnu.org
Cc: "Aaron L. Zeng" <me@bcc32.com>
Subject: [PATCH] lisp/org-agenda.el: Fix void-function string-pad in Emacs <28.1
Date: Mon, 23 Jan 2023 21:52:59 -0500	[thread overview]
Message-ID: <20230124025259.1301063-1-me@bcc32.com> (raw)

* 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	other threads:[~2023-01-24  2:54 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-24  2:52 Aaron L. Zeng [this message]
2023-01-24  9:23 ` [PATCH] lisp/org-agenda.el: Fix void-function string-pad in Emacs <28.1 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230124025259.1301063-1-me@bcc32.com \
    --to=me@bcc32.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).