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

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

Re: terminal command with output in current buff


From: Felix Dietrich
Subject: Re: terminal command with output in current buff
Date: Sat, 17 Jul 2021 13:33:13 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)

lisa-asket@perso.be writes:

> I am getting a small problem when using `(cmd-cnum (read-number "context: "))`
>
> Wrong type argument: sequencep, 8

Please provide, if possible, small self-contained examples that
reproduce your problem and more context around your snippets: I had to
hunt for the context in your past messages.  Here is a simplified
version of your code that causes the problem and serves as an example of
what I mean by “self-contained example”:


    (let* ((cmd-cnum (read-number "Number: "))
           (cmd-temp `("grep" ,cmd-cnum))
           ;; same as: (cmd-temp (list "grep" cmd-cnum))
      (mapconcat #'shell-quote-argument cmd-temp " "))


> number-to-string seems to be what is required

Anyway you have found a solution to your problem.  Let me just add a
short explanation in case the issue is not entirely clear to you yet:
‘shell-quote-argument’ works on strings; when you map over a list, you
apply the function on each element of the list and collect the results.
Therefore, in your call to ‘mapconcat’ the function
‘shell-quote-argument’ will eventually be passed the value of
‘cmd-cnum’, which you have inserted into the list.  Examples that do not
work:


    (shell-quote-argument 5)
    ⇒ Wrong type argument: sequencep, 5

    (mapconcat #'shell-quote-argument '(5) " ")
    ⇒ Wrong type argument: sequencep, 5

    (mapconcat #'shell-quote-argument '("grep" 5) " ")
    ⇒ Wrong type argument: sequencep, 5

    (mapconcat #'shell-quote-argument '(5 "grep") " ")
    ⇒ Wrong type argument: sequencep, 5


> After selecting wy search pattern and storing it in `cmd-ptrn`, how
> can I highlight the pattern when tho grep results are being
> transferred to the current buffer ?

Now itʼs getting complicated and I couldnʼt give you an answer of the of
my head: look into adding text properties [1] to strings and at process
filters [2].  How could you identify the information elements grep puts
on each line and their position?  It will probably also be insightful to
look at how the Emacs command “M-x grep” [3] is implemented.


Footnotes:
[1]  
<https://www.gnu.org/software/emacs/manual/html_node/elisp/Text-Props-and-Strings.html>

[2]  
<https://www.gnu.org/software/emacs/manual/html_node/elisp/Filter-Functions.html>

[3]  
<https://www.gnu.org/software/emacs/manual/html_node/emacs/Grep-Searching.html>


-- 
Felix Dietrich



reply via email to

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