Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

counsel-set-variable fails for variables with non-symbol values #544

kaushalmodi opened this Issue Jun 9, 2016 · 2 comments


None yet
2 participants
Copy link

kaushalmodi commented Jun 9, 2016

I have counsel-find-file-ignore-regexp set as below:

    (setq counsel-find-file-ignore-regexp
           ;; file names beginning with # or .
           ;; file names ending with # or ~

If I do, M-x counsel-set-variable for that variable, I get

Debugger entered--Lisp error: (wrong-type-argument symbolp "(?:`[#.]\)\|\(?:[#]\'\)")
call-interactively(counsel-set-variable nil nil)

I fixed it by commenting out the symbol-name call for now:

        (let ((res (ivy-read (format "Set (%S): " sym)
                             ;; :preselect (symbol-name (symbol-value sym))

This comment has been minimized.

Copy link
Contributor Author

kaushalmodi commented Jun 9, 2016

This works. I just wish to set the ‹%s› portion to a different face.

(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."
  (let ((sym (intern
              (ivy-read "Variable: "
                        :preselect (thing-at-point 'symbol)
                        :history 'counsel-set-variable-history)))
    (if (and (boundp sym)
             (setq sym-type (get sym 'custom-type))
              ((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%s›): " sym (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))))

@abo-abo abo-abo closed this in f4ec789 Jun 9, 2016


This comment has been minimized.

Copy link

abo-abo commented Jun 9, 2016


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.