emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* org-set-properties for various (all) headings
@ 2022-07-19  8:14 Uwe Brauer
  2022-07-19 10:56 ` Kaushal Modi
  0 siblings, 1 reply; 10+ messages in thread
From: Uwe Brauer @ 2022-07-19  8:14 UTC (permalink / raw)
  To: emacs-orgmode

Hi

I have
* Over
  :PROPERTIES:
  :ID:       ef19f286-8769-4fe7-8f95-8167691257a0
  :COLUMNS:  %5TODO(Status) %5NR(Nr) 
  :END:

** TODO Test
   :PROPERTIES:
   :Sent:     [X] 
   :END:

** WAIT Test2
   :PROPERTIES:
   :Sent:     [X] 
   :END:

** TODO Test3
   :PROPERTIES:
   :Sent:     [ ]
   :END:

Now, I would add to all subheadings a new property, say

 :Received:  [ ]

Whose value I will then individually change later.

Any idea how to do that 



Regards

Uwe Brauer 
-- 
I strongly condemn Putin's war of aggression against the Ukraine.
I support to deliver weapons to Ukraine's military. 
I support the ban of Russia from SWIFT.
I support the EU membership of the Ukraine. 



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

* Re: org-set-properties for various (all) headings
  2022-07-19  8:14 org-set-properties for various (all) headings Uwe Brauer
@ 2022-07-19 10:56 ` Kaushal Modi
  2022-07-19 14:53   ` Uwe Brauer
  0 siblings, 1 reply; 10+ messages in thread
From: Kaushal Modi @ 2022-07-19 10:56 UTC (permalink / raw)
  To: emacs-org list

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

Check out org-map-entries. I have one example here:
https://scripter.co/looping-through-org-mode-headings/#example-modifying-a-property-in-all-headings
.

On Tue, Jul 19, 2022, 4:16 AM Uwe Brauer <oub@mat.ucm.es> wrote:

>
>
> Now, I would add to all subheadings a new property, say
>
>  :Received:  [ ]
>
> Whose value I will then individually change later.
>
> Any idea how to do that

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

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

* Re: org-set-properties for various (all) headings
  2022-07-19 10:56 ` Kaushal Modi
@ 2022-07-19 14:53   ` Uwe Brauer
  2022-07-19 16:30     ` Kaushal Modi
  0 siblings, 1 reply; 10+ messages in thread
From: Uwe Brauer @ 2022-07-19 14:53 UTC (permalink / raw)
  To: emacs-orgmode

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

>>> "KM" == Kaushal Modi <kaushal.modi@gmail.com> writes:

> Check out org-map-entries. I have one example here:
> https://scripter.co/looping-through-org-mode-headings/#example-modifying-a-property-in-all-headings
> .

Very nice thanks however one question.

I started as test with 


#+begin_src 
** TODO Test
   :PROPERTIES:
   :Sent:     [ ]
   :END:

** WAIT Test2
   :PROPERTIES:
   :Sent:     [ ]
   :END:

** TODO Test3
   :PROPERTIES:
   :Sent:     [ ]
   :END:

#+end_src

I then used the code:
#+begin_src elisp :noexport
(defun test/set-property-at-heading ()
  "Function to be called at the beginning of an Org heading."
(interactive)
  (let ((el (org-element-at-point)))
    (org-set-property "foo" (org-element-property :title el))))
(org-map-entries #'test/set-property-at-heading)

#+end_src

And indeed ended up with 

#+begin_src 
#+COLUMNS: %TODO %40ITEM(Task) %40SUMMARY(Summary) %Received(Rec)
** TODO Test
   :PROPERTIES:
   :Sent:     [ ]
   :foo:      Test
   :END:

** WAIT Test2
   :PROPERTIES:
   :Sent:     [ ]
   :foo:      Test2
   :END:

** TODO Test3
   :PROPERTIES:
   :Sent:     [ ]
   :foo:      Test3
   :END:
#+end_src


However I wanted to insert a checkbox not a title so I tried 

#+begin_src 

#+begin_src elisp :noexport
(defun my-set-property-at-heading ()
  "Function to be called at the beginning of an Org heading."
  (interactive)
  (let ((el (org-element-at-point)))
    (org-set-property "New" (org-element-property "[ ]" el)))))
(org-map-entries #'my-set-property-at-heading)
            
#+end_src

But this did not work, I am either asked all the time (but I have 200
headers), or it does not work at all. I also tried

#+begin_src elisp :noexport
(defun my-set-property-at-heading ()
  "Function to be called at the beginning of an Org heading."
  (interactive)
  (let ((el (org-element-at-point)))
    (org-set-property "New2" (org-element-property :checkbox el))))
(org-map-entries #'my-set-property-at-heading)
            
#+end_src


Thanks again 

Uwe Brauer 

[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5673 bytes --]

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

* Re: org-set-properties for various (all) headings
  2022-07-19 14:53   ` Uwe Brauer
@ 2022-07-19 16:30     ` Kaushal Modi
  2022-07-19 16:56       ` Uwe Brauer
  0 siblings, 1 reply; 10+ messages in thread
From: Kaushal Modi @ 2022-07-19 16:30 UTC (permalink / raw)
  To: emacs-org list

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

On Tue, Jul 19, 2022, 10:54 AM Uwe Brauer <oub@mat.ucm.es> wrote:

>
>
> #+begin_src elisp :noexport
> (defun my-set-property-at-heading ()
>   "Function to be called at the beginning of an Org heading."
>   (interactive)
>   (let ((el (org-element-at-point)))
>     (org-set-property "New" (org-element-property "[ ]" el)))))
> (org-map-entries #'my-set-property-at-heading)
>
> #+end_src
>

Try replacing the `org-set-property` form to:

(org-set-property "New" "[]")

[Not tested, typing from phone.]

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

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

* Re: org-set-properties for various (all) headings
  2022-07-19 16:30     ` Kaushal Modi
@ 2022-07-19 16:56       ` Uwe Brauer
  2022-07-19 18:07         ` Kaushal Modi
  0 siblings, 1 reply; 10+ messages in thread
From: Uwe Brauer @ 2022-07-19 16:56 UTC (permalink / raw)
  To: emacs-orgmode

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


> On Tue, Jul 19, 2022, 10:54 AM Uwe Brauer <oub@mat.ucm.es> wrote:

> Try replacing the `org-set-property` form to:

> (org-set-property "New" "[]")

This does not anything (besides garbage collecting)

-- 
I strongly condemn Putin's war of aggression against the Ukraine.
I support to deliver weapons to Ukraine's military. 
I support the ban of Russia from SWIFT.
I support the EU membership of the Ukraine. 

[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5673 bytes --]

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

* Re: org-set-properties for various (all) headings
  2022-07-19 16:56       ` Uwe Brauer
@ 2022-07-19 18:07         ` Kaushal Modi
  2022-07-20  5:31           ` Uwe Brauer
  0 siblings, 1 reply; 10+ messages in thread
From: Kaushal Modi @ 2022-07-19 18:07 UTC (permalink / raw)
  To: emacs-org list

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

On Tue, Jul 19, 2022 at 12:58 PM Uwe Brauer <oub@mat.ucm.es> wrote:

>
> > On Tue, Jul 19, 2022, 10:54 AM Uwe Brauer <oub@mat.ucm.es> wrote:
>
> > Try replacing the `org-set-property` form to:
>
> > (org-set-property "New" "[]")
>
> This does not anything (besides garbage collecting)
>

Did you replace only the `org-set-property` form with my suggestion?

In any case, I got to a computer and I tested that to work alright.

=====
* Over
:PROPERTIES:
:ID:       ef19f286-8769-4fe7-8f95-8167691257a0
:COLUMNS:  %5TODO(Status) %5NR(Nr)
:foo:      Over
:END:
** TODO Test
:PROPERTIES:
:Sent:     [X]
:END:

** WAIT Test2
:PROPERTIES:
:Sent:     [X]
:END:

** TODO Test3
:PROPERTIES:
:Sent:     [ ]
:END:

#+begin_src emacs-lisp
(defun test/set-property-at-heading ()
  "Function to be called at the beginning of an Org heading."
  (interactive)
  (let ((el (org-element-at-point)))
    (org-set-property "New" "[ ]")))
(org-map-entries #'test/set-property-at-heading)
#+end_src
=====

Hit C-c C-c with the cursor in that code block, say "yes" or "y" if
prompted, and then you should see that Org buffer change to:

=====
* Over
:PROPERTIES:
:ID:       ef19f286-8769-4fe7-8f95-8167691257a0
:COLUMNS:  %5TODO(Status) %5NR(Nr)
:foo:      Over
:New:      [ ]
:END:
** TODO Test
:PROPERTIES:
:Sent:     [X]
:New:      [ ]
:END:

** WAIT Test2
:PROPERTIES:
:Sent:     [X]
:New:      [ ]
:END:

** TODO Test3
:PROPERTIES:
:Sent:     [ ]
:New:      [ ]
:END:

#+begin_src emacs-lisp
(defun test/set-property-at-heading ()
  "Function to be called at the beginning of an Org heading."
  (interactive)
  (let ((el (org-element-at-point)))
    (org-set-property "New" "[ ]")))
(org-map-entries #'test/set-property-at-heading)
#+end_src

#+RESULTS:

=====

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

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

* Re: org-set-properties for various (all) headings
  2022-07-19 18:07         ` Kaushal Modi
@ 2022-07-20  5:31           ` Uwe Brauer
  2022-07-20  7:33             ` Ihor Radchenko
  0 siblings, 1 reply; 10+ messages in thread
From: Uwe Brauer @ 2022-07-20  5:31 UTC (permalink / raw)
  To: emacs-orgmode

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

>>> "KM" == Kaushal Modi <kaushal.modi@gmail.com> writes:

> On Tue, Jul 19, 2022 at 12:58 PM Uwe Brauer <oub@mat.ucm.es> wrote:
>> 
>> > On Tue, Jul 19, 2022, 10:54 AM Uwe Brauer <oub@mat.ucm.es> wrote:
>> 
>> > Try replacing the `org-set-property` form to:
>> 
>> > (org-set-property "New" "[]")
>> 
>> This does not anything (besides garbage collecting)
>> 

> Did you replace only the `org-set-property` form with my suggestion?

This is what you said.
> In any case, I got to a computer and I tested that to work alright.

> =====
> * Over
> :PROPERTIES:
> :ID:       ef19f286-8769-4fe7-8f95-8167691257a0
> :COLUMNS:  %5TODO(Status) %5NR(Nr)
> :foo:      Over
> :END:
> ** TODO Test
> :PROPERTIES:
> :Sent:     [X]
> :END:

> ** WAIT Test2
> :PROPERTIES:
> :Sent:     [X]
> :END:

> ** TODO Test3
> :PROPERTIES:
> :Sent:     [ ]
> :END:

> #+begin_src emacs-lisp
> (defun test/set-property-at-heading ()
>   "Function to be called at the beginning of an Org heading."
>   (interactive)
>   (let ((el (org-element-at-point)))
>     (org-set-property "New" "[ ]")))
> (org-map-entries #'test/set-property-at-heading)
> #+end_src


Aha, *great* thanks a ton. That really really saved my day.

Two comments though

    1. It works, if the source block is at the beginning of the file 😉

    2. I confess I don't understand anymore the use of `(let ((el (org-element-at-point)))':

       a. In your first version you used the defined «el», but know you
          don't, hm just saying.


In any case thanks again for this very valuable advice. I suggest to
include it somehow in the documentation, since I believe that other
users have encountered similar situations.

Regards

Uwe Brauer 

[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5673 bytes --]

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

* Re: org-set-properties for various (all) headings
  2022-07-20  5:31           ` Uwe Brauer
@ 2022-07-20  7:33             ` Ihor Radchenko
  2022-07-20  8:05               ` Uwe Brauer
  0 siblings, 1 reply; 10+ messages in thread
From: Ihor Radchenko @ 2022-07-20  7:33 UTC (permalink / raw)
  To: Uwe Brauer; +Cc: emacs-orgmode

Uwe Brauer <oub@mat.ucm.es> writes:

> Two comments though
>
>     1. It works, if the source block is at the beginning of the file 😉
>
>     2. I confess I don't understand anymore the use of `(let ((el (org-element-at-point)))':
>
>        a. In your first version you used the defined «el», but know you
>           don't, hm just saying.

That's because the first version used the actual headline title as a
value of the property. That values had to be acquired somehow.
org-element API was used.

> In any case thanks again for this very valuable advice. I suggest to
> include it somehow in the documentation, since I believe that other
> users have encountered similar situations.

A.11 Using the Mapping API
A.10 Using the Property API

:)

Best,
Ihor


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

* Re: org-set-properties for various (all) headings
  2022-07-20  7:33             ` Ihor Radchenko
@ 2022-07-20  8:05               ` Uwe Brauer
  2022-07-20 13:00                 ` Kaushal Modi
  0 siblings, 1 reply; 10+ messages in thread
From: Uwe Brauer @ 2022-07-20  8:05 UTC (permalink / raw)
  To: emacs-orgmode

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

>>> "IR" == Ihor Radchenko <yantar92@gmail.com> writes:

> Uwe Brauer <oub@mat.ucm.es> writes:
>> Two comments though
>> 
>> 1. It works, if the source block is at the beginning of the file 😉
>> 
>> 2. I confess I don't understand anymore the use of `(let ((el (org-element-at-point)))':
>> 
>> a. In your first version you used the defined «el», but know you
>> don't, hm just saying.

> That's because the first version used the actual headline title as a
> value of the property. That values had to be acquired somehow.
> org-element API was used.

I expressed myself rather badly 

1.  First code

(defun test/set-property-at-heading ()
  "Function to be called at the beginning of an Org heading."
(interactive)
  (let ((el (org-element-at-point)))
    (org-set-property "foo" (org-element-property :title el))))
                                                         ^el is used
(org-map-entries #'test/set-property-at-heading)


2. Second code

(defun test/set-property-at-heading ()
  "Function to be called at the beginning of an Org heading."
  (interactive)
  (let ((el (org-element-at-point)))
        ^el is defined but not used.
    (org-set-property "New" "[ ]")))
(org-map-entries #'test/set-property-at-heading)







>> In any case thanks again for this very valuable advice. I suggest to
>> include it somehow in the documentation, since I believe that other
>> users have encountered similar situations.

> A.11 Using the Mapping API
> A.10 Using the Property API

Is this a reference to the manual?

🙄


[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5673 bytes --]

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

* Re: org-set-properties for various (all) headings
  2022-07-20  8:05               ` Uwe Brauer
@ 2022-07-20 13:00                 ` Kaushal Modi
  0 siblings, 0 replies; 10+ messages in thread
From: Kaushal Modi @ 2022-07-20 13:00 UTC (permalink / raw)
  To: emacs-org list

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

On Wed, Jul 20, 2022 at 4:07 AM Uwe Brauer <oub@mat.ucm.es> wrote:

> 2. Second code
>
> (defun test/set-property-at-heading ()
>   "Function to be called at the beginning of an Org heading."
>   (interactive)
>   (let ((el (org-element-at-point)))
>         ^el is defined but not used.
>     (org-set-property "New" "[ ]")))
> (org-map-entries #'test/set-property-at-heading)
>

Correct. The el variable is not required here. It's a relic from the
previous version of that function.


> A.11 Using the Mapping API
> > A.10 Using the Property API
>
> Is this a reference to the manual?
>

Yes. You can access those from within Emacs as Info manuals:

- (org) Using the Mapping API - online
<https://orgmode.org/manual/Using-the-Mapping-API.html>
- (org) Using the Property API - online
<https://orgmode.org/manual/Using-the-Property-API.html>

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

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

end of thread, other threads:[~2022-07-20 13:02 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-07-19  8:14 org-set-properties for various (all) headings Uwe Brauer
2022-07-19 10:56 ` Kaushal Modi
2022-07-19 14:53   ` Uwe Brauer
2022-07-19 16:30     ` Kaushal Modi
2022-07-19 16:56       ` Uwe Brauer
2022-07-19 18:07         ` Kaushal Modi
2022-07-20  5:31           ` Uwe Brauer
2022-07-20  7:33             ` Ihor Radchenko
2022-07-20  8:05               ` Uwe Brauer
2022-07-20 13:00                 ` Kaushal Modi

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