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

load-current-file! doesn't load that file's imports to psci's scope #28

Open
mpdairy opened this issue Jan 9, 2020 · 2 comments
Open

Comments

@mpdairy
Copy link

mpdairy commented Jan 9, 2020

It would be nice if, when you loaded a file, all the imports in the file would be in scope in the repl, so you could access anything that code in that file could also access. So if it imported Prelude, then when you loaded that file, all the functions in prelude would be available to use. However, it seems to only load the functions and types that are declared within that actual module. Is there a way to do that?

@shaunplee
Copy link

shaunplee commented Dec 29, 2020

@mpdairy I ran into the same annoyance and hacked together this bit of elisp, which seems to do what we both want, although I've barely tested it and it may have some unintended side effects:

(use-package psci
  :hook (purescript-mode . inferior-psci-mode)
  :config
  (defun spl/psci-send-import-lines! ()
    (interactive)
    (save-excursion
      (goto-char (point-min))
      (while (re-search-forward
              (rx (and line-start "import" (1+ space)
                       (group (and (1+ (any word "."))))
                       (opt (1+ (any space "\n")) "hiding")
                       (opt (1+ (any space "\n"))
                            "(" (0+ (any word "," space "\n")) ")")
                       (opt (1+ (any space "\n")) "as" (1+ space)
                            (group (and (1+ (any word ".")))))))
              nil t)
        (psci--run-psci-command!
         (replace-regexp-in-string "\n" " " (match-string 0)))))
    )
  (defun spl/psci-load-current-file-with-imports! ()
    (interactive)
    (psci/load-current-file!)
    (spl/psci-send-import-lines!))
  :bind (:map purescript-mode-map
              (("C-c l" . spl/psci-load-current-file-with-imports!)))
  )

I'll try this out for a bit and see how it goes.

Edit: Reconsidered my assumption that people would be using psc-ide-emacs and replaced psc-ide-import-regex with the actual regex from psc-ide.el for matching imports.

Edit 2: This isn't quite right, as it doesn't properly respect multi-line imports.

Edit 3: Revised the regex to handle multi-line imports.

@shaunplee
Copy link

One week later, my above hack seems to be working as expected, although I'm not doing anything more complicated than the exercises in PureScript by Example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants