Skip to content

Instantly share code, notes, and snippets.

@remvee
Created March 21, 2011 11:11
Show Gist options
  • Save remvee/879305 to your computer and use it in GitHub Desktop.
Save remvee/879305 to your computer and use it in GitHub Desktop.
Paredit for ruby and javascript.
;; Enable paredit for a couple for non lisp modes; tweak
;; paredit-space-for-delimiter-predicates to avoid inserting spaces
;; before open parens.
(dolist (mode '(ruby espresso))
(add-hook (intern (format "%s-mode-hook" mode))
'(lambda ()
(add-to-list (make-local-variable 'paredit-space-for-delimiter-predicates)
(lambda (_ _) nil))
(enable-paredit-mode))))
@johnbendi
Copy link

Why does paredit not complete curly braces {}?

@codeasone
Copy link

@johnbendi I had the same question and ended up binding the following function to { in the ruby-mode-map

(defun paredit-open-curly-smart ()
    (interactive)
    (if (or
         (eq major-mode 'rjsx-mode)
         (eq major-mode 'js-mode)
         (eq major-mode 'js2-mode)
         (eq major-mode 'ruby-mode)
         (eq major-mode 'python-mode)
         (eq major-mode 'lua-mode)
         )
        ;; Just do same as `paredit-open-curly' in some mode.
        (paredit-open-curly)
      ;; Otherwise do something smart operation.
      (paredit-open-curly)
      (indent-according-to-mode)
      (comment-indent-new-line)
      (open-newline-above 1)))

Source: https://www.emacswiki.org/emacs/paredit-extension.el

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment