[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 792b7b7 051/348: counsel.el (counsel-set-variable): New co
From: |
Oleh Krehel |
Subject: |
[elpa] master 792b7b7 051/348: counsel.el (counsel-set-variable): New command |
Date: |
Sat, 8 Apr 2017 11:03:23 -0400 (EDT) |
branch: master
commit 792b7b7ca87616559fe7d6a5c24da1676e0ad4a6
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
counsel.el (counsel-set-variable): New command
* counsel.el (counsel-set-variable-history): New defvar.
(counsel-read-setq-expression): New defun.
(counsel--setq-doconst): New defun.
---
Makefile | 4 ++--
counsel.el | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 76 insertions(+), 2 deletions(-)
diff --git a/Makefile b/Makefile
index 009086f..ca1d043 100644
--- a/Makefile
+++ b/Makefile
@@ -2,8 +2,6 @@ emacs ?= emacs
LOAD = -l colir.el -l ivy.el -l swiper.el -l counsel.el
-.PHONY: all compile clean
-
all: test
test:
@@ -17,3 +15,5 @@ plain:
clean:
rm -f *.elc
+
+.PHONY: all compile clean test
diff --git a/counsel.el b/counsel.el
index 73ffa21..9fef1da 100644
--- a/counsel.el
+++ b/counsel.el
@@ -474,6 +474,80 @@ Update the minibuffer with the amount of lines collected
every
(intern x)))
:caller 'counsel-describe-function)))
+;;** `counsel-set-variable'
+(defvar counsel-set-variable-history nil
+ "Store history for `counsel-set-variable'.")
+
+(defun counsel-read-setq-expression (sym)
+ "Read and eval a setq expression for SYM."
+ (setq this-command 'eval-expression)
+ (let* ((minibuffer-completing-symbol t)
+ (sym-value (symbol-value sym))
+ (expr (minibuffer-with-setup-hook
+ (lambda ()
+ (add-hook 'completion-at-point-functions
#'elisp-completion-at-point nil t)
+ (run-hooks 'eval-expression-minibuffer-setup-hook)
+ (goto-char (minibuffer-prompt-end))
+ (forward-char 6)
+ (insert (format "%S " sym)))
+ (read-from-minibuffer "Eval: "
+ (format
+ (if (and sym-value (consp sym-value))
+ "(setq '%S)"
+ "(setq %S)")
+ sym-value)
+ read-expression-map t
+ 'read-expression-history))))
+ (eval-expression expr)))
+
+(defun counsel--setq-doconst (x)
+ "Return a cons of description and value for X.
+X is an item of a radio- or choice-type defcustom."
+ (let (y)
+ (when (and (listp x)
+ (consp (setq y (last x))))
+ (setq x (car y))
+ (cons (prin1-to-string x)
+ (if (symbolp x)
+ (list 'quote x)
+ x)))))
+
+;;;###autoload
+(defun counsel-set-variable ()
+ "Set a variable, with completion.
+
+When the selected variable is a `defcustom' with the type boolean
+or radio, offer completion of all possible values.
+
+Otherwise, offer a variant of `eval-expression', with the initial
+input corresponding to the chosen variable."
+ (interactive)
+ (let ((sym (intern
+ (ivy-read "Variable: "
+ (counsel-variable-list)
+ :history 'counsel-set-variable-history)))
+ sym-type
+ cands)
+ (if (and (boundp sym)
+ (setq sym-type (get sym 'custom-type))
+ (cond
+ ((and (consp sym-type)
+ (memq (car sym-type) '(choice radio)))
+ (setq cands (delq nil (mapcar #'counsel--setq-doconst (cdr
sym-type)))))
+ ((eq sym-type 'boolean)
+ (setq cands '(("nil" . nil) ("t" . t))))
+ (t nil)))
+ (let ((res (ivy-read (format "Set (%S): " sym)
+ cands
+ :preselect (symbol-name (symbol-value sym)))))
+ (when res
+ (setq res
+ (if (assoc res cands)
+ (cdr (assoc res cands))
+ (read res)))
+ (eval `(setq ,sym ,res))))
+ (counsel-read-setq-expression sym))))
+
;;** `counsel-info-lookup-symbol'
(defvar info-lookup-mode)
(declare-function info-lookup->completions "info-look")
- [elpa] master c20867b 022/348: ivy-hydra.el: Add package tags, (continued)
- [elpa] master c20867b 022/348: ivy-hydra.el: Add package tags, Oleh Krehel, 2017/04/08
- [elpa] master 37a9629 018/348: ivy.el (ivy--reset-state): Fix ivy-resume for files, Oleh Krehel, 2017/04/08
- [elpa] master c4775b6 031/348: ivy.el (ivy-action-wrap): New defcustom, Oleh Krehel, 2017/04/08
- [elpa] master ac1dc5b 034/348: counsel.el (counsel-company): New command, Oleh Krehel, 2017/04/08
- [elpa] master cba67e4 038/348: counsel.el (counsel-bookmark): Add require, Oleh Krehel, 2017/04/08
- [elpa] master 3d48093 027/348: counsel.el (counsel--gg-sentinel): Add a work around, Oleh Krehel, 2017/04/08
- [elpa] master ddb4681 025/348: counsel.el (counsel-git-grep-cmd-default): New defvar, Oleh Krehel, 2017/04/08
- [elpa] master cf38ceb 040/348: swiper.el (swiper-font-lock-exclude): Add forth-mode, Oleh Krehel, 2017/04/08
- [elpa] master ab55e03 055/348: counsel.el (counsel-set-variable): Add :preselect, Oleh Krehel, 2017/04/08
- [elpa] master f4ec789 056/348: counsel.el (counsel-set-variable): Fix 2nd preselect, Oleh Krehel, 2017/04/08
- [elpa] master 792b7b7 051/348: counsel.el (counsel-set-variable): New command,
Oleh Krehel <=
- [elpa] master dc4a858 060/348: counsel.el (counsel-hydra-heads): New command, Oleh Krehel, 2017/04/08
- [elpa] master cd8a570 062/348: Escape `%` chars if present in the symbol value, Oleh Krehel, 2017/04/08
- [elpa] master 97cf30d 063/348: Add multiple-cursors support to ivy-completion-in-region-action, Oleh Krehel, 2017/04/08
- [elpa] master 8c7a7fc 028/348: When reading file names, check preselect and initial-input compat, Oleh Krehel, 2017/04/08
- [elpa] master 5d0fec1 032/348: ivy.el: Fix some checkdoc warnings, Oleh Krehel, 2017/04/08
- [elpa] master 2e1cebc 036/348: counsel.el (counsel-bookmark): Add, Oleh Krehel, 2017/04/08
- [elpa] master a566403 044/348: ivy.el (ivy-read): Document all args, Oleh Krehel, 2017/04/08
- [elpa] master baf89c0 054/348: ivy-test.el (colir-color-parse): Add test, Oleh Krehel, 2017/04/08
- [elpa] master be24b57 049/348: Revert "ivy.el (ivy-completion-in-region): Fix double insert bug", Oleh Krehel, 2017/04/08
- [elpa] master 77fb030 052/348: ivy.el (ivy-completion-in-region): Fix common length longer than str, Oleh Krehel, 2017/04/08