emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] master 407ce2c 051/272: counsel.el (counsel-list-processes): New


From: Oleh Krehel
Subject: [elpa] master 407ce2c 051/272: counsel.el (counsel-list-processes): New command
Date: Mon, 25 Apr 2016 10:13:16 +0000

branch: master
commit 407ce2c3e31ae264b88ee319faed1f82e2684fe6
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>

    counsel.el (counsel-list-processes): New command
    
    * counsel.el (counsel-list-processes-action-delete): New defun.
    (counsel-list-processes-action-switch): New defun.
    
    * ivy.el: re-indent.
    
    Fixes #357
---
 counsel.el |   25 +++++++++++++++++++++++++
 ivy.el     |   57 +++++++++++++++++++++++++++++----------------------------
 2 files changed, 54 insertions(+), 28 deletions(-)

diff --git a/counsel.el b/counsel.el
index 4a6e68f..b6ac36a 100644
--- a/counsel.el
+++ b/counsel.el
@@ -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 bb2aa99..2240e9e 100644
--- 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)



reply via email to

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