Re: Insert PROPERTIES drawer after heading creation
Hi Lawrence, On Wed, Mar 11, 2020 at 7:56 PM Lawrence Bottorff 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
Re: Insert PROPERTIES drawer after heading creation
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 wrote: > > On Wed, Mar 11, 2020 at 2:14 PM Lawrence Bottorff > 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 > >
Re: Insert PROPERTIES drawer after heading creation
On Wed, Mar 11, 2020 at 2:14 PM Lawrence Bottorff 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
Re: Insert PROPERTIES drawer after heading creation
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 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 > 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 >> >
Insert PROPERTIES drawer after heading creation
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