Skip to content

Commit

Permalink
Statuses are automatically re-rendered if necessary.
Browse files Browse the repository at this point in the history
* twittering-mode.el (twittering-timer-for-redisplaying): new
variable for timer of redisplaying statuses.
(twittering-timer-interval-for-redisplaying): new variable
specifying the interval of redisplaying statuses.
(twittering-update-status-on-buffer): new function to update
statuses on buffer.
(twittering-format-status): append `need-to-be-update' property to
the specifier "%@" and "%FILL{...}" including "%@".
(twittering-start): start the timer of redisplaying statuses.
(twittering-stop): stop the timer of redisplaying statuses.
  • Loading branch information
cvmat committed Feb 25, 2010
1 parent 439d246 commit 64d21b2
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 4 deletions.
11 changes: 11 additions & 0 deletions ChangeLog
Expand Up @@ -592,6 +592,17 @@
* twittering-mode.el (twittering-for-each-property-region): new
function to process each region with a certain property.

* twittering-mode.el (twittering-timer-for-redisplaying): new
variable for timer of redisplaying statuses.
(twittering-timer-interval-for-redisplaying): new variable
specifying the interval of redisplaying statuses.
(twittering-redisplay-status-on-buffer): new function to redisplay
statuses on buffer.
(twittering-format-status): append `need-to-be-update' property to
the specifier "%@" and "%FILL{...}" including "%@".
(twittering-start): start the timer of redisplaying statuses.
(twittering-stop): stop the timer of redisplaying statuses.

2010-01-29 Daiji Kanematsu <daijik@gmail.com>

* twittering-mode.el (toplevel): add `easy-menu-define' in order
Expand Down
66 changes: 62 additions & 4 deletions twittering-mode.el
Expand Up @@ -114,6 +114,13 @@ DO NOT SET VALUE MANUALLY.")
seconds for this variable because the number of API call is
limited by the hour.")

(defvar twittering-timer-for-redisplaying nil
"Timer object for timeline redisplay statuses will be stored here.
DO NOT SET VALUE MANUALLY.")

(defvar twittering-timer-interval-for-redisplaying 17
"The interval of auto redisplaying statuses.")

(defvar twittering-username nil
"An username of your Twitter account.")
(defvar twittering-username-active nil
Expand Down Expand Up @@ -2201,6 +2208,27 @@ If INTERRUPT is non-nil, the iteration is stopped if FUNC returns nil."
(setq beg (next-single-property-change beg prop)))))
(set-marker end-marker nil))))

;;;
;;; Automatic redisplay of statuses on buffer
;;;

(defun twittering-redisplay-status-on-buffer (&optional buffer)
(let ((buffer (or buffer (twittering-buffer)))
(deactivate-mark deactivate-mark))
(with-current-buffer buffer
(save-excursion
(twittering-for-each-property-region
'need-to-be-updated
(lambda (beg end value)
(let* ((func (car value))
(args (cdr value))
(updated-str (apply func args))
(buffer-read-only nil))
(delete-region beg end)
(goto-char beg)
(insert updated-str)))
buffer)))))

;;;
;;; display functions
;;;
Expand Down Expand Up @@ -2412,7 +2440,19 @@ variable `twittering-status-format'."
0 (length result)
`(mouse-face highlight face twittering-uri-face uri ,url)
result)
result)))
result))
(make-string-with-update-property
(str func &rest args)
(let ((result (copy-sequence str)))
(put-text-property 0 (length result)
'need-to-be-updated `(,func ,@args) result)
result))
(expand-update-property-if-necessary
(str func &rest args)
(if (or (get-text-property 0 'need-to-be-updated str)
(next-single-property-change 0 'need-to-be-updated str))
(apply 'make-string-with-update-property str func args)
str)))
(let* ((replace-table
`(("%" . "%")
("#" . ,(attr 'id))
Expand Down Expand Up @@ -2440,6 +2480,12 @@ variable `twittering-status-format'."
(/ (+ secs 1800) 3600)))
(t (format-time-string "%I:%M %p %B %d, %Y"
created-at))))
(time-string
(if (< secs 84600)
(make-string-with-update-property
time-string
'twittering-format-status status "%@")
time-string))
(url
(twittering-get-status-url (attr 'user-screen-name)
(attr 'id))))
Expand Down Expand Up @@ -2491,7 +2537,12 @@ variable `twittering-status-format'."
(store-match-data match-data)
(let* ((formatted-str
(twittering-format-string
(match-string 1 str) prefix mod-table)))
(match-string 1 str) prefix mod-table))
(formatted-str
(expand-update-property-if-necessary
formatted-str
'twittering-format-status
status (concat "%" str))))
(twittering-fill-string formatted-str)))))
("f" . ,(attr 'source))
("i" .
Expand Down Expand Up @@ -2830,13 +2881,20 @@ variable `twittering-status-format'."
(setq twittering-timer
(run-at-time "0 sec"
twittering-timer-interval
#'twittering-timer-action action))))
#'twittering-timer-action action))
(setq twittering-timer-for-redisplaying
(run-at-time "0 sec"
twittering-timer-interval-for-redisplaying
#'twittering-redisplay-status-on-buffer))))

(defun twittering-stop ()
(interactive)
(when twittering-timer
(cancel-timer twittering-timer)
(setq twittering-timer nil)))
(setq twittering-timer nil))
(when twittering-timer-for-redisplaying
(cancel-timer twittering-timer-for-redisplaying)
(setq twittering-timer-for-redisplaying nil)))

(defun twittering-scroll-mode (&optional arg)
(interactive "P")
Expand Down

0 comments on commit 64d21b2

Please sign in to comment.