help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Convert the shell command used in emacs init-file into its normal ve


From: Hongyi Zhao
Subject: Re: Convert the shell command used in emacs init-file into its normal version.
Date: Wed, 9 Jun 2021 16:22:38 +0800

On Wed, Jun 9, 2021 at 4:13 PM <tomas@tuxteam.de> wrote:
>
> On Wed, Jun 09, 2021 at 04:03:09PM +0800, Hongyi Zhao wrote:
> > On Wed, Jun 9, 2021 at 3:01 PM Jean Louis <bugs@gnu.support> wrote:
> > >
> > > * Hongyi Zhao <hongyi.zhao@gmail.com> [2021-06-09 09:50]:
> > > > I found the following command from
> > > > <https://github.com/jethrokuan/mathpix.el/blob/02016ca4aee9ffce32e730372f45de35c00a3657/mathpix.el#L49>:
> > > >
> > > > "curl -s https://api.mathpix.com/v3/latex -X POST -H \"app_id: %s\" -H
> > > > \"app_key: %s\" -H \"Content-Type: application/json\" --data
> > > > \"{\\\"src\\\":\\\"%s\\\",\\\"formats\\\":
> > > > [\\\"latex_styled\\\"],\\\"format_options\\\":{\\\"latex_styled\\\":
> > > > {\\\"transforms\\\": [\\\"rm_spaces\\\"]}}}\""
> > > >
> > > > I want to obtain its normal version and test it under the system's
> > > > shell terminal. Any hints for deleting the escape characters correctly
> > > > from the above command in Emacs way?
> > >
> > > You should use the function `call-process' as it will help with
> > > quoting:
> > >
> > > (call-process "curl" nil nil nil "-s" "https://api.mathpix.com/v3/latex";
> > >               "-X" "POST" "-H" (format "app_id: %s" id)
> > >               "-H" (format "app_key: %s" key)
> > >               "-H" "Content-Type: application/json"
> > >               "--data" "{\"src\":\"%s\",
> > >                          \"formats\": [\"latex_styled\"],
> > >                          \"format_options\": {\"latex_styled\":
> > >                                              {\"transforms\": 
> > > [\"rm_spaces\"]}}}")
> >
> > You've stripped the escaping characters out manually in the above code.
>
> It's a bit more complex than that: The above is one big string in Emacs
> lisp which is to be passed to a shell. So it has an "outer" syntax,
> to be interpreted by the Emacs lisp reader, and an "inner" to be
> interpreted by the shell reader.
>
> The below is split into several strings (call-process takes a list
> of arguments, which are passed to exec), so no "shell escaping" is
> necessary. But since the individual arguments are represented as
> Emacs lisp strings, they need that escaping.

Is this way more efficient than the original version?

> So in a way yes, one layer of escaping has been removed, but it's
> the lower layer, the shell escaping. It just looks very similar to
> the upper (lisp) layer :-)
>
> Cheers
>  - t



-- 
Assoc. Prof. Hongyi Zhao <hongyi.zhao@gmail.com>
Theory and Simulation of Materials
Hebei Vocational University of Technology and Engineering
NO. 552 North Gangtie Road, Xingtai, China



reply via email to

[Prev in Thread] Current Thread [Next in Thread]