Drücken Sie „Enter“, um den Inhalte zu überspringen

Timestamped message in the *Message* buffer

Beeing used to timestamped log message it always bothered me a little that emacs *Message* buffer message are not timestamped. Today I took the challange to in fact prefix messages with a timestamp by using an advice.

Not beeing the most experienced user of advices in Emacs I first google in the wrong corners of the internet it seems, because the result i got was kind of wrong (using ad-do-it, seems not to be the way it is currently done…). So somehow i fiddled this bit together:

(defun mp/message-with-timestamp (orig-fun &rest args)
  "Advice around `message` (ORIG-FUN).
Prepend a timestamp to all messages (ARGS)."
    (when args
      (let ((result (apply 'format (car args) (cdr args)))
            (args (cons (concat (format-time-string "[%Y-%m-%d %H:%M:%S] ")
                           (car args))
                   (cdr args))))
        (progn
          (apply orig-fun args)
          result))))

(advice-add 'message :around #'mp/message-with-timestamp)

Guessing around a little bit about what is done with the value mp/message-with-timestamp evaluates to, I am curious to see if this function will stand the test of time 🙂

Gib den ersten Kommentar ab

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre, wie deine Kommentardaten verarbeitet werden.