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

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

[elpa] master 1e38ed4 146/399: counsel.el (counsel-minor): Add command t


From: Oleh Krehel
Subject: [elpa] master 1e38ed4 146/399: counsel.el (counsel-minor): Add command to toggle minor mode
Date: Sat, 20 Jul 2019 14:57:12 -0400 (EDT)

branch: master
commit 1e38ed4897381b575375ed8041b09cb8b81f98f2
Author: Iku Iwasa <address@hidden>
Commit: Oleh Krehel <address@hidden>

    counsel.el (counsel-minor): Add command to toggle minor mode
    
    Like counsel-package, disabled minor modes are prefixed with "+" and
    enabled minor modes are prefixed with "-".
    By selecting one of them, the mode is called interactively. As a result,
    toggle the minor mode enability.
    
    Fixes #2000
---
 counsel.el | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)

diff --git a/counsel.el b/counsel.el
index 9b592a0..b7fea9a 100644
--- a/counsel.el
+++ b/counsel.el
@@ -5338,6 +5338,58 @@ specified by the `blddir' property."
             :action #'counsel-compile--action
             :caller 'counsel-compile))
 
+;;** `counsel-minor'
+(defun counsel--minor-candidates ()
+  "Return completion alist for `counsel-minor'.
+
+The alist element is cons of minor mode string with its lighter
+and minor mode symbol."
+  (delq nil
+        (mapcar
+         (lambda (mode)
+           (when (and (boundp mode) (commandp mode))
+             (let ((lighter (alist-get mode minor-mode-alist)))
+               (cons (concat
+                      (if (symbol-value mode) "-" "+")
+                      (symbol-name mode)
+                      (propertize
+                       (if lighter
+                           (format " \"%s\""
+                                   (format-mode-line (cons t lighter)))
+                         "")
+                       'face font-lock-string-face))
+                     mode))))
+         minor-mode-list)))
+
+;;;###autoload
+(defun counsel-minor ()
+  "Enable or disable minor mode.
+
+Disabled minor modes are prefixed with \"+\", and
+selecting one of these will enable it.
+Enabled minor modes are prefixed with \"-\", and
+selecting one of these will enable it.
+
+Additional actions:\\<ivy-minibuffer-map>
+
+  \\[ivy-dispatching-done] d: Go to minor mode definition
+  \\[ivy-dispatching-done] h: Describe minor mode"
+
+  (interactive)
+  (ivy-read "Minor modes (enable +mode or disable -mode): "
+            (counsel--minor-candidates)
+            :require-match t
+            :sort t
+            :action (lambda (x)
+                      (call-interactively (cdr x)))))
+
+(cl-pushnew '(counsel-minor . "^+") ivy-initial-inputs-alist :key #'car)
+
+(ivy-set-actions
+ 'counsel-minor
+ `(("d" ,(lambda (x) (find-function (cdr x))) "definition")
+   ("h" ,(lambda (x) (describe-function (cdr x))) "help")))
+
 ;;* `counsel-mode'
 (defvar counsel-mode-map
   (let ((map (make-sparse-keymap)))



reply via email to

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