all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: emacs-devel@gnu.org
Subject: Re: Byte-compiler warnings for todo-mode.el
Date: Sun, 05 Aug 2018 21:23:42 -0400	[thread overview]
Message-ID: <jwvva8ofg6z.fsf-monnier+gmane.emacs.devel@gnu.org> (raw)
In-Reply-To: 87zhy0fs69.fsf@gmx.net

>   (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	other threads:[~2018-08-06  1:23 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-05 20:57 Byte-compiler warnings for todo-mode.el Stephen Berman
2018-08-06  1:23 ` Stefan Monnier [this message]
2018-08-06  8:49   ` Stephen Berman
2018-08-06 15:32     ` Stefan Monnier
2018-08-06 15:56       ` Stefan Monnier
2018-08-06 16:30       ` Stephen Berman

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=jwvva8ofg6z.fsf-monnier+gmane.emacs.devel@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@gnu.org \
    /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.