Skip to content

Commit

Permalink
Render statuses in order of field property instead of id property.
Browse files Browse the repository at this point in the history
* twittering-mode.el: Render statuses in order of field property
instead of id property.
(twittering-make-common-properties): add field property.
(twittering-get-common-properties): likewise.
(twittering-field-id<): new function.
(twittering-field-id=): new function.
(twittering-make-field-id): new function.
(twittering-make-field-properties): new function.
(twittering-render-timeline): render statuses in order of their
field properties.
(twittering-show-replied-statuses): add special field property to
replied statuses.
  • Loading branch information
cvmat committed Jan 16, 2011
1 parent ebff110 commit 5284454
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 9 deletions.
14 changes: 14 additions & 0 deletions ChangeLog
Expand Up @@ -12,6 +12,20 @@
statuses. statuses.
(twittering-status-to-status-datum): likewise. (twittering-status-to-status-datum): likewise.


* twittering-mode.el: Render statuses in order of field property
instead of id property.
(twittering-make-common-properties): add field property as a
common property.
(twittering-get-common-properties): likewise.
(twittering-field-id<): new function.
(twittering-field-id=): new function.
(twittering-make-field-id): new function.
(twittering-make-field-properties): new function.
(twittering-render-timeline): render statuses in order of their
field properties.
(twittering-show-replied-statuses): add special field property to
replied statuses.

2011-01-09 Tadashi MATSUO <tad@mymail.twin.jp> 2011-01-09 Tadashi MATSUO <tad@mymail.twin.jp>


* twittering-mode.el: Ensure that encrypted strings are written * twittering-mode.el: Ensure that encrypted strings are written
Expand Down
53 changes: 44 additions & 9 deletions twittering-mode.el
Expand Up @@ -5042,6 +5042,7 @@ static char * unplugged_xpm[] = {
(defun twittering-make-common-properties (status) (defun twittering-make-common-properties (status)
"Generate a property list that tweets should have irrespective of format." "Generate a property list that tweets should have irrespective of format."
(apply 'append (apply 'append
`(field ,(twittering-make-field-id status))
(mapcar (lambda (entry) (mapcar (lambda (entry)
(let ((prop-sym (if (consp entry) (car entry) entry)) (let ((prop-sym (if (consp entry) (car entry) entry))
(status-sym (if (consp entry) (cdr entry) entry))) (status-sym (if (consp entry) (cdr entry) entry)))
Expand All @@ -5054,13 +5055,15 @@ static char * unplugged_xpm[] = {
The common property list is added to each rendered tweet irrespective The common property list is added to each rendered tweet irrespective
of format. The common properties follows: of format. The common properties follows:
properites generated by `twittering-make-common-properties', properites generated by `twittering-make-common-properties',
`field' added by `twittering-make-common-properties' or
`twittering-show-replied-statuses',
`original-id' added by `twittering-show-replied-statuses'." `original-id' added by `twittering-show-replied-statuses'."
(apply 'append (apply 'append
(mapcar (lambda (prop) (mapcar (lambda (prop)
(let ((value (get-text-property pos prop))) (let ((value (get-text-property pos prop)))
(when value (when value
`(,prop ,value)))) `(,prop ,value))))
'(id original-id source-id source-spec text username)))) '(field id original-id source-id source-spec text username))))


(defun twittering-format-string (string prefix replacement-table) (defun twittering-format-string (string prefix replacement-table)
"Format STRING according to PREFIX and REPLACEMENT-TABLE. "Format STRING according to PREFIX and REPLACEMENT-TABLE.
Expand Down Expand Up @@ -5355,6 +5358,33 @@ variable `twittering-status-format'."
;;;; Rendering ;;;; Rendering
;;;; ;;;;


(defun twittering-field-id< (field1 field2)
(string< field1 field2))

(defun twittering-field-id= (field1 field2)
(string= field1 field2))

(defun twittering-make-field-id (status &optional base-id)
"Generate a field property for STATUS.
Tweets are rendered in order of the field.

If BASE-ID is non-nil, generate a field id for a tweet rendered
as a popped ancestor tweet by `twittering-show-replied-statuses'.
In the case, BASE-ID means the ID of the descendant."
(let ((id (cdr (assq 'id status)))
(format-func (lambda (id) (format "%02d-%s" (length id) id))))
(cond
(base-id
(format "O:%s:5:ancestor:%s"
(funcall format-func base-id)
(funcall format-func id)))
(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-fill-string (str &optional adjustment prefix keep-newline) (defun twittering-fill-string (str &optional adjustment prefix keep-newline)
(when (and (not (boundp 'kinsoku-limit)) (when (and (not (boundp 'kinsoku-limit))
enable-kinsoku) enable-kinsoku)
Expand Down Expand Up @@ -5498,20 +5528,21 @@ variable `twittering-status-format'."
(twittering-get-first-status-head)))) (twittering-get-first-status-head))))
(mapc (mapc
(lambda (status) (lambda (status)
(let ((id (cdr (assq 'id status)))) (let ((field-id (twittering-make-field-id status)))
;; Find where the status should be inserted. ;; Find where the status should be inserted.
(while (while
(let ((buf-id (get-text-property pos 'id))) (let ((buf-field-id (get-text-property pos 'field)))
(if (and buf-id (if (and buf-field-id
(if twittering-reverse-mode (if twittering-reverse-mode
(twittering-status-id< buf-id id) (twittering-field-id< buf-field-id field-id)
(twittering-status-id< id buf-id))) (twittering-field-id< field-id buf-field-id)))
(let ((next-pos (let ((next-pos
(twittering-get-next-status-head pos))) (twittering-get-next-status-head pos)))
(setq pos (or next-pos (point-max))) (setq pos (or next-pos (point-max)))
next-pos) next-pos)
nil))) nil)))
(unless (twittering-status-id= id (get-text-property pos 'id)) (unless (twittering-field-id= field-id
(get-text-property pos 'field))
(let ((formatted-status (twittering-format-status status)) (let ((formatted-status (twittering-format-status status))
(separator "\n")) (separator "\n"))
(goto-char pos) (goto-char pos)
Expand Down Expand Up @@ -5747,9 +5778,13 @@ If INTERRUPT is non-nil, the iteration is stopped if FUNC returns nil."
(lambda (status) (lambda (status)
(let ((id (cdr (assq 'id status))) (let ((id (cdr (assq 'id status)))
(formatted-status (twittering-format-status status (formatted-status (twittering-format-status status
prefix))) prefix))
;; Overwrite field property.
(field-properties
(twittering-make-field-properties status base-id)))
(add-text-properties 0 (length formatted-status) (add-text-properties 0 (length formatted-status)
`(id ,base-id original-id ,id) `(id ,base-id original-id ,id
,@field-properties)
formatted-status) formatted-status)
(if twittering-reverse-mode (if twittering-reverse-mode
(insert-before-markers formatted-status separator) (insert-before-markers formatted-status separator)
Expand Down

0 comments on commit 5284454

Please sign in to comment.