2

I have Git 2.5.3 installed and am using GNU Emacs 24.4.1 on Ubuntu. I just installed Magit from MELPA:

(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/"))
(package-initialize)
(package-refresh-contents)
(package-install 'magit)

If I then try to use M-x magit-version RET to try to make sure it installed properly, Emacs helpfully tells me

M-x magit-version [No match]

But if I just type M-x magit- RET, I'm presented with a long list of Magit operations like magit-commit, magit-diff, etc. Everything seems to be all there except magit-version. How can I fix this?

5

The function magit-version is not autoloaded in magit.el. If you look at the source, you will notice that that function definition is not preceded by ;;;###autoload (as of Magit version 20150921.1712).

If you eval magit.el file, you will see that M-x magit-version would then be available.

How to get M-x magit-version working?

There are a couple of ways to do that:

  • Try doing M-x magit-version only after the magit package gets loaded. For instance, you can do that after you launch a common magit command like M-x magit-status.
  • You can add the below snippet to your emacs config if you use M-x magit-version quite frequently before using any other magit command.

    (autoload #'magit-version "magit" nil t)
    
  • If you use use-package, you can add magit-version to the list of commands after the :commands key of (use-package magit ..) instead of the above autoload statement (as use-package does the same thing under the hood).

  • Or you can open an issue on magit github asking the developer if he sees fit autoloading this function.

Check out the Autoload chapter in Elisp Manual to learn more about autoloading.

  • Ah, that makes sense. Judging from this page, I assumed that magit-version was usable outside of any context, but I guess I was mistaken. Thanks! – Sam Estep Sep 23 '15 at 21:15
  • 1
    That's a good argument for autoloading. I've done so now. – tarsius Sep 23 '15 at 23:16

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.