9

When a new version of Emacs is released it is usually the case that some variables/commands/functions become obsolete. They are usually marked as such in the corresponding documentation:

turn-on-eldoc-mode is an alias for eldoc-mode in eldoc.el. [...]

This function is obsolete since 24.4; use eldoc-mode instead.

I'd like to make sure I am not referencing any obsolete variables in my init-file, but I'd also like to avoid checking the whole thing manually.

So my question is: Is there a way to automatically identify all obsolete variables in my init-file (that possibly also works for third-party packages installed via the package manager)?

itsjeyd
  • 14,666
  • 3
  • 59
  • 87

1 Answers1

13

Byte-compile the file.

Generally, it's best to not byte-compile your init file, but here it's useful. The byte-compiler will warn you about a lot of bad practices, among them is the usage of obsolete variables or functions.

  1. Just call M-x byte-compile-file and give your init file.

  2. Afterwards, make sure you delete the generated .elc file.

Malabarba
  • 23,148
  • 6
  • 79
  • 164
  • 2
    Out of curiosity, what are the reasons not to byte-compile the init file? – Dan Oct 25 '14 at 14:41
  • 4
    @Dan The advantages are negligible. Meanwhile, occasionally you might forget to recompile after changing it, and be left wondering why your changes aren't having any effect. – Malabarba Oct 25 '14 at 14:43
  • 4
    @Dan: In addition to what Malabarba said, a given init file is sometimes (often) used for multiple Emacs versions, and byte-compiling it can reduce this kind of portability. – Drew Oct 25 '14 at 15:13
  • Just in case it's not obvious: you can byte-compile it (to see warnings etc.) and then delete the *.elc. – Drew Oct 25 '14 at 15:14
  • Thanks for the suggestions, but I don't really get the behavior you describe. For instance, if I put (add-hook 'emacs-lisp-mode-hook 'turn-on-eldoc-mode) into my init-file and compile it, the byte compiler should warn me that turn-on-eldoc-mode is obsolete. At least that's what I would expect based on the docstring. But I get no such warning. I tried to byte-compile the file with and without my customizations loaded; results were the same (w/r/t obsolete variables). – itsjeyd Oct 25 '14 at 16:22
  • 7
    That's why you should use #' instead of ' for functions. If you compile something with (add-hook 'emacs-lisp-mode-hook #'turn-on-eldoc-mode) the compiler will warn you. – Malabarba Oct 25 '14 at 16:40