Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compilation-find-file advice handling of directory #1691

Merged
merged 1 commit into from
Aug 10, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 12 additions & 18 deletions projectile.el
Original file line number Diff line number Diff line change
Expand Up @@ -4334,24 +4334,18 @@ If the prefix argument SHOW_PROMPT is non nil, the command can be edited."
(ring-insert command-history executed-command))))

(defun compilation-find-file-projectile-find-compilation-buffer (orig-fun marker filename directory &rest formats)
"Try to find a buffer for FILENAME, if we cannot find it,
fallback to the original function."
(when (and (not (file-exists-p (expand-file-name filename)))
(projectile-project-p))
(let* ((root (projectile-project-root))
(dirs (cons "" (projectile-current-project-dirs)))
(new-filename (car (cl-remove-if-not
#'file-exists-p
(mapcar
(lambda (f)
(expand-file-name
filename
(expand-file-name f root)))
dirs)))))
(when new-filename
(setq filename new-filename))))

(apply orig-fun `(,marker ,filename ,directory ,@formats)))
"Advice around compilation-find-file. We enhance its functionality by
appending the current project's directories to its search path. This way
when filenames in compilation buffers can't be found by compilation's
normal logic they are searched for in project directories."
(let* ((root (projectile-project-root))
(compilation-search-path
(if (projectile-project-p)
(append compilation-search-path (list root)
(mapcar (lambda (f) (expand-file-name f root))
(projectile-current-project-dirs)))
compilation-search-path)))
(apply orig-fun `(,marker ,filename ,directory ,@formats))))

(defun projectile-open-projects ()
"Return a list of all open projects.
Expand Down