all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stephen Berman <stephen.berman@gmx.net>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: emacs-devel@gnu.org
Subject: Re: Byte-compiler warnings for todo-mode.el
Date: Mon, 06 Aug 2018 10:49:18 +0200	[thread overview]
Message-ID: <8736vrop69.fsf@gmx.net> (raw)
In-Reply-To: <jwvva8ofg6z.fsf-monnier+gmane.emacs.devel@gnu.org> (Stefan Monnier's message of "Sun, 05 Aug 2018 21:23:42 -0400")

On Sun, 05 Aug 2018 21:23:42 -0400 Stefan Monnier <monnier@iro.umontreal.ca> wrote:

>>   (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`.

I thought I understood that this is so, but...

>> 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.

...starting emacs -Q with the above code and my ~/.emacs.d/todo/
directory, typing `F f' in todo-mode prompts for a filtered items file
and repeating M-n brings up all and only the names of my filtered items
files in the minibuffer, i.e., all and only the elements of sfnlist.
Yet when I step through the code in Edebug, after evaluating the line
(setq sfnlist (mapcar #'car falist)), the sexp (symbol-value 'sfnlist)
indeed still evaluates to nil.  So the code does appear to do exactly
what I expect, although as you say it shouldn't.  Can you explain this?
In any case, I will add the defvar, since it is evidently canonical and
correct.

>> 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).

When I replace the above if-sexp with this:

  (when (and (eval-and-compile (require 'hl-line)) hl-line-mode)
    (hl-line-highlight))

and byte-compile the file in emacs -Q, Emacs does not produce the
warning.  Should I make a bug report?

>> 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).

I'll leave the warning, then; maybe it will serve to inspire someone to
teach the byte-compiler how to avoid it.

Thanks for the feedback.

Steve Berman



  reply	other threads:[~2018-08-06  8:49 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
2018-08-06  8:49   ` Stephen Berman [this message]
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=8736vrop69.fsf@gmx.net \
    --to=stephen.berman@gmx.net \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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.