4

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?

  • 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 8:21
4

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.