emacselisp

How can I insert text to a buffer without the trailing "nil"


I've got a function to insert the current date into my file

(defun insert-date ()
   (interactive)
   (insert 
        (format-time-string "%m-%d-%Y")))

This works for inserting the date into my current buffer, however the output is 01-24-2011nil

How can I remove the nil from the input.


Solution

  • As noted above, insert returns nil and inserts the arguments as a side effect. Since you've declared your function interactive, you can call it using M-x. Even if you don't declare it interactive, you can say M-: (insert-date).