Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

emacs

elisp

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.

like image 919
chollida Avatar asked Oct 21 '25 17:10

chollida


2 Answers

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

like image 101
Ulrich Schwarz Avatar answered Oct 23 '25 08:10

Ulrich Schwarz


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.

like image 24
JSON Avatar answered Oct 23 '25 07:10

JSON



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!