]> code.delx.au - gnu-emacs-elpa/commitdiff
counsel.el (counsel-list-processes): New command
authorOleh Krehel <ohwoeowho@gmail.com>
Thu, 21 Jan 2016 08:47:20 +0000 (09:47 +0100)
committerOleh Krehel <ohwoeowho@gmail.com>
Thu, 21 Jan 2016 08:55:53 +0000 (09:55 +0100)
* counsel.el (counsel-list-processes-action-delete): New defun.
(counsel-list-processes-action-switch): New defun.

* ivy.el: re-indent.

Fixes #357

counsel.el
ivy.el

index 4a6e68f533f4ae5549af74552222940f6ecb7cc6..b6ac36ae65d306815cc976f88becfa4ef0727313 100644 (file)
@@ -1412,6 +1412,31 @@ Describe the selected candidate."
  '(("d" counsel-descbinds-action-find "definition")
    ("i" counsel-descbinds-action-info "info")))
 
+(defun counsel-list-processes-action-delete (x)
+  (delete-process x)
+  (setf (ivy-state-collection ivy-last)
+        (setq ivy--all-candidates
+              (delete x ivy--all-candidates))))
+
+(defun counsel-list-processes-action-switch (x)
+  (if (get-buffer x)
+      (switch-to-buffer x)
+    (message "Process %s doesn't have a buffer" x)))
+
+;;;###autoload
+(defun counsel-list-processes ()
+  "Offer completion for `process-list'
+The default action deletes the selected process.
+An extra action allows to switch to the process buffer."
+  (interactive)
+  (list-processes--refresh)
+  (ivy-read "Process: " (mapcar #'process-name (process-list))
+            :require-match t
+            :action
+            '(1
+              ("o" counsel-list-processes-action-delete "kill")
+              ("s" counsel-list-processes-action-switch "switch"))))
+
 (provide 'counsel)
 
 ;;; counsel.el ends here
diff --git a/ivy.el b/ivy.el
index bb2aa9955cd6064b00c555facf4dc6b1a75a9b82..2240e9e266fb765e2f5abd8d4aa79c93d5d7ff7b 100644 (file)
--- a/ivy.el
+++ b/ivy.el
@@ -1061,9 +1061,10 @@ the restoring themselves.")
 
 ;;** Entry Point
 (cl-defun ivy-read (prompt collection
-                           &key predicate require-match initial-input
-                           history preselect keymap update-fn sort
-                           action unwind re-builder matcher dynamic-collection caller)
+                    &key
+                      predicate require-match initial-input
+                      history preselect keymap update-fn sort
+                      action unwind re-builder matcher dynamic-collection caller)
   "Read a string in the minibuffer, with completion.
 
 PROMPT is a format string, normally ending in a colon and a
@@ -1135,30 +1136,30 @@ customizations apply to the current completion session."
     (ivy--reset-state ivy-last)
     (prog1
         (unwind-protect
-            (minibuffer-with-setup-hook
-                #'ivy--minibuffer-setup
-              (let* ((hist (or history 'ivy-history))
-                     (minibuffer-completion-table collection)
-                     (minibuffer-completion-predicate predicate)
-                     (resize-mini-windows (cond
-                                           ((display-graphic-p) nil)
-                                           ((null resize-mini-windows) 'grow-only)
-                                           (t resize-mini-windows))))
-                (read-from-minibuffer
-                 prompt
-                 (ivy-state-initial-input ivy-last)
-                 (make-composed-keymap keymap ivy-minibuffer-map)
-                 nil
-                 hist)
-                (when (eq ivy-exit 'done)
-                  (let ((item (if ivy--directory
-                                  ivy--current
-                                ivy-text)))
-                    (unless (equal item "")
-                      (set hist (cons (propertize item 'ivy-index ivy--index)
-                                      (delete item
-                                              (cdr (symbol-value hist))))))))
-                ivy--current))
+             (minibuffer-with-setup-hook
+                 #'ivy--minibuffer-setup
+               (let* ((hist (or history 'ivy-history))
+                      (minibuffer-completion-table collection)
+                      (minibuffer-completion-predicate predicate)
+                      (resize-mini-windows (cond
+                                             ((display-graphic-p) nil)
+                                             ((null resize-mini-windows) 'grow-only)
+                                             (t resize-mini-windows))))
+                 (read-from-minibuffer
+                  prompt
+                  (ivy-state-initial-input ivy-last)
+                  (make-composed-keymap keymap ivy-minibuffer-map)
+                  nil
+                  hist)
+                 (when (eq ivy-exit 'done)
+                   (let ((item (if ivy--directory
+                                   ivy--current
+                                 ivy-text)))
+                     (unless (equal item "")
+                       (set hist (cons (propertize item 'ivy-index ivy--index)
+                                       (delete item
+                                               (cdr (symbol-value hist))))))))
+                 ivy--current))
           (remove-hook 'post-command-hook #'ivy--exhibit)
           (when (setq unwind (ivy-state-unwind ivy-last))
             (funcall unwind))
@@ -1624,7 +1625,7 @@ Insert .* between each char."
   "Update the prompt according to `ivy--prompt'."
   (when ivy--prompt
     (unless (memq this-command '(ivy-done ivy-alt-done ivy-partial-or-done
-                                          counsel-find-symbol))
+                                 counsel-find-symbol))
       (setq ivy--prompt-extra ""))
     (let (head tail)
       (if (string-match "\\(.*\\): \\'" ivy--prompt)