Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs modes for flex and bison, or removing auto indent for these modes?

Emacs has poor handling of auto-indentation in Flex and Bison. In fact, it seems to have no support for flex mode. So, how does an emacs user cope with these? I like VIm but I would prefer not to switch because I am much faster and more comfortable in Emacs.

I had a third party elisp module for Bison a few months ago but when its indentation broke, it would never get fixed. In short, it was a bad hack.

Or is there a way I can turn off auto indentation for .l and .y files (so pressing would do one indent)? How would I also change this elisp setting for just emacs?

A nice and concise guide for elisp would be very helpful too. I wouldn't mind spending a few days to write my own flex and bison modes if I had the right documentation.

like image 698
Kizaru Avatar asked Aug 16 '10 00:08

Kizaru


2 Answers

Emacs chooses the major mode mainly based on the file name extension. .l is a contended extension: some people use it for lex, others for lisp (and there are a few other rarer uses). Emacs associates .l with lisp, and .lex with lex (for which it uses C mode).

If the .l files you work with are more often lex than lisp, you can change what .l files are associated with the following line in your .emacs:

(add-to-list 'auto-mode-alist '("\\.l\\'" . c-mode))

You can also declare inside a file what mode you want Emacs to use when it opens the file. Put the following snippet on the first line of the file (typically in a comment):

-*-mode: c-mode-*-

This is a more general feature, offering other syntaxes and other possibilities; see “File Variables” in the Emacs manual for more information.


If you would like to get started with Emacs Lisp, read the Emacs Lisp intro (which may be included in your Emacs or OS distribution). Once you've played around with the basics of the language a bit, you can turn to the chapter on modes in the Emacs Lisp reference manual.

like image 146
Gilles 'SO- stop being evil' Avatar answered Oct 22 '22 21:10

Gilles 'SO- stop being evil'


Additional tip: You might decide that what you want is Emacs' generic behavior -- what it uses when it doesn't have any special mode for a file format. That's called Fundamental mode in emacs lingo: so you can request it on the fly with M-x fundamental-mode, or put -*- mode: fundamental -*- on the first line of the file, or customize auto-mode-alist like so:

(add-to-list 'auto-mode-alist '("\\.l\\'" . fundamental-mode))

Another thing to try might be indented-text-mode (probably with auto-fill disabled).

like image 1
zwol Avatar answered Oct 22 '22 20:10

zwol