Browse Source

org.el: New command `org-set-property-and-value' bound to `C-c C-x P'

* org.el (org-last-set-property-value): New variable.
(org-read-property-name): Fix dangling parentheses.
(org-set-property-and-value): New command to manually set
both the property and the value.  A prefix arg will use the
last property-value pair set without prompting the user.
(org-set-property): Set `org-last-set-property-value'.
(org-mode-map): Bind the new command to `C-c C-x P'.

This is useful when you need to set the same property-value
pair for several entries.
Bastien Guerry 8 years ago
1 changed files with 21 additions and 2 deletions
  1. 21 2

+ 21 - 2

@@ -15083,6 +15083,7 @@ This is computed according to `org-property-set-functions-alist'."
 (defvar org-last-set-property nil)
+(defvar org-last-set-property-value nil)
 (defun org-read-property-name ()
   "Read a property name."
   (let* ((completion-ignore-case t)
@@ -15100,8 +15101,7 @@ This is computed according to `org-property-set-functions-alist'."
 			    ": ")
 		    (mapcar 'list keys)
 		    nil nil nil nil
-		    default-prop
-		    )))
+		    default-prop)))
     (if (member property keys)
       (or (cdr (assoc (downcase property)
@@ -15109,6 +15109,23 @@ This is computed according to `org-property-set-functions-alist'."
+(defun org-set-property-and-value (use-last)
+  "Allow to set [PROPERTY]: [value] direction from prompt.
+When use-default, don't even ask, just use the last
+\"[PROPERTY]: [value]\" string from the history."
+  (interactive "P")
+  (let* ((completion-ignore-case t)
+	 (pv (or (and use-last org-last-set-property-value)
+		 (org-completing-read
+		  "Enter a \"[Property]: [value]\" pair: "
+		  nil nil nil nil nil
+		  org-last-set-property-value)))
+	 prop val)
+    (when (string-match "^[ \t]*\\([^:]+\\):[ \t]*\\(.*\\)[ \t]*$" pv)
+      (setq prop (match-string 1 pv)
+	    val (match-string 2 pv))
+      (org-set-property prop val))))
 (defun org-set-property (property value)
   "In the current entry, set PROPERTY to VALUE.
 When called interactively, this will prompt for a property name, offering
@@ -15121,6 +15138,7 @@ in the current file."
 	 (value (or value (org-read-property-value property)))
 	 (fn (cdr (assoc property org-properties-postprocess-alist))))
     (setq org-last-set-property property)
+    (setq org-last-set-property-value (concat property ": " value))
     ;; Possibly postprocess the inserted value:
     (when fn (setq value (funcall fn value)))
     (unless (equal (org-entry-get nil property) value)
@@ -18392,6 +18410,7 @@ BEG and END default to the buffer boundaries."
 (org-defkey org-mode-map "\C-c\C-x\\"   'org-toggle-pretty-entities)
 (org-defkey org-mode-map "\C-c\C-x\C-b" 'org-toggle-checkbox)
 (org-defkey org-mode-map "\C-c\C-xp"    'org-set-property)
+(org-defkey org-mode-map "\C-c\C-xP"    'org-set-property-and-value)
 (org-defkey org-mode-map "\C-c\C-xe"    'org-set-effort)
 (org-defkey org-mode-map "\C-c\C-xE"    'org-inc-effort)
 (org-defkey org-mode-map "\C-c\C-xo"    'org-toggle-ordered-property)