2017-06-08 11:47:56 +02:00
|
|
|
;;; app/twitter/autoload.el -*- lexical-binding: t; -*-
|
2017-04-09 21:55:33 -04:00
|
|
|
|
2018-06-01 15:36:14 +02:00
|
|
|
(defvar +twitter-workspace-name "*Twitter*"
|
|
|
|
"The name to use for the twitter workspace.")
|
|
|
|
|
2018-01-24 17:37:39 -05:00
|
|
|
;;;###autoload
|
2019-07-23 12:30:47 +02:00
|
|
|
(defun +twitter-display-buffer-fn (buf)
|
2018-01-24 17:37:39 -05:00
|
|
|
"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
|
|
|
|
|
2018-06-01 15:36:14 +02:00
|
|
|
(defvar +twitter--old-wconf nil)
|
2017-04-09 21:55:33 -04:00
|
|
|
;;;###autoload
|
2018-06-01 15:36:14 +02:00
|
|
|
(defun =twitter (arg)
|
2018-01-24 17:37:39 -05:00
|
|
|
"Opens a workspace dedicated to `twittering-mode'."
|
2018-06-01 15:36:14 +02:00
|
|
|
(interactive "P")
|
2018-01-24 17:37:39 -05:00
|
|
|
(condition-case _
|
2017-04-11 18:48:35 -04:00
|
|
|
(progn
|
2019-04-21 19:59:44 -04:00
|
|
|
(if (and (not arg) (featurep! :ui workspaces))
|
2018-06-01 15:36:14 +02:00
|
|
|
(+workspace/new +twitter-workspace-name)
|
|
|
|
(setq +twitter--old-wconf (current-window-configuration))
|
|
|
|
(delete-other-windows)
|
|
|
|
(switch-to-buffer (doom-fallback-buffer)))
|
2017-06-08 11:47:56 +02:00
|
|
|
(call-interactively #'twit)
|
2017-04-11 18:48:35 -04:00
|
|
|
(unless (get-buffer (car twittering-initial-timeline-spec-string))
|
|
|
|
(error "Failed to open twitter"))
|
|
|
|
(switch-to-buffer (car twittering-initial-timeline-spec-string))
|
|
|
|
(dolist (name (cdr twittering-initial-timeline-spec-string))
|
|
|
|
(split-window-horizontally)
|
|
|
|
(switch-to-buffer name))
|
2018-01-24 17:37:39 -05:00
|
|
|
(balance-windows)
|
|
|
|
(call-interactively #'+twitter/rerender-all))
|
|
|
|
('error (+twitter/quit-all))))
|
2017-04-09 21:55:33 -04:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +twitter/quit ()
|
2018-01-24 17:37:39 -05:00
|
|
|
"Close the current `twitter-mode' buffer."
|
2017-04-09 21:55:33 -04:00
|
|
|
(interactive)
|
2017-04-10 22:26:33 -04:00
|
|
|
(when (eq major-mode 'twittering-mode)
|
|
|
|
(twittering-kill-buffer)
|
2018-06-01 15:36:14 +02:00
|
|
|
(cond ((one-window-p) (+twitter/quit-all))
|
2019-04-21 19:59:44 -04:00
|
|
|
((featurep! :ui workspaces)
|
2018-06-01 15:36:14 +02:00
|
|
|
(+workspace/close-window-or-workspace))
|
|
|
|
((delete-window)))))
|
2017-04-09 21:55:33 -04:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +twitter/quit-all ()
|
2018-01-24 17:37:39 -05:00
|
|
|
"Close all open `twitter-mode' buffers and the associated workspace, if any."
|
2017-04-09 21:55:33 -04:00
|
|
|
(interactive)
|
2019-04-21 19:59:44 -04:00
|
|
|
(when (featurep! :ui workspaces)
|
2018-06-01 15:36:14 +02:00
|
|
|
(+workspace/delete +twitter-workspace-name))
|
|
|
|
(when +twitter--old-wconf
|
|
|
|
(set-window-configuration +twitter--old-wconf)
|
|
|
|
(setq +twitter--old-wconf nil))
|
2018-01-24 17:37:39 -05:00
|
|
|
(dolist (buf (doom-buffers-in-mode 'twittering-mode (buffer-list) t))
|
|
|
|
(twittering-kill-buffer buf)))
|
2017-04-09 21:55:33 -04:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +twitter/rerender-all ()
|
2018-01-24 17:37:39 -05:00
|
|
|
"Rerender all `twittering-mode' buffers."
|
2017-04-09 21:55:33 -04:00
|
|
|
(interactive)
|
2018-01-24 17:37:39 -05:00
|
|
|
(dolist (buf (doom-buffers-in-mode 'twittering-mode (buffer-list) t))
|
2017-04-09 21:55:33 -04:00
|
|
|
(with-current-buffer buf
|
2018-01-24 17:37:39 -05:00
|
|
|
(twittering-rerender-timeline-all buf)
|
|
|
|
(setq-local line-spacing 0.2)
|
2018-05-14 20:35:26 +02:00
|
|
|
(goto-char (point-min)))))
|
2018-05-12 23:17:48 +02:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +twitter/ace-link ()
|
|
|
|
"Open a visible link, username or hashtag in a `twittering-mode' buffer."
|
|
|
|
(interactive)
|
2019-05-01 01:47:27 -04:00
|
|
|
(require 'avy)
|
2019-12-30 23:59:46 -05:00
|
|
|
;; REVIEW Is this necessary anymore with `link-hint'
|
2018-05-12 23:17:48 +02:00
|
|
|
(let ((pt (avy-with +twitter/ace-link
|
|
|
|
(avy--process
|
|
|
|
(+twitter--collect-links)
|
|
|
|
(avy--style-fn avy-style)))))
|
|
|
|
(when (number-or-marker-p pt)
|
|
|
|
(goto-char pt)
|
|
|
|
(let ((uri (get-text-property (point) 'uri)))
|
|
|
|
(if uri (browse-url uri))))))
|
|
|
|
|
|
|
|
(defun +twitter--collect-links ()
|
|
|
|
(let ((end (window-end))
|
|
|
|
points)
|
|
|
|
(save-excursion
|
|
|
|
(goto-char (window-start))
|
|
|
|
(while (and (< (point) end)
|
|
|
|
(ignore-errors (twittering-goto-next-thing) t))
|
|
|
|
(push (point) points))
|
|
|
|
(nreverse points))))
|