unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Q1 - the keys' bindings to work more widely
@ 2024-12-14 23:46 Tatsu Takamaro
  2024-12-15  2:15 ` [External] : " Drew Adams
  2024-12-15 10:05 ` Alain.Cochard
  0 siblings, 2 replies; 11+ messages in thread
From: Tatsu Takamaro @ 2024-12-14 23:46 UTC (permalink / raw)
  To: help-gnu-emacs

Hi there, sirs!

I'm new to Emacs, just a month from the beginning. I've managed to do 
all the major settings, wrote through the Tutorial. But for now there 
are 4 residual questions. I'll ask them one by one, one per letter to 
get more precise.

So, here is the first one. I would like to have my keys (my bindings) 
working more widely so that I could trust them more. But for now some of 
them don't work. E. g. in a Help buffer C-c doesn't work as a copy 
action (though it works globally as I set). And this is not surprising. 
I understand that major modes have priority over the global one. What is 
the best idea to make my keys more reliable? One way is to change all 
the major and minor modes, but it's a big load of work and code. Another 
way is to create my own minor mode key bindings and make it be turned on 
by default, and I managed to find how it should be done ("init-value" 
and "global" should be non-nil, in the "define-minor-mode" call). So I 
hope I'm somewhere close to the solution. Here is my function call with 
an example of C-c rebinding:

(define-minor-mode ttkeys-mode "My key bindings"
:init-value 1 :lighter " TT" :global 1
:keymap
'(
("C-c" . #'kill-ring-save)
("C-a" . #'mark-whole-buffer)
)
)

The TT mode is being shown normally, I can switch in on and off, but the 
C-c and C-a don't work as I told them to. I tried to vary signs like # 
and ', but no result. What am I doing wrong?

And, maybe there is some other advice that you could give to make my 
keys more reliable (make them work everywhere in Emacs)? Don't offer a 
CUA mode, I know about it, but it doesn't meet my needs.

Tony.


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

* RE: [External] : Q1 - the keys' bindings to work more widely
  2024-12-14 23:46 Q1 - the keys' bindings to work more widely Tatsu Takamaro
@ 2024-12-15  2:15 ` Drew Adams
  2024-12-16 23:11   ` Tatsu Takamaro
  2024-12-15 10:05 ` Alain.Cochard
  1 sibling, 1 reply; 11+ messages in thread
From: Drew Adams @ 2024-12-15  2:15 UTC (permalink / raw)
  To: Tatsu Takamaro, help-gnu-emacs@gnu.org

> I would like to have my keys (my bindings)
> working more widely so that I could trust them more. But for now some of
> them don't work. E. g. in a Help buffer C-c doesn't work as a copy
> action (though it works globally as I set). And this is not surprising.
> I understand that major modes have priority over the global one. What is
> the best idea to make my keys more reliable? One way is to change all
> the major and minor modes, but it's a big load of work and code. Another
> way is to create my own minor mode key bindings and make it be turned on
> by default, and I managed to find how it should be done ("init-value"
> and "global" should be non-nil, in the "define-minor-mode" call). So I
> hope I'm somewhere close to the solution. Here is my function call with
> an example of C-c rebinding:
> 
> (define-minor-mode ttkeys-mode "My key bindings"
> :init-value 1 :lighter " TT" :global 1
> :keymap
> '(
> ("C-c" . #'kill-ring-save)
> ("C-a" . #'mark-whole-buffer)
> )
> )
> 
> The TT mode is being shown normally, I can switch in on and off, but the
> C-c and C-a don't work as I told them to. I tried to vary signs like #
> and ', but no result. What am I doing wrong?
> 
> And, maybe there is some other advice that you could give to make my
> keys more reliable (make them work everywhere in Emacs)? Don't offer a
> CUA mode, I know about it, but it doesn't meet my needs.

See node `Key Binding Conventions' in the Elisp manual:

https://www.gnu.org/software/emacs/manual/html_node/elisp/Key-Binding-Conventions.html

That's `C-h i m elisp RET', then `g key binding conventions RET'.

See also the Emacs manual (`C-h r'), node `CUA Bindings'.


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

* Re: Q1 - the keys' bindings to work more widely
  2024-12-14 23:46 Q1 - the keys' bindings to work more widely Tatsu Takamaro
  2024-12-15  2:15 ` [External] : " Drew Adams
@ 2024-12-15 10:05 ` Alain.Cochard
  1 sibling, 0 replies; 11+ messages in thread
From: Alain.Cochard @ 2024-12-15 10:05 UTC (permalink / raw)
  To: Tatsu Takamaro; +Cc: help-gnu-emacs

Tatsu Takamaro writes on Sun 15 Dec 2024 02:46:

 > I would like to have my keys (my bindings) working more widely so that I
 > could trust them more. But for now some of them don't work. E. g. in a
 > Help buffer C-c doesn't work as a copy action (though it works globally
 > as I set). And this is not surprising.  I understand that major modes
 > have priority over the global one. What is the best idea to make my keys
 > more reliable? One way is to change all the major and minor modes, but
 > it's a big load of work and code. Another way is to create my own minor
 > mode key bindings and make it be turned on by default, and I managed to
 > find how it should be done ("init-value" and "global" should be non-nil,
 > in the "define-minor-mode" call). So I hope I'm somewhere close to the
 > solution. Here is my function call with an example of C-c rebinding:
 > 
 > (define-minor-mode ttkeys-mode "My key bindings"
 > :init-value 1 :lighter " TT" :global 1
 > :keymap
 > '(
 > ("C-c" . #'kill-ring-save)
 > ("C-a" . #'mark-whole-buffer)
 > )
 > )
 > 
 > The TT mode is being shown normally, I can switch in on and off, but the 
 > C-c and C-a don't work as I told them to. I tried to vary signs like # 
 > and ', but no result. What am I doing wrong?
 > 
 > And, maybe there is some other advice that you could give to make my 
 > keys more reliable (make them work everywhere in Emacs)? Don't offer a 
 > CUA mode, I know about it, but it doesn't meet my needs.

I am not sure it addresses your question (in particular, I do not redefine
C-c), and I have read that this way is frowned upon, but here is what I do:

;; First:
(defvar my-keys-minor-mode-map (make-keymap) "my-keys-minor-mode keymap.")

;; Then all my keys like that:
(define-key my-keys-minor-mode-map "\M-." 'scroll-up)

-- 
EOST (École et Observatoire des Sciences de la Terre) 
ITE (Institut Terre & Environnement) | alain.cochard@unistra.fr
5 rue René Descartes                 | Phone: +33 (0)3 68 85 50 44 
F-67084 Strasbourg Cedex, France     | bureau 110, ancien bât.



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

* Re: [External] : Q1 - the keys' bindings to work more widely
  2024-12-15  2:15 ` [External] : " Drew Adams
@ 2024-12-16 23:11   ` Tatsu Takamaro
  2024-12-16 23:55     ` Drew Adams via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 11+ messages in thread
From: Tatsu Takamaro @ 2024-12-16 23:11 UTC (permalink / raw)
  To: Drew Adams, help-gnu-emacs@gnu.org

>>See also the Emacs manual (`C-h r'), node `CUA Bindings'.

As I told: "Don't offer a CUA mode, I know about it, but it doesn't meet 
my needs."

I've read conventions, but did not find any answer to my questions. The 
only thing that may be close to it is about "Sequences consisting 
ofC-cfollowed by...", but it is irrelevant because 1) My "C-c" is not 
followed by anything, 2) I don't make any plugin for other users, I just 
try to set Emacs _for myself_. All the World uses Ctrl + c for copy, so 
the whole world would not sag under one program.

Anyway, my question here is why the key bindings in my minor mode don't 
work. Is there some syntax mistake? Lets' for example change them to others:

(define-minor-mode ttkeys-mode "Normal key bindings"
:init-value 1 :lighter " TT" :global 1
:keymap
'(
("a" . #'kill-ring-save)
)
)

Well, this variant doesn't work either. I get the message: "Wrong type 
argument: commandp, #'kill-ring-save"

вс, 15.12.2024 5:15, Drew Adams пишет:
>> I would like to have my keys (my bindings)
>> working more widely so that I could trust them more. But for now some of
>> them don't work. E. g. in a Help buffer C-c doesn't work as a copy
>> action (though it works globally as I set). And this is not surprising.
>> I understand that major modes have priority over the global one. What is
>> the best idea to make my keys more reliable? One way is to change all
>> the major and minor modes, but it's a big load of work and code. Another
>> way is to create my own minor mode key bindings and make it be turned on
>> by default, and I managed to find how it should be done ("init-value"
>> and "global" should be non-nil, in the "define-minor-mode" call). So I
>> hope I'm somewhere close to the solution. Here is my function call with
>> an example of C-c rebinding:
>>
>> (define-minor-mode ttkeys-mode "My key bindings"
>> :init-value 1 :lighter " TT" :global 1
>> :keymap
>> '(
>> ("C-c" . #'kill-ring-save)
>> ("C-a" . #'mark-whole-buffer)
>> )
>> )
>>
>> The TT mode is being shown normally, I can switch in on and off, but the
>> C-c and C-a don't work as I told them to. I tried to vary signs like #
>> and ', but no result. What am I doing wrong?
>>
>> And, maybe there is some other advice that you could give to make my
>> keys more reliable (make them work everywhere in Emacs)? Don't offer a
>> CUA mode, I know about it, but it doesn't meet my needs.
> See node `Key Binding Conventions' in the Elisp manual:
>
> https://www.gnu.org/software/emacs/manual/html_node/elisp/Key-Binding-Conventions.html
>
> That's `C-h i m elisp RET', then `g key binding conventions RET'.
>
> See also the Emacs manual (`C-h r'), node `CUA Bindings'.
>


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

* RE: [External] : Q1 - the keys' bindings to work more widely
  2024-12-16 23:11   ` Tatsu Takamaro
@ 2024-12-16 23:55     ` Drew Adams via Users list for the GNU Emacs text editor
  2024-12-17  0:05       ` Drew Adams
  0 siblings, 1 reply; 11+ messages in thread
From: Drew Adams via Users list for the GNU Emacs text editor @ 2024-12-16 23:55 UTC (permalink / raw)
  To: Tatsu Takamaro, help-gnu-emacs@gnu.org

Below.

I've read conventions, but did not find any answer to my questions. The only thing that may be close to it is about "Sequences consisting of C-c followed by...", but it is irrelevant because 1) My "C-c" is not followed by anything, 2) I don't make any plugin for other users, I just try to set Emacs for myself. All the World uses Ctrl + c for copy, so the whole world would not sag under one program.

A user can use any keys s?he likes. That Elisp convention tells you which keys are reserved for users. Other keys (not reserved for users) are likely to have bindings provided by Emacs or packages, so if you bind them to different keys you might change some behavior. That's all - just useful to know, for users too.

Anyway, my question here is why the key bindings in my minor mode don't work. Is there some syntax mistake? Lets' for example change them to others:

(define-minor-mode ttkeys-mode "Normal key bindings"
:init-value 1 :lighter " TT" :global 1
:keymap
'(
("a" . #'kill-ring-save)
)
)

This isn't a keymap: '(("a" . #'kill-ring-save)))

(keymapp '(("a" . #'kill-ring-save))) ; returns nil

This is a keymap: '(keymap ("a" . #'kill-ring-save)))

(keymapp '(keymap ("a" . #'kill-ring-save))) ; returns t

Well, this variant doesn't work either. I get the message: "Wrong type argument: commandp, #'kill-ring-save"

Yes, that too. You can't bind non-interactive functions to keys.

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

* RE: [External] : Q1 - the keys' bindings to work more widely
  2024-12-16 23:55     ` Drew Adams via Users list for the GNU Emacs text editor
@ 2024-12-17  0:05       ` Drew Adams
  2024-12-17  0:16         ` Tatsu Takamaro
  0 siblings, 1 reply; 11+ messages in thread
From: Drew Adams @ 2024-12-17  0:05 UTC (permalink / raw)
  To: Drew Adams, Tatsu Takamaro, help-gnu-emacs@gnu.org

Reformatting...
___

Below.

> I've read conventions, but did not find any answer to my questions. The
> only thing that may be close to it is about "Sequences consisting of C-c
> followed by...", but it is irrelevant because 1) My "C-c" is not followed
> by anything, 2) I don't make any plugin for other users, I just try to
> set Emacs for myself. All the World uses Ctrl + c for copy, so the whole
> world would not sag under one program.

A user can use any keys s?he likes. That Elisp convention tells you which
keys are reserved for users. Other keys (not reserved for users) are
likely to have bindings provided by Emacs or packages, so if you bind
them to different keys you might change some behavior. That's all - just
useful to know, for users too.

> Anyway, my question here is why the key bindings in my minor mode don't
> work. Is there some syntax mistake? Lets' for example change them to
> others:
> 
> (define-minor-mode ttkeys-mode "Normal key bindings"
> :init-value 1 :lighter " TT" :global 1
> :keymap
> '(
> ("a" . #'kill-ring-save)
> )
> )

This isn't a keymap: '(("a" . #'kill-ring-save)))

(keymapp '(("a" . #'kill-ring-save))) ; returns nil

This is a keymap: '(keymap ("a" . #'kill-ring-save)))

(keymapp '(keymap ("a" . #'kill-ring-save))) ; returns t

> Well, this variant doesn't work either. I get the message: "Wrong type
> argument: commandp, #'kill-ring-save"

Yes, that too. You can't bind non-interactive functions to keys.

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

* Re: [External] : Q1 - the keys' bindings to work more widely
  2024-12-17  0:05       ` Drew Adams
@ 2024-12-17  0:16         ` Tatsu Takamaro
  2024-12-17  2:17           ` Drew Adams
  0 siblings, 1 reply; 11+ messages in thread
From: Tatsu Takamaro @ 2024-12-17  0:16 UTC (permalink / raw)
  To: Drew Adams, help-gnu-emacs@gnu.org

 >> You can't bind non-interactive functions to keys.

But I rebound globally and this works:

*(keymap-global-unset "C-c")**
**(keymap-global-set "C-c" #'kill-ring-save)*

*
*

*
*

 >> This is a keymap: '(keymap ("a" . #'kill-ring-save)))

Do you mean this:

    *(define-minor-mode ttkeys-mode "Normal key bindings"**
    **:init-value 1 :lighter " TT" :global 1**
    **:keymap**
    **'(keymap      ("a" . #'kill-ring-save)))*

Doesn't work either.

вт, 17.12.2024 3:05, Drew Adams пишет:
> Reformatting...
> ___
>
> Below.
>
>> I've read conventions, but did not find any answer to my questions. The
>> only thing that may be close to it is about "Sequences consisting of C-c
>> followed by...", but it is irrelevant because 1) My "C-c" is not followed
>> by anything, 2) I don't make any plugin for other users, I just try to
>> set Emacs for myself. All the World uses Ctrl + c for copy, so the whole
>> world would not sag under one program.
> A user can use any keys s?he likes. That Elisp convention tells you which
> keys are reserved for users. Other keys (not reserved for users) are
> likely to have bindings provided by Emacs or packages, so if you bind
> them to different keys you might change some behavior. That's all - just
> useful to know, for users too.
>
>> Anyway, my question here is why the key bindings in my minor mode don't
>> work. Is there some syntax mistake? Lets' for example change them to
>> others:
>>
>> (define-minor-mode ttkeys-mode "Normal key bindings"
>> :init-value 1 :lighter " TT" :global 1
>> :keymap
>> '(
>> ("a" . #'kill-ring-save)
>> )
>> )
> This isn't a keymap: '(("a" . #'kill-ring-save)))
>
> (keymapp '(("a" . #'kill-ring-save))) ; returns nil
>
> This is a keymap: '(keymap ("a" . #'kill-ring-save)))
>
> (keymapp '(keymap ("a" . #'kill-ring-save))) ; returns t
>
>> Well, this variant doesn't work either. I get the message: "Wrong type
>> argument: commandp, #'kill-ring-save"
> Yes, that too. You can't bind non-interactive functions to keys.


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

* RE: [External] : Q1 - the keys' bindings to work more widely
  2024-12-17  0:16         ` Tatsu Takamaro
@ 2024-12-17  2:17           ` Drew Adams
  2024-12-17  5:41             ` Tatsu Takamaro
  2024-12-17  5:42             ` Tatsu Takamaro
  0 siblings, 2 replies; 11+ messages in thread
From: Drew Adams @ 2024-12-17  2:17 UTC (permalink / raw)
  To: Tatsu Takamaro, help-gnu-emacs@gnu.org

>> This is a keymap: '(keymap ("a" . #'kill-ring-save)))

It satisfies `keymapp', at least. ;-)  But unfortunately,
`keymapp' doesn't guarantee a keymap.  The Elisp manual
says it allows any list whose car is `keymap':

 More precisely, this function tests for a list whose CAR is
 ‘keymap’, or for a symbol whose function definition satisfies
 ‘keymapp’.

> Do you mean this:
>
> (define-minor-mode ttkeys-mode "Normal key bindings"
>:init-value 1 :lighter " TT" :global 1
>:keymap '(keymap ("a" . #'kill-ring-save)))
>
> Doesn't work either.

Try this:

:keymap '(keymap (?a . kill-ring-save)))

or this:

:keymap '(keymap (97 . kill-ring-save)))

https://www.gnu.org/software/emacs/manual/html_node/elisp/Format-of-Keymaps.html

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

* Re: [External] : Q1 - the keys' bindings to work more widely
  2024-12-17  2:17           ` Drew Adams
@ 2024-12-17  5:41             ` Tatsu Takamaro
  2024-12-17  6:28               ` Yuri Khan
  2024-12-17  5:42             ` Tatsu Takamaro
  1 sibling, 1 reply; 11+ messages in thread
From: Tatsu Takamaro @ 2024-12-17  5:41 UTC (permalink / raw)
  To: Drew Adams, help-gnu-emacs@gnu.org

This one works:

    *:keymap '(keymap (?a . kill-ring-save)))*

But I'm not sure why. I wrote the page you gave, and another one 
(https://www.gnu.org/software/emacs/manual/html_node/elisp/Classifying-Events.html) 
but I don't completely understand the meaning of sign ? before "a". It 
seems, this is to indicate a key(s) as an event, but I can't find the 
explaination of all such signs neither in the web nor in the official 
docs. Another sign of that kind is a backslash and as I got it should be 
in front on a modifier key. *But why? *You know it's always difficult to 
search the web by a one-digit symbol.

But yes, I managed to do what I wanted with this

    *(?\C-c . kill-ring-save)**
    **(?\C-a . mark-whole-buffer)*

and so on. Thank you!

Many problems of this kind are from not knowing Elisp. ^_^

вт, 17.12.2024 5:17, Drew Adams пишет:
>>> This is a keymap: '(keymap ("a" . #'kill-ring-save)))
> It satisfies `keymapp', at least. ;-)  But unfortunately,
> `keymapp' doesn't guarantee a keymap.  The Elisp manual
> says it allows any list whose car is `keymap':
>
>   More precisely, this function tests for a list whose CAR is
>   ‘keymap’, or for a symbol whose function definition satisfies
>   ‘keymapp’.
>
>> Do you mean this:
>>
>> (define-minor-mode ttkeys-mode "Normal key bindings"
>> :init-value 1 :lighter " TT" :global 1
>> :keymap '(keymap ("a" . #'kill-ring-save)))
>>
>> Doesn't work either.
> Try this:
>
> :keymap '(keymap (?a . kill-ring-save)))
>
> or this:
>
> :keymap '(keymap (97 . kill-ring-save)))
>
> https://www.gnu.org/software/emacs/manual/html_node/elisp/Format-of-Keymaps.html


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

* Re: [External] : Q1 - the keys' bindings to work more widely
  2024-12-17  2:17           ` Drew Adams
  2024-12-17  5:41             ` Tatsu Takamaro
@ 2024-12-17  5:42             ` Tatsu Takamaro
  1 sibling, 0 replies; 11+ messages in thread
From: Tatsu Takamaro @ 2024-12-17  5:42 UTC (permalink / raw)
  To: Drew Adams, help-gnu-emacs@gnu.org

I meant "read that page" of course, not wrote (in the previous letter)...

вт, 17.12.2024 5:17, Drew Adams пишет:
>>> This is a keymap: '(keymap ("a" . #'kill-ring-save)))
> It satisfies `keymapp', at least. ;-)  But unfortunately,
> `keymapp' doesn't guarantee a keymap.  The Elisp manual
> says it allows any list whose car is `keymap':
>
>   More precisely, this function tests for a list whose CAR is
>   ‘keymap’, or for a symbol whose function definition satisfies
>   ‘keymapp’.
>
>> Do you mean this:
>>
>> (define-minor-mode ttkeys-mode "Normal key bindings"
>> :init-value 1 :lighter " TT" :global 1
>> :keymap '(keymap ("a" . #'kill-ring-save)))
>>
>> Doesn't work either.
> Try this:
>
> :keymap '(keymap (?a . kill-ring-save)))
>
> or this:
>
> :keymap '(keymap (97 . kill-ring-save)))
>
> https://www.gnu.org/software/emacs/manual/html_node/elisp/Format-of-Keymaps.html


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

* Re: [External] : Q1 - the keys' bindings to work more widely
  2024-12-17  5:41             ` Tatsu Takamaro
@ 2024-12-17  6:28               ` Yuri Khan
  0 siblings, 0 replies; 11+ messages in thread
From: Yuri Khan @ 2024-12-17  6:28 UTC (permalink / raw)
  To: Tatsu Takamaro; +Cc: Drew Adams, help-gnu-emacs@gnu.org

On Tue, 17 Dec 2024 at 12:42, Tatsu Takamaro <tatsu.takamaro@gmail.com> wrote:

> This one works:
>
>     *:keymap '(keymap (?a . kill-ring-save)))*
>
> But I'm not sure why.

You’re not actually supposed to type out keymaps in their internal
representation. Drew probably does that because he learned Emacs
before the introduction of key binding helper functions.

    (defvar ttkeys-mode-map
      (define-keymap
         "C-c" #'kill-ring-save
         "C-a" #'mark-whole-buffer))

    (define-minor-mode ttkeys-mode "Regular key bindings"
      :init-value t
      :lighter " TT"
      :global t
      :keymap ttkeys-mode-map)

(I must note that you’re in for a lot of swimming against the current
if you want to reclaim C-c from its established Emacs role as a
prefix. A lot of modes bind some of their functionality to sequences
starting with C-c, and you will either have to rebind them in order to
start using them, or they will wrest C-c back from you.)



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

end of thread, other threads:[~2024-12-17  6:28 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-14 23:46 Q1 - the keys' bindings to work more widely Tatsu Takamaro
2024-12-15  2:15 ` [External] : " Drew Adams
2024-12-16 23:11   ` Tatsu Takamaro
2024-12-16 23:55     ` Drew Adams via Users list for the GNU Emacs text editor
2024-12-17  0:05       ` Drew Adams
2024-12-17  0:16         ` Tatsu Takamaro
2024-12-17  2:17           ` Drew Adams
2024-12-17  5:41             ` Tatsu Takamaro
2024-12-17  6:28               ` Yuri Khan
2024-12-17  5:42             ` Tatsu Takamaro
2024-12-15 10:05 ` Alain.Cochard

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