Skip to content
Browse files

Use a common macro for rendering a status.

* twittering-mode.el: Use a common macro for rendering a status.
(twittering-render-a-field): new macro for rendering a status.
(twittering-render-timeline): use `twittering-render-a-field'.
(twittering-show-replied-statuses): use
`twittering-render-a-field'.
  • Loading branch information...
1 parent c39ddf9 commit 13e87fd8d7bc0fc8d31d455e14204ca643a95bf1 @cvmat cvmat committed Oct 30, 2011
Showing with 61 additions and 47 deletions.
  1. +6 −0 ChangeLog
  2. +55 −47 twittering-mode.el
View
6 ChangeLog
@@ -11,6 +11,12 @@
(twittering-make-field-id): attach a greater field ID to normal
tweets than its ancestor tweets.
+ * twittering-mode.el: Use a common macro for rendering a status.
+ (twittering-render-a-field): new macro for rendering a status.
+ (twittering-render-timeline): use `twittering-render-a-field'.
+ (twittering-show-replied-statuses): use
+ `twittering-render-a-field'.
+
2011-10-23 Tadashi MATSUO <tad@mymail.twin.jp>
* twittering-mode.el: Keep the private information unless the
View
102 twittering-mode.el
@@ -6767,6 +6767,40 @@ rendered at POS, return nil."
time-string))
time-string)))
+(defmacro twittering-render-a-field (pos field-id generator)
+ "Render a field on the current buffer managed by `twittering-mode'.
+Insert a field to the position pointed by FIELD-ID. The position is searched
+after POS. The string for the field is generated by the GENERATOR expression.
+This function returns the position where the next status should be inserted."
+ `(lexical-let ((pos ,pos)
+ (field-id ,field-id))
+ (while
+ (let ((buf-field-id (get-text-property pos 'field)))
+ (if (and buf-field-id
+ (if twittering-reverse-mode
+ (twittering-field-id< buf-field-id field-id)
+ (twittering-field-id< field-id buf-field-id)))
+ (let ((next-pos
+ (twittering-get-next-status-head pos)))
+ (setq pos (or next-pos (point-max)))
+ next-pos)
+ nil)))
+ (unless (twittering-field-id= field-id (get-text-property pos 'field))
+ (let ((formatted-status ,generator)
+ (separator "\n"))
+ (goto-char pos)
+ (if (eq pos (point-max))
+ ;; Use `insert' only if no statuses are rendered on the below.
+ (insert formatted-status separator)
+ ;; Use `insert-before-markers' in order to keep
+ ;; which status is pointed by each marker.
+ (insert-before-markers formatted-status separator))
+ ;; Now, `pos' points the head of the status.
+ ;; It must be moved to the current point
+ ;; in order to skip the status inserted just now.
+ (setq pos (point))))
+ pos))
+
(defun twittering-render-timeline (buffer &optional additional timeline-data keep-point)
(with-current-buffer buffer
(let* ((spec (twittering-get-timeline-spec-for-buffer buffer))
@@ -6816,39 +6850,14 @@ rendered at POS, return nil."
(twittering-get-first-status-head))))
(mapc
(lambda (status)
- (let ((field-id (twittering-make-field-id status)))
- ;; Find where the status should be inserted.
- (while
- (let ((buf-field-id (get-text-property pos 'field)))
- (if (and buf-field-id
- (if twittering-reverse-mode
- (twittering-field-id< buf-field-id field-id)
- (twittering-field-id< field-id buf-field-id)))
- (let ((next-pos
- (twittering-get-next-status-head pos)))
- (setq pos (or next-pos (point-max)))
- next-pos)
- nil)))
- (unless (twittering-field-id= field-id
- (get-text-property pos 'field))
- (let ((formatted-status (twittering-format-status status))
- (separator "\n"))
- (goto-char pos)
- (cond
- ((eq pos (point-max))
- ;; Insert a status after the current position.
- (insert formatted-status separator))
- (t
- ;; Use `insert-before-markers' in order to keep
- ;; which status is pointed by each marker.
- (insert-before-markers formatted-status separator)))
- ;; Now, `pos' points the head of the status.
- ;; It must be moved to the current point
- ;; in order to skip the status inserted just now.
- (setq pos (point))
- (when twittering-default-show-replied-tweets
- (twittering-show-replied-statuses
- twittering-default-show-replied-tweets))))))
+ (setq pos
+ (twittering-render-a-field
+ pos
+ (twittering-make-field-id status)
+ (twittering-format-status status)))
+ (when twittering-default-show-replied-tweets
+ (twittering-show-replied-statuses
+ twittering-default-show-replied-tweets)))
timeline-data)))
(debug-print (current-buffer))
(cond
@@ -7054,28 +7063,27 @@ If INTERRUPT is non-nil, the iteration is stopped if FUNC returns nil."
statuses
(reverse statuses))))
(if statuses
- (let ((beg (if twittering-reverse-mode
+ (let ((pos (if twittering-reverse-mode
(twittering-get-current-status-head)
(or (twittering-get-next-status-head)
(point-max))))
- (separator "\n")
(prefix " ")
(buffer-read-only nil))
(save-excursion
- (goto-char beg)
(mapc
(lambda (status)
- (let ((formatted-status (twittering-format-status status
- prefix))
- ;; Overwrite field property.
- (field-properties
- (twittering-make-field-properties-of-popped-ancestors
- status base-id)))
- (add-text-properties 0 (length formatted-status)
- field-properties formatted-status)
- (if twittering-reverse-mode
- (insert-before-markers formatted-status separator)
- (insert formatted-status separator))))
+ (setq pos
+ (twittering-render-a-field
+ pos
+ (twittering-make-field-id status base-id)
+ (let ((formatted-status
+ (twittering-format-status status prefix))
+ (field-properties
+ (twittering-make-field-properties-of-popped-ancestors
+ status base-id)))
+ (add-text-properties 0 (length formatted-status)
+ field-properties formatted-status)
+ formatted-status))))
statuses)
t))
(when interactive

0 comments on commit 13e87fd

Please sign in to comment.
Something went wrong with that request. Please try again.