This is not a new bug. It has been there for a long time, but I am
only just now getting around to reporting it. I am also proposing a
fix below.
How to reproduce:
Open up a Org mode file and add the following item to it:
1. Now is the time for all good men and women to
[[id:269cedb3-9a50-4de9-9696-f8297c18a75a][come to the aid of their KEG PARTY]]
Ensure you have run `org-toggle-link-display' to show the "descriptive
display" of links, not the literal display that might show up in your
email view of the above line (e.g., the
"[id:269cedb3-9a50-4de9-9696-f8297c18a75a]" part will not show up in the
"descriptive" link display mode).
Move point to the "a" in "aid", and type C-x f (set-fill-column) to
set the fill column to 62.
Place point anywhere inside the above line after the "1. " (e.g. at
the "g" in "good").
Type M-x org-fill-paragraph.
The result is
1. Now is the time for all good men and women to
[[id:269cedb3-9a50-4de9-9696-f8297c18a75a][come to the
aid of their KEG PARTY]]
Not only is the above result visually jarring (see
https://i.imgur.com/HnY70le.png for an annotated screenshot) when in
"descriptive link" display mode, it also breaks `org-return', as
follows:
Move the point to the "g" in "good" in the line above. Type M-x
org-next-link to got to that first link, then type M-x org-return. The
result is an insertion of a newline, resulting in:
1. Now is the time for all good men and women to
[[id:269cedb3-9a50-4de9-9696-f8297c18a75a][come to the aid of
their KEG PARTY]]
when I expect it to navigate to the heading upon which is associated
with "id:269cedb3-9a50-4de9-9696-f8297c18a75a".
Here is my proposed fix:
First, it may be a separate "bug" that org-return cannot recognize the
multi-line Org link. I don't know one way or the other for that, but
instead I am arguing that org mode's fill paragraph function should
never break the line right in the middle of the link. Instead the
whole link should be treated as a word. To illustrate the fix, I have
appended my own function to `fill-nobreak-predicate' to prevent the
breakages, but taking hints from `org-setup-filling' which does
similar things for other areas of Org mode buffers:
(defun bg-org-fill-paragraph-with-link-nobreak-p ()
"Do not allow `fill-paragraph' to break inside the middle of Org mode links."
(and (assq :link (org-context)) t))
(defun bg-org-fill-paragraph-config ()
"Configure `fill-paragraph' for Org mode."
;; Append a function to fill-nobreak-predicate similarly to how org-mode does
;; inside `org-setup-filling':
(when (boundp 'fill-nobreak-predicate)
(setq-local
fill-nobreak-predicate
(org-uniquify
(append fill-nobreak-predicate
'(bg-org-fill-paragraph-with-link-nobreak-p))
And then run bg-org-fill-paragraph-config from my `org-mode-hook'
function.
The fix I propose is to change `org-setup-filling' to do the above.
Thanks,
Brent
Emacs : GNU Emacs 25.2.2 (x86_64-pc-linux-gnu, GTK+ Version 3.22.21)
of 2017-09-22, modified by Debian
Package: Org mode version 9.1.9 (release_9.1.9-580-g39837b @
/home/drunkard/emacs_lisp_imported/org-mode/org-mode/lisp/)
current state:
==
(setq
org-id-locations-file "/home/drunkard/Plans/Home/.org-id-locations"
org-tab-first-hook '(org-babel-hide-result-toggle-maybe
org-babel-header-arg-expand)
outline-minor-mode-hook '(wikipedia-outline-magic-keys (lambda nil (require
(quote outline-magic
org-clock-persist-file "/home/drunkard/Plans/Home/org-clock-save.el"
org-speed-command-hook '(org-speed-command-activate
org-babel-speed-command-activate)
org-occur-hook '(org-first-headline-recenter)
org-metaup-hook '(org-babel-load-in-session-maybe)
org-html-format-drawer-function #[514 "\207" [] 3 "\n\n(fn NAME CONTENTS)"]
org-latex-format-inlinetask-function
'org-latex-format-inlinetask-default-function
org-confirm-shell-link-function 'yes-or-no-p
org-id-link-to-org-use-id t
org-ascii-format-inlinetask-function 'org-ascii-format-inlinetask-default
org-clock-idle-time 10
org-startup-folded nil
org-file-apps '((auto-mode . emacs) ("\\.mm\\'" . default) ("\\.x?html?\\'"
browse-url-of-file (expand-file-name file))
("\\.pdf\\'" . default))
org-tab-before-tab-emulation-hook '(org-tempo-complete-tag)
org-export-with-sub-superscripts nil
org-return-follows-link t
org-latex-format-headline-function 'org-latex-format-headline-default-function
org-default-notes-file "/home/drunkard/Plans/Home/notes.org"
org-after-todo-state-change-hook '(org-clock-out-if-current)
org-latex-format-drawer-function #[514 "\207" [] 3 "\n\n(fn _ CONTENTS)"]
org-odt-format-headline-function 'org-odt-format-headline-default-function
org-src-mode-hook '(org-src-babel-configure-edit-buffer
org-src-mode-configure-edit-buffer)
org-agenda-before-write-hook '(org-agenda-add-entry-text)
org-babel-pre-tangle-hook '(save-buffer)