emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Byte-compiler warnings for todo-mode.el


From: Stefan Monnier
Subject: Re: Byte-compiler warnings for todo-mode.el
Date: Sun, 05 Aug 2018 21:23:42 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

>   (let (... falist sfnlist ...)
>     (dolist (f files)
>        ...
>        (push (...) falist))
>     (setq sfnlist (mapcar #'car falist))
>     (setq file (completing-read "Choose a filtered items file: "
>                               falist nil t nil 'sfnlist (caar falist)))
>     ...)

The above will not pass the value of `sfnlist` to `completing-read`.
I.e. the warning saying "Unused lexical variable ‘sfnlist’" is true:
that variable is *not* used.  Instead `completing-read` will look at the
symbol-value of the symbol `sfnlist` which is something completely
separate from the value of the lexical variable `sfnlist`.

> Given this, is it acceptable to leave the warning or is it preferable to
> add a defvar to suppress it?

Rename the var to `todo--sfnlist` and add a `defvar` for it, otherwise
the code will not do what you expect.

> The second warning is due to this line:
>
> (if (and (boundp 'hl-line-mode) hl-line-mode) (hl-line-highlight))
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         (bound-and-true-p hl-line-mode)

> The warning can be prevented with (eval-and-compile (require 'hl-line)).

This ideally shouldn't remove the warning (i.e. if it does, as you say,
then it's probably the result of a bug or misfeature in the compiler).

> In fact, I use that elsewhere in todo-mode.el when hl-line-mode is
> actually enabled, so that when the function the above line of code is
> part of is executed, either hl-line.el is already loaded and
> hl-line-highlight is defined, or hl-line-mode is nil, so
> (hl-line-highlight) won't be evaluated and hence it doesn't matter if
> it's not defined.  Given this, is it acceptable to leave the warning or
> is it preferable to suppress it?

Your call.  You can suppress the warning with

    (declare-function hl-line-highlight ...)
or
    (if (and (boundp 'hl-line-mode) hl-line-mode (fboundp 'hl-line-highlight))
        (hl-line-highlight))

but the warning here is a false alarm, so if you don't mind seeing the
warning you can leave it (ideally, the byte-compiler should be made to
understand the connection between `hl-line-mode` and `hl-line-highlight`
so that your code doesn't trigger a warning).


        Stefan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]