Add hooks so buffers close correctly

This commit is contained in:
Miguel de la Cruz 2022-06-07 20:52:57 +02:00
parent ea9f2c07cc
commit b98abca259

View file

@ -259,6 +259,11 @@ conform to a post plist"
"Mode to list the Mattermost teams and channels to allow the
user to check their status and select between them")
(defun mattermost--kill-root-function ()
"Function to call when the Mattermost root buffer is killed"
(when (eq major-mode 'mattermost-root-mode)
(mattermost-disconnect)))
(defvar mattermost-username-button-map
(let ((map (make-sparse-keymap)))
(set-keymap-parent map button-map)
@ -348,6 +353,12 @@ user to check their status and select between them")
"Mode use on a Mattermost channel buffer, that shows the
messages of the channel and allows the user to post theirs")
(defun mattermost--kill-buffer-function ()
"Function to call when a Mattermost buffer is killed"
(when (eq major-mode 'mattermost-channel-mode)
(setq mattermost-buffers
(plist-put mattermost-buffers (mattermost-string->keyword mattermost-channel-id) nil))))
;; ToDo: should we receive just a channel id and fetch the channel
;; data?
(defun mattermost-show-channel (channel)
@ -390,10 +401,14 @@ user to check their status and select between them")
(mattermost-disconnect)
(let ((password (mattermost-read-password)))
(mattermost-login mattermost-login-id password))
(add-hook 'kill-buffer-hook #'mattermost--kill-root-function)
(add-hook 'kill-buffer-hook #'mattermost--kill-buffer-function)
(mattermost-show-root))
(defun mattermost--kill-all-buffers ()
"Kills all Mattermost related buffers"
(remove-hook 'kill-buffer-hook #'mattermost--kill-root-function)
(remove-hook 'kill-buffer-hook #'mattermost--kill-buffer-function)
(while (car mattermost-buffers)
(let ((buf (car (cdr mattermost-buffers)))
(tail (cddr mattermost-buffers)))