I was not very statisfied with the leading zero that I got in my insert-date function.
It looks now as 09 jun 2015
, instead 9 jun 2015
.
To solve this, I looked into the source code of s.el and wrote a function for it.
(defun insert-date ()
"Insert current date 1 jun yyyy."
(interactive)
(insert
(if (string-prefix-p "0" (format-time-string "%d")) ;; Checks if there is a leding zero.
(s-right (format-time-string "%d") 1) ;; If so, chop it off with the library s, then s-right.
(format-time-string "%d")) ;; If not (for example, 10, 12, 25, 31), let it so.
(format-time-string "%b %Y")) ;; Then the rest (jun 2015).
)
After some tweaking, I still got the same error that there is a wrong type argument in sequencep 1. But I couldn't figure out.
Anybody have the golden hint?
%e
instead of%d
? As per the documentation forformat-time-string
: "%d is the day of the month, zero-padded, %e is blank-padded." And if you don't want that blank you can send it tostring-trim
. Also, if you look at the doc fors-right
, the function signature looks like this:(s-right LEN S)
. You have it swapped. – nanny Jun 9 '15 at 20:15%e
but it adds an extra space, which I don't prefer. Sofoo-bar (01-06-2015)
will befoo-bar ( 1-06-2015)
. Never knew I could send it to string-trim, but I need to check if there is any space. Thanks for the suggestion. And it seems I have swapped it, indeed. Your answer was the right, it worked again. – ReneFroger Jun 9 '15 at 20:19(string-trim (format-time-string "%e %b %Y"))
. – nanny Jun 9 '15 at 20:22