Language

Friday, November 11, 2011

Improvement on matlab-emacs


Modification to matlab-cellbreak-face




Current cvs code for matlab.el does not handle cellbreak-face correctly. It cannot distinguish between %% and %%%%, but matlab-shell-run-cell can function well. But fontifying not well is still annoying, so we need to modify it. In matlab.el, find the following lines to modify from:




;; Cell mode breaks get special treatment
'("^\\s-*\\(%%[^\n]*\n\\)" (1 matlab-cellbreak-face append))




Change it to:




;; Cell mode breaks get special treatment
'("^\\s-*\\(%%[^%\n]*\n\\)" (1 matlab-cellbreak-face append))










Evaluate cell and advance (C-S-return)






In MATLAB editor, we can press C-S-return to perform "evaluate cell and advance" function. Minor modification to matlab.el can make it happen. You can just add the following code snippet to your .emacs file.





(require 'matlab-load)
(defun matlab-goto-next-cell ()
(interactive)
(re-search-forward "^%%[^%\n]"))

(require 'matlab)
(define-key matlab-mode-map [(meta control F)] 'matlab-goto-next-cell)
(defun matlab-run-cell-and-go ()
(interactive)
(progn
(save-excursion
(matlab-shell-run-cell))
(matlab-goto-next-cell)))
(define-key matlab-mode-map [(meta shift return)] 'matlab-run-cell-and-go)





The example for running matlab cell mode is like this:





a = [1,2,3];

c = [4,5,6];

%% This is first cell

d = a * c';

%%%% This is not a cell

b = [3,2,1];

%% Another cell

c = a + b;

kkk





After pressing three <C-S-return>, the matlab-shell screen will look like:






< M A T L A B (R) >
Copyright 1984-2010 The MathWorks, Inc.
Version 7.12.0.635 (R2011a) 64-bit (maci64)
March 18, 2011


To get started, type one of these: helpwin, helpdesk, or demo.
For product information, visit www.mathworks.com.

>> addpath('/Users/jjhuang/elisp/matlab-emacs/toolbox','-begin'); rehash; emacsinit('emacsclient -n');
>> , a = [1,2,3];, c = [4,5,6];,
>> , a = [1,2,3];, c = [4,5,6];, d = a * c';, b = [3,2,1];,
>> , d = a * c';, b = [3,2,1];, c = a + b;, kkk,
??? Undefined function or variable 'kkk'.

>>





Okay, now matlab-emacs for me is more convenient right now. Hope you enjoy it!




--
My Emacs Files At GitHub

No comments: