@@ -1539,12 +1539,43 @@ Pass ORIG-FN, BEG, END, TYPE, ARGS."
1539
1539
1540
1540
(setq enable-recursive-minibuffers t)
1541
1541
1542
+ (defun common-directory-levels (path1 path2)
1543
+ "Return the number of common directory components between PATH1 and PATH2."
1544
+ (let ((dirs1 (split-string (file-name-directory (expand-file-name path1)) "/" t))
1545
+ (dirs2 (split-string (file-name-directory (expand-file-name path2)) "/" t)))
1546
+ (cl-loop for d1 in dirs1
1547
+ for d2 in dirs2
1548
+ while (string= d1 d2)
1549
+ count 1)))
1550
+
1551
+ (defun sort-files-by-closeness (files target-file)
1552
+ "Sort FILES based on how close each file is to TARGET-FILE.
1553
+ Closeness is determined by the number of common directory levels."
1554
+ (let* ((target-dir (file-name-directory target-file))
1555
+ (files-with-levels
1556
+ (cl-loop for file in files
1557
+ unless (string= file target-file)
1558
+ collect (cons file (common-directory-levels file target-dir)))))
1559
+ (mapcar #'car
1560
+ (sort files-with-levels
1561
+ (lambda (a b) (> (cdr a) (cdr b)))))))
1562
+
1563
+ (defun meain/sort-proximity (files)
1564
+ (let* ((prev-buffer (window-buffer (minibuffer-selected-window)))
1565
+ (current-file (if (buffer-file-name prev-buffer)
1566
+ (buffer-file-name prev-buffer)
1567
+ "."))
1568
+ (project-path (expand-file-name (project-root (project-current))))
1569
+ (current-file-sans-project (string-remove-prefix project-path current-file)))
1570
+ (sort-files-by-closeness files current-file-sans-project)))
1571
+
1542
1572
(vertico-multiform-mode)
1543
1573
(setq vertico-multiform-commands
1544
1574
'((consult-ripgrep buffer indexed)
1545
1575
(consult-xref buffer indexed)
1546
1576
(eglot-find-implementation indexed) ;; TODO: change to vertical
1547
1577
(consult-imenu buffer)
1578
+ (project-find-file flat (vertico-sort-function . meain/sort-proximity))
1548
1579
(xref-find-references buffer)
1549
1580
(meain/imenu-or-eglot buffer)
1550
1581
(tree-jump-search buffer)
0 commit comments