I'm rebuilding my emacs configuration, and trying to compile without warnings. I'm using also cask. I have this case:

(require 'magit)

;; Enable a right limit of 70 chars for git logs
(add-hook 'magit-log-edit-mode-hook 'turn-on-auto-fill)

(provide 'my-magit)

(fullframe magit-status magit-mode-quit-window nil)
(setq magit-last-seen-setup-instructions "1.4.0")

(global-set-key (kbd "C-c g s") 'magit-status)

(require 'git-gutter)
(global-git-gutter-mode +1)

Compiling this, give this warning:

In toplevel form:
my-magit.el:10:7:Warning: assignment to free variable

I try and changing to

(defvar magit-last-seen-setup-instructions "1.4.0")

It works well, without warning, the difference with setq is that after that if another defvar is applied to this variable will ahve no effect, but could I apply it to the other variables like this or I will have issues for that. Another doubt is that I believe that this variable is defined in the package magit that is loaded previously. so I do not get why I get this warning.

  • 1
    "I believe that this variable is defined in the package magit" -- is it, though? If it's no longer defined, your assumption doesn't hold. (n.b. in current releases of magit, it is not defined.) – phils Dec 17 '16 at 20:36

You declare variables as global with defvar and optionally initialize them. When you use the setq the variable apparently hasn't been declared. It sounds like what your after is this construction

(defvar foo)
(setq foo "foo")

The first tells the compiler that foo is a global (dynamic) variable. The second sets it unconditionally.


magit-last-seen-setup-instructions was not well received and has been removed. Also, when it was still in use, you were supposed to set it before loading magit.

magit-log-edit-mode-hook is also obsolete. magit-log-edit.el was removed three years ago and support was completely removed two and a half years ago. It's place was taken by git-commit.el and the hook to use now is git-commit-setup-hook.

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.