Chad Stovern

I'm a huge fan of Emacs and a huge fan of programming using Clojure. I've been trying to avoid Javascript, but it's reach is everywhere and learning it will definitely help my day job efforts helping teams create cloud native applications.

One hurdle I faced in setting up Emacs for Javascript development was paredit inserting a space before opening parens in Javascript and JSON modes; leaving me with things like console.log ("foo") rather than console.log("foo") as I merily typed along.

Even though non-lisps don't lend themselves to structural editing the way lisps do, I still like being able to wrap and manipulate parens, braces, quotations, etc with paredit—so I did not want to disable paredit in these modes.

Here is the quick fix I am using from my emacs configuration:

;; prevent paredit from adding a space before opening paren in certain modes
(defun cs/mode-space-delimiter-p (endp delimiter)
  "Don't insert a space before delimiters in certain modes"
   (bound-and-true-p js2-mode)
   (bound-and-true-p js-mode)
   (bound-and-true-p javascript-mode)))
(add-to-list 'paredit-space-for-delimiter-predicates #'cs/mode-space-delimiter-p))

Happy hacking; and until next time…

“If you think paredit is not for you then you need to become the kind of person that paredit is for.”