Feeds:
Posts
Comments

Archive for the ‘matlab’ Category

the title of this post is misleading … i only talk about commenting and uncommenting region.

this is a small tip for emacs users who want to edit matlab m-files and octave m-files without installing some major mode for editing matlab files. emacs already ships with a built in gnu octave mode and the true hacker will use free software only. but i m no where near being a true hacker thus i often have to write some matlab stuff. i associate all .m files with the octave mode and i have the following line in my .emacs file to achieve that

(setq auto-mode-alist (cons '("\\.m$" . octave-mode) auto-mode-alist))

the major annoyance is that matlab uses the ‘%‘ as the comment char while gnu octave uses ‘#‘. so when editing m files in emacs i often include the following local file variables

% Local Variables:
% comment-start: "%"
% comment-column: 0
% End:

at the end of the m-file. these lines are treated as comments by the matlab interpreter due to the ‘%’ prefix but emacs scans the file and reads these lines and now you can highlight text and use M-x comment-region or M-x uncomment-region. after adding the lines either kill the buffer and visit the file again or hit C-x C-v and then choose the same filename again.

there are probably many good features of the matlab editor but i have not used them much apart from the ability to run the current m file by hitting F5 or setting and clearing breakpoints with mouse clicks. i do like the F5 thingy but i m sure a little bit of elisp can solve that problem. i m sure there are some good major modes for editing matlab files or integrating with matlab but i haven’t explored this area at all.

my emacs version is “GNU Emacs 23.4.1 (i686-pc-linux-gnu, GTK+ Version 2.24.10) of 2012-04-12 on shirley.hoetzel.info”

Read Full Post »