[英]Persistent colors in an emacs text buffer
After highlighting text in an emacs buffer using a regexp (1), it's easy enough to write the setting in the file (2), but I am missing a third step for persistence. 使用正则表达式(1)在emacs缓冲区中突出显示文本之后,将设置写入文件(2)很容易,但是我缺少持久性的第三步。
(1) Set (1套
Doing Ms hr
( highlight-regexp
) and, say, \\{.*\\}
followed by italic
will highlight everything between curly braces in that style. 在Ms hr
( highlight-regexp
)上加上\\{.*\\}
再加上italic
将突出显示该样式的花括号之间的所有内容。
(2) Write (2)写
Subsequently calling Cx wb
( hi-lock-write-interactive-patterns
) will write the string 随后调用Cx wb
( hi-lock-write-interactive-patterns
)将写入字符串
# Hi-lock: (("\\{.*\\}" (0 (quote italic) t)))
in the buffer, after asking for the comment string (I used #). 在缓冲区中,要求输入注释字符串后(我使用#)。
(3) Re-use (3)再利用
What is the third step needed to make this highlighting persistent, ie, to make it survive saving/loading the file from disk? 使该突出显示持久化(即使其在从磁盘保存/加载文件时幸免于难)的第三步是什么?
If you Ch f hi-lock-write-interactive-pattern, you'll see in the help buffer a link to hi-lock.el. 如果您使用hi-lock-write-interactive-pattern,则将在帮助缓冲区中看到指向hi-lock.el的链接。 Often Lisp libraries have some usage information at the beginning of the file and it's handy to check. Lisp库通常在文件的开头有一些用法信息,检查起来很方便。
In this case, it tells how to make it persistent: 在这种情况下,它告诉如何使其持久化:
;; 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.
How about the possibility of creating a function that has a hook relating to the file you want to load -- eg, a text-mode-hook or perhaps a specific file hook (if something like that exists)? 创建具有与您要加载的文件相关的挂钩的函数的可能性怎么样?例如,文本模式挂钩或特定的文件挂钩(如果存在类似的东西)?
;; 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 "^%-@-(.+$" (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)
https://www.gnu.org/software/emacs/manual/html_node/emacs/Highlight-Interactively.html https://www.gnu.org/software/emacs/manual/html_node/emacs/Highlight-Interactively.html
Cx wi
Extract regexp/face pairs from comments in the current buffer (hi-lock-find-patterns). 从当前缓冲区的注释中提取regexp / face对(hi-lock-find-patterns)。
Thus, you can enter patterns interactively with highlight-regexp, store them into the file with hi-lock-write-interactive-patterns, edit them (perhaps including different faces for different parenthesized parts of the match), and finally use this command (hi-lock-find-patterns) to have Hi Lock highlight the edited patterns. 因此,您可以使用highlight-regexp交互式输入模式,使用hi-lock-write-interactive-patterns将其存储到文件中,对其进行编辑(可能为匹配项的不同括号部分包括不同的面孔),最后使用此命令( hi-lock-find-patterns),以使Hi Lock突出显示已编辑的图案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.