在Emacs中创建一个新模式 [英] Create a new mode in Emacs
问题描述
.packet
文件创建packet-mode.el。我想执行以下操作: - 启用C ++模式
- 使
分组
一个关键字,而剩下的C ++模式保持不变
(define-derived-mode packet-mode basic-mode
(font-lock-add-keywords'c ++ - mode`((packet。font-lock-keyword-face ))
(c ++ - mode))
(add-to-list'auto-mode-alist'(\\.packet\\ -mode)
(提供'包模式)
我也试过切换我们希望数据包
的行为是类似的。 struct
,意思是
packet foo {
int bar;
}
的突出显示方式与 struct
用于代替数据包
。
这是你需要放入 packet-mode.el
:
(defvar packet-mode-font-lock-keywords
'((\\< packet\\\&&)。 font-lock-keyword-face)))
(定义派生模式包模式c ++ - 模式数据包
编辑GNU ld脚本文件的主要模式
font-lock-add-keywords nil packet-mode-font-lock-keywords))
(add-to-list'auto-mode-alist'(\\.packet\\ 。packet-mode))
(提供'包模式')
放置 packet-mode.el
加入您的 load-path
和
(可选)字节编译它的目录。 p>
现在,将(需要包模式)
添加到您的 .emacs.el
。
I know nothing about Emacs Lisp (or any Lisp, for that matter). I want to do something that seems very simple, yet I have had no luck with online guides. I want to create "packet-mode.el" for .packet
files. I want to do the following:
- Enable C++ mode
- Make
packet
a keyword, while leaving the rest of C++ mode unchanged
(define-derived-mode packet-mode fundamental-mode
(font-lock-add-keywords 'c++-mode `(("packet" . font-lock-keyword-face)))
(c++-mode))
(add-to-list 'auto-mode-alist '("\\.packet\\'" . packet-mode)
(provide 'packet-mode)
I've also tried switching the order of the statements in packet mode, but then the C++ highlighting breaks.
I would like packet
to behave like struct
in the sense that
packet foo {
int bar;
}
is highlighted the same way it would be if struct
were used in place of packet
.
Here is what you need to put into packet-mode.el
:
(defvar packet-mode-font-lock-keywords
'(("\\<packet\\>" . font-lock-keyword-face)))
(define-derived-mode packet-mode c++-mode "Packet"
"A major mode to edit GNU ld script files."
(font-lock-add-keywords nil packet-mode-font-lock-keywords))
(add-to-list 'auto-mode-alist '("\\.packet\\'" . packet-mode))
(provide 'packet-mode)
Place packet-mode.el
into a directory in your load-path
and
(optionally) byte compile it.
Now, add (require 'packet-mode)
into your .emacs.el
.
这篇关于在Emacs中创建一个新模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!