Azzera filtri
Azzera filtri

How to pass commandline arguments to external text editor?

8 visualizzazioni (ultimi 30 giorni)
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 Commento
Nishant Elkunchwar
Nishant Elkunchwar il 11 Feb 2022
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.

Accedi per commentare.

Risposta accettata

Les Beckham
Les Beckham il 11 Feb 2022
Modificato: Les Beckham il 11 Feb 2022
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 Commenti
Nishant Elkunchwar
Nishant Elkunchwar il 11 Feb 2022
Modificato: Nishant Elkunchwar il 11 Feb 2022
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!

Accedi per commentare.

Più risposte (2)

Fangjun Jiang
Fangjun Jiang il 11 Feb 2022
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 Commenti
Nishant Elkunchwar
Nishant Elkunchwar il 11 Feb 2022
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 il 11 Feb 2022
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.

Accedi per commentare.


Image Analyst
Image Analyst il 11 Feb 2022
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.

Categorie

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

Prodotti


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by