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?
Well, let's start with this answer, which uses
define-generic-mode
.Flesh it out with some comment characters like:
/* */
, some keywords:hello
hi
etc., re-use the face from the original answer, a file extension.hello
, and a function call to do further customization.There's the additional line to get autoloading working, but you have to generate the loaddefs.el file. That's more advanced than hello world.
And, you end up with this:
there are several examples around the Web like this. I can also recommend you several Emacs book:
The Elisp manual introduces major modes pretty well, and it includes a node that presents "hello-world" examples. At least that is the intention, I think.
Those examples might not cover everything you are looking for. In that case, consider requesting whatever you think is missing that would help users more. To do that, use
M-x report-emacs-bug
(that is for enhancement requests also).Ok, after some more googling I am at least one step furhter :
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 :
Euler1.cs
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 :-) :
The mode : cs-mode.el
The .emacs, that makes the .cs files open in the right 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