From: Reuben Thomas <rrt@sc3d.org>
To: emacs-orgmode@gnu.org
Subject: Bug: Fix for org-make-link-description-function use in org-insert-link [9.0.10 (9.0.10-5-g1654a5-elpa @ /home/rrt/.emacs.d/elpa/org-20170904/)]
Date: Tue, 05 Sep 2017 17:27:24 +0100 [thread overview]
Message-ID: <874lsh5cwj.fsf@sc3d.org> (raw)
Remember to cover the basics, that is, what you expected to happen and
what in fact did happen. You don't know how to make a good report? See
http://orgmode.org/manual/Feedback.html#Feedback
Your bug report will be posted to the Org mailing list.
------------------------------------------------------------------------
I was trying to make link descriptions default to the link. This is
useful so that, for example, in LaTeX export, links without a
description do not turn into empty text if one has unnumbered sections.
Also, it’s useful if one is primarily using PDF output, with hyperlinks.
I used the following code:
(defun org-make-link-description (link desc)
(or desc link))
(setq org-make-link-description-function #'org-make-link-description)
This works; however, no description is prompted for (the description is
*always* the default).
This seems to be incorrect behaviour, as the docstring for
org-insert-link says:
If `org-make-link-description-function' is non-nil, this function will be
called with the link target, and the result will be the default
link description.
The implication is that the value returned is used as the default, not
that it overrides the prompt.
The current logic dates from commit d9e5aed2, which aims to fix a
previous bug where the prompt was not offered if
org-make-link-description-function failed. The commit message implies
that the prompt should not be offered if
org-make-link-description-function succeeds, but I believe that is
wrong.
Below is a patch which both corrects the behaviour and simplifies the
logic.
First, org-make-link-description-function is called if it is non-nil,
and used to set default-description.
Then (unless auto-desc is non-nil) the description is prompted for with
default-description as the default value (unless
org-make-link-description-function returned nil, in which case the
current value of desc, if any, is used).
There is one further matter that my patch does not address: the
docstring for org-make-link-description-function says:
“When [org-make-link-description-function is] nil, the link location
will be used.”
This does not happen (it’s precisely the behaviour I’ve been trying to
obtain!), and my patch does not make it happen. Indeed, it’s not clear
that it’s desirable (if one is using numbered sections, for example).
Patch follows:
Subject: [PATCH] Fix logic of calling org-make-link-desciption-function
* lisp/org.el (org-insert-link): Simplify so that description is only
prompted for once, and org-make-link-description-function obviously
sets the default description, as per the docstring. Then, always
prompt for the description, even if the default is set.
---
lisp/org.el | 19 +++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)
diff --git a/lisp/org.el b/lisp/org.el
index 2680cee..0731cf7 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -10286,16 +10286,15 @@ Use TAB to complete link prefixes, then RET for type-specific completion support
(setq desc path)))))
(if org-make-link-description-function
- (setq desc
- (or (condition-case nil
- (funcall org-make-link-description-function link desc)
- (error (progn (message "Can't get link description from `%s'"
- (symbol-name org-make-link-description-function))
- (sit-for 2) nil)))
- (read-string "Description: " default-description)))
- (if default-description (setq desc default-description)
- (setq desc (or (and auto-desc desc)
- (read-string "Description: " desc)))))
+ (setq default-description
+ (condition-case nil
+ (funcall org-make-link-description-function link desc)
+ (error (progn (message "Can't get link description from `%s'"
+ (symbol-name org-make-link-description-function))
+ (sit-for 2) nil)))))
+
+ (setq desc (or (and auto-desc desc)
+ (read-string "Description: " (or default-description desc))))
(unless (string-match "\\S-" desc) (setq desc nil))
(when remove (apply 'delete-region remove))
--
2.7.4
Emacs : GNU Emacs 25.2.1 (x86_64-pc-linux-gnu, GTK+ Version 3.18.9)
of 2017-04-29
Package: Org mode version 9.0.10 (9.0.10-5-g1654a5-elpa @ /home/rrt/.emacs.d/elpa/org-20170904/)
current state:
==============
(setq
org-tab-first-hook '(org-babel-hide-result-toggle-maybe org-babel-header-arg-expand)
org-latex-classes '(("article" "\\documentclass[11pt]{article}" ("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}") ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
("\\paragraph{%s}" . "\\paragraph*{%s}") ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
("report" "\\documentclass[11pt]{report}" ("\\part{%s}" . "\\part*{%s}")
("\\chapter{%s}" . "\\chapter*{%s}") ("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}") ("\\subsubsection{%s}" . "\\subsubsection*{%s}"))
("book" "\\documentclass[11pt]{book}" ("\\part{%s}" . "\\part*{%s}")
("\\chapter{%s}" . "\\chapter*{%s}") ("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}") ("\\subsubsection{%s}" . "\\subsubsection*{%s}"))
("scrartcl" "\\documentclass{scrartcl}" ("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}") ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
("\\paragraph{%s}" . "\\paragraph*{%s}") ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
)
org-latex-default-packages-alist '(("postscript" "ucs" nil) ("" "pifont" nil) ("utf8x" "inputenc" t) ("T1" "fontenc" t)
("" "fixltx2e" nil) ("" "graphicx" t) ("" "longtable" nil) ("" "float" nil)
("" "wrapfig" nil) ("" "rotating" nil) ("normalem" "ulem" t) ("" "amsmath" t)
("" "textcomp" t) ("" "marvosym" t) ("" "wasysym" t) ("" "amssymb" t)
("" "hyperref" nil) "\\tolerance=1000" ("" "palatino" nil))
org-texinfo-format-drawer-function #[514 "\207" [] 3 "\n\n(fn NAME CONTENTS)"]
org-speed-command-hook '(org-speed-command-default-hook org-babel-speed-command-hook)
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-ascii-format-inlinetask-function 'org-ascii-format-inlinetask-default
org-startup-folded nil
org-export-with-section-numbers nil
org-file-apps '((t . "xdg-open %s") (system . "xdg-open %s"))
org-export-with-toc nil
org-latex-format-headline-function 'org-latex-format-headline-default-function
org-default-notes-file "~/Notes/Notes.org"
org-startup-indented t
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-from-is-user-regexp "\\<Reuben Thomas\\>"
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-mode-hook '((lambda nil (local-set-key "\351" (quote org-toggle-iimage-in-org))) window-margin-mode
#[0 "\300\301\302\303\304$\207" [add-hook change-major-mode-hook org-show-block-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 turn-on-eldoc-mode)
org-texinfo-format-headline-function 'org-texinfo-format-headline-default-function
org-archive-hook '(org-attach-archive-delete-maybe)
org-make-link-description-function 'org-make-link-description
org-ascii-format-drawer-function #[771 "\207" [] 4 "\n\n(fn NAME CONTENTS WIDTH)"]
org-odt-format-inlinetask-function 'org-odt-format-inlinetask-default-function
org-directory "~/Notes"
org-cycle-hook '(org-cycle-hide-archived-subtrees org-cycle-hide-drawers org-cycle-show-empty-lines
org-optimize-window-after-visibility-change)
org-footnote-define-inline t
org-confirm-elisp-link-function 'yes-or-no-p
org-metadown-hook '(org-babel-pop-to-session-maybe)
org-odt-format-drawer-function #[514 "\207" [] 3 "\n\n(fn NAME CONTENTS)"]
org-latex-default-class "scrartcl"
org-html-format-headline-function 'org-html-format-headline-default-function
org-link-parameters '(("id" :follow org-id-open) ("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)
("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) ("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))))
("message" :follow (lambda (path) (browse-url (concat "message:" path))))
("news" :follow (lambda (path) (browse-url (concat "news:" path))))
("shell" :follow org--open-shell-link))
org-footnote-auto-label nil
org-html-format-inlinetask-function 'org-html-format-inlinetask-default-function
org-agenda-files '("~/Writing/Ithaky/Calendar.org")
org-texinfo-format-inlinetask-function 'org-texinfo-format-inlinetask-default-function
org-clock-out-hook '(org-clock-remove-empty-clock-drawer)
org-latex-inputenc-alist '(("utf8" . "utf8x"))
)
--
http://rrt.sc3d.org/
next reply other threads:[~2017-09-05 16:27 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-05 16:27 Reuben Thomas [this message]
2017-09-05 20:49 ` Bug: Fix for org-make-link-description-function use in org-insert-link [9.0.10 (9.0.10-5-g1654a5-elpa @ /home/rrt/.emacs.d/elpa/org-20170904/)] Nicolas Goaziou
2017-09-05 21:05 ` Reuben Thomas
2017-09-05 22:02 ` Nicolas Goaziou
2017-09-07 23:06 ` Reuben Thomas
2017-09-08 5:00 ` Nicolas Goaziou
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=874lsh5cwj.fsf@sc3d.org \
--to=rrt@sc3d.org \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.