help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Dynamic let for lexical scope?


From: Hi-Angel
Subject: Re: Dynamic let for lexical scope?
Date: Wed, 13 Feb 2019 09:39:30 +0300

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.



reply via email to

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