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.
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)
.
It's the C-j
that is inserting nil
. The function itself as you've defined it is OK. C-j
in the scratch buffer is useful for debugging Lisp that you have written, but you have to remember that it will insert the return value. If you don't want that, try C-x C-e
instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With