all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Hongyi Zhao <hongyi.zhao@gmail.com>
To: tomas@tuxteam.de
Cc: help-gnu-emacs <help-gnu-emacs@gnu.org>
Subject: Re: Convert the shell command used in emacs init-file into its normal version.
Date: Wed, 9 Jun 2021 16:22:38 +0800	[thread overview]
Message-ID: <CAGP6PO+fuvYU=HnPS=t5tep1kW4YLjAuyOK_4x+K=Nvnybydsg@mail.gmail.com> (raw)
In-Reply-To: <20210609081309.GE21706@tuxteam.de>

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	other threads:[~2021-06-09  8:22 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-09  6:49 Convert the shell command used in emacs init-file into its normal version Hongyi Zhao
2021-06-09  6:58 ` Jean Louis
2021-06-09  8:03   ` Hongyi Zhao
2021-06-09  8:13     ` tomas
2021-06-09  8:22       ` Hongyi Zhao [this message]
2021-06-09  8:50         ` tomas
2021-06-09  8:26     ` Jean Louis
2021-06-09  7:23 ` Yuri Khan
2021-06-09  7:57   ` Hongyi Zhao
2021-06-09 11:37 ` Eli Zaretskii
2021-06-09 14:21   ` Hongyi Zhao
2021-06-09 17:17     ` Eli Zaretskii
2021-06-10  2:26       ` Hongyi Zhao
2021-06-10  6:59         ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAGP6PO+fuvYU=HnPS=t5tep1kW4YLjAuyOK_4x+K=Nvnybydsg@mail.gmail.com' \
    --to=hongyi.zhao@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=tomas@tuxteam.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.