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

Write plugins/extensions/whatever to write import Universum automatically #8

Closed
gromakovsky opened this issue Oct 3, 2016 · 2 comments

Comments

@gromakovsky
Copy link
Member

For example, when I create a new file in emacs, it has these lines by default:

-- | 

module Pos.Crypto.Patak where

I want to have import Universum line there also.
We need such thing for emacs, vim, something else?

@chshersh
Copy link
Contributor

Ok, Senior Emacs Lisp developer did this. You can insert this code into your ~/.emacs file:

(require 'haskell)

(defun haskell-auto-insert-module-template-universum ()
  "Insert a module template for the newly created buffer."
  (interactive)
  (when (and (= (point-min)
                (point-max))
             (buffer-file-name))
    (insert
     "-- | "
     "\n"
     "\n"
     "module "
     )
    (let ((name (haskell-guess-module-name)))
      (if (string= name "")
          (progn (insert "Main")
                 (shm-evaporate (- (point) 5)
                                (point)))
        (insert name)))
    (insert "\n"
            "       (\n"
            "       ) where\n"
            "\n"
            "import Universum\n"
            "\n"
            )
    (goto-char (point-min))
    (forward-char 4)
    (god-mode)))

(remove-hook 'haskell-mode-hook 'haskell-auto-insert-module-template)
(add-hook 'haskell-mode-hook 'haskell-auto-insert-module-template-universum)

This creates next module for me:

-- | 

module Pos.Crypto.Instances
       (
       ) where

import Universum

@lambdadog
Copy link

Unsure whether or not Structured Haskell Mode used to be included in haskell-mode, but at least in 2022, using #'shm-evaporate (as this code does) would need (require 'shm) or (require 'shm-evaporate) to be added, and you would need to ensure the shm/structured-haskell-mode emacs package is installed, as well as haskell-mode.

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

3 participants