Skip to content

Commit

Permalink
shore up jump heuristics
Browse files Browse the repository at this point in the history
makes them work in magit buffers

Signed-off-by: Psionik K <[email protected]>
  • Loading branch information
psionic-k committed Oct 30, 2023
1 parent f22ffd2 commit c046341
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions lisp/erk.el
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,13 @@ Only understands project root or root/lisp."
;; TODO quite redundant
(defun erk--project-root-feature-file ()
"Return the path of the root feature for the project."
(let* ((project-elisp-dir (erk--project-elisp-dir))
(package-files (directory-files project-elisp-dir nil (rx ".el" string-end)))
(package-files (->> package-files
(--reject (string-match-p (rx "autoloads.el" string-end) it))))
(root-feature-file (car (sort package-files #'string<))))
(concat project-elisp-dir "/" root-feature-file)))
(if-let* ((project-elisp-dir (erk--project-elisp-dir))
(package-files (directory-files project-elisp-dir nil (rx ".el" string-end)))
(package-files (->> package-files
(--reject (string-match-p (rx "autoloads.el" string-end) it))))
(root-feature-file (car (sort package-files #'string<))))
(concat project-elisp-dir "/" root-feature-file)
(user-error "%s doesn't seem to be an elisp project" (erk--project-root))))

;; Note, these functions are kind of redundant, but just want to consume
;; consistent interfaces internally.
Expand Down Expand Up @@ -340,17 +341,20 @@ for development, and being lenient for degenerate cases is fine."
(defun erk-jump-features ()
"Jump between the corresponding package and test features."
(interactive)
(let ((file (file-name-nondirectory (buffer-file-name (current-buffer)))))
(if (string-match-p ".*\\.el" file)
(find-file (if (string-match "\\(.*\\)-tests?\\.el" file)
(let* ((filepath (buffer-file-name (current-buffer)))
(filename (when filepath
(file-name-nondirectory filepath))))
(if (and filename
(string-match-p ".*\\.el" filename))
(find-file (if (string-match "\\(.*\\)-tests?\\.el" filename)
(concat (erk--lisp-directory)
(match-string 1 file) ".el")
(concat (erk--test-directory)
(and (string-match "\\(.*\\)\\.el" file)
(match-string 1 file))
(and (string-match "\\(.*\\)\\.el" filename)
(match-string 1 filename))
"-test.el")))
;; fallback, go to root feature, convenient shortcut
;; back into elisp files
;; fallback, go to root feature, convenient shortcut
;; back into elisp files
(find-file (erk--project-root-feature-file)))))

(defun erk--insert-test (fun buffer)
Expand Down

0 comments on commit c046341

Please sign in to comment.