-
-
Notifications
You must be signed in to change notification settings - Fork 46
/
org-gtd-backward-compatibility.el
75 lines (56 loc) · 2.3 KB
/
org-gtd-backward-compatibility.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
;;; org-gtd-backward-compatibility.el --- Functions added in later versions of emacs -*- lexical-binding: t; coding: utf-8 -*-
;;
;; Copyright © 2019-2023 Aldric Giacomoni
;; Author: Aldric Giacomoni <trevoke@gmail.com>
;; This file is not part of GNU Emacs.
;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this file. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;;
;; Functions that don't exist in older vanilla emacsen
;;
;;; Code:
;;;; Requirements
(require 'subr-x)
;;;; Functions
;;;;; Public
;; this was added in emacs 28.1
(unless (fboundp 'ensure-list)
(defalias 'ensure-list 'org-gtd--ensure-list))
;; this was added in emacs 28.1
(unless (fboundp 'string-pad)
(defalias 'string-pad 'org-gtd--string-pad))
;;;;; Private
(defun org-gtd--ensure-list (object)
"Return OBJECT as a list.
If OBJECT is already a list, return OBJECT itself. If it's
not a list, return a one-element list containing OBJECT."
(if (listp object)
object
(list object)))
(defun org-gtd--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)))))))
;;;; Footer
(provide 'org-gtd-backward-compatibility)
;;; org-gtd-backward-compatibility.el ends here