Refactor & redesign app/twitter

Inspired by UI changes by @fuxialexander, mentioned in
https://github.com/hlissner/emacs-doom-themes/issues/131
This commit is contained in:
Henrik Lissner 2018-01-24 17:37:39 -05:00
parent b3c429d92a
commit 64d41ed1d9
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 74 additions and 23 deletions

View file

@ -1,12 +1,32 @@
;;; app/twitter/autoload.el -*- lexical-binding: t; -*- ;;; app/twitter/autoload.el -*- lexical-binding: t; -*-
;;;###autoload
(defun +twitter-display-buffer (buf)
"A replacement display-buffer command for `twittering-pop-to-buffer-function'
that works with the feature/popup module."
(let ((win (selected-window)))
(display-buffer buf)
;; This is required because the new window generated by `pop-to-buffer'
;; may hide the region following the current position.
(twittering-ensure-whole-of-status-is-visible win)))
;;;###autoload
(defun +twitter-buffer-p (buf)
"Return non-nil if BUF is a `twittering-mode' buffer."
(eq 'twittering-mode (buffer-local-value 'major-mode buf)))
;;
;; Commands
;;
;;;###autoload ;;;###autoload
(defun =twitter () (defun =twitter ()
"Opens a workspace dedicated to `twittering-mode'."
(interactive) (interactive)
(+workspace-switch "*Twitter*" t) (condition-case _
(delete-other-windows)
(condition-case _ex
(progn (progn
(+workspace/new "*Twitter*")
(call-interactively #'twit) (call-interactively #'twit)
(unless (get-buffer (car twittering-initial-timeline-spec-string)) (unless (get-buffer (car twittering-initial-timeline-spec-string))
(error "Failed to open twitter")) (error "Failed to open twitter"))
@ -14,12 +34,13 @@
(dolist (name (cdr twittering-initial-timeline-spec-string)) (dolist (name (cdr twittering-initial-timeline-spec-string))
(split-window-horizontally) (split-window-horizontally)
(switch-to-buffer name)) (switch-to-buffer name))
(balance-windows)) (balance-windows)
('error (call-interactively #'+twitter/rerender-all))
(+twitter/quit-all)))) ('error (+twitter/quit-all))))
;;;###autoload ;;;###autoload
(defun +twitter/quit () (defun +twitter/quit ()
"Close the current `twitter-mode' buffer."
(interactive) (interactive)
(when (eq major-mode 'twittering-mode) (when (eq major-mode 'twittering-mode)
(twittering-kill-buffer) (twittering-kill-buffer)
@ -27,15 +48,18 @@
;;;###autoload ;;;###autoload
(defun +twitter/quit-all () (defun +twitter/quit-all ()
"Close all open `twitter-mode' buffers and the associated workspace, if any."
(interactive) (interactive)
(+workspace/delete "Twitter") (+workspace/delete "*Twitter*")
(dolist (buf (doom-buffers-in-mode 'twittering-mode)) (dolist (buf (doom-buffers-in-mode 'twittering-mode (buffer-list) t))
(with-current-buffer buf (twittering-kill-buffer buf)))
(twittering-kill-buffer))))
;;;###autoload ;;;###autoload
(defun +twitter/rerender-all () (defun +twitter/rerender-all ()
"Rerender all `twittering-mode' buffers."
(interactive) (interactive)
(dolist (buf (doom-buffers-in-mode 'twittering-mode)) (dolist (buf (doom-buffers-in-mode 'twittering-mode (buffer-list) t))
(with-current-buffer buf (with-current-buffer buf
(twittering-rerender-timeline-all buf)))) (twittering-rerender-timeline-all buf)
(setq-local line-spacing 0.2)
(goto-line 0 buf))))

View file

@ -3,19 +3,47 @@
(def-package! twittering-mode (def-package! twittering-mode
:commands twit :commands twit
:config :config
(setq twittering-use-master-password t (setq twittering-private-info-file (expand-file-name "twittering-mode.gpg" doom-etc-dir)
twittering-icon-mode nil twittering-use-master-password t
twittering-request-confirmation-on-posting t
;; twittering-icon-mode t
;; twittering-use-icon-storage t ;; twittering-use-icon-storage t
;; twittering-icon-storage-file (concat doom-cache-dir "twittering-mode-icons.gz") ;; twittering-icon-storage-file (concat doom-cache-dir "twittering-mode-icons.gz")
;; twittering-convert-fix-size 12 ;; twittering-convert-fix-size 12
twittering-timeline-header "" twittering-timeline-header ""
twittering-timeline-footer "" twittering-timeline-footer ""
twittering-edit-skeleton 'inherit-any twittering-edit-skeleton 'inherit-any
twittering-status-format twittering-status-format "%FACE[font-lock-function-name-face]{ @%s} %FACE[italic]{%@} %FACE[error]{%FIELD-IF-NONZERO[❤ %d]{favorite_count}} %FACE[warning]{%FIELD-IF-NONZERO[↺ %d]{retweet_count}}
"%RT{%FACE[bold]{RT }}%S (%FACE[bold]{@%s}), %@%r%R:\n%FOLD[ ]{%t %QT{\n+----\n%FOLD[|]{ %S (@%s), %@:\n%FOLD[ ]{%t}}\n+----}}\n " %FOLD[ ]{%FILL{%t}%QT{
%FOLD[ ]{%FACE[font-lock-function-name-face]{@%s}\t%FACE[shadow]{%@}
%FOLD[ ]{%FILL{%t}}
}}}
%FACE[twitter-divider]{ }
"
;; twittering-timeline-spec-alias '()
twittering-initial-timeline-spec-string twittering-initial-timeline-spec-string
'(":home" ":mentions" ":direct_messages")) '(":home" ":mentions" ":direct_messages"))
(set! :popup "^\\*twittering-edit" nil '((transient) (quit) (select . t) (modeline . minimal)))
(defface twitter-divider
`((t (:underline (:color ,(doom-darken 'vertical-bar 0.2)))))
"The vertical divider between tweets."
:group 'twittering-mode)
(add-hook 'doom-real-buffer-functions #'+twitter-buffer-p)
(when (featurep! :feature popup)
(setq twittering-pop-to-buffer-function #'+twitter-display-buffer))
(after! solaire-mode
(add-hook 'twittering-mode-hook #'solaire-mode))
;; Custom modeline for twitter buffers
(def-modeline! twitter
(bar matches " %b " selection-info)
())
(add-hook! twittering-mode (add-hook! twittering-mode
(setq header-line-format (or (doom-modeline 'twitter) mode-line-format) (setq header-line-format (or (doom-modeline 'twitter) mode-line-format)
mode-line-format nil)) mode-line-format nil))
@ -24,11 +52,10 @@
[remap twittering-kill-buffer] #'+twitter/quit [remap twittering-kill-buffer] #'+twitter/quit
"Q" #'+twitter/quit-all "Q" #'+twitter/quit-all
"o" #'ace-link-addr "o" #'ace-link-addr
"J" #'twittering-goto-next-status
"K" #'twittering-goto-previous-status
(:when (featurep! :feature evil)
"j" #'evil-next-visual-line "j" #'evil-next-visual-line
"k" #'evil-previous-visual-line "k" #'evil-previous-visual-line
"J" #'twittering-goto-next-status "h" #'evil-window-left
"K" #'twittering-goto-previous-status) "l" #'evil-window-right)))
(def-modeline! twitter
(bar matches " %b " selection-info)
()))