1

This code

(defun insert-dateutc.* ()
  (interactive)
  (insert (with-temp-buffer
            (call-process "date" nil t nil "+%Y-%m-%dT%H:%M:%S")
            (buffer-substring-no-properties 1 (line-end-position 0)))))

(defun insert-random-uuid.* ()
  (interactive)
  (with-temp-buffer
    (call-process "uuidgen" nil t nil)
    (buffer-substring-no-properties 1 (line-end-position 0))))

which works stand-alone, but when stuck into this code

(defun foo ()
  (interactive)
  (insert (format "'(start-symbol :id %s
               :graph 
               :ts %s
               :0.0 
               :1.0 
               )" (insert-random-uuid.*) (insert-dateutc.*))))

produces this:

2015-11-19T16:07:38'(start-symbol :id 9c5a8a91-325a-44d1-8535-03afc10f405a
               :graph 
               :ts nil
               :0.0 
               :1.0 
               )nil

That is, it's sticking the formatted date outside the format output. I can only assume that I'm going to the buffer-substring-no-properties too many times, or it needs to be reset or something. An earlier version that simply did this

(defun foo ()
  (interactive)
  (insert (format "'(start-symbol :id %s
               :graph 
               :ts %s
               :0.0 
               :1.0 
               )" (insert-random-uuid.*) (format-time-string "%Y-%m-%dT%H:%M:%S"))))

played well with insert-random-uuid.*

See:

'(start-symbol :id 2bfebed2-82c3-4ccb-b9f3-84b82a421e06
               :graph 
               :ts 2015-11-19T16:21:39
               :0.0 
               :1.0 
               )nil

Not sure what the problem is. . . .

2
  • 1
    Did you forget to remove the call to insert from insert-dateutc.*? (And maybe remove "insert" from both function names?)
    – Drew
    Commented Nov 19, 2015 at 16:30
  • Thanks, that seemed to solve it. Calling insert too many times is bad.
    – 147pm
    Commented Nov 19, 2015 at 16:41

1 Answer 1

4

If your function inserts text into a buffer, it should be called insert-something and its return value should not be passed to format and friends.

I.e., rename insert-random-uuid.* to get-random-uuid.* and insert-dateutc.* to get-dateutc.* and remove the insert call from the latter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.