Skip to main content
typo
Source Link
jue
  • 4.7k
  • 10
  • 21

kill-process is working in your case. But the loop is to fast. The firstfor a reason get-buffer-process nextdoes not return nil to while returns, right after killing cat, the handle. Maybe because it refers to the cata buffer which is not yet closed, but the next get-buffer-process nearand emacs needs to take a breath? A killsit-process is returning nilfor. So kill-process tries to kill a different buffer (e.g.: "scratch") command will fix this.

A solution would be:

(let ((buf
       "*Async Shell Command*"))
  (async-shell-command "cat")
  (while (get-buffer-process buf)
    (message "still has proc")
    (kill-process (get-buffer-process buf))
    (sit-for 10.01)))

Another solution could be thisnot to use get-buffer-process:

(let ((buf
          "*Async Shell Command*"))
     (async-shell-command "cat")
     (while (not (string= (kill-process buf) buf))
       (sit-for 1)
       (message "still has proc")))

kill-process is working in your case. But the loop is to fast. The first get-buffer-process next to while returns, right after killing cat, the handle to the cat buffer, but the next get-buffer-process near kill-process is returning nil. So kill-process tries to kill a different buffer (e.g.: "scratch").

A solution would be:

(let ((buf
       "*Async Shell Command*"))
  (async-shell-command "cat")
  (while (get-buffer-process buf)
    (message "still has proc")
    (kill-process (get-buffer-process buf))
    (sit-for 1)))

Another solution could be this:

(let ((buf
          "*Async Shell Command*"))
     (async-shell-command "cat")
     (while (not (string= (kill-process buf) buf))
       (sit-for 1)
       (message "still has proc")))

kill-process is working in your case. But for a reason get-buffer-process does not return nil to while. Maybe because it refers to a buffer which is not yet closed, and emacs needs to take a breath? A sit-for command will fix this.

A solution would be:

(let ((buf
       "*Async Shell Command*"))
  (async-shell-command "cat")
  (while (get-buffer-process buf)
    (message "still has proc")
    (kill-process (get-buffer-process buf))
    (sit-for 0.01)))

Another solution could be not to use get-buffer-process:

(let ((buf
          "*Async Shell Command*"))
     (async-shell-command "cat")
     (while (not (string= (kill-process buf) buf))
       (message "still has proc")))
explanation now correct and it looks nicer
Source Link
jue
  • 4.7k
  • 10
  • 21

kill-process is working in your case. But the loop is to fast. The first get-buffer-process isnext to while returns, right after killing cat, returning the name ofhandle to the cat buffer, but the next get-buffer-process near kill-process is returning nil. So kill-process tries to kill a different buffer (eg e.g.: "scratch"). You can check this if you insert (sit-for 1) into your while-loop. Then you will get the debugger.

A solution would be:

(let ((buf
          "*Async Shell Command*"))
     (async-shell-command "cat")
     (while (get-buffer-process buf)
       (sit-for 1)
       (message "still has proc")
       (kill-process (get-buffer-process buf))
    (sit-for 1)))

To solve this, you should rewrite your code to something likeAnother solution could be this:

(let ((buf
          "*Async Shell Command*"))
     (async-shell-command "cat")
     (while (not (string= (kill-process buf) buf))
       (sit-for 1)
       (message "still has proc")))

Edit: the explanation is wrong, but the solution works. ;) i try to figure it out.

kill-process is working in your case. But get-buffer-process is, after killing cat, returning the name of a different buffer (eg scratch). You can check this if you insert (sit-for 1) into your while-loop. Then you will get the debugger.

(let ((buf
          "*Async Shell Command*"))
     (async-shell-command "cat")
     (while (get-buffer-process buf)
       (sit-for 1)
       (message "still has proc")
       (kill-process (get-buffer-process buf))))

To solve this, you should rewrite your code to something like this:

(let ((buf
          "*Async Shell Command*"))
     (async-shell-command "cat")
     (while (not (string= (kill-process buf) buf))
       (sit-for 1)
       (message "still has proc")))

Edit: the explanation is wrong, but the solution works. ;) i try to figure it out.

kill-process is working in your case. But the loop is to fast. The first get-buffer-process next to while returns, right after killing cat, the handle to the cat buffer, but the next get-buffer-process near kill-process is returning nil. So kill-process tries to kill a different buffer (e.g.: "scratch").

A solution would be:

(let ((buf
       "*Async Shell Command*"))
  (async-shell-command "cat")
  (while (get-buffer-process buf)
    (message "still has proc")
    (kill-process (get-buffer-process buf))
    (sit-for 1)))

Another solution could be this:

(let ((buf
          "*Async Shell Command*"))
     (async-shell-command "cat")
     (while (not (string= (kill-process buf) buf))
       (sit-for 1)
       (message "still has proc")))
added 88 characters in body
Source Link
jue
  • 4.7k
  • 10
  • 21

kill-process is working in your case. But get-buffer-process is, after killing cat, returning the name of a different buffer (eg scratch). You can check this if you insert (sit-for 1) into your while-loop. Then you will get the debugger.

(let ((buf
          "*Async Shell Command*"))
     (async-shell-command "cat")
     (while (get-buffer-process buf)
       (sit-for 1)
       (message "still has proc")
       (kill-process (get-buffer-process buf))))

To solve this, you should rewrite your code to something like this:

(let ((buf
          "*Async Shell Command*"))
     (async-shell-command "cat")
     (while (not (string= (kill-process buf) buf))
       (sit-for 1)
       (message "still has proc")))

Edit: the explanation is wrong, but the solution works. ;) i try to figure it out.

kill-process is working in your case. But get-buffer-process is, after killing cat, returning the name of a different buffer (eg scratch). You can check this if you insert (sit-for 1) into your while-loop. Then you will get the debugger.

(let ((buf
          "*Async Shell Command*"))
     (async-shell-command "cat")
     (while (get-buffer-process buf)
       (sit-for 1)
       (message "still has proc")
       (kill-process (get-buffer-process buf))))

To solve this, you should rewrite your code to something like this:

(let ((buf
          "*Async Shell Command*"))
     (async-shell-command "cat")
     (while (not (string= (kill-process buf) buf))
       (sit-for 1)
       (message "still has proc")))

kill-process is working in your case. But get-buffer-process is, after killing cat, returning the name of a different buffer (eg scratch). You can check this if you insert (sit-for 1) into your while-loop. Then you will get the debugger.

(let ((buf
          "*Async Shell Command*"))
     (async-shell-command "cat")
     (while (get-buffer-process buf)
       (sit-for 1)
       (message "still has proc")
       (kill-process (get-buffer-process buf))))

To solve this, you should rewrite your code to something like this:

(let ((buf
          "*Async Shell Command*"))
     (async-shell-command "cat")
     (while (not (string= (kill-process buf) buf))
       (sit-for 1)
       (message "still has proc")))

Edit: the explanation is wrong, but the solution works. ;) i try to figure it out.

Post Undeleted by jue
Post Deleted by jue
Source Link
jue
  • 4.7k
  • 10
  • 21
Loading