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

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

Run terminal command with output in current buffer


From: lisa-asket
Subject: Run terminal command with output in current buffer
Date: Fri, 16 Jul 2021 17:44:57 +0200 (CEST)

Thanks, I am using the following code



But when using `shell-command` I have to wait until the command is executed

before it gets displayed in the buffer.  Can I make it print as it is executing 
?



(shell-command cmd (current-buffer))

--------



(defun runcom ()
  "docstring"

  (interactive) 

  ;; grep -hir --exclude=\*.el --include=\*.{org,texi} -C 8 "node-gnu-fdl" .

  (let ( (cmd-excl (read-from-minibuffer "exclude: "))
         (cmd-incl (read-from-minibuffer "include: "))
     (cmd-cnum (read-from-minibuffer "cnum: "))
     (cmd-ptrn (read-from-minibuffer "pattern: "))
     (cmd-dpth (read-from-minibuffer "dpth: "))
      cmd )

    (setq cmd-excl (concat " --exclude=\\*." cmd-excl))
    (setq cmd-incl (concat " --include=\\*." cmd-incl))
    (setq cmd-cnum (concat " -C " cmd-cnum))

    (setq cmd (concat "grep -hir" cmd-excl cmd-incl
              cmd-cnum " " cmd-ptrn " " cmd-dpth))
    (message "%s" cmd)
    (shell-command cmd (current-buffer))) )



From: Stefan Monnier via Users list for the GNU Emacs text editor 
<help-gnu-emacs@gnu.org>
To: help-gnu-emacs@gnu.org
Subject: Re: Run terminal command with output in current buffer
Date: 16/07/2021 17:21:08 Europe/Paris

> You can declare local variables with “let”:
>
> (let (cmd-excl cmd-incl)
> (setq cmd-excl "value"))

Please don't. Use

(let ((cmd-excl "value")
cmd-incl)

instead.
[ This is less code to write, simpler code for the reader, simpler code
for the compiler, and even marginally more efficient. ]

Only use `setq` when you really want that variable to contain
different values at different times.


Stefan





reply via email to

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