<?xml version="1.0" encoding="UTF-8"?><rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
> <channel><title>Comments on: EditorMacro v2 &#8211; setting Command Window key-bindings</title> <atom:link href="http://undocumentedmatlab.com/blog/editormacro-v2-setting-command-window-key-bindings/feed/" rel="self" type="application/rss+xml" /><link>http://undocumentedmatlab.com/blog/editormacro-v2-setting-command-window-key-bindings/</link> <description>Charting Matlab's unsupported hidden underbelly</description> <lastBuildDate>Fri, 18 May 2012 13:56:51 +0000</lastBuildDate> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.1.1</generator> <item><title>By: Yair Altman</title><link>http://undocumentedmatlab.com/blog/editormacro-v2-setting-command-window-key-bindings/#comment-70764</link> <dc:creator>Yair Altman</dc:creator> <pubDate>Fri, 13 Jan 2012 12:59:22 +0000</pubDate> <guid
isPermaLink="false">http://undocumentedmatlab.com/?p=518#comment-70764</guid> <description>This is indeed a very good example of the risks in using internal Matlab components - their API can change dramatically from one release to another, without prior notice.Here is the alternative in the latest Matlab release (12a):&lt;pre lang=&quot;matlab&quot;&gt;
% Get the reference to the editor application
jEditorApp = com.mathworks.mde.editor.MatlabEditorApplication.getInstance;
jEditorApp = com.mathworks.mlservices.MLEditorServices.getEditorApplication;  % an alternative% Save the current file
jEditorApp.getActiveEditor.save();
jEditorApp.getActiveEditor.saveAs(filename);
&lt;/pre&gt;Other useful methods of the &lt;code&gt;jEditorApp.getActiveEditor&lt;/code&gt; reference are:
&lt;pre lang=&quot;matlab&quot;&gt;
addEventListener(com.mathworks.matlab.api.editor.EditorEventListener)
addPropertyChangeListener(java.beans.PropertyChangeListener)
addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
appendText(java.lang.String)
bringToFront()
close()
closeNoPrompt()
dispose()
fireEditorEvent(com.mathworks.matlab.api.editor.EditorEvent)
firePropertyChange(java.lang.String, java.lang.Object, java.lang.Object)
getBreakpointMargin() : com.mathworks.matlab.api.debug.BreakpointMargin
getCaretPosition() : int
getComponent() : java.awt.Component
getDocument() : javax.swing.text.Document
getExecutionArrowMargin() : com.mathworks.matlab.api.debug.ExecutionArrowMargin
getLanguage() : com.mathworks.matlab.api.editor.EditorLanguage
getLength() : int
getLineNumber() : int
getLongName() : java.lang.String
getProperty(java.lang.Object) : java.lang.Object
getSelection() : java.lang.String
getShortName() : java.lang.String
getStorageLocation() : com.mathworks.matlab.api.datamodel.StorageLocation
getText() : java.lang.String
getTextComponent() : javax.swing.text.JTextComponent
getTextWithSystemLineEndings() : java.lang.String
goToFunction(java.lang.String, java.lang.String)
goToLine(int, boolean)
goToLine(int, int)
goToPositionAndHighlight(int, int)
insertAndFormatTextAtCaret(java.lang.String)
insertTextAtCaret(java.lang.String)
isBuffer() : boolean
isDirty() : boolean
isEditable() : boolean
isMCode() : boolean
isOpen() : boolean
lineAndColumnToPosition(int, int) : int
lockIfOpen() : boolean
negotiateSave() : boolean
positionToLineAndColumn(int) : int[]
putProperty(java.lang.String, java.lang.Object)
refreshMenus()
reload()
reloadAndReturnError() : java.lang.String
removeEventListener(com.mathworks.matlab.api.editor.EditorEventListener)
removePropertyChangeListener(java.beans.PropertyChangeListener)
removePropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
replaceText(java.lang.String, int, int)
save()
saveAndReturnError() : java.lang.String
saveAs(java.lang.String)
saveAsAndReturnError(java.lang.String) : java.lang.String
setCaretPosition(int)
setClean()
setDirtyUntilSave()
setEditable(boolean)
setEditorStatusBarText(java.lang.String)
setSelection(int, int)
setStatusText(java.lang.String)
smartIndentContents()
unlock()
&lt;/pre&gt;</description> <content:encoded><![CDATA[<p>This is indeed a very good example of the risks in using internal Matlab components &#8211; their API can change dramatically from one release to another, without prior notice.</p><p>Here is the alternative in the latest Matlab release (12a):</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #228B22;">% Get the reference to the editor application</span>
jEditorApp = com.<span style="">mathworks</span>.<span style="">mde</span>.<span style="">editor</span>.<span style="">MatlabEditorApplication</span>.<span style="">getInstance</span>;
jEditorApp = com.<span style="">mathworks</span>.<span style="">mlservices</span>.<span style="">MLEditorServices</span>.<span style="">getEditorApplication</span>;  <span style="color: #228B22;">% an alternative</span>
&nbsp;
<span style="color: #228B22;">% Save the current file</span>
jEditorApp.<span style="">getActiveEditor</span>.<span style="color: #0000FF;">save</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span>;
jEditorApp.<span style="">getActiveEditor</span>.<span style="color: #0000FF;">saveAs</span><span style="color: #080;">&#40;</span>filename<span style="color: #080;">&#41;</span>;</pre></div></div><p>Other useful methods of the <code>jEditorApp.getActiveEditor</code> reference are:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">addEventListener<span style="color: #080;">&#40;</span>com.<span style="">mathworks</span>.<span style="">matlab</span>.<span style="">api</span>.<span style="">editor</span>.<span style="">EditorEventListener</span><span style="color: #080;">&#41;</span>
addPropertyChangeListener<span style="color: #080;">&#40;</span>java.<span style="">beans</span>.<span style="">PropertyChangeListener</span><span style="color: #080;">&#41;</span>
addPropertyChangeListener<span style="color: #080;">&#40;</span>java.<span style="">lang</span>.<span style="">String</span>, java.<span style="">beans</span>.<span style="">PropertyChangeListener</span><span style="color: #080;">&#41;</span>
appendText<span style="color: #080;">&#40;</span>java.<span style="">lang</span>.<span style="">String</span><span style="color: #080;">&#41;</span>
bringToFront<span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span>
<span style="color: #0000FF;">close</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span>
closeNoPrompt<span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span>
dispose<span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span>
fireEditorEvent<span style="color: #080;">&#40;</span>com.<span style="">mathworks</span>.<span style="">matlab</span>.<span style="">api</span>.<span style="">editor</span>.<span style="">EditorEvent</span><span style="color: #080;">&#41;</span>
firePropertyChange<span style="color: #080;">&#40;</span>java.<span style="">lang</span>.<span style="">String</span>, java.<span style="">lang</span>.<span style="">Object</span>, java.<span style="">lang</span>.<span style="">Object</span><span style="color: #080;">&#41;</span>
getBreakpointMargin<span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span> <span style="color: #F0F;">:</span> com.<span style="">mathworks</span>.<span style="">matlab</span>.<span style="">api</span>.<span style="">debug</span>.<span style="">BreakpointMargin</span>
getCaretPosition<span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span> <span style="color: #F0F;">:</span> int
getComponent<span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span> <span style="color: #F0F;">:</span> java.<span style="">awt</span>.<span style="">Component</span>
getDocument<span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span> <span style="color: #F0F;">:</span> javax.<span style="">swing</span>.<span style="">text</span>.<span style="">Document</span>
getExecutionArrowMargin<span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span> <span style="color: #F0F;">:</span> com.<span style="">mathworks</span>.<span style="">matlab</span>.<span style="">api</span>.<span style="">debug</span>.<span style="">ExecutionArrowMargin</span>
getLanguage<span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span> <span style="color: #F0F;">:</span> com.<span style="">mathworks</span>.<span style="">matlab</span>.<span style="">api</span>.<span style="">editor</span>.<span style="">EditorLanguage</span>
getLength<span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span> <span style="color: #F0F;">:</span> int
getLineNumber<span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span> <span style="color: #F0F;">:</span> int
getLongName<span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span> <span style="color: #F0F;">:</span> java.<span style="">lang</span>.<span style="">String</span>
getProperty<span style="color: #080;">&#40;</span>java.<span style="">lang</span>.<span style="">Object</span><span style="color: #080;">&#41;</span> <span style="color: #F0F;">:</span> java.<span style="">lang</span>.<span style="">Object</span>
getSelection<span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span> <span style="color: #F0F;">:</span> java.<span style="">lang</span>.<span style="">String</span>
getShortName<span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span> <span style="color: #F0F;">:</span> java.<span style="">lang</span>.<span style="">String</span>
getStorageLocation<span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span> <span style="color: #F0F;">:</span> com.<span style="">mathworks</span>.<span style="">matlab</span>.<span style="">api</span>.<span style="">datamodel</span>.<span style="">StorageLocation</span>
getText<span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span> <span style="color: #F0F;">:</span> java.<span style="">lang</span>.<span style="">String</span>
getTextComponent<span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span> <span style="color: #F0F;">:</span> javax.<span style="">swing</span>.<span style="">text</span>.<span style="">JTextComponent</span>
getTextWithSystemLineEndings<span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span> <span style="color: #F0F;">:</span> java.<span style="">lang</span>.<span style="">String</span>
goToFunction<span style="color: #080;">&#40;</span>java.<span style="">lang</span>.<span style="">String</span>, java.<span style="">lang</span>.<span style="">String</span><span style="color: #080;">&#41;</span>
goToLine<span style="color: #080;">&#40;</span>int, boolean<span style="color: #080;">&#41;</span>
goToLine<span style="color: #080;">&#40;</span>int, int<span style="color: #080;">&#41;</span>
goToPositionAndHighlight<span style="color: #080;">&#40;</span>int, int<span style="color: #080;">&#41;</span>
insertAndFormatTextAtCaret<span style="color: #080;">&#40;</span>java.<span style="">lang</span>.<span style="">String</span><span style="color: #080;">&#41;</span>
insertTextAtCaret<span style="color: #080;">&#40;</span>java.<span style="">lang</span>.<span style="">String</span><span style="color: #080;">&#41;</span>
isBuffer<span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span> <span style="color: #F0F;">:</span> boolean
isDirty<span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span> <span style="color: #F0F;">:</span> boolean
isEditable<span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span> <span style="color: #F0F;">:</span> boolean
isMCode<span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span> <span style="color: #F0F;">:</span> boolean
isOpen<span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span> <span style="color: #F0F;">:</span> boolean
lineAndColumnToPosition<span style="color: #080;">&#40;</span>int, int<span style="color: #080;">&#41;</span> <span style="color: #F0F;">:</span> int
lockIfOpen<span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span> <span style="color: #F0F;">:</span> boolean
negotiateSave<span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span> <span style="color: #F0F;">:</span> boolean
positionToLineAndColumn<span style="color: #080;">&#40;</span>int<span style="color: #080;">&#41;</span> <span style="color: #F0F;">:</span> int<span style="color: #080;">&#91;</span><span style="color: #080;">&#93;</span>
putProperty<span style="color: #080;">&#40;</span>java.<span style="">lang</span>.<span style="">String</span>, java.<span style="">lang</span>.<span style="">Object</span><span style="color: #080;">&#41;</span>
refreshMenus<span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span>
reload<span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span>
reloadAndReturnError<span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span> <span style="color: #F0F;">:</span> java.<span style="">lang</span>.<span style="">String</span>
removeEventListener<span style="color: #080;">&#40;</span>com.<span style="">mathworks</span>.<span style="">matlab</span>.<span style="">api</span>.<span style="">editor</span>.<span style="">EditorEventListener</span><span style="color: #080;">&#41;</span>
removePropertyChangeListener<span style="color: #080;">&#40;</span>java.<span style="">beans</span>.<span style="">PropertyChangeListener</span><span style="color: #080;">&#41;</span>
removePropertyChangeListener<span style="color: #080;">&#40;</span>java.<span style="">lang</span>.<span style="">String</span>, java.<span style="">beans</span>.<span style="">PropertyChangeListener</span><span style="color: #080;">&#41;</span>
replaceText<span style="color: #080;">&#40;</span>java.<span style="">lang</span>.<span style="">String</span>, int, int<span style="color: #080;">&#41;</span>
<span style="color: #0000FF;">save</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span>
saveAndReturnError<span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span> <span style="color: #F0F;">:</span> java.<span style="">lang</span>.<span style="">String</span>
<span style="color: #0000FF;">saveAs</span><span style="color: #080;">&#40;</span>java.<span style="">lang</span>.<span style="">String</span><span style="color: #080;">&#41;</span>
saveAsAndReturnError<span style="color: #080;">&#40;</span>java.<span style="">lang</span>.<span style="">String</span><span style="color: #080;">&#41;</span> <span style="color: #F0F;">:</span> java.<span style="">lang</span>.<span style="">String</span>
setCaretPosition<span style="color: #080;">&#40;</span>int<span style="color: #080;">&#41;</span>
setClean<span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span>
setDirtyUntilSave<span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span>
setEditable<span style="color: #080;">&#40;</span>boolean<span style="color: #080;">&#41;</span>
setEditorStatusBarText<span style="color: #080;">&#40;</span>java.<span style="">lang</span>.<span style="">String</span><span style="color: #080;">&#41;</span>
setSelection<span style="color: #080;">&#40;</span>int, int<span style="color: #080;">&#41;</span>
setStatusText<span style="color: #080;">&#40;</span>java.<span style="">lang</span>.<span style="">String</span><span style="color: #080;">&#41;</span>
smartIndentContents<span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span>
unlock<span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span></pre></div></div>]]></content:encoded> </item> <item><title>By: mb</title><link>http://undocumentedmatlab.com/blog/editormacro-v2-setting-command-window-key-bindings/#comment-70759</link> <dc:creator>mb</dc:creator> <pubDate>Fri, 13 Jan 2012 12:38:05 +0000</pubDate> <guid
isPermaLink="false">http://undocumentedmatlab.com/?p=518#comment-70759</guid> <description>Hi,
In Matlab 2011 com.mathworks.mlservices.MLEditorServices has no such method as saveDocument.
Instead of it one can use matlab editor api to save the document:&lt;pre lang=&quot;matlab&quot;&gt;
filehandle = matlab.desktop.editor.getActive
filehandle.save() ;
&lt;/pre&gt;More about it can be found here http://blogs.mathworks.com/desktop/2011/05/09/r2011a-matlab-editor-api/ .
I hope it will save someone&#039;s time.Regards,
mb</description> <content:encoded><![CDATA[<p>Hi,<br
/> In Matlab 2011 com.mathworks.mlservices.MLEditorServices has no such method as saveDocument.<br
/> Instead of it one can use matlab editor api to save the document:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;">filehandle = matlab.<span style="">desktop</span>.<span style="">editor</span>.<span style="">getActive</span> 
filehandle.<span style="color: #0000FF;">save</span><span style="color: #080;">&#40;</span><span style="color: #080;">&#41;</span> ;</pre></div></div><p>More about it can be found here <a
href="http://blogs.mathworks.com/desktop/2011/05/09/r2011a-matlab-editor-api/" rel="nofollow">http://blogs.mathworks.com/desktop/2011/05/09/r2011a-matlab-editor-api/</a> .<br
/> I hope it will save someone&#8217;s time.</p><p>Regards,<br
/> mb</p> ]]></content:encoded> </item> <item><title>By: Yair Altman</title><link>http://undocumentedmatlab.com/blog/editormacro-v2-setting-command-window-key-bindings/#comment-2261</link> <dc:creator>Yair Altman</dc:creator> <pubDate>Sat, 22 Aug 2009 19:47:28 +0000</pubDate> <guid
isPermaLink="false">http://undocumentedmatlab.com/?p=518#comment-2261</guid> <description>@Jo - Here&#039;s a snippet of a sample macro (callback) function:&lt;pre lang=&quot;matlab&quot;&gt;
function myCallback(jDocument, jEventData, varargin)
filename = jDocument.getFilename;
% do some user-defined stuff% Now save the file:
com.mathworks.mlservices.MLEditorServices.saveDocument(filename);
end  % myCallback
&lt;/pre&gt;Also look at Perttu&#039;s &lt;b&gt;&lt;i&gt;KeyBindings&lt;/i&gt;&lt;/b&gt; utility for other usage examples of MLEditorServices.Yair</description> <content:encoded><![CDATA[<p>@Jo &#8211; Here&#8217;s a snippet of a sample macro (callback) function:</p><div
class="wp_syntax"><div
class="code"><pre class="matlab" style="font-family:monospace;"><span style="color: #0000FF;">function</span> myCallback<span style="color: #080;">&#40;</span>jDocument, jEventData, <span style="color: #0000FF;">varargin</span><span style="color: #080;">&#41;</span>
   filename = jDocument.<span style="">getFilename</span>;
   <span style="color: #228B22;">% do some user-defined stuff</span>
&nbsp;
   <span style="color: #228B22;">% Now save the file:</span>
   com.<span style="">mathworks</span>.<span style="">mlservices</span>.<span style="">MLEditorServices</span>.<span style="">saveDocument</span><span style="color: #080;">&#40;</span>filename<span style="color: #080;">&#41;</span>;
<span style="color: #0000FF;">end</span>  <span style="color: #228B22;">% myCallback</span></pre></div></div><p>Also look at Perttu&#8217;s <b><i>KeyBindings</i></b> utility for other usage examples of MLEditorServices.</p><p>Yair</p> ]]></content:encoded> </item> <item><title>By: jo</title><link>http://undocumentedmatlab.com/blog/editormacro-v2-setting-command-window-key-bindings/#comment-2241</link> <dc:creator>jo</dc:creator> <pubDate>Fri, 21 Aug 2009 20:43:48 +0000</pubDate> <guid
isPermaLink="false">http://undocumentedmatlab.com/?p=518#comment-2241</guid> <description>Thanks!
EditorMacro has been added to the startup.m file! :)
So far I&#039;ve created few macros that remarkably speed up my work.
One of them is a macro that executes code between  tags embedded in a comment of an m-file - excellent alternative for Edit Run Configuration... + F5 combination during debugging an m-file, but... I cannot solve one problem: automatic saving file before run (eg. to activate fresh breakpoints).
Your post about internal commands gave me new hope. I&#039;ve made some trials to save m-file programmatically but without effect.Do you know if such an action is possible from inside the macro?</description> <content:encoded><![CDATA[<p>Thanks!<br
/> EditorMacro has been added to the startup.m file! <img
src='http://undocumentedmatlab.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br
/> So far I&#8217;ve created few macros that remarkably speed up my work.<br
/> One of them is a macro that executes code between  tags embedded in a comment of an m-file &#8211; excellent alternative for Edit Run Configuration&#8230; + F5 combination during debugging an m-file, but&#8230; I cannot solve one problem: automatic saving file before run (eg. to activate fresh breakpoints).<br
/> Your post about internal commands gave me new hope. I&#8217;ve made some trials to save m-file programmatically but without effect.</p><p>Do you know if such an action is possible from inside the macro?</p> ]]></content:encoded> </item> </channel> </rss>

<!-- W3 Total Cache: Minify debug info:
Engine:             disk: basic
Theme:              b7666
Template:           single
-->
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Served from: undocumentedmatlab.com @ 2012-05-18 22:46:10 -->

<!-- W3 Total Cache: Page cache debug info:
Engine:             disk: enhanced
Cache key:          blog/editormacro-v2-setting-command-window-key-bindings/feed/_index.xml_gzip
Caching:            enabled
Status:             not cached
Creation Time:      0.559s
Header info:
X-Pingback:         http://undocumentedmatlab.com/blog/xmlrpc.php
Set-Cookie:         wpgb_visit_last_php-default=1337406370; expires=Sun, 19-May-2013 05:46:10 GMT; path=/
Link:               <http://undocumentedmatlab.com/?p=518>; rel=shortlink
Content-Type:       text/xml; charset=UTF-8
Last-Modified:      Sat, 19 May 2012 05:46:10 GMT
Vary:               Accept-Encoding, Cookie
Expires:            Sat, 19 May 2012 06:46:10 GMT
Pragma:             public
Cache-Control:      public, must-revalidate, proxy-revalidate
Etag:               e82df7d1d8ccc134baa63cc4dc9c99b9
Content-Encoding:   gzip
-->
