Prechádzať zdrojové kódy

Introduce a way to set a property to undefined.

* lisp/org-macs.el (org-not-nil): Return the value if not interpreted
as nil.
* lisp/org.el (org-entry-get):
(org-entry-get-with-inheritance): Interpret the value "nil"
as nil for properties.

Bernt Hansen writes:

> Carsten Dominik <carsten.dominik@gmail.com> writes:
>
> > On Jun 25, 2010, at 3:23 PM, Robert Goldman wrote:
> >
> > > Question:  what is the proper way to get a NIL into a property?  Are
> > > we
> > > to use () instead of "nil"?  Or are property values always interpreted
> > > as strings?
> > >
> > > Apologies in advance if this is a stupid question!
> >
> > Not a stupid question at all.
> >
> > There is no way, currently.   Property values are string - the only
> > way to make
> > org-entry-get return nil is to not have the property defined at all.
>
> I've wanted a similar thing in the past for the LOGGING property where
> the parent task has special logging set via the LOGGING property but I
> want to undo that for some of the child tasks so they use the default
> logging setup.
>
> Having a way to undefine a property would be good in general I think.

-Bernt
Carsten Dominik 15 rokov pred
rodič
commit
bcb7f7f1ef
2 zmenil súbory, kde vykonal 18 pridanie a 10 odobranie
  1. 3 2
      lisp/org-macs.el
  2. 15 8
      lisp/org.el

+ 3 - 2
lisp/org-macs.el

@@ -44,8 +44,9 @@
   `(and (boundp (quote ,var)) ,var))
   `(and (boundp (quote ,var)) ,var))
 
 
 (defun org-not-nil (v)
 (defun org-not-nil (v)
-  "Is V not nil, and also not the string \"nil\"?"
-  (and v (not (equal v "nil"))))
+  "If V not nil, and also not the string \"nil\", then return V.
+Otherwise return nil."
+  (and v (not (equal v "nil")) v))
 
 
 (defmacro org-unmodified (&rest body)
 (defmacro org-unmodified (&rest body)
   "Execute body without changing `buffer-modified-p'.
   "Execute body without changing `buffer-modified-p'.

+ 15 - 8
lisp/org.el

@@ -13352,14 +13352,18 @@ things up because then unnecessary parsing is avoided."
 	    (push (cons "CATEGORY" value) props))
 	    (push (cons "CATEGORY" value) props))
 	  (append sum-props (nreverse props)))))))
 	  (append sum-props (nreverse props)))))))
 
 
-(defun org-entry-get (pom property &optional inherit)
+(defun org-entry-get (pom property &optional inherit literal-nil)
   "Get value of PROPERTY for entry at point-or-marker POM.
   "Get value of PROPERTY for entry at point-or-marker POM.
 If INHERIT is non-nil and the entry does not have the property,
 If INHERIT is non-nil and the entry does not have the property,
 then also check higher levels of the hierarchy.
 then also check higher levels of the hierarchy.
 If INHERIT is the symbol `selective', use inheritance only if the setting
 If INHERIT is the symbol `selective', use inheritance only if the setting
 in `org-use-property-inheritance' selects PROPERTY for inheritance.
 in `org-use-property-inheritance' selects PROPERTY for inheritance.
 If the property is present but empty, the return value is the empty string.
 If the property is present but empty, the return value is the empty string.
-If the property is not present at all, nil is returned."
+If the property is not present at all, nil is returned.
+
+If LITERAL-NIL is set, return the string value \"nil\" as a string,
+do not interpret it as the list atom nil.  This is used for inheritance
+when a \"nil\" value can supercede a non-nil value higher up the hierarchy."
   (org-with-point-at pom
   (org-with-point-at pom
     (if (and inherit (if (eq inherit 'selective)
     (if (and inherit (if (eq inherit 'selective)
 			 (org-property-inherit-p property)
 			 (org-property-inherit-p property)
@@ -13377,7 +13381,9 @@ If the property is not present at all, nil is returned."
 		    (cdr range) t))
 		    (cdr range) t))
 	      ;; Found the property, return it.
 	      ;; Found the property, return it.
 	      (if (match-end 1)
 	      (if (match-end 1)
-		  (org-match-string-no-properties 1)
+		  (if literal-nil
+		      (org-match-string-no-properties 1)
+		    (org-not-nil (org-match-string-no-properties 1)))
 		"")))))))
 		"")))))))
 
 
 (defun org-property-or-variable-value (var &optional inherit)
 (defun org-property-or-variable-value (var &optional inherit)
@@ -13481,15 +13487,16 @@ is set.")
 	(widen)
 	(widen)
 	(catch 'ex
 	(catch 'ex
 	  (while t
 	  (while t
-	    (when (setq tmp (org-entry-get nil property))
+	    (when (setq tmp (org-entry-get nil property nil 'literal-nil))
 	      (org-back-to-heading t)
 	      (org-back-to-heading t)
 	      (move-marker org-entry-property-inherited-from (point))
 	      (move-marker org-entry-property-inherited-from (point))
 	      (throw 'ex tmp))
 	      (throw 'ex tmp))
 	    (or (org-up-heading-safe) (throw 'ex nil)))))
 	    (or (org-up-heading-safe) (throw 'ex nil)))))
-      (or tmp
-	  (cdr (assoc property org-file-properties))
-	  (cdr (assoc property org-global-properties))
-	  (cdr (assoc property org-global-properties-fixed))))))
+      (org-not-nil
+       (or tmp
+	   (cdr (assoc property org-file-properties))
+	   (cdr (assoc property org-global-properties))
+	   (cdr (assoc property org-global-properties-fixed)))))))
 
 
 (defvar org-property-changed-functions nil
 (defvar org-property-changed-functions nil
   "Hook called when the value of a property has changed.
   "Hook called when the value of a property has changed.