5

I want to use C-u M-:, then (format-time-string "%m/%d/%Y") to insert a customized date string. But it is inserted into the current buffer with double quotes.

Any trick to remove these quotes?

David S.
  • 395
  • 2
  • 13
  • Side note : I tend to use a zero argument instead of plain universal argument, to avoid ellipsis in case the return value is a (longish) list. OTOH a string is never truncated so it's not directly related to your question. – YoungFrog Feb 22 '17 at 08:21

2 Answers2

5

Rather than ask M-: to insert the output of the Elisp code, just write the Elisp code that inserts the text you want:

Try M-: (insert (format-time-string "%m/%d/%Y")) RET

Stefan
  • 26,154
  • 3
  • 46
  • 84
0

I think you should not change M-: for this. I have setup C-c + to call the vicarie/eval-replace-last-sexp defined below. So, I just type (format-time-string "%Y/%m/%d") and do C-c +.

(defun vicarie/eval-last-sexp-and-do (f)
  "Eval the last sexp and call F on its value."
  (let ((standard-output (current-buffer))
        (value (eval-last-sexp nil)))
    (funcall f value)))


(defun vicarie/eval-print-last-sexp ()
    "Evaluate and print the last sexp on the same line."
  (interactive)
  (vicarie/eval-last-sexp-and-do (lambda (value)
                                   (insert (format " (= %s ) " value)))))

(defun vicarie/eval-replace-last-sexp ()
  "Evaluate and replace last sexp with its value."
  (interactive)
  (vicarie/eval-last-sexp-and-do (lambda (value)
                                   (backward-kill-sexp)
                                   (insert (format "%s" value)))))
narendraj9
  • 304
  • 2
  • 7