Borrar filtros
Borrar filtros

How to pass commandline arguments to external text editor?

8 visualizaciones (últimos 30 días)
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 comentario
Nishant Elkunchwar
Nishant Elkunchwar el 11 de Feb. de 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.

Iniciar sesión para comentar.

Respuesta aceptada

Les Beckham
Les Beckham el 11 de Feb. de 2022
Editada: Les Beckham el 11 de Feb. de 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 comentarios
Nishant Elkunchwar
Nishant Elkunchwar el 11 de Feb. de 2022
Editada: Nishant Elkunchwar el 11 de Feb. de 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!
Les Beckham
Les Beckham el 11 de Feb. de 2022
Great! I'm glad you got it working.

Iniciar sesión para comentar.

Más respuestas (2)

Fangjun Jiang
Fangjun Jiang el 11 de Feb. de 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 comentarios
Nishant Elkunchwar
Nishant Elkunchwar el 11 de Feb. de 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 el 11 de Feb. de 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.

Iniciar sesión para comentar.


Image Analyst
Image Analyst el 11 de Feb. de 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.

Categorías

Más información sobre Environment and Settings en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by