all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* ‘(vterm local)’ is a malformed function
@ 2023-08-03 15:22 hw
  2023-08-03 16:45 ` Yuri Khan
  0 siblings, 1 reply; 4+ messages in thread
From: hw @ 2023-08-03 15:22 UTC (permalink / raw)
  To: help-gnu-emacs

Hi,

I've made some functions to set up a bunch of connections with vterm:


(require 'vterm)

(defun my-vterm-connect (pretty-name fqdn)
  "Wrapper for logging into a host the name of which is given in the
argument fqdn via ssh."
  (vterm pretty-name)
  (vterm-send-string (concat "cd /tmp ; ssh " fqdn "\ntmux attach"))
  (vterm-send-return))

(defun my-connections (fqdns)
  "Set up a bunch of vterms, some with ssh connections."
  (if (not (get-buffer "local")) ((vterm "local")
				  (vterm-send-string "cd")
				  (vterm-send-return))
    (message "local terminal seems already open"))
  (dolist (this fqdns)
    (if (not (get-buffer this))
	(my-vterm-connect this this)
      (message "%s seems already connected to" this))))


That way, I can call (my-connections '("host1.example.com"
"host2.example.com")) for how many hosts I may want to connect to.

It works fine, though I'm getting a warning:


⛔ Warning (comp): connections.el:13:36: Warning: ‘(vterm local)’ is a malformed function


What's malformed about it?  It doesn't consider (vterm pretty-name) as
malformed ... "local" somehow gets unstringyfied?




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

* Re: ‘(vterm local)’ is a malformed function
  2023-08-03 15:22 ‘(vterm local)’ is a malformed function hw
@ 2023-08-03 16:45 ` Yuri Khan
  2023-08-03 19:25   ` hw
  0 siblings, 1 reply; 4+ messages in thread
From: Yuri Khan @ 2023-08-03 16:45 UTC (permalink / raw)
  To: hw; +Cc: help-gnu-emacs

On Thu, 3 Aug 2023 at 22:22, hw <hw@adminart.net> wrote:

> (defun my-connections (fqdns)
>   "Set up a bunch of vterms, some with ssh connections."
>   (if (not (get-buffer "local")) ((vterm "local")
                                    ^
You forgot a ‘progn’ here. In Lisp, you can’t just put a bunch of
forms in parentheses and expect them all to execute sequentially like
they do in C. The first expression in parentheses is expected to be a
function, and the rest will be passed as its arguments.

>                                   (vterm-send-string "cd")
>                                   (vterm-send-return))
>     (message "local terminal seems already open"))

Alternatively, since you have just one form in the ELSE branch, you
could invert the test:

    (if (get-buffer "local")
        (message "local terminal seems already open")
      (vterm "local")
      (vterm-send-string "cd")
      (vterm-send-return))

The THEN branch allows a single form (which could be a ‘(progn …)’ if
you need many); the ELSE branch allows multiple forms.

> It works fine, though I'm getting a warning:
>
>
> ⛔ Warning (comp): connections.el:13:36: Warning: ‘(vterm local)’ is a malformed function
>
>
> What's malformed about it?  It doesn't consider (vterm pretty-name) as
> malformed ... "local" somehow gets unstringyfied?

(vterm pretty-name) is within a function body, which allows multiple forms.



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

* Re: ‘(vterm local)’ is a malformed function
  2023-08-03 16:45 ` Yuri Khan
@ 2023-08-03 19:25   ` hw
  2023-08-04  5:26     ` Yuri Khan
  0 siblings, 1 reply; 4+ messages in thread
From: hw @ 2023-08-03 19:25 UTC (permalink / raw)
  To: help-gnu-emacs

On Thu, 2023-08-03 at 23:45 +0700, Yuri Khan wrote:
> On Thu, 3 Aug 2023 at 22:22, hw <hw@adminart.net> wrote:
> 
> > (defun my-connections (fqdns)
> >   "Set up a bunch of vterms, some with ssh connections."
> >   (if (not (get-buffer "local")) ((vterm "local")
>                                     ^
> You forgot a ‘progn’ here. In Lisp, you can’t just put a bunch of
> forms in parentheses and expect them all to execute sequentially like
> they do in C. The first expression in parentheses is expected to be a
> function, and the rest will be passed as its arguments.

Ohh --- thank you!  I think I never understood it that way, and it's
been such a long time that I wrote anything in elisp that it's all
difficult again because I forgot so many details.

> >                                   (vterm-send-string "cd")
> >                                   (vterm-send-return))
> >     (message "local terminal seems already open"))
> 
> Alternatively, since you have just one form in the ELSE branch, you
> could invert the test:
> 
>     (if (get-buffer "local")
>         (message "local terminal seems already open")
>       (vterm "local")
>       (vterm-send-string "cd")
>       (vterm-send-return))
> 
> The THEN branch allows a single form (which could be a ‘(progn …)’ if
> you need many); the ELSE branch allows multiple forms.

strange ...

> > It works fine, though I'm getting a warning:
> > 
> > 
> > ⛔ Warning (comp): connections.el:13:36: Warning: ‘(vterm local)’ is a malformed function
> > 
> > 
> > What's malformed about it?  It doesn't consider (vterm pretty-name) as
> > malformed ... "local" somehow gets unstringyfied?
> 
> (vterm pretty-name) is within a function body, which allows multiple forms.

Hm, this warning message seems quite misleading.  I'm not sure what it
could better say instead though.

When I look at the desription of if, it says that it'll "do THEN, else
do ELSE".  To me, that means that it'll will *do* (like evaluate) what
I say, like (vterm "local") --- not that it would treat THEN and ELSE
sometimes as a parameter of if and sometimes not (i. e. not when
"else").  What else is "do" supposed to mean here?  What does it "do"
with 5 in '(if (eq 1 1) 5 6)' other than returning 5 --- or 6 if 1
wasn't equal to 1?

And if (vterm "local") can not be treated as a parameter of if, maybe
the warning message could say exactly that.  And perhaps the
description of if could point out that "do THEN" means something else
than "do ELSE".  Both are called "expression", and they're not the
same because one gets evaluted and the other doesn't (What actually
happens to it?).

5 is a malformed function, or is it?




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

* Re: ‘(vterm local)’ is a malformed function
  2023-08-03 19:25   ` hw
@ 2023-08-04  5:26     ` Yuri Khan
  0 siblings, 0 replies; 4+ messages in thread
From: Yuri Khan @ 2023-08-04  5:26 UTC (permalink / raw)
  To: hw; +Cc: help-gnu-emacs

On Fri, 4 Aug 2023 at 02:26, hw <hw@adminart.net> wrote:

> Hm, this warning message seems quite misleading.  I'm not sure what it
> could better say instead though.
>
> When I look at the desription of if, it says that it'll "do THEN, else
> do ELSE".  To me, that means that it'll will *do* (like evaluate) what
> I say, like (vterm "local") --- not that it would treat THEN and ELSE
> sometimes as a parameter of if and sometimes not (i. e. not when
> "else").  What else is "do" supposed to mean here?  What does it "do"
> with 5 in '(if (eq 1 1) 5 6)' other than returning 5 --- or 6 if 1
> wasn't equal to 1?
>
> And if (vterm "local") can not be treated as a parameter of if, maybe
> the warning message could say exactly that.

It cannot say that. ‘if’ does not see (vterm "local") as a THEN form.
It sees the whole

    ((vterm "local")
     (vterm-send-string "cd")
     (vterm-send-return))

and that looks like a function call but with a weird thing in place of
the function. So it complains at that.

> And perhaps the
> description of if could point out that "do THEN" means something else
> than "do ELSE".  Both are called "expression", and they're not the
> same because one gets evaluted and the other doesn't (What actually
> happens to it?).

The description does point it out, very explicitly and clearly.

    if is a special form in ‘C source code’.

    (if COND THEN ELSE...)

    If COND yields non-nil, do THEN, else do ELSE...
    Returns the value of THEN or the value of the last of the ELSE’s.
    THEN must be one expression, but ELSE... can be zero or more expressions.
                 ^^^^^^^^^^^^^^                     ^^^^^^^^^^^^^^^^^^^^^^^^
    If COND yields nil, and there are no ELSE’s, the value is nil.



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

end of thread, other threads:[~2023-08-04  5:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-03 15:22 ‘(vterm local)’ is a malformed function hw
2023-08-03 16:45 ` Yuri Khan
2023-08-03 19:25   ` hw
2023-08-04  5:26     ` Yuri Khan

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.