0

Consider the following org buffer test.org:

H

[[My Target][jump to my target]]

<<My Target>> 

If I run org-toggle-link-display on this buffer I get:

enter image description here

If I now move the cursor down to the "j" in "jump to my target" and try to insert a text (note: this text should not be part of the link), the text is gobbled up as part of the link. If I try press ENTER at beginning of the link, the newlines are also included in the link. Is there a way to insert text before a link (that is not to be part of the link text) at the beginning of a line without running org-toggle-link-display first?

Note: One trick could be to insert text at the previous line and then press the delete key, but this does not work if the link is the first line of the buffer.

2

What I've noticed is that if you place the cursor on the first character and then do C-b followed by C-f (or just C-b if you're at the beginning of a buffer), what you type afterwards will be prepended to the link (and not be part of it). Does this answer your question?

  • Yes this works, but it would be nice if it was possible to turn this feature on (or off) using a single command, and then it would stay that way until you turned it off again. So this is what I envision: As long as the feature is enabled you can write text in front of any org link. If you disable the feature, things work as it does now by default: If you insert text at the beginning of a link, it is prepended to the link text. – Håkon Hægland Aug 3 '17 at 13:53
  • I would imagine you should be able to do something like this from within the function org-self-insert-command. I'll have a look and see if I find a way to accomplish this. – Wojciech Gac Aug 3 '17 at 13:59
  • One thing I found that gives a sort of clue is the function org-context. When run with the cursor anywhere within a link, it returns, among other things, a context "object" of the form (:link <start> <end>). Knowing this, you could probably use a hook (maybe org-speed-command-hook?) to override the standard insertion behavior, depending on some variable being set or not. – Wojciech Gac Aug 3 '17 at 14:10
  • No need to go crazy here, simply bind (kbd "C-b C-f") to some key in your local map. For example, I have bound it to `C-c c \`, the backslash is mnemonic for "escape". – memeplex Feb 17 at 17:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.