all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* lambda an (interactive) function but not a command
@ 2019-03-19  0:27 Emanuel Berg
  2019-03-19  1:17 ` Michael Heerdegen
  0 siblings, 1 reply; 8+ messages in thread
From: Emanuel Berg @ 2019-03-19  0:27 UTC (permalink / raw)
  To: help-gnu-emacs

In my config file for the Gnus summary
buffer [1] I have this [2]. What I wonder is,
for the "F" key to invoke the
`gnus-summary-followup-inline' function, for
such a simple one-liner, why can't one use
a lambda for that, i.e.

    (lambda (interactive) (gnus-summary-mail-forward 4))

?

Only then I get the error

    (wrong-type-argument commandp ...

Is it because the whole thing is based on
names, and a lambda by definition doesn't have
a name, and so it can just be an
anonymous *function*, not an "anonymous
command" if you will?

TIA


[1] line 72 @ http://user.it.uu.se/~embe8573/emacs-init/gnus/summary.el

[2]

(defun gnus-summary-followup-inline ()
  (interactive)
  (gnus-summary-mail-forward 4) )

;;; KEYS

(let ((the-map gnus-summary-mode-map))
    (disable-super-global-keys the-map)
    (set-vertical-keys         the-map)
    ;; group
    (define-key the-map  "o"  #'gnus-summary-insert-old-articles)
    (define-key the-map  "w"  #'gnus-summary-exit-and-update-group)
    ;; reply
    (define-key the-map  "r"  #'gnus-summary-followup-with-original)
    (define-key the-map  "R"  #'gnus-summary-reply-with-original)
    ;; message
    (define-key the-map  "d"  #'gnus-summary-delete-article)
    (define-key the-map  "D"  #'gnus-summary-mark-as-dormant)
    (define-key the-map  "D"  #'gnus-summary-mark-as-dormant)
    (define-key the-map  "f"  #'gnus-article-fill-cited-article)
    (define-key the-map  "F"  #'gnus-summary-followup-inline)
    (define-key the-map  "U"  #'gnus-summary-uncool-subject)
    (define-key the-map  "z"  #'gnus-score-edit-current-scores)
    (define-key the-map "\r"  #'gnus-summary-show-article)
    ;; mark
    (define-key the-map  "l"  #'gnus-summary-put-mark-as-unread-next)
    (define-key the-map  "s"  #'gnus-summary-mark-as-read-forward)
    )

-- 
underground experts united
http://user.it.uu.se/~embe8573




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

* Re: lambda an (interactive) function but not a command
  2019-03-19  0:27 lambda an (interactive) function but not a command Emanuel Berg
@ 2019-03-19  1:17 ` Michael Heerdegen
  2019-03-19  1:29   ` Emanuel Berg
  0 siblings, 1 reply; 8+ messages in thread
From: Michael Heerdegen @ 2019-03-19  1:17 UTC (permalink / raw)
  To: help-gnu-emacs

Emanuel Berg <moasenwood@zoho.eu> writes:

> In my config file for the Gnus summary
> buffer [1] I have this [2]. What I wonder is,
> for the "F" key to invoke the
> `gnus-summary-followup-inline' function, for
> such a simple one-liner, why can't one use
> a lambda for that, i.e.
>
>     (lambda (interactive) (gnus-summary-mail-forward 4))

If you want this to work, you should add an argument list.  An
interactive lambda also needs one.  In the above function, (interactive)
is specified as argument list, so an interactive spec is missing and it
is not a command.

Michael.



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

* Re: lambda an (interactive) function but not a command
  2019-03-19  1:17 ` Michael Heerdegen
@ 2019-03-19  1:29   ` Emanuel Berg
  2019-03-19  1:38     ` Amin Bandali
  2019-03-19  1:39     ` Michael Heerdegen
  0 siblings, 2 replies; 8+ messages in thread
From: Emanuel Berg @ 2019-03-19  1:29 UTC (permalink / raw)
  To: help-gnu-emacs

Michael Heerdegen wrote:

> If you want this to work, you should add an
> argument list. An interactive lambda also
> needs one. In the above function,
> (interactive) is specified as argument list,
> so an interactive spec is missing and it is
> not a command.

You mean like this

    (lambda (interactive) () (gnus-summary-mail-forward 4))

?

If so, it doesn't work

    (wrong-type-argument commandp (lambda
    (interactive) nil
    (gnus-summary-mail-forward 4))) in
    command-execute

Maybe you meant something else?

-- 
underground experts united
http://user.it.uu.se/~embe8573




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

* Re: lambda an (interactive) function but not a command
  2019-03-19  1:29   ` Emanuel Berg
@ 2019-03-19  1:38     ` Amin Bandali
  2019-03-19  1:39     ` Michael Heerdegen
  1 sibling, 0 replies; 8+ messages in thread
From: Amin Bandali @ 2019-03-19  1:38 UTC (permalink / raw)
  To: help-gnu-emacs

How about this?

(lambda () (interactive) (gnus-summary-mail-forward 4))



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

* Re: lambda an (interactive) function but not a command
  2019-03-19  1:29   ` Emanuel Berg
  2019-03-19  1:38     ` Amin Bandali
@ 2019-03-19  1:39     ` Michael Heerdegen
  2019-03-19  2:03       ` Emanuel Berg
  1 sibling, 1 reply; 8+ messages in thread
From: Michael Heerdegen @ 2019-03-19  1:39 UTC (permalink / raw)
  To: help-gnu-emacs

Emanuel Berg <moasenwood@zoho.eu> writes:

> You mean like this
>
>     (lambda (interactive) () (gnus-summary-mail-forward 4))
>
> ?

No,

  (lambda () (interactive) (gnus-summary-mail-forward 4))

please.  Syntax is analogue to that of `defun': argument list comes
first.  See the docstring of `lambda' :-)


Michael.



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

* Re: lambda an (interactive) function but not a command
  2019-03-19  1:39     ` Michael Heerdegen
@ 2019-03-19  2:03       ` Emanuel Berg
  2019-03-19  2:49         ` quoting lambdas (was: Re: lambda an (interactive) function but not a command) Emanuel Berg
  0 siblings, 1 reply; 8+ messages in thread
From: Emanuel Berg @ 2019-03-19  2:03 UTC (permalink / raw)
  To: help-gnu-emacs

Michael Heerdegen wrote:

> No,
>
>   (lambda () (interactive) (gnus-summary-mail-forward 4))
>
> please. Syntax is analogue to that of
> `defun': argument list comes first. See the
> docstring of `lambda' :-)

Heh heh, in my Elisp init files, I have used
`lambda' no less than 42 times!

You have to read what I think, not what I
type :)

-- 
underground experts united
http://user.it.uu.se/~embe8573




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

* quoting lambdas (was: Re: lambda an (interactive) function but not a command)
  2019-03-19  2:03       ` Emanuel Berg
@ 2019-03-19  2:49         ` Emanuel Berg
  2019-03-19 14:15           ` quoting lambdas Michael Heerdegen
  0 siblings, 1 reply; 8+ messages in thread
From: Emanuel Berg @ 2019-03-19  2:49 UTC (permalink / raw)
  To: help-gnu-emacs

Now when we are on the interesting subject of
lambdas, I've heard one shouldn't quote them.
This makes sense as they are code, not data.

But what about the hash-quote or
"function quote", i.e. the #' ? IIUC that tells
the byte-compiler that something is a function,
so the byte-compiler can examine if the
function is defined at that point, and possibly
even do some optimizations - but obviously the
byte-compiler should already know that a lambda
is a function!

So #' with lambdas should be
meaningless, right?

But I suppose if they are meaningless, one
might put them there just as well :)

What's the policy from Emacs High Command?

-- 
underground experts united
http://user.it.uu.se/~embe8573




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

* Re: quoting lambdas
  2019-03-19  2:49         ` quoting lambdas (was: Re: lambda an (interactive) function but not a command) Emanuel Berg
@ 2019-03-19 14:15           ` Michael Heerdegen
  0 siblings, 0 replies; 8+ messages in thread
From: Michael Heerdegen @ 2019-03-19 14:15 UTC (permalink / raw)
  To: help-gnu-emacs

Emanuel Berg <moasenwood@zoho.eu> writes:

> So #' with lambdas should be meaningless, right?
>
> But I suppose if they are meaningless, one might put them there just
> as well :)

Yes both times, AFAIK.

It's even the case that `lambda' is a normal macro that implicitly
sharp-quotes "itself", e.g.

 (macroexpand '(lambda () 1))

  ==> #'(lambda nil 1)

Michael.



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

end of thread, other threads:[~2019-03-19 14:15 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-03-19  0:27 lambda an (interactive) function but not a command Emanuel Berg
2019-03-19  1:17 ` Michael Heerdegen
2019-03-19  1:29   ` Emanuel Berg
2019-03-19  1:38     ` Amin Bandali
2019-03-19  1:39     ` Michael Heerdegen
2019-03-19  2:03       ` Emanuel Berg
2019-03-19  2:49         ` quoting lambdas (was: Re: lambda an (interactive) function but not a command) Emanuel Berg
2019-03-19 14:15           ` quoting lambdas Michael Heerdegen

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.