all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Phil Sainty <psainty@orcon.net.nz>
To: 32640@debbugs.gnu.org
Subject: bug#32640: 26.1; Make `kill-process' a command
Date: Wed, 5 Sep 2018 21:32:53 +1200	[thread overview]
Message-ID: <c1c3fc1e-2134-b819-142c-b2e23901745e@orcon.net.nz> (raw)

[-- Attachment #1: Type: text/plain, Size: 142 bytes --]

Not being able to use M-x kill-process (especially for killing

the current buffer's process) is something which has annoyed me
periodically.

[-- Attachment #2: kill-process-interactive.el --]
[-- Type: text/x-emacs-lisp, Size: 2304 bytes --]

;; Make `kill-process' a command.
;; (put 'kill-process 'interactive-form '(interactive))
(put 'kill-process 'interactive-form
     '(interactive (kill-process-read-arg)))

(defun kill-process-read-arg ()
  "Obtain arguments interactively for `kill-process'."
  ;; Currently supports only the PROCESS argument.
  ;; Must either return a list containing a process, or signal an error.
  ;; (Returning `nil' would mean the current buffer's process.)
  (unless (fboundp 'process-list)
    (error "Asynchronous subprocesses are not supported on this system"))
  ;; Local function to return cons of a complete-able name, and the
  ;; associated process object, for use with `completing-read'.
  (cl-flet ((procitem
             (p) (when (process-live-p p)
                   (let ((pid (process-id p))
                         (procname (process-name p))
                         (procbuf (process-buffer p)))
                     (and (eq (process-type p) 'real)
                          (cons (if procbuf
                                    (format "%s (%s) in buffer %s"
                                            procname pid
                                            (buffer-name procbuf))
                                  (format "%s (%s)" procname pid))
                                p))))))
    ;; Perform `completing-read' for a process.
    (let* ((currproc (get-buffer-process (current-buffer)))
           (proclist (or (process-list) (error "No processes found")))
           (collection (delq nil (mapcar #'procitem proclist)))
           (selection (completing-read
                       (if (and currproc (eq (process-type currproc) 'real))
                           (format "Kill process? (default %S (%s)): "
                                   currproc (process-id currproc))
                         "Kill process: ")
                       collection nil :require-match nil nil
                       (car (cl-find currproc collection :key #'cdr))))
           (process (and selection
                         (cdr (assoc selection collection)))))
      (unless process
        (error "No process selected"))
      ;; Return list of arguments for `kill-process'.
      (if (y-or-n-p (format "Kill %S? " process))
          (list process)
        (error "Process not killed")))))

             reply	other threads:[~2018-09-05  9:32 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-05  9:32 Phil Sainty [this message]
2018-09-05  9:49 ` bug#32640: 26.1; Make `kill-process' a command Phil Sainty
2018-09-05 10:23 ` Eli Zaretskii
2018-09-05 12:04   ` Phil Sainty
2018-09-05 13:37     ` Michael Albinus
2018-09-06  3:03       ` Phil Sainty
2018-09-06  6:56         ` Michael Albinus
2022-01-23 13:39         ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c1c3fc1e-2134-b819-142c-b2e23901745e@orcon.net.nz \
    --to=psainty@orcon.net.nz \
    --cc=32640@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.