emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Insert PROPERTIES drawer after heading creation
@ 2020-03-11  4:39 Lawrence Bottorff
       [not found] ` <CAGY83EdJyQeFWu3zjZtnXos_10WExAzJi7wOS7rxk84W7MonqA@mail.gmail.com>
  0 siblings, 1 reply; 5+ messages in thread
From: Lawrence Bottorff @ 2020-03-11  4:39 UTC (permalink / raw)
  To: emacs-orgmode Mailinglist

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

I want to insert upon creating a heading a PROPERTIES drawer. So far I have
this

(defadvice org-insert-heading (after add-id-stuff activate)
  (template-myid))

(defun template-myid ()
  (insert "\n:PROPERTIES:\n:TIME: "
      (substring (format "%s" (format-time-string "%Y-%m-%dT%H:%M:%S")))
      "\n:VERTEX: "
      (substring (format "%s" (shell-command "uuidgen" t)))
      "\n:EDGES:  \n:END:"))

This is working -- sort of. My problem is the uuid is getting thrown
around. The output looks like this

* Heading
:PROPERTIES:
:TIME: 2020-03-10T23:34:17
:VERTEX: 12836
:EDGES:
:END:32bf9499-f9e2-49d9-b8e7-9edb40272411

Not sure how to make this behave.

LB

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

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

* Re: Insert PROPERTIES drawer after heading creation
       [not found] ` <CAGY83EdJyQeFWu3zjZtnXos_10WExAzJi7wOS7rxk84W7MonqA@mail.gmail.com>
@ 2020-03-11 13:14   ` Lawrence Bottorff
  2020-03-11 15:37     ` Diego Zamboni
  0 siblings, 1 reply; 5+ messages in thread
From: Lawrence Bottorff @ 2020-03-11 13:14 UTC (permalink / raw)
  To: Diego Zamboni, emacs-orgmode Mailinglist

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

Yes, thanks. That substring was a bad copy. Any insight why the
(shell-command "uuidgen" t) wasn't working?

On Wed, Mar 11, 2020 at 3:03 AM Diego Zamboni <diego@zzamboni.org> wrote:

> Hi LB,
>
> How about using the =org-id-uuid= function instead of shelling out to
> uuidgen? In my quick test the following seems to behave properly:
>
> (defun template-myid ()
>   (insert "\n:PROPERTIES:\n:TIME: "
>       (format-time-string "%Y-%m-%dT%H:%M:%S")
>       "\n:VERTEX: "
>       (org-id-uuid)
>       "\n:EDGES:  \n:END:"))
>
> Note that I also removed the wrapping (substring (format ...)), which
> didn't seem to be necessary.
>
> --Diego
>
>
> On Wed, Mar 11, 2020 at 5:39 AM Lawrence Bottorff <borgauf@gmail.com>
> wrote:
>
>> I want to insert upon creating a heading a PROPERTIES drawer. So far I
>> have this
>>
>> (defadvice org-insert-heading (after add-id-stuff activate)
>>   (template-myid))
>>
>> (defun template-myid ()
>>   (insert "\n:PROPERTIES:\n:TIME: "
>>       (substring (format "%s" (format-time-string "%Y-%m-%dT%H:%M:%S")))
>>       "\n:VERTEX: "
>>       (substring (format "%s" (shell-command "uuidgen" t)))
>>       "\n:EDGES:  \n:END:"))
>>
>> This is working -- sort of. My problem is the uuid is getting thrown
>> around. The output looks like this
>>
>> * Heading
>> :PROPERTIES:
>> :TIME: 2020-03-10T23:34:17
>> :VERTEX: 12836
>> :EDGES:
>> :END:32bf9499-f9e2-49d9-b8e7-9edb40272411
>>
>> Not sure how to make this behave.
>>
>> LB
>>
>

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

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

* Re: Insert PROPERTIES drawer after heading creation
  2020-03-11 13:14   ` Lawrence Bottorff
@ 2020-03-11 15:37     ` Diego Zamboni
  2020-03-11 18:56       ` Lawrence Bottorff
  0 siblings, 1 reply; 5+ messages in thread
From: Diego Zamboni @ 2020-03-11 15:37 UTC (permalink / raw)
  To: Lawrence Bottorff; +Cc: emacs-orgmode Mailinglist

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

On Wed, Mar 11, 2020 at 2:14 PM Lawrence Bottorff <borgauf@gmail.com> wrote:

> Yes, thanks. That substring was a bad copy. Any insight why the
> (shell-command "uuidgen" t) wasn't working?
>

I hadn't looked at it yet, but the documentation for =shell-command= gives
the answer:

Execute string COMMAND in inferior shell; display output, if any.
With prefix argument, *insert the COMMAND’s output at point*.


So this function does not return a string that can be concatenated with
others, it actually inserts the output in the buffer, so it's not
guaranteed it will land where you need it.

To have the output of the command returned as a string, I think you should
use =shell-command-to-string=.

--Diego

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

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

* Re: Insert PROPERTIES drawer after heading creation
  2020-03-11 15:37     ` Diego Zamboni
@ 2020-03-11 18:56       ` Lawrence Bottorff
  2020-03-11 20:32         ` Diego Zamboni
  0 siblings, 1 reply; 5+ messages in thread
From: Lawrence Bottorff @ 2020-03-11 18:56 UTC (permalink / raw)
  To: Diego Zamboni; +Cc: emacs-orgmode Mailinglist

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

I read that too, but couldn't fathom what they meant. Still, I'm not sure
what they mean by "prefix argument." And why does (shell-command "uuidgen"
t) produces two outputs? For other readers, this is what they look like in
*scratch*

(shell-command "uuidgen" t)
2827
b5da7e0a-84c0-4db8-91f3-871b681f3022

(org-id-uuid)
"0bb7a4e1-9fc2-4428-b8de-a2d9ef5c56ab"

Also, does anyone know how I could have done this by "advise"-ing a
function in org-mode tempo templates? I could never figure out what
function was actually handling the <...-TAB.

On Wed, Mar 11, 2020 at 10:37 AM Diego Zamboni <diego@zzamboni.org> wrote:

>
> On Wed, Mar 11, 2020 at 2:14 PM Lawrence Bottorff <borgauf@gmail.com>
> wrote:
>
>> Yes, thanks. That substring was a bad copy. Any insight why the
>> (shell-command "uuidgen" t) wasn't working?
>>
>
> I hadn't looked at it yet, but the documentation for =shell-command= gives
> the answer:
>
> Execute string COMMAND in inferior shell; display output, if any.
> With prefix argument, *insert the COMMAND’s output at point*.
>
>
> So this function does not return a string that can be concatenated with
> others, it actually inserts the output in the buffer, so it's not
> guaranteed it will land where you need it.
>
> To have the output of the command returned as a string, I think you should
> use =shell-command-to-string=.
>
> --Diego
>
>

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

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

* Re: Insert PROPERTIES drawer after heading creation
  2020-03-11 18:56       ` Lawrence Bottorff
@ 2020-03-11 20:32         ` Diego Zamboni
  0 siblings, 0 replies; 5+ messages in thread
From: Diego Zamboni @ 2020-03-11 20:32 UTC (permalink / raw)
  To: Lawrence Bottorff; +Cc: emacs-orgmode Mailinglist

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

Hi Lawrence,

On Wed, Mar 11, 2020 at 7:56 PM Lawrence Bottorff <borgauf@gmail.com> wrote:

> I read that too, but couldn't fathom what they meant. Still, I'm not sure
> what they mean by "prefix argument."
>

The prefix argument in this case is not so important as the OUTPUT-BUFFER
argument, which you were passing as =t=:

"If OUTPUT-BUFFER is not a buffer and not nil, insert the output in current
buffer after point leaving mark after it."

which is why the output is inserted in the buffer.

And why does (shell-command "uuidgen" t) produces two outputs? For other
> readers, this is what they look like in *scratch*
>
> (shell-command "uuidgen" t)
> 2827
> b5da7e0a-84c0-4db8-91f3-871b681f3022
>

The first number is the return value of shell-command, which is (I think)
the position in the buffer at which the pointer was when the function was
evaluated (or something like this). Here's the output from two consecutive
executions in my *scratch* buffer:

(shell-command "uuidgen" t)
173
5E69575E-2807-40BB-B1FE-10058D3C0666

(shell-command "uuidgen" t)
243
A7FD662E-A752-4E02-B4E0-A3E48CC7E7AB

The "173" happens to appear at point position 173 in the buffer, and same
for the 243 (you can verify this with "C-u C-x =").

Hope this helps!

--Diego

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

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

end of thread, other threads:[~2020-03-11 20:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-11  4:39 Insert PROPERTIES drawer after heading creation Lawrence Bottorff
     [not found] ` <CAGY83EdJyQeFWu3zjZtnXos_10WExAzJi7wOS7rxk84W7MonqA@mail.gmail.com>
2020-03-11 13:14   ` Lawrence Bottorff
2020-03-11 15:37     ` Diego Zamboni
2020-03-11 18:56       ` Lawrence Bottorff
2020-03-11 20:32         ` Diego Zamboni

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