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

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

Re: Run terminal command with output in current buffer


From: Felix Dietrich
Subject: Re: Run terminal command with output in current buffer
Date: Fri, 16 Jul 2021 15:25:49 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)

lisa-asket@perso.be writes:
> ;; grep -hir --exclude=\*.el --include=\*.{org,texi} -C 8 "node-gnu-fdl" .
> 
> (cmd-excl (read-from-minibuffer "exclude: "))
> (setq cmd-excl (concat " -C --exclude=\*." cmd-excl))
>
> (cmd-incl (read-from-minibuffer "include: "))
> (setq cmd-incl (concat " -C --include=\*." cmd-incl))

The backslash is special in Emacs strings, and you need to escape it
with an extra backslash if you want it to be part of the string.
Compare the strings inserted by these two commands:

    (insert "\*") ; This will insert just ‘*’.

    (insert "\\*") ; This will insert ‘\*’.


In front of certain characters, the backlash translates these characters
into other characters [1][2].  Characters preceded by a backslash that
are not known “escape sequences” stand for themselves; this is the case
for ‘*’, and that is why you need to double the backslash.

Similarly, you may need to escape characters for the shell in the string
read from the minibuffer: have a look at the function
“shell-quote-argument”.

Is the first string to “concat” missing a space at itʼs end?

If this isnʼt an exercise for fun or otherwise: you can call grep from
within Emacs using the command “M-x grep”.


Footnotes:
[1]  (elisp) Basic Char Syntax

     
<https://www.gnu.org/software/emacs/manual/html_node/elisp/Basic-Char-Syntax.html>

[2]  (elisp) Syntax for Strings

     
<https://www.gnu.org/software/emacs/manual/html_node/elisp/Syntax-for-Strings.html>

-- 
Felix Dietrich



reply via email to

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