Function: f-common-parent
f-common-parent is a byte-compiled function defined in f.el.
Signature
(f-common-parent PATHS)
Documentation
Return the deepest common parent directory of PATHS.
Other relevant functions are documented in the f group.
Shortdoc
;; f
(f-common-parent '("foo/bar/baz" "foo/bar/qux" "foo/bar/mux"))
=> "foo/bar/"
(f-common-parent '("/foo/bar/baz" "/foo/bar/qux" "/foo/bax/mux"))
=> "/foo/"
(f-common-parent '("foo/bar/baz" "quack/bar/qux" "lack/bar/mux"))
=> ""
Source Code
;; Defined in ~/.emacs.d/elpa/f-20241003.1131/f.el
(defun f-common-parent (paths)
"Return the deepest common parent directory of PATHS."
(cond
((not paths) nil)
((not (cdr paths)) (f-parent (car paths)))
(:otherwise
(let* ((paths (-map 'f-split paths))
(common (caar paths))
(re nil))
(while (and (not (null (car paths))) (--all? (equal (car it) common) paths))
(setq paths (-map 'cdr paths))
(push common re)
(setq common (caar paths)))
(cond
((null re) "")
((and (= (length re) 1) (f-root-p (car re)))
(f-root))
(:otherwise
(concat (apply 'f-join (nreverse re)) "/")))))))