all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Michael Heerdegen <michael_heerdegen@web.de>
To: Hi-Angel <hiangel999@gmail.com>
Cc: help-gnu-emacs@gnu.org
Subject: Re: Dynamic let for lexical scope?
Date: Wed, 13 Feb 2019 03:59:49 +0100	[thread overview]
Message-ID: <87wom4o0ka.fsf@web.de> (raw)
In-Reply-To: <CAHGDjgARAUefL8F6XZAXbCSz7kKS=USUUd+tjiMzncV+dEmqmQ@mail.gmail.com> (Hi-Angel's message of "Wed, 13 Feb 2019 02:23:01 +0300")

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	other threads:[~2019-02-13  2:59 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 [this message]
2019-02-13  6:39   ` Hi-Angel

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=87wom4o0ka.fsf@web.de \
    --to=michael_heerdegen@web.de \
    --cc=help-gnu-emacs@gnu.org \
    --cc=hiangel999@gmail.com \
    /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.