Automatically close parenthesis when we open it
28 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
As you know in other interpreters and compilers we have a good functionality that when we open a parenthesis (or {} and []), editor automatically close it. Is anyway to add this to MATLAB R2014b?
1 comentario
Respuestas (4)
John D'Errico
el 14 de Feb. de 2015
Editada: John D'Errico
el 15 de Feb. de 2015
Yes. To some extent, but currently only at the command line.
>> (2+3
(2+3
|
Error: Expression or statement is incorrect--possibly unbalanced (, {, or [.
Did you mean:
>> (2+3)
But remember that the computer may not be able to correctly infer your intentions when you write code. For example, what was intended here:
>> reshape([2+3,5,1)
reshape([2+3,5,1)
|
Error: Unbalanced or unexpected parenthesis or bracket.
Did you mean:
>> reshape([2+3,5,1])
Did MATLAB guess wrong, as perhaps my intent was to write this instead:
reshape([2+3],5,1)
At the current time, the only automatic completion offered, i.e., closing of parens, is at the command line, in the simple fashion shown above. I would point out that this is often a precursor to the editor being able to do something similar in a future release, as they seem to test out ideas like this slowly.
A point that I should make is that there is often some ambiguity in such a completion, and the dangers inherent in any such action. For example, there are now spellcheckers that run automatically as you type. Great to some extent, but rarely perfect. Since I type somewhat quickly, and I know the keyboard well enough, I often do not need to pay much attention to either the keyboard or the screen. My mind is instead focused on the next sentence, or the next line of code, planning out what I intend to say. Normally, I'd look back after a line or so at what I typed, and any errors will be glaring.
So what happens instead is those automatic spellcheckers tend to insert their corrections for me. They may in fact replace a word that does not exist in their dictionary with the wrong word, and do so while I type. Since the error is not a glaring mistake, it becomes more difficult for me to correct.
I turn those spellcheckers off whenever I can do so, as my own grasp of spelling is better than theirs, especially when you include areas like mathematics and MATLAB code.
As I pointed out above, since the correction may be somewhat ambiguous as to where the correct placement should be, I don't want the editor doing the correction for me, as I know how to code better than an editor does.
You can of course change the editor, using your own choice of tools for that purpose. If that editor has a MATLAB mode, as some do, then it might also allow such completion. If you do make a change, you then do lose some capability that is useful. For example, the mlint flags in the current editor can be helpful.
6 comentarios
Walter Roberson
el 19 de Mayo de 2018
No, you should expect no further improvements to the traditional editor. You should expect that all further effort will be made to the Live Script editor.
Walter Roberson
el 16 de En. de 2023
(There were a small number of improvements made to the traditional editor. But then eventually the traditional editor was removed.)
emehmetcik
el 14 de Feb. de 2015
I think this is something related to the text editor preferences. You can try changing the editor used by Matlab. In File->Preferences->Editor/Debugger check "Text editor" and select the editor you want to use (e.g. notepad++).
3 comentarios
emehmetcik
el 15 de Feb. de 2015
Editada: emehmetcik
el 15 de Feb. de 2015
I also realized that it is so. Apparently this was reported before in Matlab 2013a and b as discussed previously here.
I don't know whether the problem is fixed in 2014 releases or the same problem exists with other editors (emacs, vi ?).
There was also a thread in stack overflow about this. However the last edit is in 2008. And it reminds me of this xkcd comic.
John D'Errico
el 15 de Feb. de 2015
Editada: John D'Errico
el 15 de Feb. de 2015
Yes. I wondered if that was the goal. However, the current editor allows nothing of the sort at the moment. The only case where any automatic completion is offered is currently at the command line. I point out some issues in my answer.
Jan
el 13 de Mayo de 2018
The auto-completion works sufficiently in NotePad++: Enable it in Settings -> Preferences -> Auto Completion -> Select the wanted checkboxes.
I used FEX: EditorMacro for the auto-completion in Matlab's editor. But after I got used to it, a new Matlab version broke the compatibility. In addition I'm working on many different computers and getting accustomed to a non-standard typing is more confusing than closing the parentheses manually.
0 comentarios
Yamm
el 25 de En. de 2023
Editada: Walter Roberson
el 25 de En. de 2023
Hi, I was able to find a nice solution to this using and AHK script, probaby can be written better:
#IfWinActive, MATLAB R2022b - {YOUR VERSION HERE}
(::
Send, (){Left}
return
[::
Send, []{Left}
return
{::
Send, {{}{}}{Left}
return
0 comentarios
Ver también
Categorías
Más información sobre Environment and Settings en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!