Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

emacs

elisp

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.

like image 733
V_V Avatar asked Dec 10 '22 00:12

V_V


2 Answers

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.

like image 121
Rémi Avatar answered Dec 27 '22 13:12

Rémi


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.

like image 29
event_jr Avatar answered Dec 27 '22 11:12

event_jr