all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* called-interactively-p, cedet, and Emacs 23.1 and earlier
@ 2010-03-24 16:45 Eric M. Ludlam
  2010-03-24 17:51 ` Stefan Monnier
  2010-03-24 17:53 ` Stephen J. Turnbull
  0 siblings, 2 replies; 15+ messages in thread
From: Eric M. Ludlam @ 2010-03-24 16:45 UTC (permalink / raw)
  To: emacs-devel

Hi,

Lluis has been merging changes from Emacs to CEDET.  The idea is to move 
my CEDET repository to be more easily maintained with Emacs, and getting 
them close to each other is the first step.

We have recently stumbled over called-interactively-p, which is now used 
with an argument throughout the Emacs versions of the CEDET code.  My 
externally maintained code I would like to have work in Emacs 22 and 
23.1 which does not support the argument, and XEmacs which is missing 
the feature completely, and is thus easy to make work in this case. 
Could some kind soul help me define some advice, or other trick I can 
install in older Emacs to allow this form to work?

Thanks
Eric




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

* Re: called-interactively-p, cedet, and Emacs 23.1 and earlier
  2010-03-24 16:45 called-interactively-p, cedet, and Emacs 23.1 and earlier Eric M. Ludlam
@ 2010-03-24 17:51 ` Stefan Monnier
  2010-03-25 14:33   ` Lluís
  2010-03-25 23:16   ` Eric M. Ludlam
  2010-03-24 17:53 ` Stephen J. Turnbull
  1 sibling, 2 replies; 15+ messages in thread
From: Stefan Monnier @ 2010-03-24 17:51 UTC (permalink / raw)
  To: Eric M. Ludlam; +Cc: emacs-devel

> We have recently stumbled over called-interactively-p, which is now used
> with an argument throughout the Emacs versions of the CEDET code.
> My externally maintained code I would like to have work in Emacs 22 and 23.1
> which does not support the argument, and XEmacs which is missing the feature
> completely, and is thus easy to make work in this case. Could some kind soul
> help me define some advice, or other trick I can install in older Emacs to
> allow this form to work?

How 'bout

(condition-case nil
    (called-interactively-p nil)
  (defmacro called-interactively-p (arg)
    (case arg
      (interactive `(interactive-p))
      ((any nil) `(called-interactively-p)))))


-- Stefan




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

* called-interactively-p, cedet, and Emacs 23.1 and earlier
  2010-03-24 16:45 called-interactively-p, cedet, and Emacs 23.1 and earlier Eric M. Ludlam
  2010-03-24 17:51 ` Stefan Monnier
@ 2010-03-24 17:53 ` Stephen J. Turnbull
  1 sibling, 0 replies; 15+ messages in thread
From: Stephen J. Turnbull @ 2010-03-24 17:53 UTC (permalink / raw)
  To: Eric M. Ludlam; +Cc: emacs-devel

Eric M. Ludlam writes:

 > 23.1 which does not support the argument, and XEmacs which is missing 
 > the feature completely, and is thus easy to make work in this
 > case. 

XEmacs will get the feature.  I hope to provide some sort of backwards
compatibility package, which would potentially mean that all XEmacsen
from 21.1 on could use it.





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

* Re: called-interactively-p, cedet, and Emacs 23.1 and earlier
  2010-03-24 17:51 ` Stefan Monnier
@ 2010-03-25 14:33   ` Lluís
  2010-03-25 23:16   ` Eric M. Ludlam
  1 sibling, 0 replies; 15+ messages in thread
From: Lluís @ 2010-03-25 14:33 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel, Eric M. Ludlam

>> We have recently stumbled over called-interactively-p, which is now used
>> with an argument throughout the Emacs versions of the CEDET code.
>> My externally maintained code I would like to have work in Emacs 22 and 23.1
>> which does not support the argument, and XEmacs which is missing the feature
>> completely, and is thus easy to make work in this case. Could some kind soul
>> help me define some advice, or other trick I can install in older Emacs to
>> allow this form to work?

> How 'bout

Ok, so (unless my elisp is crappier than I thought) compatibility code for both
emacs and xemacs would go like this:

(case (fboundp 'called-interactively-p)
      ((t)

> (condition-case nil
>     (called-interactively-p nil)
>   (defmacro called-interactively-p (arg)
>     (case arg
>       (interactive `(interactive-p))
>       ((any nil) `(called-interactively-p)))))

        )
      ((nil) (defun called-interactively-p (arg)
                    ...whathever xemacs needs to do...)))

Thanks,
        Lluis

--
 "And it's much the same thing with knowledge, for whenever you learn
 something new, the whole world becomes that much richer."
 -- The Princess of Pure Reason, as told by Norton Juster in The Phantom
 Tollbooth




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

* Re: called-interactively-p, cedet, and Emacs 23.1 and earlier
  2010-03-24 17:51 ` Stefan Monnier
  2010-03-25 14:33   ` Lluís
@ 2010-03-25 23:16   ` Eric M. Ludlam
  2010-03-26 15:33     ` Davis Herring
  1 sibling, 1 reply; 15+ messages in thread
From: Eric M. Ludlam @ 2010-03-25 23:16 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

On 03/24/2010 01:51 PM, Stefan Monnier wrote:
>> We have recently stumbled over called-interactively-p, which is now used
>> with an argument throughout the Emacs versions of the CEDET code.
>> My externally maintained code I would like to have work in Emacs 22 and 23.1
>> which does not support the argument, and XEmacs which is missing the feature
>> completely, and is thus easy to make work in this case. Could some kind soul
>> help me define some advice, or other trick I can install in older Emacs to
>> allow this form to work?
>
> How 'bout
>
> (condition-case nil
>      (called-interactively-p nil)
>    (defmacro called-interactively-p (arg)
>      (case arg
>        (interactive `(interactive-p))
>        ((any nil) `(called-interactively-p)))))

Hi Stefan

I've adapted the above into this:

(if (not (fboundp 'called-interactively-p))
     (defsubst called-interactively-p (&optional arg)
       "Compat function.  Calls `interactive-p'"
       (interactive-p))
   ;; Else, it is defined, but perhaps too old?
   (condition-case nil
       (called-interactively-p nil)
     (error
      (defmacro called-interactively-p (&optional arg)
        "Macro to support optional input arg for built-in."
        (case arg
	 (interactive `(interactive-p))
	 ((any nil) `(called-interactively-p))))
      )))

an in Emacs 23.1, it now emits this:

Invalid function: called-interactively-p

and I have to kill from the command prompt, because it is used so much.

I had similar issues trying to figure out how advice in this case would 
work before I emailed the first time.

Any other thoughts?
Thanks
Eric




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

* Re: called-interactively-p, cedet, and Emacs 23.1 and earlier
  2010-03-25 23:16   ` Eric M. Ludlam
@ 2010-03-26 15:33     ` Davis Herring
  2010-03-26 16:06       ` Eric M. Ludlam
  0 siblings, 1 reply; 15+ messages in thread
From: Davis Herring @ 2010-03-26 15:33 UTC (permalink / raw)
  To: Eric M. Ludlam; +Cc: Stefan Monnier, emacs-devel

> an in Emacs 23.1, it now emits this:
>
> Invalid function: called-interactively-p

Perhaps you have compiled code calling called-interactively-p, and then
are redefining it as a macro?  That won't work.  If you're going to have
to make it a macro, you'll have to also then recompile any code that calls
it.

Davis

-- 
This product is sold by volume, not by mass.  If it appears too dense or
too sparse, it is because mass-energy conversion has occurred during
shipping.




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

* Re: called-interactively-p, cedet, and Emacs 23.1 and earlier
  2010-03-26 15:33     ` Davis Herring
@ 2010-03-26 16:06       ` Eric M. Ludlam
  2010-03-27 14:11         ` Eric M. Ludlam
  0 siblings, 1 reply; 15+ messages in thread
From: Eric M. Ludlam @ 2010-03-26 16:06 UTC (permalink / raw)
  To: herring; +Cc: Lluís, Stefan Monnier, emacs-devel

On 03/26/2010 11:33 AM, Davis Herring wrote:
>> an in Emacs 23.1, it now emits this:
>>
>> Invalid function: called-interactively-p
>
> Perhaps you have compiled code calling called-interactively-p, and then
> are redefining it as a macro?  That won't work.  If you're going to have
> to make it a macro, you'll have to also then recompile any code that calls
> it.

Ah, That won't be possible since Emacs 23 has lots of code that is 
compiled using this already.

I saved off the old symbol function for called-interactively-p and used 
it in a new version of the function.  This appears to now work.

I've checked this into my CEDET CVS repository, so now Lluis should be 
able to safely finish merging Emacs changes into CEDET, and things will 
keep working in Emacs 23.1 and eaerlier, and in XEmacs.

Thanks
Eric

------------
(if (not (fboundp 'called-interactively-p))
     (defsubst called-interactively-p (&optional arg)
       "Compat function.  Calls `interactive-p'"
       (interactive-p))
   ;; Else, it is defined, but perhaps too old?
   (condition-case nil
       ;; This condition case also prevents this from running twice.
       (called-interactively-p nil)
     (error
      (defvar cedet-compat-called-interactively-p
        (let ((tmp (symbol-function 'called-interactively-p)))
	 (if (subrp tmp)
	     tmp
	   ;; Did someone else allready override it?
	   (or cedet-compat-clled-interactively-p tmp)))
        "Built-in called interactively function.")
      ;; Create a new one
      (defun cedet-called-interactively-p (&optional arg)
        "Revised from the built-in version to accept an optional arg."
        (case arg
	 (interactive (interactive-p))
	 ((any nil) (funcall cedet-compat-called-interactively-p))))
      ;; Override
      (fset 'called-interactively-p 'cedet-called-interactively-p)
      )))




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

* Re: called-interactively-p, cedet, and Emacs 23.1 and earlier
  2010-03-26 16:06       ` Eric M. Ludlam
@ 2010-03-27 14:11         ` Eric M. Ludlam
  2010-03-27 18:18           ` Stefan Monnier
  0 siblings, 1 reply; 15+ messages in thread
From: Eric M. Ludlam @ 2010-03-27 14:11 UTC (permalink / raw)
  To: herring; +Cc: emacs-devel, Lluís, Stefan Monnier

Ok, now I'm stumped again.

While the code snippet I quoted below "works", as in it allows the new 
code to run in old Emacsen, it does not work in that it always returns 
false, since there is one level of function redirection, thus that 
function (cedet-called-interactively-p) is never called interactively.

Anyway, that makes it obvious why Stefan used a macro before.

Does anyone know of a way to solve this, or do I need to maintain this 
difference in my code?

Thanks
Eric


On 03/26/2010 12:06 PM, Eric M. Ludlam wrote:
> On 03/26/2010 11:33 AM, Davis Herring wrote:
>>> an in Emacs 23.1, it now emits this:
>>>
>>> Invalid function: called-interactively-p
>>
>> Perhaps you have compiled code calling called-interactively-p, and then
>> are redefining it as a macro? That won't work. If you're going to have
>> to make it a macro, you'll have to also then recompile any code that
>> calls
>> it.
>
> Ah, That won't be possible since Emacs 23 has lots of code that is
> compiled using this already.
>
> I saved off the old symbol function for called-interactively-p and used
> it in a new version of the function. This appears to now work.
>
> I've checked this into my CEDET CVS repository, so now Lluis should be
> able to safely finish merging Emacs changes into CEDET, and things will
> keep working in Emacs 23.1 and eaerlier, and in XEmacs.
>
> Thanks
> Eric
>
> ------------
> (if (not (fboundp 'called-interactively-p))
> (defsubst called-interactively-p (&optional arg)
> "Compat function. Calls `interactive-p'"
> (interactive-p))
> ;; Else, it is defined, but perhaps too old?
> (condition-case nil
> ;; This condition case also prevents this from running twice.
> (called-interactively-p nil)
> (error
> (defvar cedet-compat-called-interactively-p
> (let ((tmp (symbol-function 'called-interactively-p)))
> (if (subrp tmp)
> tmp
> ;; Did someone else already override it?
> (or cedet-compat-clled-interactively-p tmp)))
> "Built-in called interactively function.")
> ;; Create a new one
> (defun cedet-called-interactively-p (&optional arg)
> "Revised from the built-in version to accept an optional arg."
> (case arg
> (interactive (interactive-p))
> ((any nil) (funcall cedet-compat-called-interactively-p))))
> ;; Override
> (fset 'called-interactively-p 'cedet-called-interactively-p)
> )))
>
>
>




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

* Re: called-interactively-p, cedet, and Emacs 23.1 and earlier
  2010-03-27 14:11         ` Eric M. Ludlam
@ 2010-03-27 18:18           ` Stefan Monnier
  2010-04-26 15:28             ` Bruce Stephens
  0 siblings, 1 reply; 15+ messages in thread
From: Stefan Monnier @ 2010-03-27 18:18 UTC (permalink / raw)
  To: Eric M. Ludlam; +Cc: Lluís, emacs-devel

> Anyway, that makes it obvious why Stefan used a macro before.

;-)

> Does anyone know of a way to solve this, or do I need to maintain this
> difference in my code?

Sorry for not posting more concrete code earlier (it has several other
bugs, such as not evaluating the arg), but I think the solution is
pretty much what I suggested, except you need to use
cedet-called-interactively-p everywhere and have it macro-expand to
either interactive-p or called-interactively-p with or without args
depending on what's available.


        Stefan




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

* Re: called-interactively-p, cedet, and Emacs 23.1 and earlier
  2010-03-27 18:18           ` Stefan Monnier
@ 2010-04-26 15:28             ` Bruce Stephens
  2010-04-26 17:58               ` Stefan Monnier
  0 siblings, 1 reply; 15+ messages in thread
From: Bruce Stephens @ 2010-04-26 15:28 UTC (permalink / raw)
  To: emacs-devel

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

>> Anyway, that makes it obvious why Stefan used a macro before.
>
> ;-)
>
>> Does anyone know of a way to solve this, or do I need to maintain this
>> difference in my code?
>
> Sorry for not posting more concrete code earlier (it has several other
> bugs, such as not evaluating the arg), but I think the solution is
> pretty much what I suggested, except you need to use
> cedet-called-interactively-p everywhere and have it macro-expand to
> either interactive-p or called-interactively-p with or without args
> depending on what's available.

I find it doesn't work everywhere (in Emacs 23.1, running with the
external CVS version of cedet).  I get errors about
cedet-called-interactively-p being an invalid function.  I'm fairly sure
it's this defadvice code:

(defadvice beginning-of-defun (around senator activate)
  "Move backward to the beginning of a defun.
If semantic tags are available, use them to navigate."
  (if (and senator-minor-mode (cedet-called-interactively-p))
      (senator-beginning-of-defun (ad-get-arg 0))
    ad-do-it))

As far as I can tell this is being byte-compiled with the macro visible.
So is there some magic with defadvice and macros?




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

* Re: called-interactively-p, cedet, and Emacs 23.1 and earlier
  2010-04-26 15:28             ` Bruce Stephens
@ 2010-04-26 17:58               ` Stefan Monnier
  2010-04-26 18:27                 ` Bruce Stephens
  0 siblings, 1 reply; 15+ messages in thread
From: Stefan Monnier @ 2010-04-26 17:58 UTC (permalink / raw)
  To: Bruce Stephens; +Cc: emacs-devel

> (defadvice beginning-of-defun (around senator activate)
>   "Move backward to the beginning of a defun.
> If semantic tags are available, use them to navigate."
>   (if (and senator-minor-mode (cedet-called-interactively-p))
>       (senator-beginning-of-defun (ad-get-arg 0))
>     ad-do-it))

Why not use beginning-of-defun-function rather than an advice?


        Stefan




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

* Re: called-interactively-p, cedet, and Emacs 23.1 and earlier
  2010-04-26 17:58               ` Stefan Monnier
@ 2010-04-26 18:27                 ` Bruce Stephens
  2010-04-27  3:08                   ` Stefan Monnier
  0 siblings, 1 reply; 15+ messages in thread
From: Bruce Stephens @ 2010-04-26 18:27 UTC (permalink / raw)
  To: emacs-devel

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

>> (defadvice beginning-of-defun (around senator activate)
>>   "Move backward to the beginning of a defun.
>> If semantic tags are available, use them to navigate."
>>   (if (and senator-minor-mode (cedet-called-interactively-p))
>>       (senator-beginning-of-defun (ad-get-arg 0))
>>     ad-do-it))
>
> Why not use beginning-of-defun-function rather than an advice?

I don't know.  Compatibility, maybe?  Or maybe just uniformity, since
the same file also has defadvice for narrow-to-defun, mark-defun,
c-mark-function, add-log-current-defun, insert-register,
jump-to-register, not all of which have hooks, I guess.




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

* Re: called-interactively-p, cedet, and Emacs 23.1 and earlier
  2010-04-26 18:27                 ` Bruce Stephens
@ 2010-04-27  3:08                   ` Stefan Monnier
  2010-04-27 11:22                     ` Bruce Stephens
  0 siblings, 1 reply; 15+ messages in thread
From: Stefan Monnier @ 2010-04-27  3:08 UTC (permalink / raw)
  To: Bruce Stephens; +Cc: emacs-devel

> I don't know.  Compatibility, maybe?  Or maybe just uniformity, since
> the same file also has defadvice for narrow-to-defun, mark-defun,
> c-mark-function, add-log-current-defun, insert-register,
> jump-to-register, not all of which have hooks, I guess.

beginning/end-of-defun-function should cover narrow-to-defun and
mark-defun.  add-log-current-defun has a similar hook variable.
For the rest I don't know what would be needed.  But in any case, any
defadvice should be justified by a "request for feature".


        Stefan




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

* Re: called-interactively-p, cedet, and Emacs 23.1 and earlier
  2010-04-27  3:08                   ` Stefan Monnier
@ 2010-04-27 11:22                     ` Bruce Stephens
  2010-04-27 13:56                       ` Stefan Monnier
  0 siblings, 1 reply; 15+ messages in thread
From: Bruce Stephens @ 2010-04-27 11:22 UTC (permalink / raw)
  To: emacs-devel

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

>> I don't know.  Compatibility, maybe?  Or maybe just uniformity, since
>> the same file also has defadvice for narrow-to-defun, mark-defun,
>> c-mark-function, add-log-current-defun, insert-register,
>> jump-to-register, not all of which have hooks, I guess.
>
> beginning/end-of-defun-function should cover narrow-to-defun and
> mark-defun.  add-log-current-defun has a similar hook variable.
> For the rest I don't know what would be needed.  But in any case, any
> defadvice should be justified by a "request for feature".

Sure, and in the version bundled with Emacs I imagine there's less of a
problem: it can just use called-interactively-p and (if required) add
and use the relevant hooks, presuming that's acceptable to other
developers.

However, that kind of option didn't (and doesn't) really apply to code
intended to run on a variety of versions.  Concretely, it doesn't work
for Emacs 23.1, and using defadvice seems reasonable.

But it doesn't seem to work properly: "cedet-called-interactively-p is a
Lisp macro.", but I get errors: "beginning-of-defun: Invalid function:
cedet-called-interactively-p".

So, is it the case that it's unsafe using macros in the body of advice,
or is this indicating that the macro wasn't defined when defadvice was
called, or activated?  If one or other of the latter, how could I tell?
For a normal function I could use disassemble (to make sure macros had
been expanded), but I'm not sure what object I'd look at with advice.




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

* Re: called-interactively-p, cedet, and Emacs 23.1 and earlier
  2010-04-27 11:22                     ` Bruce Stephens
@ 2010-04-27 13:56                       ` Stefan Monnier
  0 siblings, 0 replies; 15+ messages in thread
From: Stefan Monnier @ 2010-04-27 13:56 UTC (permalink / raw)
  To: Bruce Stephens; +Cc: emacs-devel

>>> I don't know.  Compatibility, maybe?  Or maybe just uniformity, since
>>> the same file also has defadvice for narrow-to-defun, mark-defun,
>>> c-mark-function, add-log-current-defun, insert-register,
>>> jump-to-register, not all of which have hooks, I guess.
>> beginning/end-of-defun-function should cover narrow-to-defun and
>> mark-defun.  add-log-current-defun has a similar hook variable.
>> For the rest I don't know what would be needed.  But in any case, any
>> defadvice should be justified by a "request for feature".
> However, that kind of option didn't (and doesn't) really apply to code
> intended to run on a variety of versions.  Concretely, it doesn't work
> for Emacs 23.1, and using defadvice seems reasonable.

Of course.  My point is that when people encounter a problem that
requires a workaround, they should also send a bug-report about it.

> But it doesn't seem to work properly: "cedet-called-interactively-p is a
> Lisp macro.", but I get errors: "beginning-of-defun: Invalid function:
> cedet-called-interactively-p".

> So, is it the case that it's unsafe using macros in the body of advice,
> or is this indicating that the macro wasn't defined when defadvice was
> called, or activated?

It's a sure sign that this part of the code was byte-compiled at a time
the macro was not defined.

> If one or other of the latter, how could I tell?

You could add a dummy macro-call to a macro of yours that does something
like call the debugger.  Make sure this macro is always defined and then
watch to see when the code gets byte-compiled.


        Stefan




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

end of thread, other threads:[~2010-04-27 13:56 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-24 16:45 called-interactively-p, cedet, and Emacs 23.1 and earlier Eric M. Ludlam
2010-03-24 17:51 ` Stefan Monnier
2010-03-25 14:33   ` Lluís
2010-03-25 23:16   ` Eric M. Ludlam
2010-03-26 15:33     ` Davis Herring
2010-03-26 16:06       ` Eric M. Ludlam
2010-03-27 14:11         ` Eric M. Ludlam
2010-03-27 18:18           ` Stefan Monnier
2010-04-26 15:28             ` Bruce Stephens
2010-04-26 17:58               ` Stefan Monnier
2010-04-26 18:27                 ` Bruce Stephens
2010-04-27  3:08                   ` Stefan Monnier
2010-04-27 11:22                     ` Bruce Stephens
2010-04-27 13:56                       ` Stefan Monnier
2010-03-24 17:53 ` Stephen J. Turnbull

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.