Browse files

Fix some byte-compilation warnings

This commit fixes the following warnings:

    autopair.el:182:1:Warning: cl package required at runtime
    autopair.el:204:34:Warning: `make-variable-buffer-local' should be called at
    In autopair-pair-p:
    autopair.el:841:23:Warning: autopair-escaped-p called with 0 arguments, but
        requires 1
  • Loading branch information...
1 parent fcb8f10 commit 661dd1e27553192f091d11194e5bab350ebccdd4 @purcell committed Nov 20, 2012
Showing with 11 additions and 5 deletions.
  1. +11 −5 autopair.el
16 autopair.el
@@ -200,7 +200,7 @@ criterious when skipping.")
The alist contains single (t MAP) association, where MAP is a
dynamic keymap set mostly from the major mode's syntax table.")
-(unless (> emacs-major-version 23)
+(unless (eval-when-compile (> emacs-major-version 23))
joaotavora Nov 20, 2012

I'm confused. Can you explain why this ifixes the make-variable-buffer-local compile-time error? Won't this break when you move an .elc across emacsen?

joaotavora Nov 21, 2012

Ohhhhh I see. This compiles to (unless t) or something deterministic and it's like defvar was called at toplevel. Am I right? is this a common technique?

purcell Nov 21, 2012 Owner

Yes. I think I saw it in ruby-mode originally, and it's recommended for things that can be determined at compile-time, like availability of certain emacs-specific features.

It does mean that the .elc will be different depending on the version of the Emacs instance in which it was compiled, but .elc files are usually (always?) incompatible between major versions. And even when they're not, imagine that a core Emacs macro definition changes between Emacs 23 and Emacs 24, and that a user compiles a library which uses it inside Emacs23; now, even if Emacs 24 can read the .elc file, it will see bytecode for the old macro expansion. So really, trying to use the same .elc file with different versions is a recipe for obscure bugs. :-)


joaotavora Nov 21, 2012

Yes, you're right. In Common Lisp, one do this is a conditional comment reader macro, I guess this is the closest thing.

purcell Nov 21, 2012 Owner

The Emacs docs describe how eval-when-compile is related to the Common Lisp equivalents:

(defvar autopair-dont-activate nil
"Control activation of `autopair-global-mode'.
@@ -334,7 +334,7 @@ For now, simply returns `last-command-event'"
(define-globalized-minor-mode autopair-global-mode autopair-mode autopair-on)
-(when (>= emacs-major-version 24)
+(when (eval-when-compile (>= emacs-major-version 24))
(defvar autopair-global-mode-emacs24-hack-flag nil)
(defadvice autopair-global-mode-enable-in-buffers (before autopairs-global-mode-emacs24-hack activate)
"Monkey patch for recent emacsen 24.
@@ -365,7 +365,7 @@ We want this advice to only kick in the *second* call to
(and (not (minibufferp))
(string-match "^ \\*" (buffer-name)))
(eq major-mode 'sldb-mode)
- (and (< emacs-major-version 24)
+ (and (eval-when-compile (< emacs-major-version 24))
(boundp 'autopair-dont-activate)
(autopair-mode 1))))
@@ -838,7 +838,7 @@ by this command. Then place point after the first, indented.\n\n"
((eq autopair-pair-criteria 'always)
- (not (autopair-escaped-p)))))))
+ (not (autopair-escaped-p syntax-info)))))))
joaotavora Nov 20, 2012

Nice, this probably never broke because of dynamic binding and because autopair-escaped-p uses a local with the same name.

;; post-command-hook stuff
@@ -1132,5 +1132,11 @@ by this command. Then place point after the first, indented.\n\n"
(unintern sym))))))
(provide 'autopair)
+;; Local Variables:
+;; coding: utf-8
+;; byte-compile-warnings: (not cl-functions)
+;; End:
;;; autopair.el ends here

1 comment on commit 661dd1e


See my comments about eval-when-compile, otherwise looks good.

Please sign in to comment.