[Top][All Lists]

[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) 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

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”.

[1]  (elisp) Basic Char Syntax


[2]  (elisp) Syntax for Strings


Felix Dietrich

reply via email to

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