Lisp/SLY: Add duration and timestamp to prompt.
parent
4946779074
commit
8848532777
|
@ -178,9 +178,49 @@ changed, of when called interactively."
|
|||
cd-shell))))))
|
||||
(advice-add 'helm-ff-switch-to-shell :override #'ambrevar/helm-ff-switch-to-shell))
|
||||
|
||||
(defvar ambrevar/sly-status--last-command-time nil)
|
||||
(make-variable-buffer-local 'ambrevar/sly-status--last-command-time)
|
||||
(defun ambrevar/sly-status--record ()
|
||||
(setq ambrevar/sly-status--last-command-time (current-time)))
|
||||
|
||||
(defun ambrevar/sly-status-formatter (timestamp duration)
|
||||
"Return the status display for `ambrevar/sly-status'.
|
||||
TIMESTAMP is the value returned by `current-time' and DURATION is the floating
|
||||
time the command took to complete in seconds."
|
||||
(format "#[STATUS] End time %s, duration %.3fs\n"
|
||||
(format-time-string "%F %T" timestamp)
|
||||
duration))
|
||||
|
||||
(defcustom ambrevar/sly-status-min-duration 1
|
||||
"If a command takes more time than this, display its status with `ambrevar/sly-status'."
|
||||
:group 'sly
|
||||
:type 'number)
|
||||
|
||||
(defun ambrevar/sly-status (&optional formatter min-duration)
|
||||
"Termination timestamp and duration of command.
|
||||
Status is only returned if command duration was longer than
|
||||
MIN-DURATION \(defaults to `ambrevar/sly-status-min-duration'). FORMATTER
|
||||
is a function of two arguments, TIMESTAMP and DURATION, that
|
||||
returns a string."
|
||||
(if ambrevar/sly-status--last-command-time
|
||||
(let ((duration (time-to-seconds
|
||||
(time-subtract (current-time) ambrevar/sly-status--last-command-time))))
|
||||
(setq ambrevar/sly-status--last-command-time nil)
|
||||
(if (> duration (or min-duration
|
||||
ambrevar/sly-status-min-duration))
|
||||
(funcall (or formatter
|
||||
#'ambrevar/sly-status-formatter)
|
||||
(current-time)
|
||||
duration)
|
||||
""))
|
||||
(progn
|
||||
(advice-add 'sly-mrepl--send-input-sexp :after #'ambrevar/sly-status--record)
|
||||
"")))
|
||||
|
||||
(defun ambrevar/sly-prepare-prompt (old-func &rest args)
|
||||
(let ((package (nth 0 args))
|
||||
(new-prompt (format "%s:%s"
|
||||
(new-prompt (format "%s%s\n%s"
|
||||
(ambrevar/sly-status)
|
||||
(abbreviate-file-name default-directory)
|
||||
(nth 1 args)))
|
||||
(error-level (nth 2 args))
|
||||
|
|
Loading…
Reference in New Issue