Emacs 中主要模式的“hello world"示例? [英] A 'hello world' example for a major mode in Emacs?

查看:20
本文介绍了Emacs 中主要模式的“hello world"示例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能为我提供一个关于 emacs 中主要模式的 hello world 示例?我想这是一个初学者的问题,我仍然很喜欢写一个主要模式,既学习emacs又学习elisp,以便能够充分利用定制.

到目前为止我所做的(并且正在工作):

  • 写了一个文件 sample-mode.el 并将其放入 lisp 目录
  • 在 .emacs 中调用 (require 'sample-mode)
  • 在里面写了一些定义,并在最后提供它(provide 'sample-mode)

但它似乎仍然没有激活,我不能用 M-sample-mode 调用它.

那怎么做呢?谁能给我提供一个非常简单的 Hello World 之类的工作示例?

解决方案

好的,经过更多的谷歌搜索后,我至少前进了一步:

(定义派生模式样本模式...)

因为提供并没有像我首先想到的那样定义模式..这是我发现的:

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

一个非常适合 emacs 爱好者的网站.

在此帮助下:我现在自己制作了一个 HelloWorld 示例:这是一个(尽可能小)Csharp 模式.我使用 Euler1 而不是 HelloWorld 作为示例.您需要了解的文件是:

  • 模式将应用于Euler1.cs
  • 的文件
  • .emacs
  • 当然还有模式本身

既然一张照片值得,至少一堆字:一个屏幕上的所有文件:

但是由于这张漂亮的图片似乎有一半时间消失了(有人知道吗?在新标签页中打开总是会打开它,而且网址还可以)还有一些话:-):

  1. 模式:cs-mode.el

    <块引用>

    (setq myKeywords'((WriteLine".字体锁定功能名称面)("public\|static\|void\|int\|for\|if\|class".font-lock-constant-face)))(定义派生模式 cs-mode 基本模式(setq font-lock-defaults '(myKeywords)))(提供'cs-mode)

  2. .emacs,使 .cs 文件以正确的模式打开:

<块引用>

<代码>;;CS(需要 'cs 模式)(添加到列表'自动模式列表'(\.cs\'".cs-mode))

仅此而已:cs-code 本身对她没用,因为它不会显示关键字着色的效果.要查看,请查看图片,或在另一个选项卡/窗口中打开图片.

干杯,电话

Can anyone provide me with a hello world example for a major mode in emacs? I guess it's a beginner question, still I really like to write a major mode, both to learn emacs and elisp, as to be able to use customization to the fullest.

What I have done so far (and is working) :

  • wrote a file sample-mode.el and put it in a lisp dir
  • called in .emacs (require 'sample-mode)
  • wrote some defuns in it, and provided it at the end (provide 'sample-mode)

But still it doesn't seem to be activated, I cannot call it with M-sample-mode.

So how to do that? And can anyone provide me with a very very simple Hello World like working sample?

解决方案

Ok, after some more googling I am at least one step furhter :

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

since the providing isn't defining the mode as I thought first.. This I found on :

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

A very very nice site for emacs-lovers.

With the help of that : I have made a HelloWorld example myself now : It's a (as small as possible) Csharp mode. I have used Euler1 as example rather than HelloWorld. The files you need to know about are :

  • the file the mode will be applied on Euler1.cs
  • the .emacs
  • and of course the mode itself

Since a pic is worth, at least a bunch of words : all files on 1 screen :

But since this nice pic seems to disappear half the time (anyone a clue? Open in new tab always brings it on, and the url is ok) some words too :-) :

  1. The mode : 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. The .emacs, that makes the .cs files open in the right mode :

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

And thats all : the cs-code itself is useless her, cause it won't show the effect of coloring the key-words. To see that see the pic, or open the pic in another tab/window.

Cheers, ph

这篇关于Emacs 中主要模式的“hello world"示例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆