任何人都可以为emacs中的主要模式提供一个hello world示例吗?我想这是一个初学者的问题,我仍然非常想写一个主要的模式,既学习emacs又学习elisp,以便能够充分利用自定义.
到目前为止我做了什么(并且正在工作):
(require 'sample-mode)
(provide 'sample-mode)
但它似乎没有被激活,我不能用M-sample-mode调用它.
那怎么办呢?谁能为我提供一个非常简单的Hello World,就像工作样本一样?
Pet*_*ter 11
好吧,经过一些谷歌搜索后,我至少迈出了一步:
(define-derived-mode sample-mode ...)
Run Code Online (Sandbox Code Playgroud)
因为提供没有像我先想到的那样定义模式..我发现:
http://xahlee.org/emacs/elisp_syntax_coloring.html
对于emacs爱好者来说,这是一个非常好的网站.
借助于此:我现在自己创建了一个HelloWorld示例:它是一个(尽可能小)Csharp模式.我使用Euler1作为示例而不是HelloWorld.您需要了解的文件是:
Euler1.cs
由于pic是值得的,至少有一堆词:1个屏幕上的所有文件:
但是,因为这个漂亮的图片似乎消失了一半的时间(任何人都有线索?在新标签中打开总是带来它,并且网址没问题)一些词也是:-):
模式:cs-mode.el
Run Code Online (Sandbox Code Playgroud)(setq myKeywords '(("WriteLine" . font-lock-function-name-face) ("public\\|static\\|void\\|int\\|for\\|if\\|class" . font-lock-constant-face))) (define-derived-mode cs-mode fundamental-mode (setq font-lock-defaults '(myKeywords))) (provide 'cs-mode)
.emacs,使.cs文件以正确的模式打开:
Run Code Online (Sandbox Code Playgroud);; cs (require 'cs-mode) (add-to-list 'auto-mode-alist '("\\.cs\\'" . cs-mode))
这就是全部:cs-code
本身对她没用,因为它不会显示关键词着色的效果.要查看图片,或在另一个标签/窗口中打开图片.
干杯,电话
好吧,让我们从这个使用的答案开始吧define-generic-mode
.
使用一些注释字符充实它,例如:/* */
,某些关键字:hello
hi
等等,重新使用原始答案中的面部,文件扩展名.hello
和函数调用来进行进一步的自定义.
有额外的行可以使自动加载工作,但您必须生成loaddefs.el文件.这比你好世界更先进.
而且,你最终得到这个:
(make-face 'my-date-face)
(set-face-attribute 'my-date-face nil :underline t)
(set-face-attribute 'my-date-face nil :family "times")
(set-face-attribute 'my-date-face nil :slant 'normal)
(set-face-attribute 'my-date-face nil :height '340)
;;;###autoload
(define-generic-mode hello-world
'(("/*" . "*/")) ; comment characters
'("hello" "hi" "howdy" "greetings" "hola") ; keywords
'(("\\([0-9]+/[0-9]+/[0-9]+\\)"
(1 'my-date-face))) ; font lock
'("\\.hello$") ; auto-mode-alist
'(hello-world-special-setup) ; function-list
"An example major mode.
We have comments, keywords, a special face for dates, and recognize .hello files.")
(defun hello-world-special-setup ()
"Some custom setup stuff done here by mode writer."
(message "You've just enabled the most amazing mode ever."))
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2212 次 |
最近记录: |