aboutsummaryrefslogtreecommitdiff
path: root/compat-28.el
diff options
context:
space:
mode:
authorDaniel Mendler <mail@daniel-mendler.de>2023-01-05 08:14:44 +0100
committerDaniel Mendler <mail@daniel-mendler.de>2023-01-05 08:14:44 +0100
commit92121f59348c8a6321d87bbefa2e4bb4517f14c2 (patch)
tree46544a91c13485b20ab4f863d07824e6f1fd7e0c /compat-28.el
parentc0cc3ba86b2bb3b217cb1dacf80e96fca8d7dc8e (diff)
Fix file-name-concat
Diffstat (limited to 'compat-28.el')
-rw-r--r--compat-28.el23
1 files changed, 13 insertions, 10 deletions
diff --git a/compat-28.el b/compat-28.el
index b60720c..a799972 100644
--- a/compat-28.el
+++ b/compat-28.el
@@ -85,23 +85,26 @@ issues are inherited."
;;;; Defined in fileio.c
-(compat-defun file-name-concat (directory &rest components) ;; <UNTESTED>
+(compat-defun file-name-concat (directory &rest components) ;; <OK>
"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."
- (let ((seperator (eval-when-compile
+ (let ((separator (eval-when-compile
(if (memq system-type '(ms-dos windows-nt cygwin))
"\\" "/")))
- (last (if components (car (last components)) directory)))
- (mapconcat (lambda (part)
- (if (eq part last) ;the last component is not modified
- last
- (replace-regexp-in-string
- (concat seperator "+\\'") "" part)))
- (cons directory components)
- seperator)))
+ (components (delq nil
+ (mapcar (lambda (x) (and (not (equal "" x)) x))
+ (cons directory components))))
+ (result ""))
+ (while components
+ (let ((c (pop components)))
+ (setq result (concat result c
+ (and components
+ (not (string-suffix-p separator c))
+ separator)))))
+ result))
;;;; Defined in alloc.c