unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Getting magic numbers 134217734 etc in a repetable keymap
@ 2021-04-03  6:20 Ramesh Nedunchezian
  2021-04-03  7:32 ` Eli Zaretskii
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Ramesh Nedunchezian @ 2021-04-03  6:20 UTC (permalink / raw)
  To: emacs-devel


I would like to create a repeatable keymap which has magic number
134217734 etc in it using either `define-key' or any other API.

I have tried the following, and it desn't work

    (define-key sexp--repeat-map
      (vector
       (car
	(listify-key-sequence
	 (kbd "C-M-f"))))
      'forward-sexp)

Getting numbers like 134217734 etc in to the repeatable keymap are
important for successful setting up of repetition. That is, for
repetition to succeed, the condition below in `repeat-post-hook' need
to succeed.

    (or (memq last-command-event keys)
	(memq this-original-command '(universal-argument
				      universal-argument-more
				      digit-argument
				      negative-argument)))

... and when I invoke C-M-f `last-command-event' comes out as 134217734.

----------------

For now I have hard-coded `sexp--repeat-map' as below, and this works
as expected.  But I want a cleaner and less-hackish recipe for achieving the same.



(setq sexp--repeat-map
      '(keymap
	;; How can I get 134217734 here?
	
	;; (define-key sexp--repeat-map (kbd "C-M-f") 'forward-sexp)
	;; puts a nested list in keymap

	;; The numerical vaues here are values of `last-command-event'  in
	;; `repeat-post-hook'
	(134217734 . forward-sexp)
	(134217730 . backward-sexp)
	(134217729 . beginning-of-defun)
	(134217733 . end-of-defun)
	(134217732 . down-list)
	(134217749 . backward-up-list)

	;; I can get 102 here with
	;;   (define-key sexp--repeat-map "f" 'forward-sexp)
	(102 . forward-sexp)
	(98 . backward-sexp)
	(97 . beginning-of-defun)
	(101 . end-of-defun)
	(100 . down-list)
	(117 . backward-up-list)))

(progn
  (put 'forward-sexp 'repeat-map 'sexp--repeat-map)
  (put 'backward-sexp 'repeat-map 'sexp--repeat-map)
  (put 'beginning-of-defun 'repeat-map 'sexp--repeat-map)
  (put 'end-of-defun 'repeat-map 'sexp--repeat-map)
  (put 'down-list 'repeat-map 'sexp--repeat-map)
  (put 'backward-up-list 'repeat-map 'sexp--repeat-map))

----------------

FWIW, to convert C-M-f to 102, I used this

    (vector
     (event-basic-type
      (car
       (listify-key-sequence
	(kbd "C-M-f")))))












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

* Re: Getting magic numbers 134217734 etc in a repetable keymap
  2021-04-03  6:20 Getting magic numbers 134217734 etc in a repetable keymap Ramesh Nedunchezian
@ 2021-04-03  7:32 ` Eli Zaretskii
  2021-04-03 11:58   ` Ramesh Nedunchezian
  2021-04-03  8:16 ` Andreas Schwab
  2021-04-05 20:47 ` Juri Linkov
  2 siblings, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2021-04-03  7:32 UTC (permalink / raw)
  To: Ramesh Nedunchezian; +Cc: emacs-devel

> From: Ramesh Nedunchezian <rameshnedunchezian@outlook.com>
> Date: Sat, 3 Apr 2021 11:50:50 +0530
> 
> I would like to create a repeatable keymap which has magic number
> 134217734 etc in it using either `define-key' or any other API.
> 
> I have tried the following, and it desn't work
> 
>     (define-key sexp--repeat-map
>       (vector
>        (car
> 	(listify-key-sequence
> 	 (kbd "C-M-f"))))
>       'forward-sexp)
> 
> Getting numbers like 134217734 etc in to the repeatable keymap are
> important for successful setting up of repetition. That is, for
> repetition to succeed, the condition below in `repeat-post-hook' need
> to succeed.
> 
>     (or (memq last-command-event keys)
> 	(memq this-original-command '(universal-argument
> 				      universal-argument-more
> 				      digit-argument
> 				      negative-argument)))
> 
> ... and when I invoke C-M-f `last-command-event' comes out as 134217734.
> 
> ----------------
> 
> For now I have hard-coded `sexp--repeat-map' as below, and this works
> as expected.  But I want a cleaner and less-hackish recipe for achieving the same.

Display the "magic" numbers in hex, and I think you will see the way
clearly.



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

* Re: Getting magic numbers 134217734 etc in a repetable keymap
  2021-04-03  6:20 Getting magic numbers 134217734 etc in a repetable keymap Ramesh Nedunchezian
  2021-04-03  7:32 ` Eli Zaretskii
@ 2021-04-03  8:16 ` Andreas Schwab
  2021-04-05 20:47 ` Juri Linkov
  2 siblings, 0 replies; 7+ messages in thread
From: Andreas Schwab @ 2021-04-03  8:16 UTC (permalink / raw)
  To: Ramesh Nedunchezian; +Cc: emacs-devel

On Apr 03 2021, Ramesh Nedunchezian wrote:

> ... and when I invoke C-M-f `last-command-event' comes out as 134217734.

?\C-\M-f

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."



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

* Re: Getting magic numbers 134217734 etc in a repetable keymap
  2021-04-03  7:32 ` Eli Zaretskii
@ 2021-04-03 11:58   ` Ramesh Nedunchezian
  2021-04-03 13:14     ` Eli Zaretskii
  0 siblings, 1 reply; 7+ messages in thread
From: Ramesh Nedunchezian @ 2021-04-03 11:58 UTC (permalink / raw)
  To: emacs-devel



On 03/04/21 1:02 pm, Eli Zaretskii wrote:
>> From: Ramesh Nedunchezian <rameshnedunchezian@outlook.com>
>> Date: Sat, 3 Apr 2021 11:50:50 +0530
>>
>> I would like to create a repeatable keymap which has magic number
>> 134217734 etc in it using either `define-key' or any other API.
>>
>> I have tried the following, and it desn't work
>>
>>     (define-key sexp--repeat-map
>>       (vector
>>        (car
>> 	(listify-key-sequence
>> 	 (kbd "C-M-f"))))
>>       'forward-sexp)
>>
>> Getting numbers like 134217734 etc in to the repeatable keymap are
>> important for successful setting up of repetition. That is, for
>> repetition to succeed, the condition below in `repeat-post-hook' need
>> to succeed.
>>
>>     (or (memq last-command-event keys)
>> 	(memq this-original-command '(universal-argument
>> 				      universal-argument-more
>> 				      digit-argument
>> 				      negative-argument)))
>>
>> ... and when I invoke C-M-f `last-command-event' comes out as 134217734.
>>
>> ----------------
>>
>> For now I have hard-coded `sexp--repeat-map' as below, and this works
>> as expected.  But I want a cleaner and less-hackish recipe for achieving the same.
> 
> Display the "magic" numbers in hex, and I think you will see the way
> clearly.
> 

I am dumb.  I unable to take your hint.  Can I have a full
recipe.

Getting the magic value of C-M-f is not an issue.

But, getting the magic number _verbatim_ in to the _repeat-map__ is
the issue.  Note the emphasis on words "verbatim" and "repeat-map".

i.e., I want a recipe which will create this keymap

  '(keymap
	  (134217734 . forward-sexp)
	  ;; (102 . forward-sexp)
	  )

instead of the

  (keymap
   (27 keymap
       (6 . forward-sexp)))

i.e. The problem with `define-key' is that it is converting C-M-f in
to ESC C-f and this 2-level keymap I DO NOT want.  The two level
keymap gets in the way of setting up a repeatable keymap which will
help me do C-M-f f f f f etc.

To  summarize, I want the "not ok" to be fixed.

  (progn
    (defvar test-repeat-map
      (let
	  ((map
	    (make-sparse-keymap)))
	map)
      "Keymap used to repeatedly invoke  `forward-sexp' with C-M-f f f f .....")
    (cl-loop for
	     (cmd . key)
	     in
	     '((forward-sexp .
			     [134217734]) ;; Not ok
	       (forward-sexp . "f"))
	     do
	     (define-key test-repeat-map key cmd)
	     (put cmd 'repeat-map 'test-repeat-map))
    test-repeat-map)

----------------

This is the crux of my problem, and it appears in the context of
newly introduced `repeat-mode' feature.

  Getting numbers like 134217734 etc in to the repeatable keymap are
  important for successful setting up of repetition. That is, for
  repetition to succeed, the condition below in `repeat-post-hook' need
  to succeed.

      (or (memq last-command-event keys)
	  (memq this-original-command '(universal-argument
					universal-argument-more
					digit-argument
					negative-argument)))

  ... and when I invoke C-M-f `last-command-event' comes out as 134217734.




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

* Re: Getting magic numbers 134217734 etc in a repetable keymap
  2021-04-03 11:58   ` Ramesh Nedunchezian
@ 2021-04-03 13:14     ` Eli Zaretskii
  2021-04-03 15:14       ` Ramesh Nedunchezian
  0 siblings, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2021-04-03 13:14 UTC (permalink / raw)
  To: Ramesh Nedunchezian; +Cc: emacs-devel

> From: Ramesh Nedunchezian <rameshnedunchezian@outlook.com>
> Date: Sat, 3 Apr 2021 17:28:12 +0530
> 
> > Display the "magic" numbers in hex, and I think you will see the way
> > clearly.
> 
> I am dumb.  I unable to take your hint.  Can I have a full
> recipe.

Maybe I don't understand what kind of recipe you are looking for.

I thought you were asking how to synthesize those "magic numbers"
given the key description such as "C-M-f".  That is what I tried to
explain: if you display the number 134217734 in hex you will see
#x8000006, which is C-f (ASCII 6) with the Meta bit ORed.

> Getting the magic value of C-M-f is not an issue.
> 
> But, getting the magic number _verbatim_ in to the _repeat-map__ is
> the issue.  Note the emphasis on words "verbatim" and "repeat-map".

I'm dumb, I don't think I see the difference.

> i.e., I want a recipe which will create this keymap
> 
>   '(keymap
> 	  (134217734 . forward-sexp)
> 	  ;; (102 . forward-sexp)
> 	  )
> 
> instead of the
> 
>   (keymap
>    (27 keymap
>        (6 . forward-sexp)))
> 
> i.e. The problem with `define-key' is that it is converting C-M-f in
> to ESC C-f and this 2-level keymap I DO NOT want.  The two level
> keymap gets in the way of setting up a repeatable keymap which will
> help me do C-M-f f f f f etc.

I think I explained exactly what you want: how to get the numerical
value corresponding to C-M-f and any other key that includes modifiers.

If that still doesn't help you, then I'm sorry; someone else will have
to do better.



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

* Re: Getting magic numbers 134217734 etc in a repetable keymap
  2021-04-03 13:14     ` Eli Zaretskii
@ 2021-04-03 15:14       ` Ramesh Nedunchezian
  0 siblings, 0 replies; 7+ messages in thread
From: Ramesh Nedunchezian @ 2021-04-03 15:14 UTC (permalink / raw)
  To: emacs-devel



On 03/04/21 6:44 pm, Eli Zaretskii wrote:
>> From: Ramesh Nedunchezian <rameshnedunchezian@outlook.com>
>> Date: Sat, 3 Apr 2021 17:28:12 +0530
>>
>>> Display the "magic" numbers in hex, and I think you will see the way
>>> clearly.
>>
>> I am dumb.  I unable to take your hint.  Can I have a full
>> recipe.
> 
> Maybe I don't understand what kind of recipe you are looking for.
> 
> I thought you were asking how to synthesize those "magic numbers"
> given the key description such as "C-M-f".  That is what I tried to
> explain: if you display the number 134217734 in hex you will see
> #x8000006, which is C-f (ASCII 6) with the Meta bit ORed.
> 
>> Getting the magic value of C-M-f is not an issue.
>>
>> But, getting the magic number _verbatim_ in to the _repeat-map__ is
>> the issue.  Note the emphasis on words "verbatim" and "repeat-map".
> 
> I'm dumb, I don't think I see the difference.
> 
>> i.e., I want a recipe which will create this keymap
>>
>>   '(keymap
>> 	  (134217734 . forward-sexp)
>> 	  ;; (102 . forward-sexp)
>> 	  )
>>
>> instead of the
>>
>>   (keymap
>>    (27 keymap
>>        (6 . forward-sexp)))
>>

I am hoping that someone will help me.

I am NOT asking how to create a keymap.  Not at all.

People who have responded to me--thanks, for your time--have
overlooked the fact that I am trying to exercise the all new
`repeat-mode' feature.  I am having some issues with making a keymap
that would be acceptable to `repeat-mode-hook'.



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

* Re: Getting magic numbers 134217734 etc in a repetable keymap
  2021-04-03  6:20 Getting magic numbers 134217734 etc in a repetable keymap Ramesh Nedunchezian
  2021-04-03  7:32 ` Eli Zaretskii
  2021-04-03  8:16 ` Andreas Schwab
@ 2021-04-05 20:47 ` Juri Linkov
  2 siblings, 0 replies; 7+ messages in thread
From: Juri Linkov @ 2021-04-05 20:47 UTC (permalink / raw)
  To: Ramesh Nedunchezian; +Cc: emacs-devel

> I have tried the following, and it desn't work
>
>     (define-key sexp--repeat-map
>       (vector
>        (car
> 	(listify-key-sequence
> 	 (kbd "C-M-f"))))
>       'forward-sexp)
>
> Getting numbers like 134217734 etc in to the repeatable keymap are
> important for successful setting up of repetition. That is, for
> repetition to succeed, the condition below in `repeat-post-hook' need
> to succeed.
>
>     (or (memq last-command-event keys)

Thanks for reporting this problem.  This is fixed now in 9c51a9d000,
please try again.



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

end of thread, other threads:[~2021-04-05 20:47 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-03  6:20 Getting magic numbers 134217734 etc in a repetable keymap Ramesh Nedunchezian
2021-04-03  7:32 ` Eli Zaretskii
2021-04-03 11:58   ` Ramesh Nedunchezian
2021-04-03 13:14     ` Eli Zaretskii
2021-04-03 15:14       ` Ramesh Nedunchezian
2021-04-03  8:16 ` Andreas Schwab
2021-04-05 20:47 ` Juri Linkov

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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