branch: externals/org
commit fb931b1b8216beac77da86ed2812b0175d55ba4c
Author: Rudolf Adamkovič <[email protected]>
Commit: Ihor Radchenko <[email protected]>

    ol-bbdb: Pre-populate the description for BBDB links
    
    * etc/ORG-NEWS (Add completion for ID links): Announce the feature in
    the Miscellaneous section.
    * lisp/ol-bbdb.el ("bbdb"): Plug the new `org-bbdb-describe-link'
    function into the Org Link machinery.
    (org-bbdb-complete-link): Re-capitalize "BBDB" per the Boy Scout Rule.
    (org-bbdb-describe-link): Add a function that computes the default
    description for BBDB links.
    * testing/lisp/test-ol-bbdb.el (test-org-bbdb-describe-link): Test the
    newly added function.
---
 etc/ORG-NEWS                 | 5 +++++
 lisp/ol-bbdb.el              | 9 ++++++++-
 testing/lisp/test-ol-bbdb.el | 7 +++++++
 3 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 3cfc2b011d..9113e68ea0 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -818,6 +818,11 @@ known to contain headlines with IDs.  You can use new 
option
 ~org-id-completion-targets~ to change where the candidates are
 searched.
 
+*** Pre-populate the description for BBDB links
+
+When inserting BBDB links, use the full name as the default link
+description, instead of nothing.
+
 * Version 9.7
 
 ** Important announcements and breaking changes
diff --git a/lisp/ol-bbdb.el b/lisp/ol-bbdb.el
index b01c6d7013..30fef2be3b 100644
--- a/lisp/ol-bbdb.el
+++ b/lisp/ol-bbdb.el
@@ -221,6 +221,7 @@ date year)."
                         :follow #'org-bbdb-open
                         :export #'org-bbdb-export
                         :complete #'org-bbdb-complete-link
+                         :insert-description #'org-bbdb-describe-link
                         :store #'org-bbdb-store-link)
 
 ;;; Implementation
@@ -498,7 +499,7 @@ must be positive"))
              dates)))))
 
 (defun org-bbdb-complete-link ()
-  "Read a bbdb link with name completion."
+  "Read a BBDB link with name completion."
   (org-require-package 'bbdb-com "bbdb")
   (let ((rec (bbdb-completing-read-record "Name: ")))
     (concat "bbdb:"
@@ -506,6 +507,12 @@ must be positive"))
                                  (car rec)
                                rec)))))
 
+(defun org-bbdb-describe-link (link desc)
+  "Return a description for a BBDB link."
+  (or (org-string-nw-p desc)
+      (if (string-prefix-p "bbdb:" link)
+          (string-remove-prefix "bbdb:" link))))
+
 (defun org-bbdb-anniv-export-ical ()
   "Extract anniversaries from BBDB and convert them to icalendar format."
   (org-require-package 'bbdb)
diff --git a/testing/lisp/test-ol-bbdb.el b/testing/lisp/test-ol-bbdb.el
index 25f6c22e03..5a7c50d32b 100644
--- a/testing/lisp/test-ol-bbdb.el
+++ b/testing/lisp/test-ol-bbdb.el
@@ -31,6 +31,13 @@
   (should (equal '(9 22 2018) (org-bbdb-anniv-extract-date "2018-09-22")))
   (should (equal '(9 22 nil) (org-bbdb-anniv-extract-date "09-22"))))
 
+(ert-deftest test-org-bbdb-describe-link ()
+  (should (equal (org-bbdb-describe-link "bbdb:Richard Stallman" "RMS")
+                 "RMS"))
+  (should (equal (org-bbdb-describe-link "bbdb:Richard Stallman" "")
+                 "Richard Stallman"))
+  (should-not (org-bbdb-describe-link "https://example.com"; "")))
+
 (provide 'test-ol-bbdb)
 
 ;;; test-org-bbdb.el ends here

Reply via email to