Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use rendered-as property for rendering replied statuses.

* twittering-mode.el: Use rendered-as property for rendering
replied statuses instead of a trick with id and original-id
properties.
(twittering-get-common-properties): add rendered-as property as a
common property.
(twittering-make-field-properties): add rendered-as property if
necessary.
(twittering-make-field-properties-of-popped-ancestors): new
function.
(twittering-rendered-as-ancestor-status-p): new function.
(twittering-get-base-id-of-ancestor-at): new function.
(twittering-replied-statuses-visible-p): use the new function
`twittering-get-base-id-of-ancestor-at' instead of directly
referring id and original-id properties.
(twittering-hide-replied-statuses): likewise.
(twittering-show-replied-statuses): use
`twittering-make-field-properties-of-popped-ancestors'.
  • Loading branch information...
commit f1f0362fcdb6de58d0b75afd6e97617018ad3c32 1 parent 26aabfc
@cvmat cvmat authored
Showing with 92 additions and 39 deletions.
  1. +18 −0 ChangeLog
  2. +74 −39 twittering-mode.el
View
18 ChangeLog
@@ -34,6 +34,24 @@
(twittering-get-next-status-head): likewise.
(twittering-get-previous-status-head): likewise.
+ * twittering-mode.el: Use rendered-as property for rendering
+ replied statuses instead of a trick with id and original-id
+ properties.
+ (twittering-get-common-properties): add rendered-as property as a
+ common property.
+ (twittering-make-field-properties): add rendered-as property if
+ necessary.
+ (twittering-make-field-properties-of-popped-ancestors): new
+ function.
+ (twittering-rendered-as-ancestor-status-p): new function.
+ (twittering-get-base-id-of-ancestor-at): new function.
+ (twittering-replied-statuses-visible-p): use the new function
+ `twittering-get-base-id-of-ancestor-at' instead of directly
+ referring id and original-id properties.
+ (twittering-hide-replied-statuses): likewise.
+ (twittering-show-replied-statuses): use
+ `twittering-make-field-properties-of-popped-ancestors'.
+
2011-01-09 Tadashi MATSUO <tad@mymail.twin.jp>
* twittering-mode.el: Ensure that encrypted strings are written
View
113 twittering-mode.el
@@ -5055,15 +5055,15 @@ static char * unplugged_xpm[] = {
The common property list is added to each rendered tweet irrespective
of format. The common properties follows:
properites generated by `twittering-make-common-properties',
- `field' added by `twittering-make-common-properties' or
- `twittering-show-replied-statuses',
+ `field' and `rendered-as' generated by `twittering-make-field-properties',
`original-id' added by `twittering-show-replied-statuses'."
(apply 'append
(mapcar (lambda (prop)
(let ((value (get-text-property pos prop)))
(when value
`(,prop ,value))))
- '(field id original-id source-id source-spec text username))))
+ '(field id original-id rendered-as source-id source-spec
+ text username))))
(defun twittering-format-string (string prefix replacement-table)
"Format STRING according to PREFIX and REPLACEMENT-TABLE.
@@ -5381,9 +5381,28 @@ In the case, BASE-ID means the ID of the descendant."
(t
(format "O:%s" (funcall format-func id))))))
-(defun twittering-make-field-properties (status &optional replied-by)
- (let ((field-id (twittering-make-field-id status replied-by)))
- `(field ,field-id)))
+(defun twittering-make-field-properties (status &optional rendered-as)
+ (let* ((base-id (cdr (assq 'ancestor-of rendered-as)))
+ (field-id (twittering-make-field-id status base-id)))
+ (if rendered-as
+ `(field ,field-id rendered-as ,rendered-as)
+ `(field ,field-id))))
+
+(defun twittering-make-field-properties-of-popped-ancestors (status base-id)
+ (twittering-make-field-properties status `((ancestor-of . ,base-id))))
+
+(defun twittering-rendered-as-ancestor-status-p (&optional pos)
+ "Return non-nil if the status at POS is rendered as an ancestor.
+Ancestor statuses are rendered by `twittering-show-replied-statuses'."
+ (let ((pos (or pos (point))))
+ (assq 'ancestor-of (get-text-property pos 'rendered-as))))
+
+(defun twittering-get-base-id-of-ancestor-at (&optional pos)
+ "Return the base ID of a popped ancestor status rendered at POS.
+If the status at POS is not a popped ancestor status or no status is
+rendered at POS, return nil."
+ (let ((pos (or pos (point))))
+ (cdr (assq 'ancestor-of (get-text-property pos 'rendered-as)))))
(defun twittering-fill-string (str &optional adjustment prefix keep-newline)
(when (and (not (boundp 'kinsoku-limit))
@@ -5741,16 +5760,17 @@ If INTERRUPT is non-nil, the iteration is stopped if FUNC returns nil."
(defun twittering-replied-statuses-visible-p ()
(let* ((pos (twittering-get-current-status-head))
- (id (get-text-property pos 'id))
+ (id (twittering-get-id-at pos))
(prev (twittering-get-previous-status-head pos))
(next (twittering-get-next-status-head pos)))
- (or (get-text-property pos 'original-id)
- (and prev
- (twittering-status-id= id (get-text-property prev 'id))
- (get-text-property prev 'original-id))
- (and next
- (twittering-status-id= id (get-text-property next 'id))
- (get-text-property next 'original-id)))))
+ (or
+ (twittering-get-base-id-of-ancestor-at pos)
+ (and prev
+ (twittering-status-id=
+ id (twittering-get-base-id-of-ancestor-at prev)))
+ (and next
+ (twittering-status-id=
+ id (twittering-get-base-id-of-ancestor-at next))))))
(defun twittering-show-replied-statuses (&optional count interactive)
(interactive)
@@ -5781,7 +5801,8 @@ If INTERRUPT is non-nil, the iteration is stopped if FUNC returns nil."
prefix))
;; Overwrite field property.
(field-properties
- (twittering-make-field-properties status base-id)))
+ (twittering-make-field-properties-of-popped-ancestors
+ status base-id)))
(add-text-properties 0 (length formatted-status)
`(id ,base-id original-id ,id
,@field-properties)
@@ -5799,32 +5820,46 @@ If INTERRUPT is non-nil, the iteration is stopped if FUNC returns nil."
(defun twittering-hide-replied-statuses (&optional interactive)
(interactive)
- (if (twittering-replied-statuses-visible-p)
- (let* ((pos (point))
- (id (twittering-get-id-at pos))
- (beg
+ (cond
+ ((twittering-replied-statuses-visible-p)
+ (let* ((pos (twittering-get-current-status-head (point)))
+ (base-id (or (twittering-get-base-id-of-ancestor-at pos)
+ (twittering-get-id-at pos)))
+ (pointing-to-base-status
+ (not (twittering-rendered-as-ancestor-status-p pos)))
+ (beg
+ (if (and pointing-to-base-status (not twittering-reverse-mode))
+ (twittering-get-next-status-head pos)
(let ((pos pos))
(while
- (let* ((prev (or (twittering-get-previous-status-head pos)
- (point-min)))
- (prev-id (get-text-property prev 'id)))
- (when (twittering-status-id= id prev-id)
- (not (eq (setq pos prev) (point-min))))))
- pos))
- (buffer-read-only nil))
- (when (get-text-property pos 'original-id)
- (goto-char beg))
- (while (when (twittering-status-id= id (get-text-property beg 'id))
- (let ((end (or (twittering-get-next-status-head beg)
- (point-max))))
- (if (get-text-property beg 'original-id)
- (delete-region beg end)
- (setq beg end)))
- t))
- t)
- (when interactive
- (message "The replied statuses were already hided."))
- nil))
+ (let* ((prev (twittering-get-previous-status-head pos))
+ (prev-base-id
+ (when prev
+ (twittering-get-base-id-of-ancestor-at prev))))
+ (and prev
+ (twittering-status-id= base-id prev-base-id)
+ (setq pos prev))))
+ (or pos (point-min)))))
+ (end
+ (if (and pointing-to-base-status twittering-reverse-mode)
+ pos
+ (let ((pos beg))
+ (while
+ (let ((current-base-id
+ (twittering-get-base-id-of-ancestor-at pos)))
+ (and current-base-id
+ (twittering-status-id= base-id current-base-id)
+ (setq pos (twittering-get-next-status-head pos)))))
+ (or pos (point-max)))))
+ (buffer-read-only nil))
+ (unless pointing-to-base-status
+ (goto-char (if twittering-reverse-mode
+ beg
+ (or (twittering-get-previous-status-head beg)
+ (point-min)))))
+ (delete-region beg end)))
+ (interactive
+ (message "The replied statuses were already hidden."))))
(defun twittering-toggle-show-replied-statuses ()
(interactive)
Please sign in to comment.
Something went wrong with that request. Please try again.