diff --git a/lisp/erk.el b/lisp/erk.el index de07c84..8252eab 100644 --- a/lisp/erk.el +++ b/lisp/erk.el @@ -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. @@ -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)