emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nick Dokos <ndokos@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: [PATCH] org: add property names from #+PROPERTY keywords to completion list
Date: Tue, 07 Jul 2020 12:48:26 -0400	[thread overview]
Message-ID: <87y2nvw9t1.fsf@alphaville.usersys.redhat.com> (raw)
In-Reply-To: <87v9j054ya.fsf@kyleam.com>

Here's the amended patch: it includes the fixes from Kyle's review, the modification
he suggested that adds the plain property for each _ALL property to the list
and a few test cases to the test/org-buffer-property-keys test.

--8<---------------cut here---------------start------------->8---
From 60b9ababe42c91ec6fcd2c53f6923d75daa12454 Mon Sep 17 00:00:00 2001
From: Nick Dokos <ndokos@redhat.com>
Date: Mon, 6 Jul 2020 21:49:41 -0400
Subject: [PATCH] org: add property names from #+PROPERTY keywords to
 completion list

* lisp/org.el (org-buffer-property-keys): Enhance the completion list
with property names from #+PROPERTY keywords, not just property
drawers. Also, for each xxx_ALL property, make sure that the bare xxx
property is added too.

* testing/lisp/test-org.el (test-org/buffer-property-keys): Add test
cases for #+PROPERTY keywords and also for xxx_ALL --> xxx properties.

See https://emacs.stackexchange.com/questions/59448/ for details.
 lisp/org.el              | 17 +++++++++++++++--
 testing/lisp/test-org.el | 21 +++++++++++++++++++++
 2 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 4a1a83d0f..ccdb0dd5c 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -13084,7 +13084,12 @@ COLUMN formats in the current buffer."
 	(props (append
 		(and specials org-special-properties)
 		(and defaults (cons org-effort-property org-default-properties))
-		nil)))
+		;; Get property names from #+PROPERTY keywords as well
+		(mapcar (lambda (s)
+			  (nth 0 (split-string s)))
+			(cdar (org-collect-keywords '("PROPERTY"))))
+		nil))
+	bare-props)
      (goto-char (point-min))
      (while (re-search-forward org-property-start-re nil t)
@@ -13132,7 +13137,15 @@ COLUMN formats in the current buffer."
 		 (let ((p (match-string-no-properties 1 value)))
 		   (unless (member-ignore-case p org-special-properties)
 		     (push p props))))))))))
-    (sort (delete-dups props) (lambda (a b) (string< (upcase a) (upcase b))))))
+    (sort (delete-dups (append props
+			       ;; for each xxx_ALL property, make sure
+			       ;; the bare xxx property is also
+			       ;; included
+			       (dolist (x props bare-props)
+				 (if (string-match "_ALL\\b" x)
+				     (setq bare-props (cons (substring x 0 -4)
+							    bare-props))))))
+	  (lambda (a b) (string< (upcase a) (upcase b))))))
 (defun org-property-values (key)
   "List all non-nil values of property KEY in current buffer."
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index 30a8067db..61e642d4f 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -5409,6 +5409,27 @@ Paragraph<point>"
    (equal '("A")
 	  (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
+  ;; Add bare property if xxx_ALL property is there
+  (should
+   (equal '("A" "B" "B_ALL")
+	  (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:B_ALL: foo bar\n:END:"
+	    (org-buffer-property-keys))))
+  ;; Add bare property if xxx_ALL property is there - check dupes
+  (should
+   (equal '("A" "B" "B_ALL")
+	  (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:B_ALL: foo bar\n:END:"
+	    (org-buffer-property-keys))))
+  ;; Retrieve properties from #+PROPERTY keyword lines
+  (should
+   (equal '("A" "C")
+	  (org-test-with-temp-text "#+PROPERTY: C foo\n* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
+	    (org-buffer-property-keys))))
+  ;; Retrieve properties from #+PROPERTY keyword lines - make sure an _ALL property also
+  ;; adds the bare property
+  (should
+   (equal '("A" "C" "C_ALL")
+	  (org-test-with-temp-text "#+PROPERTY: C_ALL foo bar\n* H\n:PROPERTIES:\n:A: 1\n:A+: 2\n:END:"
+	    (org-buffer-property-keys))))
   ;; With non-nil COLUMNS, extract property names from columns.
    (equal '("A" "B")

--8<---------------cut here---------------end--------------->8---


"There are only two hard problems in computer science: cache
invalidation, naming things, and off-by-one errors." -Martin Fowler

  parent reply	other threads:[~2020-07-07 16:49 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-07  2:01 Nick Dokos
2020-07-07  2:40 ` Nick Dokos
2020-07-07  4:23 ` Kyle Meyer
2020-07-07 12:44   ` Nick Dokos
2020-07-07 13:38   ` Nick Dokos
2020-07-07 16:48   ` Nick Dokos [this message]
2020-07-08  3:52     ` Kyle Meyer
2020-07-08 15:47       ` Nick Dokos
2020-07-08 16:07       ` Nick Dokos
2020-07-09  4:36         ` [PATCH] agenda: Fold case when retrieving user-configured effort values Kyle Meyer
2020-07-09  7:50           ` Nick Dokos

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:

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87y2nvw9t1.fsf@alphaville.usersys.redhat.com \
    --to=ndokos@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --subject='Re: [PATCH] org: add property names from #+PROPERTY keywords to completion list' \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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


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