松尾です。

> 一通りsyncして、それなりに動いている気がしたので、topic
> branchに起こしました。
> 
> http://github.com/yata/twittering-mode/tree/search-mode

twittering-search()がtwittering-get-and-render-timeline()を
経由しないのでspec-stringの更新ができていなかったのと、
method内にqueryも埋め込んでいる部分が気になったので
少し整理してpatchを作ってみました。fix-search-mode.patch
として添付してあります。

大きい変更点は2点です。
・twittering-timeline-spec-to-host-method()がsearch specに
 対しては3要素のリストを返すようにしてます。
 (名前に合わないですが…)

・twittering-search()は自分自身でspecを生成して
  twittering-get-and-render-timeline()を呼びます。
  何らかのtweets取得時には必ず
  twittering-get-and-render-timeline()を
  通りますので、twittering-get-tweets()にあったjson.elに
  関するエラー出力も...-get-and-render-timeline()に移動して
  あります。

> > queryのエスケープをどうすべきかが判断できなかったのでsearchは
> > 未実装です。
> 
> と書かれていたのを思い出してちょっと途方に暮れましたが、
> 結局それは棚上げしたので、とりあえずの実装としては
> 
> | QUERY_STRING ::= /[a-zA-Z0-9_-]+/
> 
> です。動作確認には"twittering-mode"で検索してました…。

こちらの件ですが、queryとして空白も含められるように
するべきと思います。とりあえず:filterと同じ形式で
:search/QUERY/
という風にしてみました。QUERYとして任意の文字を使えるように
するため、終了文字/を追加しています。\でエスケープすれば
QUERY自体に/も含められます。
:search/QUERY/ではQUERYの部分が正規表現のリテラルみたいにも
見えるので、区切り文字/は何か別のものにすべきかもしれません。
patchはfix-search-spec-string.patchとして添付してあります。

今は完全に:search/QUERY/に合致するものだけを受け付けますが
単一のspecを入力している時には終了文字は自動的に補完した方が
良いかもしれません。あと、現状のcompleting-readでは空白文字の
入力時にquoted-insertしないといけないので少し面倒です。

---
松尾 直志 <t...@mymail.twin.jp>
# HG changeset patch
# User Tadashi MATSUO <t...@mymail.twin.jp>
# Date 1264192131 -32400
# Node ID f8fa2461e70978cbd59510ff75a03cd85615da2e
# Parent  055ba3733517ffbbf13797c6cb3e24bd5183f770
[mq]: fix-search-mode

diff --git a/ChangeLog b/ChangeLog
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2010-01-23  Tadashi MATSUO  <t...@mymail.twin.jp>
+
+       * twittering-mode.el (twittering-timeline-spec-to-host-method):
+       return query string as a element of returned list.
+       (twittering-host-method-to-timeline-spec): receive query string as
+       a optional argument.
+       (twittering-http-get): remove special adjustment for search
+       method, which is now unnecessary.
+       (twittering-get-tweets): always receive query string as an
+       argument for search method.
+       (twittering-get-search): removed.
+       (twittering-get-and-render-timeline): send query string if the
+       given spec is `search'.
+       (twittering-search): execute search via
+       `twittering-get-and-render-timeline'.
+
 2010-01-22  Satoshi Yatagawa  <yata_git...@y.haun.org>
 
        * twittering-mode.el: Add search support (which was originally
diff --git a/twittering-mode.el b/twittering-mode.el
--- a/twittering-mode.el
+++ b/twittering-mode.el
@@ -788,13 +788,13 @@
          '("api.twitter.com" "1/statuses/retweets_of_me"))
         ((eq type 'search)
          (let ((word (car value)))
-           `("search.twitter.com" ,(concat "search=" word))))
+           `("search.twitter.com" "search" ,word)))
         (t
          (error "Invalid timeline spec")
          nil)))
     nil))
 
-(defun twittering-host-method-to-timeline-spec (host method)
+(defun twittering-host-method-to-timeline-spec (host method &optional word)
   (cond
    ((or (not (stringp host)) (not (stringp method))) nil)
    ((string= host "twitter.com")
@@ -820,11 +820,7 @@
        `(list ,username ,listname)))
      (t nil)))
    ((string= host "search.twitter.com")
-    (cond
-     ((string-match "^search=\\([a-zA-Z0-9_-]+\\)" method)
-      (let ((word (match-string-no-properties 1 method)))
-       `(search ,word)))
-     (t nil)))
+    `(search ,word))
    (t nil)))
 
 (defun twittering-add-timeline-history (&optional timeline-spec)
@@ -1447,13 +1443,6 @@
       (setq sentinel 'twittering-http-get-default-sentinel))
   (if (null format)
       (setq format "xml"))
-
-  ;; NOTE: in search-mode, a 'method' variable is now contains a query
-  ;; word for internal use. for this reason, we must adjust it before
-  ;; pass it into 'twittering-start-http-session'.
-  (if (string-match "^search=" method)
-      (setq method "search"))
-
   (twittering-start-http-session
    "GET" (twittering-http-application-headers "GET")
    host nil (concat "/" method "." format) parameters noninteractive sentinel))
@@ -2493,9 +2482,7 @@
     (if (not buf)
        (twittering-stop)
       (let* ((default-count 20)
-            (regexp-search-method "^search=\\([a-zA-Z0-9_-]+\\)$")
-            (do-search-flag (string-match regexp-search-method method))
-            (prev_word (match-string 1 method))
+            (do-search-flag (not (null word)))
             (max-count (if do-search-flag
                            100 ;; FIXME: refer to defconst.
                          twittering-max-number-of-tweets-on-retrieval))
@@ -2511,9 +2498,7 @@
 
        (cond
         (do-search-flag
-         (or (require 'json nil t)
-             (error "A search-mode is currently disabled; need json.el"))
-         (add-to-list 'parameters (cons "q" (if word word prev_word)))
+         (add-to-list 'parameters (cons "q" word))
          (add-to-list 'parameters (cons "rpp" (number-to-string count)))
          (if id
              (add-to-list 'parameters `("max_id" . ,id)))
@@ -2545,13 +2530,6 @@
       (mapc 'twittering-retrieve-image twittering-image-stack)
     ))
 
-(defun twittering-get-search (word)
-  (let ((pair (twittering-timeline-spec-to-host-method `(search ,word))))
-    (when pair
-      (let ((host (car pair))
-           (method (cadr pair)))
-       (twittering-get-tweets host method nil nil word)))))
-
 (defun twittering-get-and-render-timeline (spec &optional noninteractive id)
   (let* ((original-spec spec)
         (spec-string (if (stringp spec)
@@ -2570,11 +2548,22 @@
       (setq twittering-timeline-last-update nil
            twittering-timeline-data nil))
     (if (twittering-timeline-spec-primary-p spec)
-       (let ((pair (twittering-timeline-spec-to-host-method spec)))
-         (when pair
-           (let ((host (car pair))
-                 (method (cadr pair)))
-             (twittering-get-tweets host method noninteractive id))))
+       (let ((info (twittering-timeline-spec-to-host-method spec)))
+         (cond
+          ((null info) nil)
+          ((eq 'search (car spec))
+           (let ((host (elt info 0))
+                 (method (elt info 1))
+                 (word (elt info 2)))
+             (if (require 'json nil t)
+                 (twittering-get-tweets host method noninteractive id word)
+               (message "search-mode is currently disabled; need json.el.")
+               )))
+          (t
+           (let ((host (car info))
+                 (method (cadr info)))
+             (twittering-get-tweets host method noninteractive id)))
+          ))
       (let ((type (car spec)))
        (error "%s has not been supported yet" type)))))
 
@@ -2972,7 +2961,8 @@
        (if (null word)
            (setq word (read-from-minibuffer "search: " nil nil nil 
'twittering-search-history nil t)))
        (if (> (length word) 0)
-           (twittering-get-search word)
+             (let ((spec `(search ,word)))
+               (twittering-get-and-render-timeline spec))
          (message "No query string")))
     (message "search-mode is currently disabled; need json.el.")))
 
# HG changeset patch
# User Tadashi MATSUO <t...@mymail.twin.jp>
# Date 1264192166 -32400
# Node ID 8ec080dc54d0635ab78715a56b46da8b5c4c5ab4
# Parent  f8fa2461e70978cbd59510ff75a03cd85615da2e
[mq]: fix-search-spec-string

diff --git a/ChangeLog b/ChangeLog
--- a/ChangeLog
+++ b/ChangeLog
@@ -14,6 +14,10 @@
        (twittering-search): execute search via
        `twittering-get-and-render-timeline'.
 
+       * twittering-mode.el (twittering-timeline-spec-to-string): modify
+       the string format of `search' spec.
+       (twittering-extract-timeline-spec): likewise.
+
 2010-01-22  Satoshi Yatagawa  <yata_git...@y.haun.org>
 
        * twittering-mode.el: Add search support (which was originally
diff --git a/twittering-mode.el b/twittering-mode.el
--- a/twittering-mode.el
+++ b/twittering-mode.el
@@ -587,8 +587,8 @@
 ;;; RETWEETED_TO_ME ::= ":retweeted_to_me"
 ;;; RETWEETS_OF_ME ::= ":retweets_of_me"
 ;;;
-;;; SEARCH ::= ":search=" QUERY_STRING
-;;; QUERY_STRING ::= /[a-zA-Z0-9_-]+/
+;;; SEARCH ::= ":search/" QUERY_STRING "/"
+;;; QUERY_STRING ::= any string, where "/" is escaped by a backslash.
 ;;; MERGE ::= "(" MERGED_SPECS ")"
 ;;; MERGED_SPECS ::= SPEC | SPEC "+" MERGED_SPECS
 ;;; FILTER ::= ":filter/" REGEXP "/" SPEC
@@ -615,7 +615,11 @@
      ((eq type 'retweeted_by_me) ":retweeted_by_me")
      ((eq type 'retweeted_to_me) ":retweeted_to_me")
      ((eq type 'retweets_of_me) ":retweets_of_me")
-     ((eq type 'search) (concat ":search=" (car value)))
+     ((eq type 'search)
+      (let ((query (car value)))
+       (concat ":search/"
+               (replace-regexp-in-string "/" "\\/" query nil t)
+               "/")))
      ;; composite
      ((eq type 'filter)
       (let ((regexp (car value))
@@ -666,10 +670,12 @@
        (let ((first-spec (list (cdr (assoc type alist)))))
          (cons first-spec following)))
        ((string= type "search")
-       (if (string-match "^:search=\\([a-zA-Z0-9_-]+\\)" str)
-           (let ((word (match-string 1 str))
-                 (rest (substring str (match-end 0))))
-             `((search ,word) . ,rest))))
+       (if (string-match "^:search/\\(.*?[^\\]\\)??/" str)
+           (let* ((escaped-query (match-string 1 str))
+                  (query (replace-regexp-in-string "\\\\/" "/"
+                                                   escaped-query nil t))
+                  (rest (substring str (match-end 0))))
+             `((search ,query) . ,rest))))
        ((string= type "filter")
        (if (string-match "^:filter/\\(.*?[^\\]\\)??/" str)
            (let* ((escaped-regexp (or (match-string 1 str) ""))
------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________
twmode-users mailing list
twmode-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/twmode-users

メールによる返信