unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Introspecting yas tab binding
@ 2024-02-02 12:34 Psionic K
  2024-02-02 12:39 ` Eli Zaretskii
  0 siblings, 1 reply; 12+ messages in thread
From: Psionic K @ 2024-02-02 12:34 UTC (permalink / raw)
  To: help-gnu-emacs

As far as I can tell, Yas minor mode uses a menu item to define the tab binding.

In this case I knew where to look, and the keymap was simple.  I could
guess yas's minor mode keymap was responsible by turning the minor
mode off.  Still, it was not a  regular binding, and so I almost
missed it.

I do think I should be able to figure this out without the prior
knowledge.  I debugged the call but saw no evidence on the stack.
`where-is' for the command did not find the binding.  Command log and
lossage are both dead ends.

As far as I can tell, yas is using this menu hack to implement a form
of conditional binding, intercepting the key sequence conditionally
with a `:filter' function in the menu binding.

How should I have discovered this?



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

* Re: Introspecting yas tab binding
  2024-02-02 12:34 Psionic K
@ 2024-02-02 12:39 ` Eli Zaretskii
  0 siblings, 0 replies; 12+ messages in thread
From: Eli Zaretskii @ 2024-02-02 12:39 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Psionic K <psionik@positron.solutions>
> Date: Fri, 2 Feb 2024 21:34:54 +0900
> 
> As far as I can tell, Yas minor mode uses a menu item to define the tab binding.
> 
> In this case I knew where to look, and the keymap was simple.  I could
> guess yas's minor mode keymap was responsible by turning the minor
> mode off.  Still, it was not a  regular binding, and so I almost
> missed it.
> 
> I do think I should be able to figure this out without the prior
> knowledge.  I debugged the call but saw no evidence on the stack.
> `where-is' for the command did not find the binding.  Command log and
> lossage are both dead ends.
> 
> As far as I can tell, yas is using this menu hack to implement a form
> of conditional binding, intercepting the key sequence conditionally
> with a `:filter' function in the menu binding.
> 
> How should I have discovered this?

What is "Yas minor mode"?  I don't see it in Emacs 29 or in Emacs 30.



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

* Re: Introspecting yas tab binding
@ 2024-02-03  2:14 Psionic K
  2024-02-03  6:11 ` tomas
  2024-02-03  8:06 ` Eli Zaretskii
  0 siblings, 2 replies; 12+ messages in thread
From: Psionic K @ 2024-02-03  2:14 UTC (permalink / raw)
  To: Eli Zaretskii, help-gnu-emacs

> What is "Yas minor mode"?  I don't see it in Emacs 29 or in Emacs 30.

I will ignore what appears to me to be some kind of sarcastic
perversion of reality attempting to imply "go away, this is not
Emacs", which it most surely is not, and rephrase the question to
focus on Emacs specific elements.

I have identified a command by viewing lossage called
`mysterious-command`.  It is called in some situations when I press
TAB, but not always.

`where-is' reports that `mysterious-command' is not bound on any key.
Lossage reports:

 <tab>          ;; mysterious-command

I have found `mysterious-command' in a keymap menu item, and the key
definition matches the command I observe, but I cannot get debug to
trigger when using `debug-on-entry' on the function assigned as the
`:filter' in that menu item, so I'm unsure if the menu item is related
at all.

I can get a debugger for `mysterious-command' itself, which displays a
stack beginning with `command-execute', called only with
`mysterious-command'.   I need to discover how `mysterious-command' is
arrived at to work backwards toward the mechanism used to make it only
receive the TAB key in certain situations.

Evaluating (key-binding (kbd "TAB")) shows that the binding is
situational, returning different commands depending on the location of
the point, but still not how.   After following the code into
`lookup_key_1', I am expecting attaching a debugger will reveal that
the external state, the keymap with the menu item, is changed between
calls, but again not where this behavior originates.

What Emacs facilities might uncover the states and execution flow
responsible for this situational behavior for the TAB key sequence?
How can I identify or rule out the menu item's responsibility?



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

* Re: Introspecting yas tab binding
  2024-02-03  2:14 Psionic K
@ 2024-02-03  6:11 ` tomas
  2024-02-03  6:43   ` Joost Kremers
  2024-02-03  6:54   ` Emanuel Berg
  2024-02-03  8:06 ` Eli Zaretskii
  1 sibling, 2 replies; 12+ messages in thread
From: tomas @ 2024-02-03  6:11 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 865 bytes --]

On Sat, Feb 03, 2024 at 11:14:13AM +0900, Psionic K wrote:
> > What is "Yas minor mode"?  I don't see it in Emacs 29 or in Emacs 30.
> 
> I will ignore what appears to me to be some kind of sarcastic
> perversion of reality attempting to imply "go away, this is not
> Emacs", which it most surely is not, and rephrase the question to
> focus on Emacs specific elements.

It is not. Still, it might be helpful to tell us what Yas is, instead
of being so... misterious.

> I have identified a command by viewing lossage called
> `mysterious-command`.  It is called in some situations when I press
> TAB, but not always.
> 
> `where-is' reports that `mysterious-command' is not bound on any key.
> Lossage reports:
> 
>  <tab>          ;; mysterious-command

[...]

Sounds a bit like a lambda -- those functions have no names.

Cheers
-- 
t

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

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

* Re: Introspecting yas tab binding
  2024-02-03  6:11 ` tomas
@ 2024-02-03  6:43   ` Joost Kremers
  2024-02-03  7:09     ` Emanuel Berg
  2024-02-03  7:42     ` Eli Zaretskii
  2024-02-03  6:54   ` Emanuel Berg
  1 sibling, 2 replies; 12+ messages in thread
From: Joost Kremers @ 2024-02-03  6:43 UTC (permalink / raw)
  To: tomas; +Cc: help-gnu-emacs


On Sat, Feb 03 2024, tomas@tuxteam.de wrote:
> [[PGP Signed Part:Undecided]]
> On Sat, Feb 03, 2024 at 11:14:13AM +0900, Psionic K wrote:
>> > What is "Yas minor mode"?  I don't see it in Emacs 29 or in Emacs 30.
>> 
>> I will ignore what appears to me to be some kind of sarcastic
>> perversion of reality attempting to imply "go away, this is not
>> Emacs", which it most surely is not, and rephrase the question to
>> focus on Emacs specific elements.
>
> It is not. Still, it might be helpful to tell us what Yas is, instead
> of being so... misterious.

'yas' is a prefix used by Yasnippet <https://github.com/joaotavora/yasnippet>.

@Psionic K, Yasnippet is not part of Emacs, so you cannot assume all Emacs
maintainers know what it is.
 

-- 
Joost Kremers
Life has its moments



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

* Re: Introspecting yas tab binding
  2024-02-03  6:11 ` tomas
  2024-02-03  6:43   ` Joost Kremers
@ 2024-02-03  6:54   ` Emanuel Berg
  1 sibling, 0 replies; 12+ messages in thread
From: Emanuel Berg @ 2024-02-03  6:54 UTC (permalink / raw)
  To: help-gnu-emacs

tomas wrote:

>>> What is "Yas minor mode"? I don't see it in Emacs 29 or in
>>> Emacs 30.
>> 
>> I will ignore what appears to me to be some kind of
>> sarcastic perversion of reality attempting to imply "go
>> away, this is not Emacs", which it most surely is not, and
>> rephrase the question to focus on Emacs specific elements.
>
> It is not. Still, it might be helpful to tell us what Yas
> is, instead of being so... misterious.

As iou know, what is refered to is

  https://www.emacswiki.org/emacs/Yasnippet

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: Introspecting yas tab binding
  2024-02-03  6:43   ` Joost Kremers
@ 2024-02-03  7:09     ` Emanuel Berg
  2024-02-03  7:42     ` Eli Zaretskii
  1 sibling, 0 replies; 12+ messages in thread
From: Emanuel Berg @ 2024-02-03  7:09 UTC (permalink / raw)
  To: help-gnu-emacs

Joost Kremers wrote:

> 'yas' is a prefix used by Yasnippet [...]
>
> Psionic K, Yasnippet is not part of Emacs, so you cannot
> assume all Emacs maintainers know what it is.

It is in GNU ELPA so it is part of Emacs.

Is it rather that some Emacs maintainers aren't paying it
enough attention?

Package yasnippet is available.

     Status: Available from gnu -- [Install]
    Archive: gnu
    Version: 0.14.1
     Commit: 297546f0853a6a51f5b05e954d0c6aea8caa5ec2
    Summary: Yet another snippet extension for Emacs
   Requires: cl-lib-0.5, emacs-24.4
    Website: https://github.com/joaotavora/yasnippet
   Keywords: [convenience] [emulation] 
 Maintainer: Noam Postavsky <npostavs@gmail.com>
Other versions: 20240124.258 (melpa).

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: Introspecting yas tab binding
  2024-02-03  6:43   ` Joost Kremers
  2024-02-03  7:09     ` Emanuel Berg
@ 2024-02-03  7:42     ` Eli Zaretskii
  2024-02-03  7:57       ` Emanuel Berg
  1 sibling, 1 reply; 12+ messages in thread
From: Eli Zaretskii @ 2024-02-03  7:42 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Joost Kremers <joostkremers@fastmail.fm>
> Cc: help-gnu-emacs@gnu.org
> Date: Sat, 03 Feb 2024 07:43:58 +0100
> 
> >> I will ignore what appears to me to be some kind of sarcastic
> >> perversion of reality attempting to imply "go away, this is not
> >> Emacs", which it most surely is not, and rephrase the question to
> >> focus on Emacs specific elements.
> >
> > It is not. Still, it might be helpful to tell us what Yas is, instead
> > of being so... misterious.
> 
> 'yas' is a prefix used by Yasnippet <https://github.com/joaotavora/yasnippet>.
> 
> @Psionic K, Yasnippet is not part of Emacs, so you cannot assume all Emacs
> maintainers know what it is.

FTR: it was a good-faith question.  I wanted to look at the relevant
code to try to help answer the question.

This is a help forum, so sarcasm in response to a question is not
appropriate, and so sarcasm should not be the first interpretation of
responses to questions, if there could be other, more civilized,
interpretations.



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

* Re: Introspecting yas tab binding
  2024-02-03  7:42     ` Eli Zaretskii
@ 2024-02-03  7:57       ` Emanuel Berg
  0 siblings, 0 replies; 12+ messages in thread
From: Emanuel Berg @ 2024-02-03  7:57 UTC (permalink / raw)
  To: help-gnu-emacs

Eli Zaretskii wrote:

> FTR: it was a good-faith question. I wanted to look at the
> relevant code to try to help answer the question.
>
> This is a help forum, so sarcasm in response to a question
> is not appropriate, and so sarcasm should not be the first
> interpretation of responses to questions, if there could be
> other, more civilized, interpretations.

Maybe you can also explain, why meta-discussion should
be avoided?

And, to prevent this from turning into a discussion what
exactly qualifies as meta-discussion - i.e., what would be
a meta-meta-discussion - I propose a simple definition:
meta-discussion are mails that don't mention Emacs
a single time.

E.g., as applied to this very message:

  PASS (1)

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: Introspecting yas tab binding
  2024-02-03  2:14 Psionic K
  2024-02-03  6:11 ` tomas
@ 2024-02-03  8:06 ` Eli Zaretskii
  2024-02-03  8:29   ` Emanuel Berg
  1 sibling, 1 reply; 12+ messages in thread
From: Eli Zaretskii @ 2024-02-03  8:06 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Psionic K <psionik@positron.solutions>
> Date: Sat, 3 Feb 2024 11:14:13 +0900
> 
> I have found `mysterious-command' in a keymap menu item, and the key
> definition matches the command I observe, but I cannot get debug to
> trigger when using `debug-on-entry' on the function assigned as the
> `:filter' in that menu item, so I'm unsure if the menu item is related
> at all.

The simplest way is to add some call to 'message' in the function
assigned to :filter, and then look for that message in *Messages*.
The message could include the details you are looking for, like the
current keymap in effect, for example.

The fact that :filter function cannot be debugged using debug-on-entry
perhaps warrants a bug report.

> I can get a debugger for `mysterious-command' itself, which displays a
> stack beginning with `command-execute', called only with
> `mysterious-command'.   I need to discover how `mysterious-command' is
> arrived at to work backwards toward the mechanism used to make it only
> receive the TAB key in certain situations.

This is a much more general question, and I don't think we have
facilities other than stepping through the code to answer such general
questions.

> What Emacs facilities might uncover the states and execution flow
> responsible for this situational behavior for the TAB key sequence?
> How can I identify or rule out the menu item's responsibility?

The first question is much more general than the second.

For the first question, we have trace.el, stepping through Lisp code
in Edebug, and stepping through code in keyboard.c in GDB.  For the
second, I would modify the offending menu entry in some way that would
signal that it is responsible, like produce some message or maybe call
an entirely different function, and then watch for the effects.



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

* Re: Introspecting yas tab binding
  2024-02-03  8:06 ` Eli Zaretskii
@ 2024-02-03  8:29   ` Emanuel Berg
  0 siblings, 0 replies; 12+ messages in thread
From: Emanuel Berg @ 2024-02-03  8:29 UTC (permalink / raw)
  To: help-gnu-emacs

Eli Zaretskii wrote:

> The simplest way is to add some call to 'message' in the
> function assigned to :filter, and then look for that message
> in *Messages*. The message could include the details you are
> looking for, like the current keymap in effect, for example.

That doesn't sound so simple?

Maybe we should instead have a visual, interactive mode,
a control room with sensor readings, dedicated to the
(virtual) keyboard, with all the associated data - as well as
its current state?

-- 
underground experts united
https://dataswamp.org/~incal




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

* Re: Introspecting yas tab binding
@ 2024-02-03 13:47 Psionic K
  0 siblings, 0 replies; 12+ messages in thread
From: Psionic K @ 2024-02-03 13:47 UTC (permalink / raw)
  To: Eli Zaretskii, help-gnu-emacs

It's solved.  The general method is described at the end.

> For the first question, we have trace.el, stepping through Lisp code
> in Edebug, and stepping through code in keyboard.c in GDB.  For the
> second, I would modify the offending menu entry in some way that would
> signal that it is responsible

I re-bound the command to "X" like so:

    (setcar  (car(last yas-minor-mode-map)) (string-to-char "X"))

This confirmed the responsibility of the menu binding, the contents of
which are:

    (9 menu-item "" yas-expand :filter yas-maybe-expand-abbrev-key-filter)

> The fact that :filter function cannot be debugged using debug-on-entry
> perhaps warrants a bug report.

I confirmed that `trace-function' was able to see the filter be
called.  However, debug-on-entry did not trigger a debugger session.

`key-binding' succeeds in uncovering that a binding exists, but not where it is.

Identifying keymaps from `current-active-maps' and corroborating the
symbol names with the obarray values, then calling `keymap-lookup'
appears to be viable.

The `keymap-lookup' returns nil or `yas-expand' depending on the
:filter result.  The user must configure the filter to be true to
observer the binding.  This is the only such conditional binding I
have observed in Emacs that didn't rely on variables in
`emulation-mode-alists` or modifying keymaps themselves.



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

end of thread, other threads:[~2024-02-03 13:47 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-03 13:47 Introspecting yas tab binding Psionic K
  -- strict thread matches above, loose matches on Subject: below --
2024-02-03  2:14 Psionic K
2024-02-03  6:11 ` tomas
2024-02-03  6:43   ` Joost Kremers
2024-02-03  7:09     ` Emanuel Berg
2024-02-03  7:42     ` Eli Zaretskii
2024-02-03  7:57       ` Emanuel Berg
2024-02-03  6:54   ` Emanuel Berg
2024-02-03  8:06 ` Eli Zaretskii
2024-02-03  8:29   ` Emanuel Berg
2024-02-02 12:34 Psionic K
2024-02-02 12:39 ` Eli Zaretskii

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