Skip to main content
added 1040 characters in body
Source Link
NickD
  • 33.6k
  • 3
  • 30
  • 47

DisclamerDisclaimer

I couldn't find a resource providing a good and for none-Emacs-experienced-users understandable explanation about prefix keysarguments for new Emacs users. So I am a newbie and my explanation may not be the best.

Prefix keyargument concept

Emacs has the concept of prefix keysprefix arguments to commands. WithThe command loop looks for prefix arguments and arranges to pass them you can modifyto the usual/default behaviour of a key-binding or its functioncommand.

TheE.g. the C-u C-c C-l can be described as C-u (the prefix-key argument) plus C-c C-l (the original key-binding). That is why you aren't able to ask for the keybinding with C-h k C-u C-c C-l (describe-key RET C-u C-c C-l). Do it without the prefix key C-u (i.e. just C-h k C-c C-l) and you find out that the key-binding points do sequence C-c C-l is bound to org-insert-link. [1]

In the description of that function, the possible prefix-keys arguments and what dohow they modify in the function's behaviour are described. For org-insert-linkE.g. the doc string above states:

With a ‘C-u’ prefix, prompts for a file to link to. The file name can be selected using completion. The path to the file will be relative to the current directory ...

In this example, you can also use two C-us as the prefix-keys twice argument: C-u C-u C-c C-l which cause treating the file path. The doc string says:

With a ‘C-u C-u’ prefix, enforce an absolute path even if the file is in the current directory or below.

or you can even use three C-us as absolute insteadthe prefix argument:

A ‘C-u C-u C-u’ prefix negates ‘org-link-keep-stored-after-insertion’.

The principle is that you have to ask for the documentation of relativethe keybinding without any prefix arguments and look at the doc string of the command in order to figure out what various prefix arguments do.

[1] Note that you have to do that in an Org mode buffer: the keybinding C-c C-l does not generally exist in other keymaps.


N.B. Do not confuse prefix arguments as described above with prefix keys in a keymap. These two concepts are orthogonal.

Disclamer

I couldn't find a resource providing a good and for none-Emacs-experienced-users understandable explanation about prefix keys. So I am a newbie and my explanation may not be the best.

Prefix key concept

Emacs has the concept of prefix keys. With them you can modify the usual/default behaviour of a key-binding or its function.

The C-u C-c C-l can be described as C-u (the prefix-key) plus C-c C-l (the original key-binding). That is why you aren't able to ask for the keybinding with C-h k C-u C-c C-l (describe-key RET C-u C-c C-l). Do it without the prefix key (C-h C-c C-l) and you find out that key-binding points do org-insert-link.

In the description of that function the possible prefix-keys and what do they modify in the function's behaviour are described. For org-insert-link you can also use the prefix-keys twice: C-u C-u C-c C-l which cause treating the file path as absolute instead of relative.

Disclaimer

I couldn't find a resource providing a good and understandable explanation about prefix arguments for new Emacs users. So I am a newbie and my explanation may not be the best.

Prefix argument concept

Emacs has the concept of prefix arguments to commands. The command loop looks for prefix arguments and arranges to pass them to the command.

E.g. the C-u C-c C-l can be described as C-u (the prefix argument) plus C-c C-l (the original key-binding). That is why you aren't able to ask for the keybinding with C-h k C-u C-c C-l (describe-key RET C-u C-c C-l). Do it without the C-u (i.e. just C-h k C-c C-l) and you find out that the key sequence C-c C-l is bound to org-insert-link. [1]

In the description of that function, the possible prefix arguments and how they modify the function's behaviour are described. E.g. the doc string above states:

With a ‘C-u’ prefix, prompts for a file to link to. The file name can be selected using completion. The path to the file will be relative to the current directory ...

In this example, you can also use two C-us as the prefix argument: C-u C-u C-c C-l. The doc string says:

With a ‘C-u C-u’ prefix, enforce an absolute path even if the file is in the current directory or below.

or you can even use three C-us as the prefix argument:

A ‘C-u C-u C-u’ prefix negates ‘org-link-keep-stored-after-insertion’.

The principle is that you have to ask for the documentation of the keybinding without any prefix arguments and look at the doc string of the command in order to figure out what various prefix arguments do.

[1] Note that you have to do that in an Org mode buffer: the keybinding C-c C-l does not generally exist in other keymaps.


N.B. Do not confuse prefix arguments as described above with prefix keys in a keymap. These two concepts are orthogonal.

Source Link
buhtz
  • 749
  • 7
  • 23

Disclamer

I couldn't find a resource providing a good and for none-Emacs-experienced-users understandable explanation about prefix keys. So I am a newbie and my explanation may not be the best.

Prefix key concept

Emacs has the concept of prefix keys. With them you can modify the usual/default behaviour of a key-binding or its function.

The C-u C-c C-l can be described as C-u (the prefix-key) plus C-c C-l (the original key-binding). That is why you aren't able to ask for the keybinding with C-h k C-u C-c C-l (describe-key RET C-u C-c C-l). Do it without the prefix key (C-h C-c C-l) and you find out that key-binding points do org-insert-link.

In the description of that function the possible prefix-keys and what do they modify in the function's behaviour are described. For org-insert-link you can also use the prefix-keys twice: C-u C-u C-c C-l which cause treating the file path as absolute instead of relative.