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

Always search for the full package name in existing IMPORT-FROMs #593

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions contrib/sly-package-fu.el
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,15 @@ symbol in the Lisp image if possible."
;;

(defun sly-package-fu--search-import-from (package)
"Moves point to the end of the package name corresponding to
the (:IMPORT-FROM) for package. If no such import-from exists,
returns nil."
(let* ((normalized-package (sly-package-fu--normalize-name package))
(regexp (format "(:import-from[ \t']*\\(:\\|#:\\)?%s"
(regexp (format "(:import-from[ \t']*\\(:\\|#:\\)?%s[)[:space:]]"
(regexp-quote normalized-package))))
(re-search-forward regexp nil t)))
(when (re-search-forward regexp nil t)
(goto-char (- (point) 1))
(point))))


(defun sly-package-fu--create-new-import-from (package symbol)
Expand Down
58 changes: 56 additions & 2 deletions test/sly-package-fu-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,29 @@
:position
:find))
(in-package :foo))
bknr.datastore-dummy::position))
(let ((file (make-temp-file "sly-package-fu--fixture")))
bknr.datastore-dummy::position)
(((defpackage :foo
(:import-from :bar/car :find))
(in-package :foo))
((defpackage :foo
(:import-from :bar/car :find)
(:import-from :bar :position))
(in-package :foo))
bar::position)
(((defpackage :foo
(:import-from :bar))
(in-package :foo))
((defpackage :foo
(:import-from :bar :position))
(in-package :foo))
bar::position))
(let ((file (make-temp-file "sly-package-fu--fixture"))
(sly-export-symbol-representation-auto nil)
(sly-export-symbol-representation-function
;; For the purpose of these tests, reading back the
;; #:.. style symbols breaks equality, since they are
;; uninterned.
(lambda (n) (format ":%s" n))))
(with-temp-buffer
(find-file file)
(lisp-mode)
Expand All @@ -25,11 +46,44 @@
;; FIXME: using internal implementation detail
(sly-package-fu--add-or-update-import-from-form
(pp-to-string symbol-to-import))

(should (equal final
(cl-loop initially (goto-char (point-min))
for f = (ignore-errors (read (current-buffer)))
while f collect f))))))

(define-sly-ert-test package-fu-jumps-to-import-from-happy-path ()
(with-temp-buffer
(insert "(defpackage :foo (:import-from #:bar #:car))")
;; Expect to be here:........................^
(goto-char (point-min))
(sly-package-fu--search-import-from "bar")
(should (equal 37 (point)))))

(define-sly-ert-test package-fu-jumps-to-import-from-with-new-line ()
(with-temp-buffer
(insert "(defpackage :foo (:import-from #:bar\n#:car))")
;; Expect to be here:........................^
(goto-char (point-min))
(sly-package-fu--search-import-from "bar")
(should (equal 37 (point)))))

(define-sly-ert-test package-fu-does-not-jump-to-package-prefix ()
(with-temp-buffer
(insert "(defpackage :foo (:import-from #:barcelona\n#:car))")
(goto-char (point-min))
(should
(equal nil
(sly-package-fu--search-import-from "bar")))
(should (equal 1 (point)))))

(define-sly-ert-test package-fu-jump-to-end-even-when-closing-parenthesis ()
(with-temp-buffer
(insert "(defpackage :foo (:import-from #:bar))")
;; Expect to be here:........................^
(goto-char (point-min))
(sly-package-fu--search-import-from "bar")
(should (equal 37 (point)))))


(provide 'sly-package-fu-tests)