Skip to content
Browse files

Support a new format specifier "%u" for `twittering-retweet-format'.

* twittering-mode.el: Support a new format specifier "%u" for
`twittering-retweet-format'. It is replaced with the URL of the
cited tweet.
(twittering-retweet-format): update the docstring.
(twittering-get-status-url-from-alist): new function.
(twittering-organic-retweet): support a new format specifier
"%u".
  • Loading branch information...
1 parent 8423b8b commit dfe25b699deb0e59335e196c9967bac0df7d9329 @cvmat cvmat committed Feb 28, 2012
Showing with 64 additions and 33 deletions.
  1. +8 −0 ChangeLog
  2. +11 −5 NEWS
  3. +9 −5 NEWS.ja
  4. +36 −23 twittering-mode.el
View
8 ChangeLog
@@ -129,6 +129,14 @@
should be sent as a normal tweet when it has been edited as a
reply but it does not include a mention to the cited user.
+ * twittering-mode.el: Support a new format specifier "%u" for
+ `twittering-retweet-format'. It is replaced with the URL of the
+ cited tweet.
+ (twittering-retweet-format): update the docstring.
+ (twittering-get-status-url-from-alist): new function.
+ (twittering-organic-retweet): support a new format specifier
+ "%u".
+
2012-02-12 Tadashi MATSUO <tad@mymail.twin.jp>
* twittering-mode.el: Accept a symbol as FUNC of a composite
View
16 NEWS
@@ -102,18 +102,24 @@
Since the Emacs LISP program `windows.el' written by HIROSE Yuuji
implicitly loads `revive.el' if possible, you should also take care
of the order of loading `windows.el' and the configuration.
+* New format specifier "%u" for `twittering-retweet-format'.
+ "%u" is added as a new format specifier for
+ `twittering-retweet-format'. It is replaced with the URL of the
+ cited tweet.
* Skeleton for initializing an organic retweet.
You can use a skeleton as the variable `twittering-retweet-format'
for initializing an organic retweet. This means that you can also
specify the initial cursor position. Strings included in the
skeleton are converted with the below replacement table and then the
skeleton is inserted with `skeleton-insert'.
The replacement table is as follows.
- %s: screen_name
- %t: text
- %%: %
- This is equivalent to the previous rule applied for
- `twittering-retweet-format'.
+ %s - The screen-name of the cited tweet.
+ %t - The text of the cited tweet.
+ %u - The URL of the cited tweet.
+ %# - The ID of the cited tweet.
+ %% - % itself.
+ This is equivalent to the rule applied for
+ `twittering-retweet-format' as a string.
Note that it is inserted before the edit skeleton specified by
`twittering-edit-skeleton' is performed.
* Tweet type of edit skeleton for an organic retweet.
View
14 NEWS.ja
@@ -101,18 +101,22 @@
また、同じくHIROSE Yuujiさん作のEmacs LISPプログラム`windows.el'は
`revive.el'を暗黙にloadしますので、`windows.el'をloadするタイミング
にも注意してください。
+* `twittering-retweet-format'用の新しい書式指定子"%u"
+ `twittering-retweet-format'で指定できる書式指定子として"%u"が追加さ
+ れました。これは引用されるtweetを指すURLと置き換えられます。
* skeletonによる非公式ReTweetの初期文字列設定
非公式ReTweetを編集する際の初期文字列を指定する変数
`twittering-retweet-format'にskeletonを指定できるようになりました。
文字列に加えて編集開始時のカーソル位置も指定できます。skeletonに含ま
れる文字列を下記の対応表によって変換してから、関数`skeleton-insert'
で挿入します。
対応表は以下の通りです。
- %s: screen_name
- %t: text
- %%: %
- この表は従来から`twittering-retweet-format'に適用されていた規則と同
- じです。
+ %s - 引用されるtweetの投稿者のscreen-name
+ %t - 引用されるtweetの内容
+ %u - 引用されるtweetを指すURL
+ %# - 引用されるtweetのID
+ %% - %自身
+ この表は`twittering-retweet-format'に適用される規則と同じです。
この変数`twittering-retweet-format'による初期文字列の挿入後に変数
`twittering-edit-skeleton'で指定されたedit skeletonが適用される点に
注意してください。
View
59 twittering-mode.el
@@ -407,10 +407,11 @@ Note that this skeleton is performed before the edit skeleton specified by
`twittering-edit-skeleton' is performed.
Replacement table:
- %s - screen_name
- %t - text
- %% - %
-")
+ %s - The screen-name of the cited tweet.
+ %t - The text of the cited tweet.
+ %u - The URL of the cited tweet.
+ %# - The ID of the cited tweet.
+ %% - % itself.")
(defvar twittering-fill-column nil
"*The fill-column used for \"%FILL{...}\" in `twittering-status-format'.
@@ -4245,6 +4246,17 @@ Statuses are stored in ascending-order with respect to their IDs."
twittering-service-method-table)))))
(funcall func username id)))
+(defun twittering-get-status-url-from-alist (status)
+ "Generate a URL of a tweet specified by an alist STATUS."
+ (let ((username (cdr (assq 'user-screen-name status)))
+ (id (cdr (assq 'id status)))
+ (func
+ (cdr (assq
+ 'status-url
+ (assq twittering-service-method
+ twittering-service-method-table)))))
+ (funcall func username id)))
+
(defun twittering-get-list-url (username listname)
"Generate a URL of a specific list."
(let ((func
@@ -9376,30 +9388,31 @@ How to edit a tweet is determined by `twittering-update-status-funcion'."
(defun twittering-organic-retweet ()
(interactive)
(let* ((id (twittering-get-id-at))
- (status (twittering-find-status (twittering-get-id-at))))
- (when (cdr (assq 'user-protected status))
- (error "Cannot retweet protected tweets.")))
- (let ((username (get-text-property (point) 'username))
- (text (get-text-property (point) 'text))
- (id (get-text-property (point) 'id))
- (retweet-time (current-time))
- (skeleton-with-format-string
- (cond
- ((null twittering-retweet-format)
- '(nil _ " RT: %t (via @%s)"))
- ((stringp twittering-retweet-format)
- `(nil ,twittering-retweet-format _))
- ((listp twittering-retweet-format)
- twittering-retweet-format)
- (t
- nil))))
- (when username
+ (status (twittering-find-status id))
+ (username (cdr (assq 'user-screen-name status)))
+ (text (cdr (assq 'text status)))
+ (retweet-time (current-time))
+ (skeleton-with-format-string
+ (cond
+ ((null twittering-retweet-format)
+ '(nil _ " RT: %t (via @%s)"))
+ ((stringp twittering-retweet-format)
+ `(nil ,twittering-retweet-format _))
+ ((listp twittering-retweet-format)
+ twittering-retweet-format)
+ (t
+ nil))))
+ (cond
+ ((cdr (assq 'user-protected status))
+ (error "Cannot retweet protected tweets."))
+ (username
(let ((prefix "%")
(replace-table
`(("%" . "%")
("s" . ,username)
("t" . ,text)
("#" . ,id)
+ ("u" . ,(twittering-get-status-url-from-alist status))
("C{\\([^}]*\\)}" .
(lambda (context)
(let ((str (cdr (assq 'following-string context)))
@@ -9415,7 +9428,7 @@ How to edit a tweet is determined by `twittering-update-status-funcion'."
element))
skeleton-with-format-string)
id nil 'organic-retweet)
- ))))
+ )))))
(defun twittering-native-retweet ()
(interactive)

0 comments on commit dfe25b6

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