From mboxrd@z Thu Jan 1 00:00:00 1970 From: Reuben Thomas 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 Message-ID: <874lsh5cwj.fsf@sc3d.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:49527) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dpGhL-0004Mn-0w for emacs-orgmode@gnu.org; Tue, 05 Sep 2017 12:27:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dpGhF-0005gq-0M for emacs-orgmode@gnu.org; Tue, 05 Sep 2017 12:27:35 -0400 Received: from mail-wr0-x22c.google.com ([2a00:1450:400c:c0c::22c]:36050) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dpGhE-0005eK-Jo for emacs-orgmode@gnu.org; Tue, 05 Sep 2017 12:27:28 -0400 Received: by mail-wr0-x22c.google.com with SMTP id p14so7888023wrg.3 for ; Tue, 05 Sep 2017 09:27:27 -0700 (PDT) Received: from skwd ([2a02:c7d:51cb:c700:e269:95ff:fe68:9cf2]) by smtp.gmail.com with ESMTPSA id e186sm1052333wma.3.2017.09.05.09.27.24 for (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 05 Sep 2017 09:27:24 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org 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=E2=80=99s useful if one is primarily using PDF output, with hyperl= inks. 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: =E2=80=9CWhen [org-make-link-description-function is] nil, the link location will be used.=E2=80=9D This does not happen (it=E2=80=99s precisely the behaviour I=E2=80=99ve bee= n trying to obtain!), and my patch does not make it happen. Indeed, it=E2=80=99s not cl= ear that it=E2=80=99s 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 t= ype-specific completion support (setq desc path))))) =20 (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-descript= ion-function)) + (sit-for 2) nil))))) + + (setq desc (or (and auto-desc desc) + (read-string "Description: " (or default-description de= sc)))) =20 (unless (string-match "\\S-" desc) (setq desc nil)) (when remove (apply 'delete-region remove)) --=20 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: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D (setq org-tab-first-hook '(org-babel-hide-result-toggle-maybe org-babel-header-a= rg-expand) org-latex-classes '(("article" "\\documentclass[11pt]{article}" ("\\sectio= n{%s}" . "\\section*{%s}") ("\\subsection{%s}" . "\\subsection*{%s}") ("\\subsub= section{%s}" . "\\subsubsection*{%s}") ("\\paragraph{%s}" . "\\paragraph*{%s}") ("\\subparag= raph{%s}" . "\\subparagraph*{%s}")) ("report" "\\documentclass[11pt]{report}" ("\\part{%s}= " . "\\part*{%s}") ("\\chapter{%s}" . "\\chapter*{%s}") ("\\section{%s}"= . "\\section*{%s}") ("\\subsection{%s}" . "\\subsection*{%s}") ("\\subsub= section{%s}" . "\\subsubsection*{%s}")) ("book" "\\documentclass[11pt]{book}" ("\\part{%s}" . = "\\part*{%s}") ("\\chapter{%s}" . "\\chapter*{%s}") ("\\section{%s}"= . "\\section*{%s}") ("\\subsection{%s}" . "\\subsection*{%s}") ("\\subsub= section{%s}" . "\\subsubsection*{%s}")) ("scrartcl" "\\documentclass{scrartcl}" ("\\section{%s= }" . "\\section*{%s}") ("\\subsection{%s}" . "\\subsection*{%s}") ("\\subsub= section{%s}" . "\\subsubsection*{%s}") ("\\paragraph{%s}" . "\\paragraph*{%s}") ("\\subparag= raph{%s}" . "\\subparagraph*{%s}")) ) org-latex-default-packages-alist '(("postscript" "ucs" nil) ("" "pifont" n= il) ("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=3D1000= " ("" "palatino" nil)) org-texinfo-format-drawer-function #[514 "\207" [] 3 "\n\n(fn NAME CONTENT= S)"] org-speed-command-hook '(org-speed-command-default-hook org-babel-speed-co= mmand-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-func= tion 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 "\\" org-src-mode-hook '(org-src-babel-configure-edit-buffer org-src-mode-confi= gure-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-mod= e-hook org-show-block-all append local] 5] #[0 "\300\301\302\303\304$\207" [add-hook change-major-mod= e-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-func= tion org-directory "~/Notes" org-cycle-hook '(org-cycle-hide-archived-subtrees org-cycle-hide-drawers o= rg-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-functi= on org-link-parameters '(("id" :follow org-id-open) ("rmail" :follow org-rmai= l-open :store org-rmail-store-link) ("mhe" :follow org-mhe-open :store org-mhe-store-lin= k) ("irc" :follow org-irc-visit :store org-irc-store-li= nk) ("info" :follow org-info-open :export org-info-expor= t :store org-info-store-link) ("gnus" :follow org-gnus-open :store org-gnus-store-= link) ("docview" :follow org-docview-open :export org-docv= iew-export :store org-docview-store-link) ("bibtex" :follow org-bibtex-open :store org-bibtex-= store-link) ("bbdb" :follow org-bbdb-open :export org-bbdb-expor= t :complete org-bbdb-complete-link :store org-bbdb-store-link) ("w3m" :store org-w3m-store-link) ("file+sys") ("fil= e+emacs") ("doi" :follow org--open-doi-link) ("elisp" :follow org--open-elisp-link) ("file" :comp= lete org-file-complete-link) ("ftp" :follow (lambda (path) (browse-url (concat "f= tp:" 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 (conca= t "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-fu= nction org-agenda-files '("~/Writing/Ithaky/Calendar.org") org-texinfo-format-inlinetask-function 'org-texinfo-format-inlinetask-defa= ult-function org-clock-out-hook '(org-clock-remove-empty-clock-drawer) org-latex-inputenc-alist '(("utf8" . "utf8x")) ) --=20 http://rrt.sc3d.org/