Skip to content

Commit 5a0693f

Browse files
committed
Fix destructive sort bug in clojure-project-root-path
`sort' in Emacs Lisp is destructive — the original list variable may no longer point to the head of the sorted result. The fallback `(car choices)' after `(sort choices ...)' could return the wrong directory. Capture the sort result in a binding instead.
1 parent e7d8b57 commit 5a0693f

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

clojure-mode.el

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2148,10 +2148,12 @@ Return nil if not inside a project."
21482148
(or (locate-dominating-file dir-name clojure-preferred-build-tool)
21492149
(car (sort choices #'file-in-directory-p)))
21502150
;; Otherwise, prefer candidates that contain a .git directory.
2151-
(or (car (seq-filter (lambda (dir)
2152-
(file-directory-p (expand-file-name ".git" dir)))
2153-
(sort choices #'file-in-directory-p)))
2154-
(car choices))))))
2151+
;; Note: `sort' is destructive, so we must capture its return value.
2152+
(let ((sorted (sort choices #'file-in-directory-p)))
2153+
(or (car (seq-filter (lambda (dir)
2154+
(file-directory-p (expand-file-name ".git" dir)))
2155+
sorted))
2156+
(car sorted)))))))
21552157

21562158
(defun clojure-project-relative-path (path)
21572159
"Denormalize PATH by making it relative to the project root."

0 commit comments

Comments
 (0)