フィルターのクリア

How to pass commandline arguments to external text editor?

8 ビュー (過去 30 日間)
Nishant Elkunchwar
Nishant Elkunchwar 2022 年 2 月 11 日
編集済み: Nishant Elkunchwar 2022 年 2 月 11 日
I want to use emacsclient to edit .m files opened through matlab. The Preferences > Editor/Debugger section has an option to configure an external text editor. Using
C:\Program Files\Emacs\x86_64\bin\runemacs.exe
works as expected. However, starting emacsclient requires commandline arguments:
C:\Program Files\Emacs\x86_64\bin\emacsclientw.exe -n -c -a ""
Adding this (or even just the required bare minimum -c flag) as the external editor and opening a .m file opens a cmd window showing the error:
'"C:\Program Files\Emacs\x86_64\bin\emacsclientw.exe -c"' is not recognized as an internal or external command,
operable program or batch file.
Is there an option to include commandline arguments?
  1 件のコメント
Nishant Elkunchwar
Nishant Elkunchwar 2022 年 2 月 11 日
Let me clarify my question: it is not to open a file in an external editor by using a matlab command / script; it is to set an external program as a text editor in the matlab preferences so that any (not only one particular file) matlab script file opened from Matlab gets opened in the external text editor instead of Matlab's own Editor. As mentioned already, just setting an external text editor program in the "Preferences > Editor/Debugger > Text editor" field works, but what doesn't work is adding commandline arguments in that field since Matlab apparently quotes the entire text in that text box. I also tried:
s = settings
s.matlab.editor.OtherEditor.PersonalValue = '"C:\Program Files\Emacs\x86_64\bin\emacsclientw.exe" -n -c -a ""'
but that doesn't work either.

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

採用された回答

Les Beckham
Les Beckham 2022 年 2 月 11 日
編集済み: Les Beckham 2022 年 2 月 11 日
I don't have access to Matlab at the moment so I can't test this, but perhaps you can create a .bat file similar to this and put the path to that bat file in the "Preferences > Editor/Debugger > Text editor" field:
C:\Program Files\Emacs\x86_64\bin\emacsclientw.exe -n -c -a "" %1
  2 件のコメント
Nishant Elkunchwar
Nishant Elkunchwar 2022 年 2 月 11 日
編集済み: Nishant Elkunchwar 2022 年 2 月 11 日
Nice solution! It works, only had to do the following modifications:
  1. Add quotes around the path since it contains a space.
  2. Had to provide the -f "path\to\.emacs.d\server\server" argument in this case for some reason.
  3. Add exit at the end so the command window doesn't unnecessarily float around
So the .bat file I created was:
"C:\Program Files\Emacs\x86_64\bin\emacsclientw.exe" -n -c -a "" -f "C:\Users\<your username>\.emacs.d\server\server" %1
exit
Thanks!
Les Beckham
Les Beckham 2022 年 2 月 11 日
Great! I'm glad you got it working.

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

その他の回答 (2 件)

Fangjun Jiang
Fangjun Jiang 2022 年 2 月 11 日
You need to run system("C:\Program Files\Emacs\x86_64\bin\emacsclientw.exe -n -c -a")
or add this line to your own edit.m file
  2 件のコメント
Nishant Elkunchwar
Nishant Elkunchwar 2022 年 2 月 11 日
Adding system("C:\Program Files\Emacs\x86_64\bin\emacsclientw.exe -n -c -a") to the external editor field does not work either. A cmd window opens saying:
The filename, directory name, or volume label syntax is incorrect.
Fangjun Jiang
Fangjun Jiang 2022 年 2 月 11 日
I meant if exeternal .exe file requries arguments, then you can run the system() in Command Window, or make your own edit.m file to include the system() line. Then you can run "edit" in Comand Window to bring up your own Editor.

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


Image Analyst
Image Analyst 2022 年 2 月 11 日
Here is an example of how I pass two filenames to my calibration chart editor program:
% Now run the Calibration Chart editor program.
% First construct the command line for the system() function.
% Enclose all filenames in double quotes because we may have spaces in the filenames.
editorFullFileName = 'C:\Program Files (x86)\CalibrationChartEditor\CalibrationChartEditor.exe';
arguments = sprintf('-chartfile "%s" -chartimage "%s"', fullRefChartDataFileName, fullRefChartImageFileName);
commandLine = sprintf('"%s" %s', editorFullFileName, arguments);
fprintf('\n%s\n', commandLine);
%----------------------------------------------------------
% Now launch the Calibration Chart editor program using the "system()" function.
% msgboxw(commandLine);
system(commandLine);
Note, if you're passing in strings that have spaces in them, they must be enclosed in double quotes, like I did.

カテゴリ

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

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by