2012-04-22 76 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