Add temporary fix for Org alignment of links to headlines

When a headline ends on a closing bracket, Org adds an escape character
to the link text to distinguish the end of the link from the link
description.  This escape character is a zero-width space, which is
counted for Org table alignment as one character, but the link itself is
displayed shorter, because the zero-width character is displayed as a
single pixel by emacs.

To work around this issue until the upstream fix is released, let's add
a final non-breaking space to those link descriptions to avoid the need
for the zero-width escape characters.
This commit is contained in:
Daniel Borchmann 2024-08-05 17:45:10 +02:00
parent 726f1baf8c
commit 40bafe78ce
No known key found for this signature in database
GPG Key ID: 784AA8DF0CCDF625

18
init.el
View File

@ -890,7 +890,23 @@ quickly loose their meaning."
(org-trim (org-trim
(replace-regexp-in-string (replace-regexp-in-string
"\\[[0-9]*%\\]\\|\\[[0-9]+/[0-9]+\\]\\|\\[/\\]" "" "\\[[0-9]*%\\]\\|\\[[0-9]+/[0-9]+\\]\\|\\[/\\]" ""
description))))))) description)))))
(define-advice org-link-make-string (:around
(orig-func link &optional description)
db/org--add-final-nbsp-to-fix-table-alignment)
"Add final non-breaking space to DESCRIPTION when ending on a closing bracket.
This is to fix the current alignment of Org tables, which counts
a zero-width character, which is used to escape the end of an Org
link, as one character but does not adjust the width of the table
accordingly."
(funcall orig-func
link
(if (and description
(string-match "\\]$" description))
(concat description " ")
description)))))
(use-package ol-bbdb (use-package ol-bbdb
:config (add-to-list 'org-bbdb-anniversary-format-alist :config (add-to-list 'org-bbdb-anniversary-format-alist