From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Kitchin Subject: Re: Limiting properties and property values Date: Sun, 23 Feb 2020 08:37:34 -0500 Message-ID: References: <87sgj17ioa.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="0000000000001c42b7059f3e5cdd" Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:42939) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j5rSC-0006qm-UY for emacs-orgmode@gnu.org; Sun, 23 Feb 2020 08:37:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j5rSB-0001Mv-G3 for emacs-orgmode@gnu.org; Sun, 23 Feb 2020 08:37:52 -0500 In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane-mx.org@gnu.org Sender: "Emacs-orgmode" To: Vikas Rawal Cc: Bastien , org-mode mailing list --0000000000001c42b7059f3e5cdd Content-Type: text/plain; charset="UTF-8" One solution to this is a function you would write that validates the properties, and prevents saving if they are invalid. You would want to use it in a buffer/directory hook. For example: (defun validate-properties () (goto-char (point-min)) (catch 'error (while (re-search-forward org-heading-regexp nil t) (let ((v (org-entry-get (point) "NUMERIC"))) (when v ;; Let's say we only allow +/- integers (if (string-match "\\`[-+]?[0-9]+\\'" v) nil (error "Non-integer value found: %s" v) (throw 'error nil) nil)))))) (add-hook 'write-file-functions 'validate-properties t) You could use a different function for floats, or to make sure a value was one of a few allowed options... This only works if you only edit the files through emacs, and if everyone is setup so this is automatically loaded in the directory, etc. An alternative place to put something like this is in a git hook, if you have your project in a git repo. you would have to figure out how to write a script that would run emacs to do this kind of thing. But, then you could make sure no invalid files were commited, for example. John ----------------------------------- Professor John Kitchin Doherty Hall A207F Department of Chemical Engineering Carnegie Mellon University Pittsburgh, PA 15213 412-268-7803 @johnkitchin http://kitchingroup.cheme.cmu.edu On Sun, Feb 23, 2020 at 4:40 AM Vikas Rawal wrote: > > > On Sun, 23 Feb 2020 at 15:02, Bastien wrote: > >> Hi Vikas, >> >> Vikas Rawal writes: >> >> > 1. Is it possible to restrict the sub-tree of a headline to have only >> > properties specified in the column property of the parent? That is, >> > no additional property can be specified. >> >> No, it is currently not possible. What would be the use-case? >> > > > I am thinking of using org-mode to compile a small database. I would like > to use properties to add data, and some restrictions of this kind to limit > what properties a particular kind of headline could have. > > It might seem like an over-kill, but then for org-mode, almost nothing is > an over-kill. > > I am missing a few nuts and bolts, but would really like to see how it > works to use org-mode for a small org-mode-skilled team to use it as a data > platform. > > Warmest greetings and regards, > > Vikas > --0000000000001c42b7059f3e5cdd Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
One solution to this is a function you wo= uld write that validates the properties, and prevents saving if they are in= valid. You would want to use it in a buffer/directory hook.

For example:

=
(defun validate-properties ()
=C2=A0 (goto-char (= point-min))
=C2=A0 (catch 'error
=C2=A0 =C2=A0 (while (re-search-= forward org-heading-regexp nil t)
=C2=A0 =C2=A0 =C2=A0 (let ((v (org-ent= ry-get (point) "NUMERIC")))
(when v
=C2=A0;; Let's s= ay we only allow +/- integers
=C2=A0(if (string-match "\\`[-+]?[0= -9]+\\'" v)
=C2=A0 =C2=A0 =C2=A0nil
=C2=A0 =C2=A0(error = "Non-integer value found: %s" v)
=C2=A0 =C2=A0(throw 'er= ror nil)
=C2=A0 =C2=A0nil))))))

(add-hook 'write-file-funct= ions 'validate-properties t)

You c= ould use a different function for floats, or to make sure a value was one o= f a few allowed options...

This only works if you only edit the files through emacs, and if everyone = is setup so this is automatically loaded in the directory, etc. An alternat= ive place to put something like this is in a git hook, if you have your pro= ject in a git repo. you would have to figure out how to write a script that= would run emacs to do this kind=C2=A0of thing. But, then you could make su= re no invalid files were commited, for example.


=

John

----------------------= -------------
Professor John Kitchin=C2=A0
Doherty Hall A207F
Depa= rtment of Chemical Engineering
Carnegie Mellon University
Pittsburgh,= PA 15213
412-268-7803

=
On Sun= , Feb 23, 2020 at 4:40 AM Vikas Rawal <vikasrawal@gmail.com> wrote:


=
On Sun, 23= Feb 2020 at 15:02, Bastien <bzg@gnu.org> wrote:
Hi Vikas,

Vikas Rawal <v= ikasrawal@gmail.com> writes:

> 1. Is it possible to restrict the sub-tree of a headline to have only<= br> > properties specified in the column property of the parent? That is, > no additional property can be specified.

No, it is currently not possible.=C2=A0 What would be the use-case?


I am thinking of using org-mode to compile= a small database. I would like to use properties to add data, and some res= trictions of this kind to limit what properties a particular kind of headli= ne could have.

It might seem like an over-kill, but the= n for org-mode, almost nothing is an over-kill.

I am missing a few nuts and bolts= , but would really like to see how it works to use org-mode for a small org= -mode-skilled team to use it as a data platform.

Warmest greetings and regards,

Vik= as
--0000000000001c42b7059f3e5cdd--