all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* de-dynamicizing some code
@ 2014-11-20  3:42 Eric Abrahamsen
  2014-11-20  3:57 ` Stefan Monnier
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Abrahamsen @ 2014-11-20  3:42 UTC (permalink / raw
  To: help-gnu-emacs; +Cc: Stefan Monnier

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




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: de-dynamicizing some code
  2014-11-20  3:42 de-dynamicizing some code Eric Abrahamsen
@ 2014-11-20  3:57 ` Stefan Monnier
  2014-11-20  4:13   ` Eric Abrahamsen
  0 siblings, 1 reply; 3+ messages in thread
From: Stefan Monnier @ 2014-11-20  3:57 UTC (permalink / raw
  To: help-gnu-emacs

> I assume the proper solution is to replace this:
>      (funcall formatfun record)
> with:
>      (funcall formatfun record indent fmt)
> Is that correct?

There are various solutions, but this one looks like a very good
option, indeed.

The next best thing is to rename the variables to bbdb-fmt and
bbdb-indent (and to add "(defvar bbdb-indent) (defvar bbdb-fmt)"
somewhere at top-level (to tell the compiler that these vars should use
dynamic binding).


        Stefan




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: de-dynamicizing some code
  2014-11-20  3:57 ` Stefan Monnier
@ 2014-11-20  4:13   ` Eric Abrahamsen
  0 siblings, 0 replies; 3+ messages in thread
From: Eric Abrahamsen @ 2014-11-20  4:13 UTC (permalink / raw
  To: help-gnu-emacs

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> I assume the proper solution is to replace this:
>>      (funcall formatfun record)
>> with:
>>      (funcall formatfun record indent fmt)
>> Is that correct?
>
> There are various solutions, but this one looks like a very good
> option, indeed.
>
> The next best thing is to rename the variables to bbdb-fmt and
> bbdb-indent (and to add "(defvar bbdb-indent) (defvar bbdb-fmt)"
> somewhere at top-level (to tell the compiler that these vars should use
> dynamic binding).

Interesting -- thanks. I guess in this case the simpler solution is
enough.

E




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-11-20  4:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-20  3:42 de-dynamicizing some code Eric Abrahamsen
2014-11-20  3:57 ` Stefan Monnier
2014-11-20  4:13   ` Eric Abrahamsen

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.