Ocaml - Emacs tuareg mode - emacs

I just started to use the tuareg mode in emacs for ocaml programming. So can someone tell me what are the main advantages of using it? Can someone suggest me any tutorial for that?

Tuareg-mode is good because it can parse code and calculate indentation & font-lock basing on this information. Plus it provides pretty good possibilities to interactive work with code.
Regarding tutorial - I don't think that such exists (although I planned to write it long time ago). All information for installation is in README file, and you can learn about available commands by visiting file with OCaml source code, and pressing C-h m to get description of mode, or by getting description of tuareg-mode function (if tuareg.el is loaded already).
Useful addition to these descriptions is Tuareg mode refcard that lists all (or almost) available commands.

Tuareg is really nice for:
Highlighting your code
Indenting your code correctly
Easily sending portions of code to a REPL
Easily compiling your code

Syntax highlight, indentation, as (almost) all language modes.
Compile or evaluate in a top level from a single buffer (you no longer need to open a ocaml toplevel in a command line to test some crap functions)
Caml-types minor mode : after a successful or partial compilation, you can easily point a variable and get the type the compiler inferred for it.

Related

LESS syntax highlighting for emacs

Does anyone know of a syntax file to get LESS working in emacs?
You are probably looking for a less-css emacs mode, which is an elisp file that can be loaded in your emacs environment. Another version is also available in github.

Add/edit functions of Emacs Editor

I need to implement some new functions on an editor. I picked Emacs - although my main programming knowledge is in Java and C - and I want to add some functions and edit some existing functions of Emacs Editor. I looked at the source code of it and I'm a bit lost. I was wondering whether anyone can give me some advice about where to start and whether there are any tutorials that can help?
P.S. One specific question would be how one can start to write a new mode with all new features and behaviour? or how I can disable some basic functions like copy/paste?
Cheers
An Introduction to Programming in Emacs Lisp http://www.gnu.org/software/emacs/emacs-lisp-intro/ or type in emacs:
M-: (info "(eintr)Top") RET
Emacs Lisp Manual http://www.gnu.org/software/emacs/manual/elisp.html or type in emacs:
M-: (info "(elisp)Top") RET
There are some tutorials out there specifically geared towards writing a major mode.
emacs extension guide [pdf]
how to write a major mode...
Other than that, writing modes in Emacs is just writing Lisp functions.
One thing I will note is that what you're proposing to do here may be pointless; if you implement a permission system as a major mode, a user can simply switch modes to turn it off. That's fine if the point of this permission system is to avoid clobbering edits (in which case I assume your users will cooperate with your aims). If you're expecting your users to be adversarial, then Emacs is the wrong tool for this.
Here is the manual section on defining major and minor modes:
C-hig (elisp) Modes RET
It is often beneficial to derive a new mode from an existing one which provides similar basic functionality to what you need.
If there's nothing which matches closely enough, examining the source code for modes which provide some of the same behaviour would be the next best thing.
I note that 'deriving' a mode from nil seems to be the common way of creating a completely new major mode. That way you still get all the benefits of the define-derived-mode macro.

What is the short-cut key to jump to declaration in Emacs?

In visual studio it 's easier to push F12 button to jump to a declaration of a function or variable when editing C/C++ code.
Is there a short-cut key in emacs to do that?
Well, it's a bit more involved than that.
By default, Emacs doesn't "know" about function declarations for C or C++ code. First, obtain Exuberant Ctags. Then, use command etags (ctags for Emacs) on your source code. A file named TAGS will be generated.
Then, while editing your source code, when you want to jump to a declaration, press M-. (meta and dot, or alt and dot on modern keyboards). At first, Emacs will ask you for location of your tags file. Point it to the one you generated and afterwards navigation will be automatic.
I'd suggest reading Emacswiki article about tags for a better understanding of this functionality.
The newest version of Emacs (23.2) comes with CEDET integrated, which has more advanced features for C and C++ navigation, but it can be a bit difficult to set up right, so read more about it if you're interested.
M-. key will take you to the function definition emacs.
As others have said there is no built-in universal solution for this in emacs. That said, after having this functionality in IntelliJ I wanted it in emacs too so I made Dumb Jump.
Right now Dumb Jump has basic support for:
JavaScript
Emacs Lisp
Python
Go
PHP
Ruby
Faust
and more... (over 20 now)
It's available via MELPA and is actively being developed.
There are multiple ways to do this. As darioo mentioned, Ctags is one, but it goes to the definition by default (which might work for you). Looking further, though, you can see that prefixing M-.(ie, C-u M-.) will take you to the next tag match (which is often the declaration). There is also a --declarations option, but Exuberant Ctags doesn't seem to support it.
CEDET is another option, but in my experience, it's still not ready for production. Often times in C++ semantic-ia-fast-jump will go to forward declarations instead of the definition or the declaration.

Is there such a thing as an "elisp bundle" for TextMate?

I started using Code Collector Pro to organise and save my Emacs codes, and this software requires TextMate bundles for syntax highlighting. They have a lisp bundle, but not an elisp bundle, at least not that I can see. I would think that the syntax highlighting would work under the lisp bundle, but for some reason it isn't happening.
I have never even seen any lisp code with syntax highlighting, so it is possible that the thing is working and I don't know, but I honestly don't think so, because the ;; before a line seems to me to be a comment thing, so anything after that should be in the color defined for comments which in my case is green. Here is a picture of my code collector screen with a piece of code written by huaiyuan answering my question posted here:
Is this looking as it should or is there something wrong?
Back to the initial question: is there a textmate bundle for elisp or a bundle like the ones from textmate I can download to get syntax highlighting?
I wouldn't have thought so, because anyone writing elisp is going to do it in Emacs so there wouldn't be any call for a Textmate bundle for it.

How to change emacs config in Lisp In A Box

I have been a programmer for a decade now, but I believe this is the first time I've ever asked a question on a forum. I just can't figure this out and can't find the answer already online.
I am trying to turn on CUA mode so that emacs is more bearable for a windows user (normal copy paste functions). I am running Windows 7 and installed emacs through the Lisp In A Box package. I understand that I need to add a line to my .emacs file or init.el file. I'm not sure which, but I can't find either in my Lip In A Box install directory. The emacs package install also did not come with any tutorials or help files, so its really hard to pick this up.
I am stuck, any help is greatly appreciated!
The .emacs can be found by looking at the answers to this similar question.
Regarding documentation and tutorials, it looks like the link you provided for "Lisp in a Box" says:
If you are new to Emacs, it is
recommended that you read the Emacs
Tutorial which you can access from
with Emacs by going to the Help menu,
or by typing Control-h, letting go,
and hitting t. A more extensive manual
is also available from the Help menu,
or on the web at
http://www.gnu.org/software/emacs/manual/.
Which makes it sound like the manual is there, and certainly the tutorial (I made bold the directions to get to the tutorial).
As far as other places to get information, there is a collection of screencasts on the wiki.
Your question doesn't specify whether or not you what to add to your .emacs to activate CUA mode. You can check out the CUA mode documentation on the wiki (which has links to the manual). The minimal installation is just adding this to your .emacs: (cua-mode t).
For GNU/Emacs, you can choose to use any one of the following three file names as the start-up configuration file:
${HOME}/.emacs
${HOME}/.emacs.el
${HOME}/.emacs.d/init.el
It would probably be a good idea to decide on one of the three options and then stick to it - the first one seems to be the most widely used one. In any case, ${HOME} stands for your home directory -- which is likely to be different from the Lisp In A Box install directory!
Coming from a Unix tradition, Emacs understands ~ (tilde) as an abbreviation for your home directory, so you can visit the .emacs file by typing:
C-x C-f ~/.emacs [ENTER]
(Note that the capital C is Emacs standard notation for a combination of the CTRL key and a second key, i.e. here you press CTRL-x CTRL-f which stands for "find-file" and will then ask you for a file name in the bottom part of the Frame (aka mini-buffer).)
If these are your first customizations, you will just see an empty buffer. Enter
;; start CUA mode every time Emacs starts
(cua-mode t)
and save the buffer with C-x C-s.
Next time you start Emacs, CUA mode should be turned on automatically.
What the others have told you is true: Simply adding (cua-mode t) to your dotfile would be sufficient. HOWEVER: Lisp in a box' Emacs doesn't load this file by default.
Therefore, be sure to edit the shortcut so that it does load the dotfile. This is important, because otherwise you would get weird behavior, where you would add the correct line to the dotfile, start emacs, and then not get cua mode. That would suck.
The reason it does this is to ensure that it starts a vanilla emacs everytime, instead of finding, say C:/_emacs and loading that instead, giving you another user's customizations and confusing you.
The flag for not loading an init file is -q or --no-init-file. Also make sure that --no-site-file is not there.
(I realize that this is an old post, but I found this while looking for something related, and I don't want people walking away frustrated over something that doesn't work.)