Skip to content

Commit

Permalink
fix(workspace): make finding in directory work with embark
Browse files Browse the repository at this point in the history
The function called by embark for `project-find-file` always takes the
project root. This is why `wal-find-in-here` now sets a variable that
when present makes that function return the sub-directory instead.
  • Loading branch information
Walheimat committed Mar 25, 2024
1 parent 66543b7 commit dcec633
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
19 changes: 18 additions & 1 deletion lib/wal-workspace.org
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,23 @@ possible through =C-x 4 p o= which is a bit cumbersome).

(user-error "Project '%s' has no parent project (controlled by `wal-project-parent-project')" name))))

(defvar wal-project-find--directory nil)

(defun wal-project-find-relative-path-instead (_type target)
"Find TARGET in a sub-directory.

This is used by `wal-project-find-in-here'."
(when wal-project-find--directory
(cons 'file (expand-file-name target wal-project-find--directory))))

(defun wal-project-find-in-here (&optional include-all)
"Find a project file in the current directory.

If INCLUDE-ALL is t, don't ignore otherwise ignored fils."
(interactive "P")

(when-let ((project (project-current nil)))
(when-let ((project (project-current nil))
(wal-project-find--directory default-directory))

(project-find-file-in nil (list default-directory) project include-all)))

Expand Down Expand Up @@ -187,6 +197,10 @@ Root markers (how projects are found) and =vc= ignores are extended.
;; Allow setting custom names.
(put 'project-vc-name 'safe-local-variable #'stringp)

(advice-add
'embark--project-file-full-path :before-until
#'wal-project-find-relative-path-instead)

:custom
(project-vc-extra-root-markers '("pom.xml"
"package.json"
Expand Down Expand Up @@ -222,6 +236,9 @@ Root markers (how projects are found) and =vc= ignores are extended.
("M-h" . wal-project-find-file-other-window)))
#+END_SRC

#+RESULTS:
: wal-project-find-file-other-window

* Footer
:PROPERTIES:
:VISIBILITY: folded
Expand Down
9 changes: 9 additions & 0 deletions test/wal-workspace-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@

(should (equal (wal-project-local-value 'major-mode) 'text-mode)))))

(ert-deftest wal-project-find-relative-path-instead ()
:tags '(workspace)

(should-not (wal-project-find-relative-path-instead nil "test.el"))

(let ((wal-project-find--directory "/tmp/one"))

(should (string= "/tmp/one/test.el" (cdr (wal-project-find-relative-path-instead nil "test.el"))))))

(ert-deftest wal-project-find-in-here ()
:tags '(workspace user-facing)

Expand Down

0 comments on commit dcec633

Please sign in to comment.