1

I have the following function, where I would like to use completion to set the style. But the way I have done does not reset the style using M-x rk-bracemk-companion.

 (defcustom rk-bracemk-companion-style '("parenthesis" "expression" "mixed") "Set bracemk-companion-style." :type '(repeat string) :group 'convenience) (defun rk-bracemk-companion (style) "Indicates counterpart character when matching bracketing pairs." (interactive (list (completing-read "bracemk-companion, Sel Style: " rk-bracemk-companion-style))) (show-paren-mode 1) (setq show-paren-delay 1.3) ;; Options: Style | `parenthesis', `expression', `mixed' (setq show-paren-style style) (setq show-paren-when-point-inside-paren t)) 

1 Answer 1

1

Your code has a couple of problems.

  1. Option show-paren-style expects a symbol, not a string. So (a) change your defcustom to use symbols, and (b) use intern on the value returned by completing-read (which is a string).

  2. Don't use setq with user options, as a general rule (good habit). Why? Because some defcustoms use :set functions, and just changing the value with setq won't do the right thing in that case.

  3. You probably want a non-nil REQUIRE-MATCH arg for completing-read.

(defcustom rk-bracemk-companion-style '(parenthesis expression mixed) "Completion candidates for `rk-bracemk-companion'." :type '(repeat symbol) :group 'convenience) (defun rk-bracemk-companion (style) "Choose a `show-paren-style' and use it." (interactive (list (completing-read "Style: " rk-bracemk-companion-style nil t))) (customize-set-variable 'show-paren-delay 1.3) (customize-set-variable 'show-paren-style (intern style)) (customize-set-variable 'show-paren-when-point-inside-paren t) (show-paren-mode -1) (show-paren-mode 1)) 
5
  • I am getting customize-set-variable: Wrong type argument: stringp, expression when applying your suggestions. Commented Mar 24, 2022 at 22:57
  • Try starting Emacs with emacs -Q. And be sure you copied the code correctly. Works for me. Commented Mar 24, 2022 at 23:07
  • In my minor-mode definition, I use (rk-bracemk-companion 'expression). This could be the problem that is being introduced. Commented Mar 24, 2022 at 23:23
  • I get a bit confused on what to do when calling a function in my elisp code that has the interactive declaration. Can one simple call it with parameters irrespective of how the interactive statement is set up? Commented Mar 25, 2022 at 0:50
  • Post questions as questions. Commented Mar 26, 2022 at 2:07

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.