From: Hi-Angel <hiangel999@gmail.com>
To: Michael Heerdegen <michael_heerdegen@web.de>
Cc: help-gnu-emacs@gnu.org
Subject: Re: Dynamic let for lexical scope?
Date: Wed, 13 Feb 2019 09:39:30 +0300 [thread overview]
Message-ID: <CAHGDjgAR6CZRwfT=9sAjX+h40VFz3GNv4mmZ8Rx=_APAukYsag@mail.gmail.com> (raw)
In-Reply-To: <87wom4o0ka.fsf@web.de>
Thank you!
On Wed, 13 Feb 2019 at 05:59, Michael Heerdegen
<michael_heerdegen@web.de> wrote:
>
> Hi-Angel <hiangel999@gmail.com> writes:
>
> > I have the following function:
> >
> > (defun sort-lines-nocase (beg end)
> > (let ((sort-fold-case t))
> > (sort-lines nil beg end)))
> >
> > It temporarily changes sort-fold-case. Now, when compiled with
> >
> > ;;; -*- lexical-binding: t -*-
> >
> > at the top, it causes a warning "Unused lexical variable
> > ‘sort-fold-case’".
>
> The canonical answer is: add (defvar sort-fold-case) to get local
> dynamical binding:
>
> (defun sort-lines-nocase (beg end)
> (defvar sort-fold-case)
> (let ((sort-fold-case t))
> (sort-lines nil beg end)))
>
> In your case, I guess the problem is that `sort-lines' is autoloaded and
> the variable is not yet declared when you compile (or evaluate for the
> first time). So you could also add
>
> (eval-when-compile (require 'sort))
>
> It's a matter of taste which alternative is better or cleaner. If you
> use more stuff from sort.el, it's probably better to `require' it.
>
>
> Michael.
prev parent reply other threads:[~2019-02-13 6:39 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-12 23:23 Dynamic let for lexical scope? Hi-Angel
2019-02-13 2:59 ` Michael Heerdegen
2019-02-13 6:39 ` Hi-Angel [this message]
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAHGDjgAR6CZRwfT=9sAjX+h40VFz3GNv4mmZ8Rx=_APAukYsag@mail.gmail.com' \
--to=hiangel999@gmail.com \
--cc=help-gnu-emacs@gnu.org \
--cc=michael_heerdegen@web.de \
/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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).