Automatically close parenthesis when we open it

40 visualizzazioni (ultimi 30 giorni)
Jack
Jack il 14 Feb 2015
Modificato: Walter Roberson il 25 Gen 2023
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 Commento
Yamm
Yamm il 16 Gen 2023
Modificato: Yamm il 25 Gen 2023
I think it could be solved with ahk scripts.

Accedi per commentare.

Risposte (4)

John D'Errico
John D'Errico il 14 Feb 2015
Modificato: John D'Errico il 15 Feb 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 Commenti
Walter Roberson
Walter Roberson il 19 Mag 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
Walter Roberson il 16 Gen 2023
(There were a small number of improvements made to the traditional editor. But then eventually the traditional editor was removed.)

Accedi per commentare.


emehmetcik
emehmetcik il 14 Feb 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 Commenti
emehmetcik
emehmetcik il 15 Feb 2015
Modificato: emehmetcik il 15 Feb 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
John D'Errico il 15 Feb 2015
Modificato: John D'Errico il 15 Feb 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.

Accedi per commentare.


Jan
Jan il 13 Mag 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.

Yamm
Yamm il 25 Gen 2023
Modificato: Walter Roberson il 25 Gen 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

Categorie

Scopri di più su Environment and Settings in Help Center e File Exchange

Tag

Non è stata ancora inserito alcun tag.

Prodotti

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by