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 Answers 2

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?

4
  • 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. Commented Aug 3, 2017 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. Commented Aug 3, 2017 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. Commented Aug 3, 2017 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
    Commented Feb 17, 2019 at 17:42
0

I've made a simple hack to make C-a treat a link in the line beginning correctly, with https://emacs.stackexchange.com/users/5198/wojciech-gac answer:

(global-set-key (kbd "C-a") (lambda () (interactive)
  (doom/backward-to-bol-or-indent) ;; I'm using doom emacs - for vanilla emacs it would be something else - just put here your default for `C-a` (find out with `C-h k C-a`)
  (backward-char)
  (forward-char)
))

Seems to work for now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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