unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* flet vs cl-flet vs compilation-start
@ 2017-02-01 23:33 Stephen Leake
  2017-02-01 23:49 ` John Mastro
  2017-02-02  9:16 ` Michael Heerdegen
  0 siblings, 2 replies; 3+ messages in thread
From: Stephen Leake @ 2017-02-01 23:33 UTC (permalink / raw)
  To: emacs-devel

I'm using compilation-mode to show results from running an external
program; it produces output that looks like compilation errors (it's
actually cross-reference info).

Some users would like to preserve output from several calls to the
external program.

compilation-start does not provide an option for this; it calls
(erase-buffer) unconditionally.

So someone suggested this hack:

(require 'cl)
(flet ((erase-buffer nil (goto-char (point-max))))
    (compilation-start ... ))

That works, but produces byte-compiler warnings about cl and flet.

So I tried:

(require 'cl-lib)
(cl-flet ((erase-buffer nil (goto-char (point-max))))
    (compilation-start ... ))

This does _not_ work. Apparently in the "flet" case, the local
definition of 'erase-buffer' overrides the global one, but in the
'cl-flet' case it does not.

I'm running emacs-25 compiled from the branch with mingw64.

This is consistent with the doc strings:

cl-flet says:

Make local function definitions.

flet says:

Make temporary overriding function definitions.

and goes on to say "use cl-flet".

Perhaps the doc string of flet should be improved to point out that
cl-flet does not produce _overriding_ function definitions, and suggest
workarounds.


I could try applying and removing advice on erase-buffer, but a simpler
workaround is to copy the buffer content into a local string var, then
paste it back.

Is there any support for introducing a parameter to compilation-start
that says "don't erase the buffer"?

-- 
-- Stephe



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

* Re: flet vs cl-flet vs compilation-start
  2017-02-01 23:33 flet vs cl-flet vs compilation-start Stephen Leake
@ 2017-02-01 23:49 ` John Mastro
  2017-02-02  9:16 ` Michael Heerdegen
  1 sibling, 0 replies; 3+ messages in thread
From: John Mastro @ 2017-02-01 23:49 UTC (permalink / raw)
  To: emacs-devel; +Cc: Stephen Leake

Stephen Leake <stephen_leake@stephe-leake.org> wrote:
> This is consistent with the doc strings:
>
> cl-flet says:
>
> Make local function definitions.
>
> flet says:
>
> Make temporary overriding function definitions.
>
> and goes on to say "use cl-flet".
>
> Perhaps the doc string of flet should be improved to point out that
> cl-flet does not produce _overriding_ function definitions, and suggest
> workarounds.

It's not as well known, but you can use `cl-letf' for this:

(cl-letf (((symbol-function 'erase-buffer)
           (lambda () (goto-char (point-max)))))
  (compilation-start ...))



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

* Re: flet vs cl-flet vs compilation-start
  2017-02-01 23:33 flet vs cl-flet vs compilation-start Stephen Leake
  2017-02-01 23:49 ` John Mastro
@ 2017-02-02  9:16 ` Michael Heerdegen
  1 sibling, 0 replies; 3+ messages in thread
From: Michael Heerdegen @ 2017-02-02  9:16 UTC (permalink / raw)
  To: Stephen Leake; +Cc: emacs-devel

Stephen Leake <stephen_leake@stephe-leake.org> writes:

> I'm using compilation-mode to show results from running an external
> program; it produces output that looks like compilation errors (it's
> actually cross-reference info).
>
> Some users would like to preserve output from several calls to the
> external program.
>
> compilation-start does not provide an option for this; it calls
> (erase-buffer) unconditionally.
>
> So someone suggested this hack:
>
> (require 'cl)
> (flet ((erase-buffer nil (goto-char (point-max))))
>     (compilation-start ... ))
>
> That works, but produces byte-compiler warnings about cl and flet.
>
> So I tried:
>
> (require 'cl-lib)
> (cl-flet ((erase-buffer nil (goto-char (point-max))))
>     (compilation-start ... ))
>
> This does _not_ work. Apparently in the "flet" case, the local
> definition of 'erase-buffer' overrides the global one, but in the
> 'cl-flet' case it does not.

The cause is that the function bindings created by cl-flet and cl-labels
have lexical scope.  And that is documented.

As already has been mentioned, as a last resort, use cl-letf in such
cases.


Michael.



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

end of thread, other threads:[~2017-02-02  9:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-02-01 23:33 flet vs cl-flet vs compilation-start Stephen Leake
2017-02-01 23:49 ` John Mastro
2017-02-02  9:16 ` Michael Heerdegen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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).