Endless Parentheses

Ramblings on productivity and technical subjects.

profile for Malabarba on Stack Exchange

Locally configure or disable show-paren-mode

show-paren-mode is a minor-mode that highlights the bracket at point (be it round, square, or curly) as well as its corresponding open/close counterpart. I find it a must-have for Elisp and Clojure programming. On the other hand, when editing Ruby code, it also highlights whole block delimiters, like def, do, if, and end, and all that must-haviness quickly turns into in-your-faceviness.

The catch here is that show-paren-mode is a global minor-mode. So you can’t just enable it locally in lisp-mode-hook, and if you try to do (show-paren-mode -1) in ruby-mode-hook you’re going to disable it globally every time you visit a ruby file.

Fortunately, show-paren-function checks the value of the variable show-paren-mode, so we can pseudo-disable it by setting this variable locally.

(show-paren-mode 1)

(defun endless/locally-disable-show-paren ()
  (interactive)
  (setq-local show-paren-mode nil))

(add-hook 'ruby-mode-hook
          #'endless/locally-disable-show-paren)

With this, the mode will still be active in ruby-mode buffers, but it won’t actually do anything.

Alternatively, you could reset show-paren-data-function to its original value (also inside ruby-mode-hook). This will keep only the basic bracket highlighting.

(setq-local show-paren-data-function #'show-paren--default)

Tags: init.el, emacs,

comments powered by Disqus