2009-06-30 78 views
11

任何人都可以提供给我一个在emacs中的主要模式hello世界的例子? 我想这是一个初学者的问题,我仍然非常喜欢编写一个主要的模式,以学习emacs和elisp,以便能够充分利用定制。Emacs中主要模式的'hello world'示例?

我迄今所做的(并且正在):

  • 写文件样本-mode.el并把它放在一个口齿不清DIR
  • 叫的.emacs (require 'sample-mode)
  • 写了一些defuns在里面,只要在最后(provide 'sample-mode)

但还是它似乎并没有被激活,我不能把它M-采样模式。

那么该怎么做?任何人都可以为我提供一个非常非常简单的Hello World,就像工作示例一样吗?

回答

10

好了,经过一些google搜索,我至少一个步骤furhter:

(define-derived-mode sample-mode ...) 

由于提供,因为我首先想到是不是定义模式.. 这我发现:

http://xahlee.org/emacs/elisp_syntax_coloring.html

一个emacs爱好者非常非常好的网站。

在此帮助下:我自己现在创建了一个HelloWorld示例:它是一个(尽可能小)Csharp模式。我用Euler1作为例子而不是HelloWorld。你需要了解的文件有:

  • 模式将在Euler1.cs
  • 的的.emacs
  • 和课程模式本身

应用于该文件由于PIC是值得,至少一堆话:1个屏幕上的所有文件:

alt text

但是,既然这个漂亮的照片似乎消失了一半时间(任何人的线索?在新分页开启总提起这件事上,而网址是确定)有些话太:-):

  1. 模式:CS-mode.el

    (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) 
    
  2. 的.emacs,这使得。CS文件在正确的模式下打开:

;; cs 
(require 'cs-mode) 
(add-to-list 'auto-mode-alist '("\\.cs\\'" . cs-mode)) 

并且那一切:cs-code本身是没用她的,因为它不会显示着色的关键字的效果。看到图片,或在另一个标签页/窗口中打开图片。

干杯,PH

+0

+1对于非常好的网站 – dfa 2009-06-30 12:15:01

+1

@jrockway:不同意在这里,我从他身上学到了很多东西,包括写作主要模式 虽然他自己可能没有空闲时间还有自己的想法,但是你有一点 – Peter 2009-07-02 07:55:47

5

周围有网络like this几个例子。 我也可以给你推荐几款Emacs的书:

  • 学习GNU Emacs的(最好恕我直言)
  • 编写GNU Emacs的扩展
  • 官方GNU的Emacs Lisp参考/手动
5

好,我们从this answer开始,它使用define-generic-mode

肉它与像一些评论文字:/* */,一些关键字:hellohi等,再使用面从原来的答案,文件扩展名.hello,和函数调用做进一步的定制。

还有一行可以让自动加载工作,但你必须要generate the 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.")) 
0

的elisp的手册介绍主要的模式非常好,它包括用于呈现“你好,世界” examples一个节点。至少这是我的意图。

这些示例可能不会涵盖您要查找的所有内容。在这种情况下,请考虑请求您认为错过的任何内容,以帮助用户更多。为此,请使用M-x report-emacs-bug(也适用于增强请求)。