purescript-emacs/psc-ide-emacs

Emacs integration for PureScript's psc-ide tool.

Emacs Lisp

130

227 commits

updated May 23, 2025

See the code

README

[[http://melpa.org/#/psc-ide][file:http://melpa.org/packages/psc-ide-badge.svg]]

* psc-ide-emacs

  Emacs integration for [[https://github.com/purescript/purescript/tree/master/psc-ide][psc-ide]]

** Installation

   The package is available on [[http://melpa.org/#/psc-ide][MELPA]]. Please read the MELPA's [[http://melpa.org/#/getting-started][Getting Started]] guide
   for more information. Once you have MELPA configured install psc-ide-emacs
   via =package.el=:

   #+BEGIN_SRC elisp
   M-x package-install RET psc-ide RET
   #+END_SRC

** Configuration

   Add the following to your =~/.emacs=:

   #+BEGIN_SRC elisp

   (require 'psc-ide)

   (add-hook 'purescript-mode-hook
     (lambda ()
       (psc-ide-mode)
       (company-mode)
       (flycheck-mode)
       (turn-on-purescript-indentation)))
   #+END_SRC

   If you want to use the psc-ide server that is relative to your ~npm bin~
   directory, e.g. ~./node_modules/.bin/purs~, add this line to your
   config:

   #+BEGIN_SRC elisp
   (setq psc-ide-use-npm-bin t)
   #+END_SRC

   If you would like to use a custom codegen target for your rebuild. (default
   is "js")

   There is a `psc-ide-codegen` option that can be set globally in your user config:

   #+BEGIN_SRC elisp
   (setq psc-ide-codegen '("corefn"))
   #+END_SRC

   or in specific files by addind this to the top of file:

   #+BEGIN_SRC elisp
   -- -*- psc-ide-codegen: ("corefn") -*-
   #+END_SRC


** Usage

*** Start the Server ~C-c C-s~

*** Load all the modules ~C-c C-l~
    This isn't usually necessary, as the start server command sends a load all
    command after starting the server.
*** Get completions from the modules you imported while you type (through ~company-mode~)
    [[http://i.imgur.com/8WnRh0s.gif]]

*** Get completions from all modules in your project with ~company-complete~
    This was bound to ~C-SPC~ in earlier versions but was too intrusive for
    usual emacs users so you'll have to bind it to a key of choice.

    eg. ~(global-set-key (kbd "C-SPC") 'company-complete)~

    [[http://i.imgur.com/LR69MdN.gif]]

*** Show type for identifier under cursor ~C-c C-t~
    [[http://i.imgur.com/A8cXe9t.gif]]

    Prepending the universal argument expands type synonyms in the displayed
    type.

    For example:
    ~C-c C-t~ might return ~getName :: Person -> String~

    If ~Person~ is a type synonym for a record you can use the universal
    argument to inspect that record:

    ~C-u C-c C-t~ will then return ~getName :: { name :: String, age :: Int } ->
    String~

*** Go to definition =M-.=
    You can use M-, to jump back to where you came from . If your sourcefiles
    are not captured by the default globs you can add a ~.dir-locals.el~ file to
    the root of your project, like so:

    #+BEGIN_SRC elisp
      ((purescript-mode
        . ((psc-ide-source-globs
            . ("src/**/*.purs" "test/**/*.purs" "examples/**/*.purs")))))
    #+END_SRC
    Modify the globs accordingly and don't worry about dependency
    globs for bower, psc-package or spago projects. The plugin picks
    these up by default. Check the doc-string for
    `psc-ide-source-globs` for some advanced options.

*** Add an import for the identifier under cursor ~C-c C-i~

    If the import is ambiguous you will get a selection of modules, from which
    you can choose the identifier you want.

    [[http://i.imgur.com/VBXDvPg.gif]]

*** Add an import on completion (turned on by default)
    Can be turned off with:
    #+BEGIN_SRC elisp
    (customize-set-variable 'psc-ide-add-import-on-completion nil)
    #+END_SRC

    [[http://i.imgur.com/r6rl2lT.gif]]

*** Case Split the given type under cursor ~C-c C-c~
    [[http://i.imgur.com/hTnHxhK.gif]]
*** Add a clause for the function definition under cursor ~C-c C-a~
    [[http://i.imgur.com/VNeC3z8.gif]]

*** Rebuild the current module and get quick error reporting ~C-c C-b~
    If you set ~(customize-set-variable 'psc-ide-rebuild-on-save t)~ psc-ide will
    try to rebuild your module on every save.

    [[http://i.imgur.com/c0L6C4B.gif]]

*** Flycheck Support
**** Ignore certain errors or warnings
This is determined by the variable ~psc-ide-flycheck-ignored-error-codes~. It can be configured
with ~customize-option~ or similar methods.

**** Insert suggestion from error ~C-c M-s~
     When the cursor is placed over an error that includes suggestion information, use ~C-c M-s~ to
     apply the suggestion.

*** Keybindings

   | Key         | Function                             |
   |-------------+--------------------------------------|
   | ~C-c C-s~   | ~psc-ide-server-start~               |
   | ~C-c C-q~   | ~psc-ide-server-quit~                |
   | ~C-c C-t~   | ~psc-ide-show-type~                  |
   | ~C-c C-i~   | ~psc-ide-add-import~                 |
   | ~C-c C-a~   | ~psc-ide-add-clause~                 |
   | ~C-c C-c~   | ~psc-ide-case-split~                 |
   | ~C-c C-l~   | ~psc-ide-load-all~                   |
   | ~C-c C-b~   | ~psc-ide-rebuild~                    |
   | ~C-c C-S-l~ | ~psc-ide-load-module~                |
   | ~C-c M-s~   | ~psc-ide-flycheck-insert-suggestion~ |

Not written in Markdown, so it's shown here as plain text — view it formatted on GitHub.

emacs
emacs-mode
ide
purescript

Contributors

kritzcreek

74 commits

epost

43 commits

purcell

34 commits

bsermons

24 commits

purescript-emacs/psc-ide-emacs

Emacs integration for PureScript's psc-ide tool.

Emacs Lisp

130

227 commits

updated May 23, 2025

See the code

README

[[http://melpa.org/#/psc-ide][file:http://melpa.org/packages/psc-ide-badge.svg]]

* psc-ide-emacs

  Emacs integration for [[https://github.com/purescript/purescript/tree/master/psc-ide][psc-ide]]

** Installation

   The package is available on [[http://melpa.org/#/psc-ide][MELPA]]. Please read the MELPA's [[http://melpa.org/#/getting-started][Getting Started]] guide
   for more information. Once you have MELPA configured install psc-ide-emacs
   via =package.el=:

   #+BEGIN_SRC elisp
   M-x package-install RET psc-ide RET
   #+END_SRC

** Configuration

   Add the following to your =~/.emacs=:

   #+BEGIN_SRC elisp

   (require 'psc-ide)

   (add-hook 'purescript-mode-hook
     (lambda ()
       (psc-ide-mode)
       (company-mode)
       (flycheck-mode)
       (turn-on-purescript-indentation)))
   #+END_SRC

   If you want to use the psc-ide server that is relative to your ~npm bin~
   directory, e.g. ~./node_modules/.bin/purs~, add this line to your
   config:

   #+BEGIN_SRC elisp
   (setq psc-ide-use-npm-bin t)
   #+END_SRC

   If you would like to use a custom codegen target for your rebuild. (default
   is "js")

   There is a `psc-ide-codegen` option that can be set globally in your user config:

   #+BEGIN_SRC elisp
   (setq psc-ide-codegen '("corefn"))
   #+END_SRC

   or in specific files by addind this to the top of file:

   #+BEGIN_SRC elisp
   -- -*- psc-ide-codegen: ("corefn") -*-
   #+END_SRC


** Usage

*** Start the Server ~C-c C-s~

*** Load all the modules ~C-c C-l~
    This isn't usually necessary, as the start server command sends a load all
    command after starting the server.
*** Get completions from the modules you imported while you type (through ~company-mode~)
    [[http://i.imgur.com/8WnRh0s.gif]]

*** Get completions from all modules in your project with ~company-complete~
    This was bound to ~C-SPC~ in earlier versions but was too intrusive for
    usual emacs users so you'll have to bind it to a key of choice.

    eg. ~(global-set-key (kbd "C-SPC") 'company-complete)~

    [[http://i.imgur.com/LR69MdN.gif]]

*** Show type for identifier under cursor ~C-c C-t~
    [[http://i.imgur.com/A8cXe9t.gif]]

    Prepending the universal argument expands type synonyms in the displayed
    type.

    For example:
    ~C-c C-t~ might return ~getName :: Person -> String~

    If ~Person~ is a type synonym for a record you can use the universal
    argument to inspect that record:

    ~C-u C-c C-t~ will then return ~getName :: { name :: String, age :: Int } ->
    String~

*** Go to definition =M-.=
    You can use M-, to jump back to where you came from . If your sourcefiles
    are not captured by the default globs you can add a ~.dir-locals.el~ file to
    the root of your project, like so:

    #+BEGIN_SRC elisp
      ((purescript-mode
        . ((psc-ide-source-globs
            . ("src/**/*.purs" "test/**/*.purs" "examples/**/*.purs")))))
    #+END_SRC
    Modify the globs accordingly and don't worry about dependency
    globs for bower, psc-package or spago projects. The plugin picks
    these up by default. Check the doc-string for
    `psc-ide-source-globs` for some advanced options.

*** Add an import for the identifier under cursor ~C-c C-i~

    If the import is ambiguous you will get a selection of modules, from which
    you can choose the identifier you want.

    [[http://i.imgur.com/VBXDvPg.gif]]

*** Add an import on completion (turned on by default)
    Can be turned off with:
    #+BEGIN_SRC elisp
    (customize-set-variable 'psc-ide-add-import-on-completion nil)
    #+END_SRC

    [[http://i.imgur.com/r6rl2lT.gif]]

*** Case Split the given type under cursor ~C-c C-c~
    [[http://i.imgur.com/hTnHxhK.gif]]
*** Add a clause for the function definition under cursor ~C-c C-a~
    [[http://i.imgur.com/VNeC3z8.gif]]

*** Rebuild the current module and get quick error reporting ~C-c C-b~
    If you set ~(customize-set-variable 'psc-ide-rebuild-on-save t)~ psc-ide will
    try to rebuild your module on every save.

    [[http://i.imgur.com/c0L6C4B.gif]]

*** Flycheck Support
**** Ignore certain errors or warnings
This is determined by the variable ~psc-ide-flycheck-ignored-error-codes~. It can be configured
with ~customize-option~ or similar methods.

**** Insert suggestion from error ~C-c M-s~
     When the cursor is placed over an error that includes suggestion information, use ~C-c M-s~ to
     apply the suggestion.

*** Keybindings

   | Key         | Function                             |
   |-------------+--------------------------------------|
   | ~C-c C-s~   | ~psc-ide-server-start~               |
   | ~C-c C-q~   | ~psc-ide-server-quit~                |
   | ~C-c C-t~   | ~psc-ide-show-type~                  |
   | ~C-c C-i~   | ~psc-ide-add-import~                 |
   | ~C-c C-a~   | ~psc-ide-add-clause~                 |
   | ~C-c C-c~   | ~psc-ide-case-split~                 |
   | ~C-c C-l~   | ~psc-ide-load-all~                   |
   | ~C-c C-b~   | ~psc-ide-rebuild~                    |
   | ~C-c C-S-l~ | ~psc-ide-load-module~                |
   | ~C-c M-s~   | ~psc-ide-flycheck-insert-suggestion~ |

Not written in Markdown, so it's shown here as plain text — view it formatted on GitHub.

emacs
emacs-mode
ide
purescript

Contributors

kritzcreek

74 commits

epost

43 commits

purcell

34 commits

bsermons

24 commits

Languages

Emacs Lisp

100.0%