Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
jfaz1 committed Mar 2, 2025
1 parent a2dd7af commit c84653c
Showing 1 changed file with 14 additions and 22 deletions.
36 changes: 14 additions & 22 deletions src/commands/project.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,6 @@
(defvar *respect-gitignore* t
"If non-nil, project-find-file will respect .gitignore files.")

(defun git-repository-p (pathname)
(let ((subdirectories (list-subdirectories pathname)))
(member (uiop:merge-pathnames*
(add-directory-separator ".git") pathname)
subdirectories
:test #'equal)))

(defun list-project-files-git (directory)
"List all files in a git project using git ls-files."
(handler-case
Expand Down Expand Up @@ -178,21 +171,20 @@
(project-root (find-root cwd))
(root (or project-root cwd)))
(uiop:with-current-directory (root)
(let ((filename
(if (and *respect-gitignore* (git-repository-p root))
;; In a git repo and respecting gitignore, use git ls-files
(let ((files (list-project-files-git root)))
(if files
(prompt-for-string
"Find file: "
:completion-function (lambda (x)
(completion-strings x files))
:test-function (lambda (name)
(member name files :test #'string=)))
;; Fallback if ls-files fails
(prompt-for-files-recursively)))
;; Use regular prompt
(prompt-for-files-recursively))))
(let* ((use-git-ls (and *respect-gitignore*
(uiop:directory-exists-p (uiop:merge-pathnames* ".git/" root))))
(git-files (when use-git-ls (list-project-files-git root)))
(filename
(if (and use-git-ls git-files)
;; In a git repo and respecting gitignore, use git ls-files
(prompt-for-string
"Find file: "
:completion-function (lambda (x)
(completion-strings x git-files))
:test-function (lambda (name)
(member name git-files :test #'string=)))
;; Fallback
(prompt-for-files-recursively))))
(when filename
(let* ((absolute-filename (merge-pathnames filename root))
(buffer (execute-find-file *find-file-executor*
Expand Down

0 comments on commit c84653c

Please sign in to comment.