unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Eric Abrahamsen <eric@ericabrahamsen.net>
To: help-gnu-emacs@gnu.org
Cc: Stefan Monnier <monnier@iro.umontreal.ca>
Subject: de-dynamicizing some code
Date: Thu, 20 Nov 2014 11:42:11 +0800	[thread overview]
Message-ID: <87h9xuv8q4.fsf@ericabrahamsen.net> (raw)

I'm addressing this to Stefan, because of some comments he made
previously, but posting this here because it's probably of general
interest.

I'm working around some BBDB code that looks like this:

  (let* ((indent (or (bbdb-layout-get-option layout 'indentation) 21))
         (fmt (format " %%%ds: " (- indent 3)))
         start field formatfun)
    (dolist (field field-list)
      (setq start (point))
      (cond (;; customized formatting
             (setq formatfun (intern-soft (format "bbdb-display-%s-multi-line" field)))
             (funcall formatfun record))

What's happening is, you can provide a custom formatting function for a
field on a BBDB record, and BBDB will call the format function if it
exists.

The local vars `indent' and `fmt' are necessary for formatting the
field, and you access them dynamically from within the `formatfun'. This
makes compiler warnings, and is presumably bad for our lexical future.

I assume the proper solution is to replace this:

(funcall formatfun record)

with:

(funcall formatfun record indent fmt)

Is that correct?

Thanks,
Eric




             reply	other threads:[~2014-11-20  3:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-20  3:42 Eric Abrahamsen [this message]
2014-11-20  3:57 ` de-dynamicizing some code Stefan Monnier
2014-11-20  4:13   ` Eric Abrahamsen

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=87h9xuv8q4.fsf@ericabrahamsen.net \
    --to=eric@ericabrahamsen.net \
    --cc=help-gnu-emacs@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.
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).