emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Bug: Prevent fill-paragraph from breaking inside Org mode links [9.1.9 (release_9.1.9-580-g39837b @ /home/drunkard/emacs_lisp_imported/org-mode/org-mode/lisp/)]
@ 2018-04-08 15:51 Brent Goodrick
  2018-04-08 16:43 ` Nicolas Goaziou
  0 siblings, 1 reply; 3+ messages in thread
From: Brent Goodrick @ 2018-04-08 15:51 UTC (permalink / raw)
  To: emacs-orgmode


------------------------------------------------------------------------

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)
 org-html-head-include-default-style nil
 org-mode-hook '(org-tempo-setup org-clock-load bg-org-mode-hook
		 #[0 "\300\301\302\303\304$\207" [add-hook change-major-mode-hook org-show-all append local] 5]
		 #[0 "\300\301\302\303\304$\207" [add-hook change-major-mode-hook org-babel-show-result-all append local] 5]
		 org-babel-result-hide-spec org-babel-hide-all-hashes)
 org-refile-targets '((nil :maxlevel . 9) (org-agenda-files :maxlevel . 9))
 org-bibtex-headline-format-function #[257 "\300\x01\236A\207" [:title] 3 "\n\n(fn ENTRY)"]
 org-archive-hook '(org-attach-archive-delete-maybe)
 org-ascii-format-drawer-function #[771 "\x01\207" [] 4 "\n\n(fn NAME CONTENTS WIDTH)"]
 org-odt-format-inlinetask-function 'org-odt-format-inlinetask-default-function
 org-clock-persist t
 org-refile-use-outline-path 'file
 org-directory "/home/drunkard/Plans/Home"
 org-cycle-hook '(org-cycle-hide-archived-subtrees org-cycle-show-empty-lines org-optimize-window-after-visibility-change)
 org-plantuml-jar-path "/home/drunkard/plantuml/plantuml.jar"
 org-edit-src-auto-save-idle-delay 5
 org-todo-keywords '((sequence "TODO(t)" "|" "DONE(d)" "SHELVED(s)" "DELEGATED(e)"))
 org-babel-tangle-lang-exts '(("python" . "py") ("emacs-lisp" . "el") ("elisp" . "el"))
 org-confirm-elisp-link-function 'bg-org-confirm-elisp-link
 org-html-htmlize-output-type 'css
 org-metadown-hook '(org-babel-pop-to-session-maybe)
 outline-mode-hook '((lambda nil (require (quote outline-magic))))
 org-odt-format-drawer-function #[514 "\207" [] 3 "\n\n(fn NAME CONTENTS)"]
 org-babel-after-execute-hook '(bg-org-babel-after-execute-hook)
 org-html-format-headline-function 'org-html-format-headline-default-function
 org-link-parameters '(("rmail" :follow org-rmail-open :store org-rmail-store-link)
		       ("mhe" :follow org-mhe-open :store org-mhe-store-link)
		       ("irc" :follow org-irc-visit :store org-irc-store-link :export org-irc-export)
		       ("info" :follow org-info-open :export org-info-export :store org-info-store-link)
		       ("gnus" :follow org-gnus-open :store org-gnus-store-link)
		       ("docview" :follow org-docview-open :export org-docview-export :store org-docview-store-link)
		       ("bibtex" :follow org-bibtex-open :store org-bibtex-store-link)
		       ("bbdb" :follow org-bbdb-open :export org-bbdb-export :complete org-bbdb-complete-link :store org-bbdb-store-link)
		       ("w3m" :store org-w3m-store-link) ("id" :follow org-id-open) ("file+sys") ("file+emacs")
		       ("doi" :follow org--open-doi-link) ("elisp" :follow org--open-elisp-link)
		       ("file" :complete org-file-complete-link) ("ftp" :follow (lambda (path) (browse-url (concat "ftp:" path))))
		       ("help" :follow org--open-help-link) ("http" :follow (lambda (path) (browse-url (concat "http:" path))))
		       ("https" :follow (lambda (path) (browse-url (concat "https:" path))))
		       ("mailto" :follow (lambda (path) (browse-url (concat "mailto:" path))))
		       ("news" :follow (lambda (path) (browse-url (concat "news:" path)))) ("shell" :follow org--open-shell-link))
 org-babel-load-languages '((emacs-lisp . t) (python . t) (shell . t) (sqlite . t) (dot . t) (plantuml . t))
 org-clock-in-hook '(bg-org-clock-in-hook)
 org-html-format-inlinetask-function 'org-html-format-inlinetask-default-function
 org-agenda-files "/home/drunkard/Plans/Home/org-agenda-files-list-file.txt"
 org-clock-out-hook '(org-clock-remove-empty-clock-drawer)
 org-confirm-babel-evaluate 'bg-org-confirm-babel-evaluate
 org-export-headline-levels 100
 org-publish-project-alist '(("my-emacs-lisp-org" :base-directory "~/emacs_lisp/" :publishing-directory "~/public_html/emacs_lisp"
			      :recursive t :table-of-contents t :base-extension "org" :publishing-function org-html-publish-to-html
			      :style-include-default nil :section-numbers t :with-sub-superscript nil :html-head
			      "<link rel=\"stylesheet\" href=\"org.css\" type=\"text/css\" />" :author-info nil :creator-info nil)
			     ("my-emacs-lisp-extra" :base-directory "~/emacs_lisp/" :publishing-directory "~/public_html/emacs_lisp"
			      :base-extension "css\\|pdf\\|png\\|jpg\\|gif" :publishing-function org-publish-attachment :recursive t
			      :author nil)
			     ("my-emacs-lisp" :components ("my-emacs-lisp-org" "my-emacs-lisp-extra")))
 )

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

* Re: Bug: Prevent fill-paragraph from breaking inside Org mode links [9.1.9 (release_9.1.9-580-g39837b @ /home/drunkard/emacs_lisp_imported/org-mode/org-mode/lisp/)]
  2018-04-08 15:51 Bug: Prevent fill-paragraph from breaking inside Org mode links [9.1.9 (release_9.1.9-580-g39837b @ /home/drunkard/emacs_lisp_imported/org-mode/org-mode/lisp/)] Brent Goodrick
@ 2018-04-08 16:43 ` Nicolas Goaziou
  2018-04-09 19:29   ` Brent Goodrick
  0 siblings, 1 reply; 3+ messages in thread
From: Nicolas Goaziou @ 2018-04-08 16:43 UTC (permalink / raw)
  To: Brent Goodrick; +Cc: emacs-orgmode

Hello,

Brent Goodrick <bgoodr@gmail.com> writes:

> First, it may be a separate "bug" that org-return cannot recognize the
> multi-line Org link.

Fixed. Thank you.

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

I disagree. Link descriptions can be arbitrarily long and Org should be
able to fill them. We could improve the fontification, however (e.g.,
not using link face on blanks at the beginning of a line).

> 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

I think this is the way to go: prevent filling in your own config.


Regards,

-- 
Nicolas Goaziou

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

* Re: Bug: Prevent fill-paragraph from breaking inside Org mode links [9.1.9 (release_9.1.9-580-g39837b @ /home/drunkard/emacs_lisp_imported/org-mode/org-mode/lisp/)]
  2018-04-08 16:43 ` Nicolas Goaziou
@ 2018-04-09 19:29   ` Brent Goodrick
  0 siblings, 0 replies; 3+ messages in thread
From: Brent Goodrick @ 2018-04-09 19:29 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1015 bytes --]

Hi Nicolas,

All of that sounds reasonable.  Thanks for the reply.

-Brent



On Sun, Apr 8, 2018, 9:43 AM Nicolas Goaziou <mail@nicolasgoaziou.fr> wrote:

> Hello,
>
> Brent Goodrick <bgoodr@gmail.com> writes:
>
> > First, it may be a separate "bug" that org-return cannot recognize the
> > multi-line Org link.
>
> Fixed. Thank you.
>
> > 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.
>
> I disagree. Link descriptions can be arbitrarily long and Org should be
> able to fill them. We could improve the fontification, however (e.g.,
> not using link face on blanks at the beginning of a line).
>
> > 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
>
> I think this is the way to go: prevent filling in your own config.
>
>
> Regards,
>
> --
> Nicolas Goaziou
>

[-- Attachment #2: Type: text/html, Size: 1621 bytes --]

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

end of thread, other threads:[~2018-04-09 19:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-04-08 15:51 Bug: Prevent fill-paragraph from breaking inside Org mode links [9.1.9 (release_9.1.9-580-g39837b @ /home/drunkard/emacs_lisp_imported/org-mode/org-mode/lisp/)] Brent Goodrick
2018-04-08 16:43 ` Nicolas Goaziou
2018-04-09 19:29   ` Brent Goodrick

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

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