9

I am trying to make an interactive toggle in emacs 27.0.90

When I eval-region no warnings or errors are shown.

However, when I do (helm/toggle-frame) in ielm it throws Symbol’s function definition is void: helm-in-frame-p

Here is the code,

(let ((helm-in-frame-p t))
  (defun helm/toggle-frame ()
    "Toggle helm in frame or in buffer.
    Default is buffer because it is faster on Xforwarding."
    (interactive)
    (setq helm-in-frame-p (not helm-in-frame-p))
    (if (helm-in-frame-p)
        (progn
          (global-set-key (kbd "M-x") 'helm-M-x-in-frame))
      (progn
        (global-set-key (kbd "M-x") 'helm-M-x)))
    (message "Helm in frame is now %s"
             (if helm-in-frame-p "Enabled" "Disabled"))))

Here is the ielm output

ELISP> helm/toggle-frame
*** Eval error ***  Symbol’s value as variable is void: helm/toggle-frame
ELISP> (helm/toggle-frame)
*** Eval error ***  Symbol’s function definition is void: helm-in-frame-p
Drew
  • 75,699
  • 9
  • 109
  • 225
546756ryd
  • 93
  • 1
  • 1
  • 3
  • I presume you've set `lexical-binding` for this library? – phils Jul 22 '20 at 10:45
  • yes, in fact, I've tried turning off lexical scoping and using a separate setq statement without let binding; same errors – 546756ryd Jul 22 '20 at 12:07
  • Yep; I was just asking in case that was going to be an additional problem once you'd solved the immediate one. – phils Jul 22 '20 at 12:40

1 Answers1

7

You define a local variable, then later call a non-existent function with the same name in the if:

(if (helm-in-frame-p)

Drop the surrounding parentheses and it should work again.

phils
  • 48,657
  • 3
  • 76
  • 115
wasamasa
  • 21,803
  • 1
  • 65
  • 97