Prechádzať zdrojové kódy

New hooks for external support for allowed property values

Carsten Dominik 15 rokov pred
rodič
commit
cfb2550bba
2 zmenil súbory, kde vykonal 25 pridanie a 3 odobranie
  1. 5 0
      lisp/ChangeLog
  2. 20 3
      lisp/org.el

+ 5 - 0
lisp/ChangeLog

@@ -1,6 +1,11 @@
 2009-12-11  Carsten Dominik  <carsten.dominik@gmail.com>
 
 	* org.el (org-startup-with-beamer-mode): New option.
+	(org-property-changed-functions)
+	(org-property-allowed-value-functions): New hooks.
+	(org-entry-put, org-property-get-allowed-values): Run the new
+	hooks.
+	(org-property-next-allowed-value): Run the new hooks.
 
 	* org-exp.el (org-export-select-backend-specific-text): Add the
 	special beamer tags.

+ 20 - 3
lisp/org.el

@@ -12564,6 +12564,11 @@ is set.")
 	  (cdr (assoc property org-global-properties))
 	  (cdr (assoc property org-global-properties-fixed))))))
 
+(defvar org-property-changed-functions nil
+  "Hook called when the value of a property has changed.
+Each hook function should accept two arguments, the name of the property
+and the new value.")
+
 (defun org-entry-put (pom property value)
   "Set PROPERTY to VALUE for entry at point-or-marker POM."
   (org-with-point-at pom
@@ -12616,7 +12621,8 @@ is set.")
 	    (org-indent-line-function)
 	    (insert ":" property ":"))
 	  (and value (insert " " value))
-	  (org-indent-line-function)))))))
+	  (org-indent-line-function)))))
+    (run-hook-with-args 'org-property-changed-functions property value)))
 
 (defun org-buffer-property-keys (&optional include-specials include-defaults include-columns)
   "Get all property keys in the current buffer.
@@ -12799,6 +12805,15 @@ then applies it to the property in the column format's scope."
       (error "No operator defined for property %s" prop))
     (org-columns-compute prop)))
 
+(defvar org-property-allowed-value-functions nil
+  "Hook for functions supplying allowed values for specific.
+The functions must take a single argument, the name of the property, and
+return a flat list of allowed values.  If \":ETC\" is one of
+the values, this means that these values are intended as defaults for
+completion, but that other values should be allowed too.
+The functions must return nil if they are now responsible for this
+prioerty.")
+
 (defun org-property-get-allowed-values (pom property &optional table)
   "Get allowed values for the property PROPERTY.
 When TABLE is non-nil, return an alist that can directly be used for
@@ -12814,9 +12829,10 @@ completion."
 	  (push (char-to-string n) vals)
 	  (setq n (1- n)))))
      ((member property org-special-properties))
+     ((setq vals (run-hook-with-args-until-success
+		  'org-property-allowed-value-functions property)))
      (t
       (setq vals (org-entry-get pom (concat property "_ALL") 'inherit))
-
       (when (and vals (string-match "\\S-" vals))
 	(setq vals (car (read-from-string (concat "(" vals ")"))))
 	(setq vals (mapcar (lambda (x)
@@ -12858,7 +12874,8 @@ completion."
     (replace-match (concat " :" key ": " nval) t t)
     (org-indent-line-function)
     (beginning-of-line 1)
-    (skip-chars-forward " \t")))
+    (skip-chars-forward " \t")
+    (run-hook-with-args 'org-property-changed-functions key nval)))
 
 (defun org-find-entry-with-id (ident)
   "Locate the entry that contains the ID property with exact value IDENT.