Am using the following function, but getting the error

In bracemk-balance:
fencones.el:109:9:Warning: assignment to free variable

What is wrong with this?

(defun bracemk-balance ()
  "Completing brace marks group."

  (setq skeleton-pair t)

  (global-set-key (kbd "(")  'skeleton-pair-insert-maybe)
  (global-set-key (kbd "[")  'skeleton-pair-insert-maybe)
  (global-set-key (kbd "{")  'skeleton-pair-insert-maybe)
  (global-set-key (kbd "<")  'skeleton-pair-insert-maybe)

  (global-set-key (kbd "`")  'skeleton-pair-insert-maybe)
  (global-set-key (kbd "'")  'skeleton-pair-insert-maybe)
  (global-set-key (kbd "\"") 'skeleton-pair-insert-maybe))

1 Answer 1


It's just a warning.

With your setq you're assigning a value to a global variable. Emacs is just letting you know this.

You didn't explicitly tell Emacs that skeleton-pair is a global variable. To do that, use (defvar skeleton-pair) (no initial value). Then you won't see the warning. That's the way to tell Emacs that a variable is "special" - scoped dynamically.

If you don't tell Emacs that, then Emacs tells you when you use such a variable -- in particular in case you weren't aware of it. (If you're aware of it then you should tell Emacs: (defvar skeleton-pair).)

Emacs is letting you know that within your function bracemk-balance variable skeleton-pair is a free variable - it's not bound by or within your function (not a function parameter and not bound with let, for example). It's not a lexically scoped variable; it's a dynamically scoped variable. It's not local to your function.

Emacs tells you this, for one thing, to let you know in case you misspelled a variable that is bound in your function. By misspelling it you can end up using a different, likely new, likely global variable.

See the Elisp manual, node Variable Scoping.

  • Is there a better way to set up completion for parentheses? Not quite so sure if I require (setq skeleton-pair t).
    – Ephram
    Jul 12, 2022 at 5:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.