emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: John Kitchin <jkitchin@andrew.cmu.edu>
To: Vikas Rawal <vikasrawal@gmail.com>
Cc: Bastien <bzg@gnu.org>, org-mode mailing list <emacs-orgmode@gnu.org>
Subject: Re: Limiting properties and property values
Date: Sun, 23 Feb 2020 08:37:34 -0500	[thread overview]
Message-ID: <CAJ51ETqTpM+Dx00sRiV5VP=ktAy9x4NZYLqGFU4fFPK++P+BWQ@mail.gmail.com> (raw)
In-Reply-To: <CALtzAB0j6kfR5tbpSHQVLn4AWrBH=TGd-VCy0x_cPA22x--qqg@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2360 bytes --]

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 <vikasrawal@gmail.com> wrote:

>
>
> On Sun, 23 Feb 2020 at 15:02, Bastien <bzg@gnu.org> wrote:
>
>> Hi Vikas,
>>
>> Vikas Rawal <vikasrawal@gmail.com> 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
>

[-- Attachment #2: Type: text/html, Size: 3850 bytes --]

  reply	other threads:[~2020-02-23 13:37 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-22 15:26 Limiting properties and property values Vikas Rawal
2020-02-23  9:32 ` Bastien
2020-02-23  9:40   ` Vikas Rawal
2020-02-23 13:37     ` John Kitchin [this message]
2020-02-23 16:50     ` Fraga, Eric
2020-02-23 23:39       ` Vikas Rawal

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:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  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='CAJ51ETqTpM+Dx00sRiV5VP=ktAy9x4NZYLqGFU4fFPK++P+BWQ@mail.gmail.com' \
    --to=jkitchin@andrew.cmu.edu \
    --cc=bzg@gnu.org \
    --cc=emacs-orgmode@gnu.org \
    --cc=vikasrawal@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

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