2012-04-22 148 views
4

如何仅为* .el文件启用Show-Paren模式?如何启用仅用于* .el文件的Show-Paren模式

我已经试过

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

但它仍然能够显示,括号模式,所有的案件。即使在*scratch*缓冲区中,我也启用了Show-Paren模式。

回答

9

如前所述,show-paren-mode是一个全球性的次要模式。也就是说,人们可能只能在某种缓冲区上运行它,例如:

(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) 

它未经测试,可能无法正常工作。看看文档可能会起作用,但看看它可能工作的代码。这可能只适用于某些show-paren-mode版本。

+0

谢谢。这是工作! – 2012-04-22 15:46:40

1

您的代码是正确的。但是,你应该考虑的事实*scratch*缓冲区的主要模式是lisp-interaction-modeemacs-lisp-mode派生(其中大部分是无关紧要的)和模式的定义:

(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是这里的关键是 - 模式是全球性的,无论主要模式如何,都在所有缓冲区中启用。

+0

但是为什么文本模式会出现同样的问题? – 2012-04-22 11:58:43

+0

这是一个全球性的小模式,在正常的操作中,它在任何地方或任何地方都被激活。 – 2012-04-22 13:40:42

+0

啊,是的 - 我错过了源代码中的':global t'。 – 2012-04-23 07:34:21

4

show-paren-mode是一个全球性的小模式。这意味着它听起来如何。 这是非常多的设计,因为大多数人(包括我自己)都会在所有缓冲区中找到对这种小模式有用的 。为什么要禁用任何 文件?

从文档

显示括号模式是一个全球性的辅助模式。当启用时,任何 匹配的括号在Emacs空闲时间的show-paren-style' after show-paren-delay的秒数中突出显示。

+1

显示Paren模式对于Lisp来说绝对是不可或缺的。但是使用简单的文本并不需要太多的工作,因此我不想在使用常规文本时突出显示某些内容。 – 2012-04-22 15:43:29

相关问题