emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* File Scoped Properties?
@ 2020-03-05 15:28 Tim Visher
  2020-03-05 22:53 ` Gustav Wikström
  2020-03-06  6:51 ` Fraga, Eric
  0 siblings, 2 replies; 7+ messages in thread
From: Tim Visher @ 2020-03-05 15:28 UTC (permalink / raw)
  To: Emacs Org Mode mailing list

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

Hello,

I'm trying to get org-attach to use a different data directory for a
particular file.

My understanding is that this is controlled by `org-attach-id-dir` by
default but can be overridden at the file or entry level by use of the
`DIR` property. I can successfully override it at the entry level by adding
`DIR` to the entries properties but I can't figure out how to set it for
all entries in the file.

I tried:

```
#+DIR: ~/.foo/data
```

as the first line of the file.

I _am_ able to get it to work by adding a file local variable like

```
# Local Variables:
# org-attach-id-dir: "~/.foo/data"
# End:
```

but then whenever I open the file it tells me it's possibly not safe to set
that.

Any ideas?

--

In Christ,

Timmy V.

https://blog.twonegatives.com
https://five.sentenc.es

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: File Scoped Properties?
  2020-03-05 15:28 File Scoped Properties? Tim Visher
@ 2020-03-05 22:53 ` Gustav Wikström
  2020-03-06  6:51 ` Fraga, Eric
  1 sibling, 0 replies; 7+ messages in thread
From: Gustav Wikström @ 2020-03-05 22:53 UTC (permalink / raw)
  To: Tim Visher, Emacs Org Mode mailing list

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

Hi Tim,

First you must make sure to allow property inheritance. That can be done by setting org-attach-use-inheritance to t. Then add the DIR property to a property block for the file, or using a property keyword. I.e. either this:

#+begin_src org
  :PROPERTIES:
  :DIR:      ~/.foo/data
  :END:
#+end_src

#+begin_src org
  ,#+PROPERTY DIR ~/.foo/data
#+end_src

Running org-attach with option s will give you a prompt that will set DIR for you. If you invoke that before first headline it should result in a DIR property that applies for the whole buffer (when org-attach-use-inheritance is set to t that is). Note that property blocks before first headline is a new feature for version 9.4 and currently only exist in the master branch.

Regards
Gustav

From: Emacs-orgmode <emacs-orgmode-bounces+gustav=whil.se@gnu.org> On Behalf Of Tim Visher
Sent: den 5 mars 2020 16:28
To: Emacs Org Mode mailing list <emacs-orgmode@gnu.org>
Subject: File Scoped Properties?

Hello,

I'm trying to get org-attach to use a different data directory for a particular file.

My understanding is that this is controlled by `org-attach-id-dir` by default but can be overridden at the file or entry level by use of the `DIR` property. I can successfully override it at the entry level by adding `DIR` to the entries properties but I can't figure out how to set it for all entries in the file.

I tried:

```
#+DIR: ~/.foo/data
```

as the first line of the file.

I _am_ able to get it to work by adding a file local variable like

```
# Local Variables:
# org-attach-id-dir: "~/.foo/data"
# End:
```

but then whenever I open the file it tells me it's possibly not safe to set that.

Any ideas?

--

In Christ,

Timmy V.

https://blog.twonegatives.com
https://five.sentenc.es

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: File Scoped Properties?
  2020-03-05 15:28 File Scoped Properties? Tim Visher
  2020-03-05 22:53 ` Gustav Wikström
@ 2020-03-06  6:51 ` Fraga, Eric
  2020-03-06 14:09   ` Tim Visher
  1 sibling, 1 reply; 7+ messages in thread
From: Fraga, Eric @ 2020-03-06  6:51 UTC (permalink / raw)
  To: Tim Visher; +Cc: Emacs Org Mode mailing list

On Thursday,  5 Mar 2020 at 10:28, Tim Visher wrote:
> I _am_ able to get it to work by adding a file local variable like
>
> ```
> # Local Variables:
> # org-attach-id-dir: "~/.foo/data"
> # End:
> ```
>
> but then whenever I open the file it tells me it's possibly not safe to set
> that.

You've already received a more org-ish response but I'll give you an
Emacs response to this part of your post: Emacs is simply making sure
you are aware that a variable is being set when visiting a file.  It's a
form of security to ensure you don't have a file do something you don't
want it to do.  If you are happy for that variable to be set by files in
this way generally, Emacs does give you the option of saving this
information in the customization file and you won't get asked
again.

It's not that setting this variable this way is dangerous per se.  But,
for instance, this variable could be set by some file you receive from
somebody else to a destination that is off your computer, e.g. using
tramp.  This is the closest that Emacs comes to being vulnerable to
viruses (computer, not COVID-19 ;-)).

-- 
: Eric S Fraga via Emacs 28.0.50, Org release_9.3.6-354-g9d5880

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: File Scoped Properties?
  2020-03-06  6:51 ` Fraga, Eric
@ 2020-03-06 14:09   ` Tim Visher
  2020-03-08 12:52     ` Eric S Fraga
  2020-03-09 13:24     ` Tim Visher
  0 siblings, 2 replies; 7+ messages in thread
From: Tim Visher @ 2020-03-06 14:09 UTC (permalink / raw)
  To: Fraga, Eric; +Cc: Emacs Org Mode mailing list

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

Thanks for the response, Eric. :)

On Fri, Mar 6, 2020 at 1:51 AM Fraga, Eric <e.fraga@ucl.ac.uk> wrote:

> On Thursday,  5 Mar 2020 at 10:28, Tim Visher wrote:
> > I _am_ able to get it to work by adding a file local variable like
> >
> > ```
> > # Local Variables:
> > # org-attach-id-dir: "~/.foo/data"
> > # End:
> > ```
> >
> > but then whenever I open the file it tells me it's possibly not safe to
> set
> > that.
>
> You've already received a more org-ish response but I'll give you an
> Emacs response to this part of your post: Emacs is simply making sure
> you are aware that a variable is being set when visiting a file.
>

Yep. That's fully understood. I'm less clear on why certain variables are
considered safe and some are not but that doesn't seem relevant. I've done
enough with file local and directory local variables in the past that I
have a pretty clear understanding of what they do.

My question was more around why I had to do it at all since based on my
reading of the manual it seems like I should've been able to do this with
some kind of file-wide property. Specifically, I've never been able to wrap
my head around `(info "(org) Property Syntax")`.

"Properties are key–value pairs. When they are associated with a single
entry or with a tree…," for instance, seems to imply by "When they are
associated with a single entry…" that they can be associated with all the
entries (or a particular tree or node).

Anyway, I think between you and Gustav I finally have this sorted.

   1. To set properties at the top level of a file you need to use the
   `#+PROPERTY: <PROPERTY_NAME> <PROPERTY_VALUE>` syntax. I've been trying to
   figure out how I misinterpreted that in the past and I _think_ it was
   because I assumed that the `#+PROPERTY` was actually `#+<PROPERTY>` as in
   `#+DIR` rather than `#+PROPERTY: DIR`. It looks like to set a file local
   property in an org file you _must_ (at least on 9.3 or earlier) use the
   `#+PROPERTY: <PROPERTY_NAME> <PROPERTY_VALUE>` syntax.

   2. Even then by default org-attach property inheritance is set to
   `'selective` and `org-use-property-inheritance` is set to off. I've now
   customized `org-use-property-inheritance` to `'("DIR")` which I believe
   says that I consider the `DIR` property to be a possible candidate for
   inheritance and no others. I'm a little concerned about performance
   implications as the manual gives me all kinds of scary warnings but we'll
   see about that.

Anyway this appears to work as I expect it to. I don't have to set a
file-local variable to anything. I'm using org properties. And
`org-attach-dir` now returns the proper directory for this file.

Thanks all! If you think I'm still misunderstanding something please
correct me. :)

--

In Christ,

Timmy V.

https://blog.twonegatives.com
https://five.sentenc.es

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: File Scoped Properties?
  2020-03-06 14:09   ` Tim Visher
@ 2020-03-08 12:52     ` Eric S Fraga
  2020-03-09 13:24     ` Tim Visher
  1 sibling, 0 replies; 7+ messages in thread
From: Eric S Fraga @ 2020-03-08 12:52 UTC (permalink / raw)
  To: Tim Visher; +Cc: Emacs Org Mode mailing list

On Friday,  6 Mar 2020 at 09:09, Tim Visher wrote:
> I'm less clear on why certain variables are considered safe and some
> are not but that doesn't seem relevant. 

My understanding is that all (most?) variables are considered unsafe
unless you tell emacs otherwise.  I know that my emacs custom variable
include safe-local-variable-values which is a long list of variables
that I have at one time or another told emacs are "safe".

-- 
: Eric S Fraga via Emacs 28.0.50, Org release_9.3.6-354-g9d5880

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: File Scoped Properties?
  2020-03-06 14:09   ` Tim Visher
  2020-03-08 12:52     ` Eric S Fraga
@ 2020-03-09 13:24     ` Tim Visher
  2020-03-25  0:57       ` Tim Visher
  1 sibling, 1 reply; 7+ messages in thread
From: Tim Visher @ 2020-03-09 13:24 UTC (permalink / raw)
  To: Fraga, Eric; +Cc: Emacs Org Mode mailing list

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

On Fri, Mar 6, 2020 at 9:09 AM Tim Visher <tim.visher@gmail.com> wrote:

> Thanks for the response, Eric. :)
>
> On Fri, Mar 6, 2020 at 1:51 AM Fraga, Eric <e.fraga@ucl.ac.uk> wrote:
>
>> On Thursday,  5 Mar 2020 at 10:28, Tim Visher wrote:
>> > I _am_ able to get it to work by adding a file local variable like
>> >
>> > ```
>> > # Local Variables:
>> > # org-attach-id-dir: "~/.foo/data"
>> > # End:
>> > ```
>> >
>> > but then whenever I open the file it tells me it's possibly not safe to
>> set
>> > that.
>>
>> You've already received a more org-ish response but I'll give you an
>> Emacs response to this part of your post: Emacs is simply making sure
>> you are aware that a variable is being set when visiting a file.
>>
>
> My question was more around why I had to do it at all since based on my
> reading of the manual it seems like I should've been able to do this with
> some kind of file-wide property. Specifically, I've never been able to wrap
> my head around `(info "(org) Property Syntax")`.
>
> "Properties are key–value pairs. When they are associated with a single
> entry or with a tree…," for instance, seems to imply by "When they are
> associated with a single entry…" that they can be associated with all the
> entries (or a particular tree or node).
>
> Anyway, I think between you and Gustav I finally have this sorted.
>
>    1. To set properties at the top level of a file you need to use the
>    `#+PROPERTY: <PROPERTY_NAME> <PROPERTY_VALUE>` syntax. I've been trying to
>    figure out how I misinterpreted that in the past and I _think_ it was
>    because I assumed that the `#+PROPERTY` was actually `#+<PROPERTY>` as in
>    `#+DIR` rather than `#+PROPERTY: DIR`. It looks like to set a file local
>    property in an org file you _must_ (at least on 9.3 or earlier) use the
>    `#+PROPERTY: <PROPERTY_NAME> <PROPERTY_VALUE>` syntax.
>
>    2. Even then by default org-attach property inheritance is set to
>    `'selective` and `org-use-property-inheritance` is set to off. I've now
>    customized `org-use-property-inheritance` to `'("DIR")` which I believe
>    says that I consider the `DIR` property to be a possible candidate for
>    inheritance and no others. I'm a little concerned about performance
>    implications as the manual gives me all kinds of scary warnings but we'll
>    see about that.
>
> Anyway this appears to work as I expect it to. I don't have to set a
> file-local variable to anything. I'm using org properties. And
> `org-attach-dir` now returns the proper directory for this file.
>
> Thanks all! If you think I'm still misunderstanding something please
> correct me. :)
>

I'll go ahead and correct myself. (-‸ლ)

It turns out that I wasn't understanding what the `DIR` property actually
does. If `DIR` is set, it makes that the attachment directory, period. In
other words it's different than the default `./data/` prefix directory in
that ID paths are not then suffixed upon the end of it like
`./data/XX/XXXXX-XXX-XXX/` for each entry. Instead, if you have `DIR` set,
that headings attachment directory == `DIR`.

So the way to change the attachment directory prefix is just not to mess
with `DIR` at all. Instead, you must set the variable `org-attach-id-dir`,
and if you want that to be local to a file the natural way to do that is
with a file-local variable.

```
# Local Variables:
# org-attach-id-dir: "~/.foo/data"
# End:
```

Cheers. :)

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: File Scoped Properties?
  2020-03-09 13:24     ` Tim Visher
@ 2020-03-25  0:57       ` Tim Visher
  0 siblings, 0 replies; 7+ messages in thread
From: Tim Visher @ 2020-03-25  0:57 UTC (permalink / raw)
  To: Fraga, Eric; +Cc: Emacs Org Mode mailing list

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

On Mon, Mar 9, 2020 at 9:24 AM Tim Visher <tim.visher@gmail.com> wrote:

> On Fri, Mar 6, 2020 at 9:09 AM Tim Visher <tim.visher@gmail.com> wrote:
>
>> Thanks for the response, Eric. :)
>>
>> On Fri, Mar 6, 2020 at 1:51 AM Fraga, Eric <e.fraga@ucl.ac.uk> wrote:
>>
>>> On Thursday,  5 Mar 2020 at 10:28, Tim Visher wrote:
>>> > I _am_ able to get it to work by adding a file local variable like
>>> >
>>> > ```
>>> > # Local Variables:
>>> > # org-attach-id-dir: "~/.foo/data"
>>> > # End:
>>> > ```
>>> >
>>> > but then whenever I open the file it tells me it's possibly not safe
>>> to set
>>> > that.
>>>
>>> You've already received a more org-ish response but I'll give you an
>>> Emacs response to this part of your post: Emacs is simply making sure
>>> you are aware that a variable is being set when visiting a file.
>>>
>>
>> My question was more around why I had to do it at all since based on my
>> reading of the manual it seems like I should've been able to do this with
>> some kind of file-wide property. Specifically, I've never been able to wrap
>> my head around `(info "(org) Property Syntax")`.
>>
>> "Properties are key–value pairs. When they are associated with a single
>> entry or with a tree…," for instance, seems to imply by "When they are
>> associated with a single entry…" that they can be associated with all the
>> entries (or a particular tree or node).
>>
>> Anyway, I think between you and Gustav I finally have this sorted.
>>
>>    1. To set properties at the top level of a file you need to use the
>>    `#+PROPERTY: <PROPERTY_NAME> <PROPERTY_VALUE>` syntax. I've been trying to
>>    figure out how I misinterpreted that in the past and I _think_ it was
>>    because I assumed that the `#+PROPERTY` was actually `#+<PROPERTY>` as in
>>    `#+DIR` rather than `#+PROPERTY: DIR`. It looks like to set a file local
>>    property in an org file you _must_ (at least on 9.3 or earlier) use the
>>    `#+PROPERTY: <PROPERTY_NAME> <PROPERTY_VALUE>` syntax.
>>
>>    2. Even then by default org-attach property inheritance is set to
>>    `'selective` and `org-use-property-inheritance` is set to off. I've now
>>    customized `org-use-property-inheritance` to `'("DIR")` which I believe
>>    says that I consider the `DIR` property to be a possible candidate for
>>    inheritance and no others. I'm a little concerned about performance
>>    implications as the manual gives me all kinds of scary warnings but we'll
>>    see about that.
>>
>> Anyway this appears to work as I expect it to. I don't have to set a
>> file-local variable to anything. I'm using org properties. And
>> `org-attach-dir` now returns the proper directory for this file.
>>
>> Thanks all! If you think I'm still misunderstanding something please
>> correct me. :)
>>
>
> I'll go ahead and correct myself. (-‸ლ)
>
> It turns out that I wasn't understanding what the `DIR` property actually
> does. If `DIR` is set, it makes that the attachment directory, period. In
> other words it's different than the default `./data/` prefix directory in
> that ID paths are not then suffixed upon the end of it like
> `./data/XX/XXXXX-XXX-XXX/` for each entry. Instead, if you have `DIR` set,
> that headings attachment directory == `DIR`.
>
> So the way to change the attachment directory prefix is just not to mess
> with `DIR` at all. Instead, you must set the variable `org-attach-id-dir`,
> and if you want that to be local to a file the natural way to do that is
> with a file-local variable.
>
> ```
> # Local Variables:
> # org-attach-id-dir: "~/.foo/data"
> # End:
> ```
>
> Cheers. :)
>

This ended up producing more of a learning opportunity than I had initially
suspected and I wrote it up on my blog. In case anyone else is interested
in the details:
https://blog.twonegatives.com/post/613474532727095296/how-to-set-the-attach-directory-prefix-for

Happy Org!

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-03-25  0:57 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-05 15:28 File Scoped Properties? Tim Visher
2020-03-05 22:53 ` Gustav Wikström
2020-03-06  6:51 ` Fraga, Eric
2020-03-06 14:09   ` Tim Visher
2020-03-08 12:52     ` Eric S Fraga
2020-03-09 13:24     ` Tim Visher
2020-03-25  0:57       ` Tim Visher

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