branch: elpa/helm
commit 8ba77082fd8d6e194b798e966ca139d054a0fbef
Author: Thierry Volpiatto <[email protected]>
Commit: Thierry Volpiatto <[email protected]>
Fix helm-common dir with files not coming from same drive
---
helm-files.el | 8 ++++++--
helm-lib.el | 26 ++++++++++++++++++++++----
2 files changed, 28 insertions(+), 6 deletions(-)
diff --git a/helm-files.el b/helm-files.el
index c81007183f..5a41385423 100644
--- a/helm-files.el
+++ b/helm-files.el
@@ -1284,8 +1284,12 @@ ACTION can be `rsync' or any action supported by
`helm-dired-action'."
(length ifiles)
(if (memq action '(symlink relsymlink hardlink))
"from" "to")))
- (cdir (and (eq action 'compress)
- (helm-common-dir ifiles)))
+ (cdir (helm-aand
+ (eq action 'compress)
+ (helm-common-dir ifiles)
+ (if (stringp it)
+ it
+ (error "Try to compress files not belonging to same
drive"))))
helm-ff--move-to-first-real-candidate
helm-display-source-at-screen-top ; prevent setting window-start.
helm-ff-auto-update-initial-value
diff --git a/helm-lib.el b/helm-lib.el
index 5b78ade8b9..68710a7cd1 100644
--- a/helm-lib.el
+++ b/helm-lib.el
@@ -1895,12 +1895,30 @@ Take same args as `directory-files'."
;; at least 27.1, see bug#2662.
(apply #'directory-files directory args)))
-(defun helm-common-dir (files)
- "Return the longest common directory path of FILES list"
+(defun helm-common-dir-1 (files)
+ "Find the common directories of FILES."
(cl-loop with base = (car files)
+ with others = nil
for file in files
- do (setq base (fill-common-string-prefix base file))
- finally return (file-name-directory base)))
+ for cpart = (fill-common-string-prefix base file)
+ if cpart
+ do (setq base cpart)
+ else do (push file others)
+ finally return (if (and others base)
+ (append (list (directory-file-name base))
+ (let ((res (helm-common-dir-1 others)))
+ (if (listp res)
+ res
+ (list res))))
+ (list (and base (directory-file-name base))))))
+
+(defun helm-common-dir (files)
+ "Return the longest common directory path of FILES list.
+If FILES are not all common to the same drive (Windows) a list of
+common directory is returned."
+ (let ((result (helm-common-dir-1 files)))
+ (if (cdr result) result (car result))))
+
;;; helm internals
;;