Automatically close parenthesis when we open it

30 ビュー (過去 30 日間)
Jack
Jack 2015 年 2 月 14 日
編集済み: Walter Roberson 2023 年 1 月 25 日
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 件のコメント
Yamm
Yamm 2023 年 1 月 16 日
編集済み: Yamm 2023 年 1 月 25 日
I think it could be solved with ahk scripts.

サインインしてコメントする。

回答 (4 件)

John D'Errico
John D'Errico 2015 年 2 月 14 日
編集済み: John D'Errico 2015 年 2 月 15 日
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 件のコメント
Walter Roberson
Walter Roberson 2018 年 5 月 19 日
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 2023 年 1 月 16 日
(There were a small number of improvements made to the traditional editor. But then eventually the traditional editor was removed.)

サインインしてコメントする。


emehmetcik
emehmetcik 2015 年 2 月 14 日
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 件のコメント
emehmetcik
emehmetcik 2015 年 2 月 15 日
編集済み: emehmetcik 2015 年 2 月 15 日
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 2015 年 2 月 15 日
編集済み: John D'Errico 2015 年 2 月 15 日
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
Jan 2018 年 5 月 13 日
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 2023 年 1 月 25 日
編集済み: Walter Roberson 2023 年 1 月 25 日
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

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

タグ

タグが未入力です。

製品

Community Treasure Hunt

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

Start Hunting!

Translated by