浏览代码

Fix compatibility for older Emacs versions

* lisp/org-compat.el (org-length>, org-file-name-concat): Add backward
compatibility for `length>' and `org-file-name-concat'.
Ihor Radchenko 4 年之前
父节点
当前提交
bc52c4d9ab
共有 1 个文件被更改,包括 27 次插入0 次删除
  1. 27 0
      lisp/org-compat.el

+ 27 - 0
lisp/org-compat.el

@@ -74,6 +74,33 @@
 
 ;;; Emacs < 28.1 compatibility
 
+(if (fboundp 'length>)
+    (defalias 'org-length> #'length>)
+  (defun org-length> (sequence length)
+    "Return non-nil if SEQUENCE is longer than LENGTH."
+    (> (length sequence) length)))
+
+(if (fboundp 'file-name-concat)
+    (defalias 'org-file-name-concat #'file-name-concat)
+  (defun org-file-name-concat (directory &rest components)
+    "Append COMPONENTS to DIRECTORY and return the resulting string.
+
+Elements in COMPONENTS must be a string or nil.
+DIRECTORY or the non-final elements in COMPONENTS may or may not end
+with a slash -- if they don't end with a slash, a slash will be
+inserted before contatenating."
+    (save-match-data
+      (mapconcat
+       #'identity
+       (delq nil
+             (mapcar
+              (lambda (str)
+                (when (and str (not (string-empty-p str))
+                           (string-match "\\(.+\\)/?" str))
+                  (match-string 1 str)))
+              (cons directory components)))
+       "/"))))
+
 (if (fboundp 'directory-empty-p)
     (defalias 'org-directory-empty-p #'directory-empty-p)
   (defun org-directory-empty-p (dir)