From 433c9e344d46971070342f4d423c12064477f8ce Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Fri, 5 Aug 2022 17:19:04 +0200 Subject: [PATCH] feat(lib): backport file-name-concat from 28.1 May replace doom-path in the future. --- lisp/doom-lib.el | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lisp/doom-lib.el b/lisp/doom-lib.el index f01ebd5a4..e1ee9faa3 100644 --- a/lisp/doom-lib.el +++ b/lisp/doom-lib.el @@ -813,5 +813,23 @@ This function accepts any number of ARGUMENTS, but ignores them. Also see `ignore'." t)) +;; Introduced in 28.1 +(unless (fboundp 'file-name-concat) + (defun 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." + (mapconcat + #'identity + (save-match-data + (cl-loop for str in (cons directory components) + when (and str (/= 0 (length str)) + (string-match "\\(.+\\)/?" str)) + collect (match-string 1 str))) + "/"))) + (provide 'doom-lib) ;;; doom-lib.el ends here