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

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

问题描述

任何人都可以为我提供一个关于emacs的主要模式的hello world示例吗?
我想这是一个初学者的问题,我仍然非常喜欢写一个主要的模式,既可以学习emacs和elisp,也能够最全面地使用定制。



我迄今为止所做的(正在工作):




  • 写一个文件sample-mode.el并将其放在.emacs中调用的lisp目录

  • (require'sample-mode) / li>
  • 在其中写了一些defun,并在结尾提供(提供'sample'模式)



但是,似乎没有被激活,我无法使用M-sample模式调用它。



那么怎么做呢?任何人都可以为我提供非常简单的Hello World,例如工作示例?

解决方案

至少有一个步骤:

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

由于提供没有按照我的想法定义模式..
我发现:



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



一个非常非常漂亮的网站为emacs-lovers。



在此帮助下:我现在自己做了一个HelloWorld的例子:它是一个(尽可能小的)Csharp模式。我以 Euler1 为例,而不是HelloWorld。您需要了解的文件有:




  • 该模式将应用于 Euler1.cs

  • .emacs

  • 当然模式本身



由于pic值得,至少有一堆单词:1屏幕上的所有文件:





但是,由于这个漂亮的图片似乎消失了一半时间(任何人线索?打开新标签总是把它打开,url也可以)一些话:-):


  1. 模式:cs-mode.el


     (setq myKeywords 
    '((WriteLine 。font-lock-function-name-face)
    (public\\ | static\\ | void\\ | int\\ | | for\\ | if $ c

    (define-derived-mode cs-mode基本模式
    (setq font-lock -defaults'(myKeywords)))

    (pro视频cs模式)



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





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


这就是全部: cs-code 本身没有用,因为它不会显示关键词的着色效果。看到图片,或在另一个标签/窗口中打开图片。



干杯,ph


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天全站免登陆