2013-06-29 73 views
0

使用regexp(1)突出显示emacs缓冲区中的文本后,很容易在文件(2)中写入设置,但我缺少持久性的第三步。emacs文本缓冲区中的持久颜色

(1)设置

M-s h rhighlight-regexp),并说,\{.*\}其次italic将突出这种风格大括号之间的一切。

(2)写

随后调用C-x w bhi-lock-write-interactive-patterns)写出字符串

# Hi-lock: (("\\{.*\\}" (0 (quote italic) t))) 

在缓冲区中,要求注释字符串后(我用#)。

(3)再利用

是什么力量让这个高亮持久的,即,使其生存保存/加载从磁盘上的文件需要第三步?

回答

0

如果您使用C-h f hi-lock-write-interactive-pattern,则会在帮助缓冲区中看到hi-lock.el的链接。通常Lisp库在文件的开始处有一些使用信息,并且它很方便检查。

在这种情况下,它会告诉如何让它持续性:从当前缓冲区的意见

;; To enable the use of patterns found in files (presumably placed 
;; there by hi-lock) include the following in your init file: 
;; 
;; (setq hi-lock-file-patterns-policy 'ask) 
;; 
;; If you get tired of being asked each time a file is loaded replace 
;; `ask' with a function that returns t if patterns should be read. 
+0

感谢您的提示。我已经有(setq hi-lock-file-patterns-policy t)在我的.emacs中,但只有(setq hi-lock-file-patterns-policy'ask)触发器询问。为什么简单地写t不会触发突出显示而不询问? – Calaf

+0

显然只是写“t”已经坏了(在Emacs 24中也是如此)。我们需要写(setq hi-lock-file-patterns-policy(lambda(pattern)t))。参考:http://lists.gnu.org/archive/html/bug-gnu-emacs/2010-01/msg00226。html – Calaf

0

如何创建一个与您要加载的文件相关的钩子函数的可能性 - 例如,文本模式钩子或可能是特定的文件钩子(如果类似的东西存在)?

;; M-x ae-hi-lock-features 

(global-hi-lock-mode 1) 

(defface af-bold-yellow-box '((t (:background "black" 
            :foreground "yellow" 
            :underline "red" 
            :height 200 
            :bold t 
           ))) "yellow-box-face") 

(defun z-hi-lock-quizzes() 
    ;; this next line is necessary to correct sloppy hi-locking 
    (if (not hi-lock-mode) 
     (progn (hi-lock-mode -1) 
      (hi-lock-mode 1)) 
    (hi-lock-mode) 
    (hi-lock-mode)) 
    (highlight-regexp "^%-\\*-mode:LaTeX.*$" (quote hi-conceal-content)); 
    (highlight-regexp "^%[email protected](.+$"   (quote hi-lock-page-break)); 
    (highlight-regexp "food"   (quote af-bold-yellow-box)); 
) 

(defun ae-hi-lock-features() 
    (interactive) 
    (z-hi-lock-quizzes) 
;; ... call other functions ... 
) 

(add-hook 'text-mode-hook 'ae-hi-lock-features) 
+1

hi-lock-write-interactive-patterns存在似乎是一个强烈的暗示,我在我的文本文件中只是丢失了一行或两行。 – Calaf

0

https://www.gnu.org/software/emacs/manual/html_node/emacs/Highlight-Interactively.html

C-x w i

提取的正则表达式/面部对(HI-锁找到-patterns)。

因此,你可以使用高亮,正则表达式输入模式交互 ,并将其存储到文件, HI-锁定写交互式模式,对其进行编辑(可能包括的不同括号内的部分 不同的面孔匹配)和 终于使用此命令(hi-lock-find-patterns)让Hi Lock 突出显示编辑后的模式。

+0

M-x hi-lock-write-interactive-patterns是所需的功能,而(来自emacs info)“C-x w i运行hi-lock-find-patterns命令。” – Calaf