Changeset 61 for lang/elisp/twittering-mode
- Timestamp:
- 07/31/08 16:10:43 (16 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/elisp/twittering-mode/branches/tsuyoshi/twittering-mode.el
r50 r61 59 59 (defvar twittering-mode-map (make-sparse-keymap)) 60 60 61 (defvar twittering-timer nil 62 "Timer object for timeline refreshing will be stored here. DO NOT SET VALUE 63 MANUALLY.") 61 (defvar twittering-timer nil "Timer object for timeline refreshing will be stored here. DO NOT SET VALUE MANUALLY.") 64 62 65 63 (defvar twittering-idle-time 20) … … 77 75 (make-variable-buffer-local 'twittering-jojo-mode) 78 76 79 (defvar twittering-status-format "%i %s, %@:\n %t // from %f%L"80 "Formatt Rule: 81 %s - screen_name82 %S - name83 %i - profile_image84 %d - description85 %l - location86 %L - \" [location]\"87 %u - url88 %j - user.id89 %p - protected?90 %c - created_at (raw UTC string)91 %C{time-format-str} - created_at (formatted with time-format-str)92 %@ - X seconds ago93 %t - text94 %' - truncated95 %f - source96 %# - id") 77 (defvar twittering-status-format nil) 78 (setq twittering-status-format "%i %s, %@:\n %t // from %f%L") 79 ;; %s - screen_name 80 ;; %S - name 81 ;; %i - profile_image 82 ;; %d - description 83 ;; %l - location 84 ;; %L - " [location]" 85 ;; %u - url 86 ;; %j - user.id 87 ;; %p - protected? 88 ;; %c - created_at (raw UTC string) 89 ;; %C{time-format-str} - created_at (formatted with time-format-str) 90 ;; %@ - X seconds ago 91 ;; %t - text 92 ;; %' - truncated 93 ;; %f - source 94 ;; %# - id 97 95 98 96 (defvar twittering-buffer "*twittering*") … … 100 98 (twittering-get-or-generate-buffer twittering-buffer)) 101 99 102 (defvar twittering-http-buffer " 100 (defvar twittering-http-buffer "*twittering-http-buffer*") 103 101 (defun twittering-http-buffer () 104 102 (twittering-get-or-generate-buffer twittering-http-buffer)) 105 103 106 104 (defvar twittering-friends-timeline-data nil) 105 (defvar twittering-friends-timeline-last-update nil) 107 106 108 107 (defvar twittering-username-face 'twittering-username-face) … … 156 155 ;;; to show image files 157 156 158 (defvar twittering-wget-buffer " 157 (defvar twittering-wget-buffer "*twittering-wget-buffer*") 159 158 (defun twittering-wget-buffer () 160 159 (twittering-get-or-generate-buffer twittering-wget-buffer)) … … 205 204 (t nil))) 206 205 206 (defun twittering-setftime (fmt string uni) 207 (format-time-string fmt ; like "%Y-%m-%d %H:%M:%S" 208 (apply 'encode-time (parse-time-string string)) 209 uni)) 207 210 (defun twittering-local-strftime (fmt string) 208 (format-time-string fmt ; like "%Y-%m-%d %H:%M:%S", shown in localtime 209 (apply 'encode-time (parse-time-string string)))) 211 (twittering-setftime fmt string nil)) 212 (defun twittering-global-strftime (fmt string) 213 (twittering-setftime fmt string t)) 214 210 215 211 216 (defvar twittering-debug-mode nil) … … 255 260 (define-key km "s" 'twittering-scroll-mode) 256 261 (define-key km "t" 'twittering-toggle-proxy) 257 (define-key km "F" 'twittering-status-toggle-favorite)258 262 (define-key km "\C-c\C-p" 'twittering-toggle-proxy) 259 263 nil)) … … 327 331 ;;; 328 332 329 (defun twittering-http-get (method-class method &optional sentinel)333 (defun twittering-http-get (method-class method &optional parameters sentinel) 330 334 (if (null sentinel) (setq sentinel 'twittering-http-get-default-sentinel)) 331 335 … … 357 361 request) 358 362 (setq request 359 (concat "GET http://twitter.com/" method-class "/" method ".xml HTTP/1.1" nl 363 (concat "GET http://twitter.com/" method-class "/" method 364 ".xml" 365 (when parameters 366 (concat "?" 367 (mapconcat 368 (lambda (param-pair) 369 (format "%s=%s" 370 (twittering-percent-encode (car param-pair)) 371 (twittering-percent-encode (cdr param-pair)))) 372 parameters 373 "&"))) 374 " HTTP/1.1" nl 360 375 "Host: twitter.com" nl 361 376 "User-Agent: " (twittering-user-agent) nl … … 380 395 proxy-password)) 381 396 nl))) 382 nl nl))397 nl)) 383 398 (debug-print (concat "GET Request\n" request)) 384 399 request))) … … 544 559 (let ((formatted-status (apply 'concat (nreverse result)))) 545 560 (add-text-properties 0 (length formatted-status) 546 `(username ,(attr 'user-screen-name) 547 id ,(attr 'id) 548 favorited ,(attr 'favorited)) 561 `(username ,(attr 'user-screen-name)) 549 562 formatted-status) 550 563 formatted-status) … … 586 599 request) 587 600 (setq request 588 (concat "POST http://twitter.com/" method-class "/" method ".xml?" 589 (if parameters 590 (mapconcat 591 (lambda (param-pair) 592 (format "%s=%s" 593 (twittering-percent-encode (car param-pair)) 594 (twittering-percent-encode (cdr param-pair)))) 595 parameters 596 "&")) 601 (concat "POST http://twitter.com/" method-class "/" method ".xml" 602 (when parameters 603 (concat "?" 604 (mapconcat 605 (lambda (param-pair) 606 (format "%s=%s" 607 (twittering-percent-encode (car param-pair)) 608 (twittering-percent-encode (cdr param-pair)))) 609 parameters 610 "&"))) 597 611 " HTTP/1.1" nl 598 612 "Host: twitter.com" nl … … 613 627 proxy-password)) 614 628 nl))) 615 nl nl))629 nl)) 616 630 (debug-print (concat "POST Request\n" request)) 617 631 request))))) … … 683 697 (let* ((status-data (cddr status)) 684 698 id text source created-at truncated 685 favorited in_reply_to_status_id in_reply_to_user_id686 699 (user-data (cddr (assq 'user status-data))) 687 700 user-id user-name … … 701 714 (setq created-at (assq-get 'created_at status-data)) 702 715 (setq truncated (assq-get 'truncated status-data)) 703 (setq favorited (assq-get 'favorited status-data))704 (setq in_reply_to_user_id (assq-get 'in_reply_to_user_id status-data))705 (setq in_reply_to_user_id (assq-get 'in_reply_to_status_id status-data))706 716 (setq user-id (string-to-number (assq-get 'id user-data))) 707 717 (setq user-name (twittering-decode-html-entities … … 776 786 )) 777 787 788 ;; save last update time 789 (setq twittering-friends-timeline-last-update created-at) 790 778 791 (mapcar 779 792 (lambda (sym) 780 793 `(,sym . ,(symbol-value sym))) 781 794 '(id text source created-at truncated 782 favorited in_reply_to_status_id in_reply_to_user_id783 795 user-id user-name user-screen-name user-location 784 796 user-description … … 888 900 ("source" . "twmode"))))) 889 901 890 (defun twittering-http-get-fav-sentinel (proc stat &optional suc-msg)891 (flet ((assq-get (item seq)892 (car (cddr (assq item seq)))))893 (let ((header (twittering-get-response-header))894 (body (twittering-get-response-body))895 (status nil))896 (if (string-match "HTTP/1\.[01] \\([a-z0-9 ]+\\)\r?\n" header)897 (progn898 (setq status (match-string-no-properties 1 header))899 (case-string900 status901 (("200 OK")902 (let ((status-data903 ;;(assq-get 'status body)904 (cddr (car body))905 ))906 (message "status %s: favorited - %s"907 (assq-get 'id status-data)908 (assq-get 'favorited status-data))))909 (t (message status))))910 (message "Failure: Bad http response.")))))911 912 (defun twittering-status-set-favorite (id)913 (with-temp-buffer914 (twittering-http-get "favourings" (format "create/%d" id)915 'twittering-http-get-fav-sentinel)))916 917 (defun twittering-status-destroy-favorite (id)918 (with-temp-buffer919 (twittering-http-get "favourings" (format "destroy/%d" id)920 'twittering-http-get-fav-sentinel)))921 922 (defun twittering-status-toggle-favorite ()923 (interactive)924 (let ((id (get-text-property (point) 'id))925 (favorite-status926 (string-equal "true" (get-text-property (point) 'favorited))))927 (if favorite-status928 ;; destroy929 (progn930 (twittering-status-destroy-favorite id)931 (message "Destory favorite : %d" id))932 (twittering-status-set-favorite id)933 (message "Set favorite : %d" id))))934 935 902 ;;; 936 903 ;;; Commands … … 958 925 (if (not buf) 959 926 (twittering-stop) 960 (twittering-http-get "statuses" "friends_timeline") 961 )) 927 (if (not twittering-friends-timeline-last-update) 928 (twittering-http-get "statuses" "friends_timeline") 929 (let* ((system-time-locale "C") 930 (since 931 (twittering-global-strftime 932 "%a, %d %b %Y %H:%M:%S GMT" 933 twittering-friends-timeline-last-update))) 934 (twittering-http-get "statuses" "friends_timeline" 935 `(("since" . ,since))))))) 962 936 963 937 (if twittering-icon-mode … … 988 962 (interactive) 989 963 (setq twittering-friends-timeline-data nil) 990 (twittering-http-get "statuses" "friends_timeline")) 964 (if (not twittering-friends-timeline-last-update) 965 (twittering-http-get "statuses" "friends_timeline") 966 (let* ((system-time-locale "C") 967 (since 968 (twittering-global-strftime 969 "%a, %d %b %Y %H:%M:%S GMT" 970 twittering-friends-timeline-last-update))) 971 (twittering-http-get "statuses" "friends_timeline" 972 `(("since" . ,since)))))) 991 973 992 974 (defun twittering-click ()