Skip to content

Instantly share code, notes, and snippets.

@luisgerhorst
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luisgerhorst/139601a977e9291471e4 to your computer and use it in GitHub Desktop.
Save luisgerhorst/139601a977e9291471e4 to your computer and use it in GitHub Desktop.
Emacs: Make paredit work with erlang-mode (or any other non-lisp mode)

When you want to use awesome paredit with erlang-mode or any other non-lisp language there's a problem when you want to insert a pair of parenthesis for a function call.

Say you have typed myFunction and now type (, paredit assumes you're in a lisp and creates myFunction () instead of myFunction().

The snippet prevents paredit from inserting a space before parentheses by locally resetting the predicate functions used to determine if a space should be inserted before a pair of parentheses. By changing the hook used you could also make this work in any other mode for non-lisp languages. For exampe for js2-mode replace erlang-mode-hook in line 1 with js2-mode-hook.

(add-hook 'erlang-mode-hook 'my/disable-paredit-spaces-before-paren)
(defun my/disable-paredit-spaces-before-paren ()
;; Function which always returns nil -> never insert a space when insert a parentheses.
(defun my/erlang-paredit-space-for-delimiter-p (endp delimiter) nil)
;; Set this function locally as only predicate to check when determining if a space should be inserted
;; before a newly created pair of parentheses.
(setq-local paredit-space-for-delimiter-predicates '(my/erlang-paredit-space-for-delimiter-p)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment