how to enable Show-Paren mode only for *.el files
Asked Answered
H

5

5

How can I enable Show-Paren mode only for *.el files?

I have tried

(add-hook 'emacs-lisp-mode-hook '(lambda()
                                   (show-paren-mode 1)
                                   ))

But it still enables Show-Paren mode for all the cases. Even in *scratch* buffer I have Show-Paren mode enabled.

Hebron answered 22/4, 2012 at 9:59 Comment(0)
C
9

As already said, show-paren-mode is a global minor mode. That said, one might be able to run it only on some buffer with something like:

(show-paren-mode)                       ;; activate the needed timer
(setq show-paren-mode ())                ;; The timer will do nothing if this is nil

(defun show-paren-local-mode ()
  (interactive)
  (make-local-variable 'show-paren-mode) ;; The value of shom-paren-mode will be local to this buffer.
  (setq show-paren-mode t))

(add-hook 'emacs-lisp-mode-hook 'show-paren-local-mode)

It's untested, it might not work. Looking at the doc in might work, but looking at the code it might work. This might work only with some version of show-paren-mode.

Cutaway answered 22/4, 2012 at 13:39 Comment(0)
H
4

show-paren-mode is a global minor-mode. It means exactly how it sounds. This is very much by design, as most people (myself included) find this minor-mode helpful across all buffers. Why do you want to disable it for any file?

from the documentation

Show Paren mode is a global minor mode. When enabled, any matching parenthesis is highlighted in show-paren-style' after show-paren-delay' seconds of Emacs idle time.

Hynda answered 22/4, 2012 at 12:51 Comment(1)
Show Paren mode is absolutely indispensable working with Lisp. But it is not much necessary working with simple text, therefore I dont want additional distraction of something highlighting when working with usual text.Hebron
R
1

Your code is correct. However, you should consider the fact that the *scratch* buffer's major mode is lisp-interaction-mode which derives from emacs-lisp-mode (which is mostly irrelevant) and the mode's definition:

(define-minor-mode show-paren-mode
  "Toggle visualization of matching parens (Show Paren mode).
With a prefix argument ARG, enable Show Paren mode if ARG is
positive, and disable it otherwise.  If called from Lisp, enable
the mode if ARG is omitted or nil.

Show Paren mode is a global minor mode.  When enabled, any
matching parenthesis is highlighted in `show-paren-style' after
`show-paren-delay' seconds of Emacs idle time."
  :global t :group 'paren-showing
...)

:global t is the key thing here - the mode is global and is enabled in all buffers regardless of their major mode.

Rochellerochemont answered 22/4, 2012 at 10:12 Comment(2)
But why the same problem occurs for Text mode?Hebron
It's a global minor-mode, in normal operation, it's activated everywhere or nowhere.Caladium
M
0

I think you can use

(setq-default show-paren-data-function #'ignore)
(show-paren-mode)

to formally enable the mode but keeping it quiet. And then something like

(defun set-up-emacs-lisp-mode ()
  (setq-local show-paren-data-function #'show-paren--default))

(add-hook 'emacs-lisp-mode-hook #'set-up-emacs-lisp-mode)

to enable it in Emacs Lisp buffers. I've not tested this set-up, only the opposite (usually enabled, disabled just in Text Mode).

I used to use (setq-local show-paren-mode nil) but this makes Emacs highlight the braces in Ido promps, so I prefer (setq-default show-paren-data-function #'ignore).

Meek answered 9/1, 2022 at 17:47 Comment(0)
P
0

M-x customize-group RET paren-showing

In search string type: show-paren-predicate and hit RET

By default Lisp expression for this predicate is

(not (derived-mode . special-mode))

To make show-paren-mode work only for elisp files, you could set show-paren-predicate to

(major-mode . emacs-lisp-mode)

Then just C-x C-s.

Palliasse answered 29/6 at 15:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.