branch: externals/dtache commit b75af1b9a70ba00ef16f7f03d4e8eed8b1724d6e Author: Niklas Eklund <niklas.ekl...@posteo.net> Commit: Niklas Eklund <niklas.ekl...@posteo.net>
Update notification setup Notification function is now defined with the variable dtache-notification-function. Which makes it possible for users to define their own and assign to this variable. --- README.org | 14 +++++--------- dtache.el | 10 ++++++---- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/README.org b/README.org index c3641cfb74..1b57eb930d 100644 --- a/README.org +++ b/README.org @@ -172,8 +172,8 @@ The [[https://gitlab.com/niklaseklund/consult-dtache][consult-dtache]] package p By default =dtache= uses the echo area to notify the user when a session has finished. An alternative is to utilize the [[https://github.com/jwiegley/alert][alert]] package to get a system notification instead. #+begin_src elisp :lexical t :results none - (defun my/dtache-session-finish-alert (session) - "Send an alert notification when SESSION finish." + (defun my/dtache-inactive-session-notification (session) + "Send an `alert' notification when SESSION becomes inactive." (let ((status (dtache--session-status session)) (title (pcase (dtache--session-status session) @@ -186,14 +186,10 @@ By default =dtache= uses the echo area to notify the user when a session has fin ('failure 'high)) :category 'compile :id (pcase status - ('success 'compile-ok) - ('failure 'compile-fail))))) -#+end_src - -With the usage of =advice= the user can override the default implantation with the alert version. + ('success 'dtache-success) + ('failure 'dtache-failure))))) -#+begin_src elisp :lexical t :results none - (advice-add 'dtache-session-finish-notification :override #'my/dtache-session-finish-alert) + (setq dtache-notification-function #'my/dtache-inactive-session-notification) #+end_src * Customization diff --git a/dtache.el b/dtache.el index db7628bf12..9725af6eb5 100644 --- a/dtache.el +++ b/dtache.el @@ -70,8 +70,10 @@ "Variable to specify the origin of the session.") (defvar dtache-open-session-function nil "Custom function to use to open a session.") +(defvar dtache-notification-function #'dtache-inactive-session-notification + "Variable to specify notification function when a session becomes inactive.") (defvar dtache-session-callback-function nil - "Custom function to callback when a session finish.") + "Custom function to callback when a session becomes inactive.") (defvar dtache-session-status-function nil "Custom function to deduce the status of a session.") (defvar dtache-compile-hooks nil @@ -535,8 +537,8 @@ Optionally make the path LOCAL to host." (point-max)))) (buffer-substring beginning end))))) -(defun dtache-session-finish-notification (session) - "Send a notification when SESSION finish." +(defun dtache-inactive-session-notification (session) + "Send a notification when SESSION becomes inactive." (let ((status (pcase (dtache--session-status session) ('success "Dtache finished") ('failure "Dtache failed")) )) @@ -815,7 +817,7 @@ Optionally make the path LOCAL to host." (setf (dtache--session-status session) (dtache-session-exit-code-status session))) ;; Send notification - (dtache-session-finish-notification session) + (funcall dtache-notification-function session) ;; Update session in database (dtache--db-update-entry session t)