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

Closed
kaushalmodi opened this Issue Jun 9, 2016 · 2 comments

Comments

Projects
None yet
2 participants
@kaushalmodi
Copy link
Contributor

kaushalmodi commented Jun 9, 2016

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

    (setq counsel-find-file-ignore-regexp
          (concat
           ;; 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 "(?:`[#.]\)\|\(?:[#]\'\)")
symbol-name("\(?:\`[#.])|(?:[#
]')")
counsel-set-variable()
funcall-interactively(counsel-set-variable)
call-interactively(counsel-set-variable nil nil)
command-execute(counsel-set-variable)

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

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

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."
  (interactive)
  (let ((sym (intern
              (ivy-read "Variable: "
                        (counsel-variable-list)
                        :preselect (thing-at-point 'symbol)
                        :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%s›): " sym (symbol-value sym))
                             cands)))
          (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

@abo-abo

This comment has been minimized.

Copy link
Owner

abo-abo commented Jun 9, 2016

Thanks.

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.