<?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="https://undocumentedmatlab.com/articles/editormacro-v2-setting-command-window-key-bindings/feed" rel="self" type="application/rss+xml" />
	<link>https://undocumentedmatlab.com/articles/editormacro-v2-setting-command-window-key-bindings?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=editormacro-v2-setting-command-window-key-bindings</link>
	<description>Professional Matlab consulting, development and training</description>
	<lastBuildDate>Fri, 13 Jan 2012 12:59:22 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.2</generator>
	<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/editormacro-v2-setting-command-window-key-bindings#comment-70764</link>

		<dc:creator><![CDATA[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><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/editormacro-v2-setting-command-window-key-bindings#comment-70759&quot;&gt;mb&lt;/a&gt;.

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>In reply to <a href="https://undocumentedmatlab.com/articles/editormacro-v2-setting-command-window-key-bindings#comment-70759">mb</a>.</p>
<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>
<pre lang="matlab">
% 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);
</pre>
<p>Other useful methods of the <code>jEditorApp.getActiveEditor</code> reference are:</p>
<pre lang="matlab">
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()
</pre>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: mb		</title>
		<link>https://undocumentedmatlab.com/articles/editormacro-v2-setting-command-window-key-bindings#comment-70759</link>

		<dc:creator><![CDATA[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><![CDATA[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>
<pre lang="matlab">
filehandle = matlab.desktop.editor.getActive 
filehandle.save() ;
</pre>
<p>More about it can be found here <a href="http://blogs.mathworks.com/desktop/2011/05/09/r2011a-matlab-editor-api/" rel="nofollow ugc">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>https://undocumentedmatlab.com/articles/editormacro-v2-setting-command-window-key-bindings#comment-2261</link>

		<dc:creator><![CDATA[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><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/editormacro-v2-setting-command-window-key-bindings#comment-2241&quot;&gt;jo&lt;/a&gt;.

@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>In reply to <a href="https://undocumentedmatlab.com/articles/editormacro-v2-setting-command-window-key-bindings#comment-2241">jo</a>.</p>
<p>@Jo &#8211; Here&#8217;s a snippet of a sample macro (callback) function:</p>
<pre lang="matlab">
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
</pre>
<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>https://undocumentedmatlab.com/articles/editormacro-v2-setting-command-window-key-bindings#comment-2241</link>

		<dc:creator><![CDATA[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><![CDATA[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! 🙂<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>
