app/twitter: decouple from feature/workspaces

This commit is contained in:
Henrik Lissner 2018-06-01 15:36:14 +02:00
parent 80bd587d87
commit c8a7005a22
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -1,5 +1,8 @@
;;; app/twitter/autoload.el -*- lexical-binding: t; -*-
(defvar +twitter-workspace-name "*Twitter*"
"The name to use for the twitter workspace.")
;;;###autoload
(defun +twitter-display-buffer (buf)
"A replacement display-buffer command for `twittering-pop-to-buffer-function'
@ -20,13 +23,18 @@ that works with the feature/popup module."
;; Commands
;;
(defvar +twitter--old-wconf nil)
;;;###autoload
(defun =twitter ()
(defun =twitter (arg)
"Opens a workspace dedicated to `twittering-mode'."
(interactive)
(interactive "P")
(condition-case _
(progn
(+workspace/new "*Twitter*")
(if (and (not arg) (featurep! :feature workspaces))
(+workspace/new +twitter-workspace-name)
(setq +twitter--old-wconf (current-window-configuration))
(delete-other-windows)
(switch-to-buffer (doom-fallback-buffer)))
(call-interactively #'twit)
(unless (get-buffer (car twittering-initial-timeline-spec-string))
(error "Failed to open twitter"))
@ -44,13 +52,20 @@ that works with the feature/popup module."
(interactive)
(when (eq major-mode 'twittering-mode)
(twittering-kill-buffer)
(+workspace/close-window-or-workspace)))
(cond ((one-window-p) (+twitter/quit-all))
((featurep! :feature workspaces)
(+workspace/close-window-or-workspace))
((delete-window)))))
;;;###autoload
(defun +twitter/quit-all ()
"Close all open `twitter-mode' buffers and the associated workspace, if any."
(interactive)
(+workspace/delete "*Twitter*")
(when (featurep! :feature workspaces)
(+workspace/delete +twitter-workspace-name))
(when +twitter--old-wconf
(set-window-configuration +twitter--old-wconf)
(setq +twitter--old-wconf nil))
(dolist (buf (doom-buffers-in-mode 'twittering-mode (buffer-list) t))
(twittering-kill-buffer buf)))