all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Sebastian Wiesner <swiesner@lunaryorn.com>
To: Sebastien Vauban <sva-news@mygooglest.com>
Cc: help-gnu-emacs@gnu.org
Subject: Re: Flycheck reports are never satisfying!?
Date: Mon, 1 Sep 2014 12:23:21 +0200	[thread overview]
Message-ID: <814CFCAE-EA3C-4C92-889F-20A247A13AA1@lunaryorn.com> (raw)
In-Reply-To: <86oauzhd9a.fsf@somewhere.org>

Am 01.09.2014 um 12:00 schrieb Sebastien Vauban <sva-news@mygooglest.com>:

> Hallo Sebastian,
> 
> Sebastien Vauban wrote:
>> Sebastian Wiesner wrote:
>>> Am 28.08.2014 um 17:39 schrieb Sebastien Vauban <sva-news@mygooglest.com>:
>>>> Sebastian Wiesner wrote:
>>>>> However, as far as "init.el" is concerned, Flycheck should
>>>>> automatically enable package.el for syntax checking.  This doesn't
>>>>> seem to work in your case, and indicates that there is something
>>>>> unusual about your setup.
>>>> 
>>>> In my case, in fact, my init.el is just a stub with my really really
>>>> personal settings. It calls another file with more general settings,
>>>> which I share with colleagues. All my problems are in this last file.
>>>> 
>>>> This particularity can explain that package is not enabled, right?
>>> 
>>> I presume that this “shared” file is not in "~/.emacs.d/", is it?
> 
> Right.
>>> In that case, Flycheck can't know that it's part of your Emacs
>>> configuration, and treats it as if it were any random Emacs Lisp
>>> file, which means that packages aren't enabled.
>>> 
>>> Add "flycheck-emacs-lisp-initialize-packages" to the file-local
>>> variables of that file, with a value of t.  This forces Flycheck to
>>> enable packages when checking the file.
>> 
>> I just tested this, on another MWE:
>> 
>> ;;; .emacs-minimal.el --- Test file
>> 
>> ;;; Commentary:
>> 
>> ;;; Code:
>> 
>> (defun try-require (feature)
>>  "Attempt to load a FEATURE (or library).
>> Return true if the library given as argument is successfully loaded.  If
>> not, just print a message."
>>  (condition-case err
>>      (progn (if (stringp feature)
>>                 (load-library feature)
>>               (require feature)) t)
>>    (file-error (message "Requiring `%s'... missing" feature) nil)))
>> 
>> (when (require 'idle-require nil t)
>>  (setq idle-require-idle-delay 5)
>>  (setq idle-require-load-break 2))
>> 
>> (when (try-require 'idle-require)
>>  (setq idle-require-idle-delay 5)
>>  (setq idle-require-load-break 2))
>> 
>> (provide '.emacs-minimal)
>> 
>> ;; This is for the sake of Emacs.
>> ;; Local Variables:
>> ;; flycheck-emacs-lisp-initialize-packages: t
>> ;; flyspell-mode: nil
>> ;; End:
>> 
>> ;;; .emacs-minimal.el ends here
>> 
>> See the results on http://screencast.com/t/bnfoDJqBX:
>> 
>> - I still have the variables from the package `idle-require' reported as
>>  unknown...
>> 
>> - while that's a package which is under ELPA (right now in
>>  ~/.emacs.d/elpa/idle-require-20090716.3/) and I do have
>>  `flycheck-emacs-lisp-initialize-packages' set to `t'.
> 
> Any idea why the local var `flycheck-emacs-lisp-initialize-packages'
> seems to have no effect?

The variable does have the intended effect:  The package system is initialized and the package is placed in `load-path'. 

But it's still not loaded, because neither `require' nor `try-require' are ever called during compilation.

As said before, only *top-level* `require' forms are evaluated by the byte compiler.   Your `try-require' is a `require' form, obviously, and your `require' call isn't top-level, since it's wrapped in `when'. The byte compiler just treats these like any other expression, and compiles them to byte code without evaluating them first.

You'll either have to `require' the package at *top-level*, or use `eval-when-compile'/`eval-and-compile' at the appropriate places to force the byte compiler to load your package during byte compilation.

For customization purposes specifically, you may use the following macro:

(defmacro lunaryorn-after (feature &rest forms)
  (declare (indent 1) (debug t))
  (when (bound-and-true-p byte-compile-current-file)
    (message "LOADING")
    (if (stringp feature)
        (load feature nil 'no-error)
      (require feature nil 'no-error)))
  `(with-eval-after-load ',feature ,@forms))

It's lazy like `with-eval-after-load', that is, delays the body until after the feature is loaded, but requires the feature during compilation to make variable definitions available.  Use it like this:

(lunaryorn-after idle-require
  (setq idle-require-idle-delay 5
        idle-require-load-break 2))

You'll need Emacs 24.4 for `with-eval-after-load`, or copy the definition of `with-eval-after-load' for earlier Emacsen.  See http://www.lunaryorn.com/2013/06/25/introducing-with-eval-after-load.html


  reply	other threads:[~2014-09-01 10:23 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-28 12:05 Flycheck reports are never satisfying!? Sebastien Vauban
2014-08-28 13:40 ` Stefan Monnier
2014-08-28 15:15   ` Sebastian Wiesner
2014-08-28 15:48     ` Stefan Monnier
2014-08-29  9:01       ` Sebastian Wiesner
2014-08-29 13:05         ` Stefan Monnier
     [not found]     ` <mailman.7732.1409240949.1147.help-gnu-emacs@gnu.org>
2014-08-28 17:35       ` Sebastien Vauban
2014-08-29  3:32         ` Stefan Monnier
     [not found] ` <mailman.7720.1409233288.1147.help-gnu-emacs@gnu.org>
2014-08-28 14:14   ` Sebastien Vauban
2014-08-28 14:38     ` Stefan Monnier
2014-08-28 15:51       ` worrying about byte-compiler warnings [was: Flycheck reports are never satisfying!?] Drew Adams
2014-08-28 15:25 ` Flycheck reports are never satisfying!? Sebastian Wiesner
     [not found]   ` <61C65218-4004-4FD5-ABE0-6C863E5F60A6-MMJ3jE1zGgOaMJb+Lgu22Q@public.gmane.org>
2014-08-28 15:39     ` Sebastien Vauban
2014-08-28 15:45       ` Sebastian Wiesner
     [not found]         ` <B540BE8A-D03C-4F2D-ADB7-2A17F8E55F4E-MMJ3jE1zGgOaMJb+Lgu22Q@public.gmane.org>
2014-08-28 18:35           ` Sebastien Vauban
     [not found]         ` <mailman.7753.1409250970.1147.help-gnu-emacs@gnu.org>
     [not found]           ` <mailman.7753.1409250970.1147.help-gnu-emacs-mXXj517/zsQ@public.gmane.org>
2014-09-01 10:00             ` Sebastien Vauban
2014-09-01 10:23               ` Sebastian Wiesner [this message]
2014-09-01 12:27 ` sokobania.01
2014-09-01 12:30 ` sokobania.01

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=814CFCAE-EA3C-4C92-889F-20A247A13AA1@lunaryorn.com \
    --to=swiesner@lunaryorn.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=sva-news@mygooglest.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.