all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* tramp-compat-funcall -> compat-funcall?
@ 2016-09-22 11:04 Ted Zlatanov
  2016-09-22 12:31 ` Stefan Monnier
  0 siblings, 1 reply; 17+ messages in thread
From: Ted Zlatanov @ 2016-09-22 11:04 UTC (permalink / raw)
  To: emacs-devel

Looking at some recent things Michael did in Tramp, I noticed this
function in tramp-compat.el:

;; For not existing functions, obsolete functions, or functions with a
;; changed argument list, there are compiler warnings.  We want to
;; avoid them in cases we know what we do.
(defmacro tramp-compat-funcall (function &rest arguments)
  "Call FUNCTION if it exists.  Do not raise compiler warnings."
  `(when (or (subrp ,function) (functionp ,function))
     (with-no-warnings (funcall ,function ,@arguments))))

I think it would be a great addition to the Emacs core, so other
packages can use it. It just needs to be copied and then Tramp can
switch to it. Here's an example of a reimplementation that's not as good
(it seems) in gnus-fun.el:

(defun gnus-funcall-no-warning (function &rest args)
  (when (fboundp function)
    (apply function args)))

Thanks
Ted




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

* Re: tramp-compat-funcall -> compat-funcall?
  2016-09-22 11:04 tramp-compat-funcall -> compat-funcall? Ted Zlatanov
@ 2016-09-22 12:31 ` Stefan Monnier
  2016-09-22 13:22   ` Michael Albinus
  2016-09-22 20:18   ` Ted Zlatanov
  0 siblings, 2 replies; 17+ messages in thread
From: Stefan Monnier @ 2016-09-22 12:31 UTC (permalink / raw)
  To: emacs-devel

> ;; For not existing functions, obsolete functions, or functions with a
> ;; changed argument list, there are compiler warnings.  We want to
> ;; avoid them in cases we know what we do.
> (defmacro tramp-compat-funcall (function &rest arguments)
>   "Call FUNCTION if it exists.  Do not raise compiler warnings."
>   `(when (or (subrp ,function) (functionp ,function))
>      (with-no-warnings (funcall ,function ,@arguments))))

[ The `subrp' check looks wrong/redundant.  `functionp' should already return
  non-nil if `function` is a subr (unless it's a special form, in which
  case using `funcall` would be wrong anyway).  ]

FWIW, using tramp-compat-funcall "for not existing functions" is a bad
idea: better use (if (fboundp <foo>) (<foo> ...)).

I think the same kind of consideration should hold for the other two
cases, tho maybe currently the byte-compiler does not offer/detect any
syntax for that.

I think hiding this behind (tramp-)compat-funcall would be better
avoided (just like using with-no-warnings should be avoided whenever
possible).

IOW, if there's a kind of situation that recurs often enough to warrant
something like (tramp-)compat-funcall you should report this as a bug.


        Stefan




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

* Re: tramp-compat-funcall -> compat-funcall?
  2016-09-22 12:31 ` Stefan Monnier
@ 2016-09-22 13:22   ` Michael Albinus
  2016-09-22 17:46     ` Stefan Monnier
  2016-09-22 20:18   ` Ted Zlatanov
  1 sibling, 1 reply; 17+ messages in thread
From: Michael Albinus @ 2016-09-22 13:22 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

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

> [ The `subrp' check looks wrong/redundant.  `functionp' should already return
>   non-nil if `function` is a subr (unless it's a special form, in which
>   case using `funcall` would be wrong anyway).  ]

IIRC, it was not the case in older Emacsen and/or XEmacs. If `functionp'
behaves this way since Emacs 23, Tramp could remove the check for
`subrp', indeed.

> IOW, if there's a kind of situation that recurs often enough to warrant
> something like (tramp-)compat-funcall you should report this as a bug.

`tramp-compat-funcall' is almost used for backward compatibility. Who
shall be the target of a bug report then?

>         Stefan

Best regards, Michael.



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

* Re: tramp-compat-funcall -> compat-funcall?
  2016-09-22 13:22   ` Michael Albinus
@ 2016-09-22 17:46     ` Stefan Monnier
  2016-09-22 17:54       ` Michael Albinus
  0 siblings, 1 reply; 17+ messages in thread
From: Stefan Monnier @ 2016-09-22 17:46 UTC (permalink / raw)
  To: Michael Albinus; +Cc: emacs-devel

> IIRC, it was not the case in older Emacsen and/or XEmacs.  If `functionp'
> behaves this way since Emacs 23, Tramp could remove the check for
> `subrp', indeed.

I do remember changing `functionp` at some point, but at least in
Emacs-21.4 (functionp (symbol-function '+)) returns non-nil.

>> IOW, if there's a kind of situation that recurs often enough to warrant
>> something like (tramp-)compat-funcall you should report this as a bug.
> `tramp-compat-funcall' is almost used for backward compatibility.
> Who shall be the target of a bug report then?

M-x report-emacs-bug.


        Stefan



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

* Re: tramp-compat-funcall -> compat-funcall?
  2016-09-22 17:46     ` Stefan Monnier
@ 2016-09-22 17:54       ` Michael Albinus
  2016-09-22 18:23         ` Stefan Monnier
  0 siblings, 1 reply; 17+ messages in thread
From: Michael Albinus @ 2016-09-22 17:54 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

Stefan Monnier <monnier@IRO.UMontreal.CA> writes:

>> IIRC, it was not the case in older Emacsen and/or XEmacs.  If `functionp'
>> behaves this way since Emacs 23, Tramp could remove the check for
>> `subrp', indeed.
>
> I do remember changing `functionp` at some point, but at least in
> Emacs-21.4 (functionp (symbol-function '+)) returns non-nil.

So it was XEmacs. I'll recheck, and change it then in Tramp. Thanks for
the heads up!

>>> IOW, if there's a kind of situation that recurs often enough to warrant
>>> something like (tramp-)compat-funcall you should report this as a bug.
>> `tramp-compat-funcall' is almost used for backward compatibility.
>> Who shall be the target of a bug report then?
>
> M-x report-emacs-bug.

Package: Emacs
Version: 23.1

And the mob will jump on this, and fix :-)

>         Stefan

Best regards, Michael.



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

* Re: tramp-compat-funcall -> compat-funcall?
  2016-09-22 17:54       ` Michael Albinus
@ 2016-09-22 18:23         ` Stefan Monnier
  0 siblings, 0 replies; 17+ messages in thread
From: Stefan Monnier @ 2016-09-22 18:23 UTC (permalink / raw)
  To: Michael Albinus; +Cc: emacs-devel

>>>> IOW, if there's a kind of situation that recurs often enough to warrant
>>>> something like (tramp-)compat-funcall you should report this as a bug.
>>> `tramp-compat-funcall' is almost used for backward compatibility.
>>> Who shall be the target of a bug report then?
>> M-x report-emacs-bug.
> Package: Emacs
> Version: 23.1

If you want the warning to be fixed in Emacs-23.1 then indeed I won't
help you (I think it's a waste of time).

But if you want to eliminate the warning (about code that should work in
Emacs-23) in Emacs-25/26 then `M-x report-emacs-bug` is a good way to
ask for that.


        Stefan



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

* Re: tramp-compat-funcall -> compat-funcall?
  2016-09-22 12:31 ` Stefan Monnier
  2016-09-22 13:22   ` Michael Albinus
@ 2016-09-22 20:18   ` Ted Zlatanov
  2016-09-23 15:49     ` Stefan Monnier
  1 sibling, 1 reply; 17+ messages in thread
From: Ted Zlatanov @ 2016-09-22 20:18 UTC (permalink / raw)
  To: emacs-devel

On Thu, 22 Sep 2016 08:31:22 -0400 Stefan Monnier <monnier@iro.umontreal.ca> wrote: 

SM> I think hiding this behind (tramp-)compat-funcall would be better
SM> avoided (just like using with-no-warnings should be avoided whenever
SM> possible).

SM> IOW, if there's a kind of situation that recurs often enough to warrant
SM> something like (tramp-)compat-funcall you should report this as a bug.

The use case, I think, is "to provide compatibility with older Emacsen,
I need a convenient way to call a function softly without compiler
warnings if it doesn't exist." I think, based on the two examples I gave
(`gnus-funcall-no-warning' was the other instance), that it's not an
uncommon need, and it's better to provide it in a core facility than ask
package maintainers to implement it.

If the use case is misguided, then what's the right way to call
functions that are missing in 25.1 but are needed in 24.3 for example?
Do we need a layered cond-like funcall instead, which tries several
invocations (not necessarily with the same arguments) until one
succeeds? In either case, the compiler warnings seem better silenced
than active, unless none of the cases succeed.

Ted




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

* Re: tramp-compat-funcall -> compat-funcall?
  2016-09-22 20:18   ` Ted Zlatanov
@ 2016-09-23 15:49     ` Stefan Monnier
  2016-09-24  6:54       ` Michael Albinus
  0 siblings, 1 reply; 17+ messages in thread
From: Stefan Monnier @ 2016-09-23 15:49 UTC (permalink / raw)
  To: emacs-devel

> The use case, I think, is "to provide compatibility with older Emacsen,
> I need a convenient way to call a function softly without compiler
> warnings if it doesn't exist." I think, based on the two examples I gave
> (`gnus-funcall-no-warning' was the other instance), that it's not an
> uncommon need, and it's better to provide it in a core facility than ask
> package maintainers to implement it.

There's  (if (fboundp '<foo>) (<foo> <bar>))  already (which is much
better than tramp-compat-funcall since it says explicitly what to do if
the function doesn't exist).

So the question is what to do for the use cases of
tramp-compat-funcall not covered by this if/fboundp idiom.


        Stefan




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

* Re: tramp-compat-funcall -> compat-funcall?
  2016-09-23 15:49     ` Stefan Monnier
@ 2016-09-24  6:54       ` Michael Albinus
  2016-09-24 13:57         ` Stefan Monnier
  0 siblings, 1 reply; 17+ messages in thread
From: Michael Albinus @ 2016-09-24  6:54 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

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

>> The use case, I think, is "to provide compatibility with older Emacsen,
>> I need a convenient way to call a function softly without compiler
>> warnings if it doesn't exist." I think, based on the two examples I gave
>> (`gnus-funcall-no-warning' was the other instance), that it's not an
>> uncommon need, and it's better to provide it in a core facility than ask
>> package maintainers to implement it.
>
> There's  (if (fboundp '<foo>) (<foo> <bar>))  already (which is much
> better than tramp-compat-funcall since it says explicitly what to do if
> the function doesn't exist).
>
> So the question is what to do for the use cases of
> tramp-compat-funcall not covered by this if/fboundp idiom.

Your code snippet misses the `with-no-warnings' umbrella.

The <bar> part is not part of the `tramp-compat-funcall' spec by
intention. It will be always compatibility code, which I don't want to
see in the mainstream code. All such compatibility code is collected in
tramp-compat.el, in the Tramp case. Furthermore, there's not only the
case that <foo> does not exist, but there might be abother argument list
now. Also handled in tramp-compat.el.

`tramp-compat-funcall' has its history, and it was more complex when it
had to support also XEmacs. It's simpler now, but I like to identify all
backward compatibility code in Tramp by searching "C-s tramp-compat".
That covers all objects declared in tramp-compat.el. This makes
maintenance much easier, for example back in January when I removed
XEmacs and Emacs 22 support.

It doesn't hurt, so I prefer to keep it in Tramp.

>         Stefan

Best regards, Michael.



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

* Re: tramp-compat-funcall -> compat-funcall?
  2016-09-24  6:54       ` Michael Albinus
@ 2016-09-24 13:57         ` Stefan Monnier
  2016-09-24 15:39           ` Michael Albinus
  2016-09-24 22:42           ` Ted Zlatanov
  0 siblings, 2 replies; 17+ messages in thread
From: Stefan Monnier @ 2016-09-24 13:57 UTC (permalink / raw)
  To: Michael Albinus; +Cc: emacs-devel

>> There's  (if (fboundp '<foo>) (<foo> <bar>))  already (which is much
> Your code snippet misses the `with-no-warnings' umbrella.

No, it doesn't: the byte-compiler understands the the if+fboundp means
that any call to this function in the branch is "safe" and it won't
signal a warning.  That's my point.


        Stefan



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

* Re: tramp-compat-funcall -> compat-funcall?
  2016-09-24 13:57         ` Stefan Monnier
@ 2016-09-24 15:39           ` Michael Albinus
  2016-09-24 18:40             ` Stefan Monnier
  2016-09-24 22:42           ` Ted Zlatanov
  1 sibling, 1 reply; 17+ messages in thread
From: Michael Albinus @ 2016-09-24 15:39 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

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

>>> There's  (if (fboundp '<foo>) (<foo> <bar>))  already (which is much
>> Your code snippet misses the `with-no-warnings' umbrella.
>
> No, it doesn't: the byte-compiler understands the the if+fboundp means
> that any call to this function in the branch is "safe" and it won't
> signal a warning.  That's my point.

With Emacs 25, yes. But there are still warnings when compiling with
Emacs 23, I  believe.

>         Stefan

Best regards, Michael.



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

* Re: tramp-compat-funcall -> compat-funcall?
  2016-09-24 15:39           ` Michael Albinus
@ 2016-09-24 18:40             ` Stefan Monnier
  2016-09-25 11:44               ` Michael Albinus
  0 siblings, 1 reply; 17+ messages in thread
From: Stefan Monnier @ 2016-09-24 18:40 UTC (permalink / raw)
  To: emacs-devel

> With Emacs 25, yes. But there are still warnings when compiling with
> Emacs 23, I  believe.

As I said, if you care about the warnings you get under old Emacsen,
I can't help you (I can understand supporting some older Emacsen, but
worrying about the warnings they give baffles me completely).


        Stefan




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

* Re: tramp-compat-funcall -> compat-funcall?
  2016-09-24 13:57         ` Stefan Monnier
  2016-09-24 15:39           ` Michael Albinus
@ 2016-09-24 22:42           ` Ted Zlatanov
  2016-09-25 14:17             ` Stefan Monnier
  1 sibling, 1 reply; 17+ messages in thread
From: Ted Zlatanov @ 2016-09-24 22:42 UTC (permalink / raw)
  To: emacs-devel

On Sat, 24 Sep 2016 09:57:32 -0400 Stefan Monnier <monnier@iro.umontreal.ca> wrote: 

>>> There's  (if (fboundp '<foo>) (<foo> <bar>))  already (which is much
>> Your code snippet misses the `with-no-warnings' umbrella.

SM> No, it doesn't: the byte-compiler understands the the if+fboundp means
SM> that any call to this function in the branch is "safe" and it won't
SM> signal a warning.  That's my point.

I didn't know that. Thanks for explaining. I think the Gnus function
`gnus-funcall-no-warning' can be safely removed then? It's only in three
places, so it's an easy fix, but I want to check in case I missed something.

Ted




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

* Re: tramp-compat-funcall -> compat-funcall?
  2016-09-24 18:40             ` Stefan Monnier
@ 2016-09-25 11:44               ` Michael Albinus
  2016-09-25 14:00                 ` Stefan Monnier
  0 siblings, 1 reply; 17+ messages in thread
From: Michael Albinus @ 2016-09-25 11:44 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

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

>> With Emacs 25, yes. But there are still warnings when compiling with
>> Emacs 23, I  believe.
>
> As I said, if you care about the warnings you get under old Emacsen,
> I can't help you (I can understand supporting some older Emacsen, but
> worrying about the warnings they give baffles me completely).

I haven't asked for help :-)

I'm just explaining why `tramp-compat-funcall' is still used. And yes,
warning-free compilation even with older Emacsen is a benefit for me.

>         Stefan

Best regards, Michael.



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

* Re: tramp-compat-funcall -> compat-funcall?
  2016-09-25 11:44               ` Michael Albinus
@ 2016-09-25 14:00                 ` Stefan Monnier
  2016-09-25 17:23                   ` Ted Zlatanov
  0 siblings, 1 reply; 17+ messages in thread
From: Stefan Monnier @ 2016-09-25 14:00 UTC (permalink / raw)
  To: Michael Albinus; +Cc: emacs-devel

>>> With Emacs 25, yes. But there are still warnings when compiling with
>>> Emacs 23, I  believe.
>> As I said, if you care about the warnings you get under old Emacsen,
>> I can't help you (I can understand supporting some older Emacsen, but
>> worrying about the warnings they give baffles me completely).
> I haven't asked for help :-)

Can't remember who, but someone requested something like
`compat-funcall` in core Emacs.  That's what I was responding
to, fundamentally, and my answer is that we do have that but in
a different form: in the form of idioms like (if (fboundp 'foo) (foo
...)).


        Stefan



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

* Re: tramp-compat-funcall -> compat-funcall?
  2016-09-24 22:42           ` Ted Zlatanov
@ 2016-09-25 14:17             ` Stefan Monnier
  0 siblings, 0 replies; 17+ messages in thread
From: Stefan Monnier @ 2016-09-25 14:17 UTC (permalink / raw)
  To: emacs-devel

> I didn't know that. Thanks for explaining. I think the Gnus function
> `gnus-funcall-no-warning' can be safely removed then? It's only in three
> places, so it's an easy fix, but I want to check in case I missed something.

Most likely, yes.


        Stefan




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

* Re: tramp-compat-funcall -> compat-funcall?
  2016-09-25 14:00                 ` Stefan Monnier
@ 2016-09-25 17:23                   ` Ted Zlatanov
  0 siblings, 0 replies; 17+ messages in thread
From: Ted Zlatanov @ 2016-09-25 17:23 UTC (permalink / raw)
  To: emacs-devel

On Sun, 25 Sep 2016 10:00:59 -0400 Stefan Monnier <monnier@iro.umontreal.ca> wrote: 

>>>> With Emacs 25, yes. But there are still warnings when compiling with
>>>> Emacs 23, I  believe.
>>> As I said, if you care about the warnings you get under old Emacsen,
>>> I can't help you (I can understand supporting some older Emacsen, but
>>> worrying about the warnings they give baffles me completely).
>> I haven't asked for help :-)

SM> Can't remember who, but someone requested something like
SM> `compat-funcall` in core Emacs.  That's what I was responding
SM> to, fundamentally, and my answer is that we do have that but in
SM> a different form: in the form of idioms like (if (fboundp 'foo) (foo
SM> ...)).

It was me just a few days ago, and I think we've clarified things.

Thanks
Ted




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

end of thread, other threads:[~2016-09-25 17:23 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-22 11:04 tramp-compat-funcall -> compat-funcall? Ted Zlatanov
2016-09-22 12:31 ` Stefan Monnier
2016-09-22 13:22   ` Michael Albinus
2016-09-22 17:46     ` Stefan Monnier
2016-09-22 17:54       ` Michael Albinus
2016-09-22 18:23         ` Stefan Monnier
2016-09-22 20:18   ` Ted Zlatanov
2016-09-23 15:49     ` Stefan Monnier
2016-09-24  6:54       ` Michael Albinus
2016-09-24 13:57         ` Stefan Monnier
2016-09-24 15:39           ` Michael Albinus
2016-09-24 18:40             ` Stefan Monnier
2016-09-25 11:44               ` Michael Albinus
2016-09-25 14:00                 ` Stefan Monnier
2016-09-25 17:23                   ` Ted Zlatanov
2016-09-24 22:42           ` Ted Zlatanov
2016-09-25 14:17             ` Stefan Monnier

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.