Changeset 54 for lang/elisp/wassr-mode/trunk
- Timestamp:
- 07/09/08 14:33:59 (16 years ago)
- Files:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
lang/elisp/wassr-mode/trunk/wassr-mode.el
r47 r54 1 ;;; twittering-mode.el --- Major mode for Twitter 2 3 ;; Copyright (C) 2007 Yuto Hayamizu. 4 ;; 2008 Tsuyoshi CHO 1 ;;; wassr-mode.el --- Major mode for Wassr 2 3 ;; Copyright (C) 2008 Tsuyoshi CHO 5 4 6 5 ;; Author: Y. Hayamizu <y.hayamizu@gmail.com> … … 8 7 ;; Created: Sep 4, 2007 9 8 ;; Version: 0.4 10 ;; Keywords: twitter web11 ;; URL: http://lambdarepos.svnrepository.com/share/trac.cgi/browser/lang/elisp/twittering-mode9 ;; Keywords: wassr web 10 ;; URL: 12 11 13 12 ;; This file is free software; you can redistribute it and/or modify … … 28 27 ;;; Commentary: 29 28 30 ;; twittering-mode.el is a major mode for Twitter.29 ;; wassr-mode.el based on wassr-mode.el is a major mode for Wassr. 31 30 ;; You can check friends timeline, and update your status on Emacs. 32 31 33 32 ;;; Feature Request: 34 35 ;; URL : http://twitter.com/d00dle/statuses/57787608236 ;; URL : http://twitter.com/d00dle/statuses/57787973237 ;; * Status Input from Popup buffer and C-cC-c to POST.38 ;; * Mark fav(star)39 ;; URL : http://code.nanigac.com/source/view/41940 ;; * update status for region41 33 42 34 ;;; Code: … … 46 38 (require 'parse-time) 47 39 48 (defconst twittering-mode-version "0.5")49 50 (defun twittering-mode-version ()51 "Display a message for twittering-mode version."40 (defconst wassr-mode-version "0.1") 41 42 (defun wassr-mode-version () 43 "Display a message for wassr-mode version." 52 44 (interactive) 53 45 (let ((version-string 54 (format " twittering-mode-v%s" twittering-mode-version)))46 (format "wassr-mode-v%s" wassr-mode-version))) 55 47 (if (interactive-p) 56 48 (message "%s" version-string) 57 49 version-string))) 58 50 59 (defvar twittering-mode-map (make-sparse-keymap))60 61 (defvar twittering-timer nil "Timer object for timeline refreshing will be stored here. DO NOT SET VALUE MANUALLY.")62 63 (defvar twittering-idle-time 20)64 65 (defvar twittering-timer-interval 90)66 67 (defvar twittering-username nil)68 69 (defvar twittering-password nil)70 71 (defvar twittering-scroll-mode nil)72 (make-variable-buffer-local ' twittering-scroll-mode)73 74 (defvar twittering-jojo-mode nil)75 (make-variable-buffer-local ' twittering-jojo-mode)76 77 (defvar twittering-status-format nil)78 (setq twittering-status-format "%i %s, %@:\n %t // from %f%L")51 (defvar wassr-mode-map (make-sparse-keymap)) 52 53 (defvar wassr-timer nil "Timer object for timeline refreshing will be stored here. DO NOT SET VALUE MANUALLY.") 54 55 (defvar wassr-idle-time 20) 56 57 (defvar wassr-timer-interval 90) 58 59 (defvar wassr-username nil) 60 61 (defvar wassr-password nil) 62 63 (defvar wassr-scroll-mode nil) 64 (make-variable-buffer-local 'wassr-scroll-mode) 65 66 (defvar wassr-jojo-mode nil) 67 (make-variable-buffer-local 'wassr-jojo-mode) 68 69 (defvar wassr-status-format nil) 70 (setq wassr-status-format "%i %s, %@:\n %t // from %f%L") 79 71 ;; %s - screen_name 80 72 ;; %S - name … … 94 86 ;; %# - id 95 87 96 (defvar twittering-buffer "*twittering*")97 (defun twittering-buffer ()98 ( twittering-get-or-generate-buffer twittering-buffer))99 100 (defvar twittering-http-buffer "*twittering-http-buffer*")101 (defun twittering-http-buffer ()102 ( twittering-get-or-generate-buffer twittering-http-buffer))103 104 (defvar twittering-friends-timeline-data nil)105 106 (defvar twittering-username-face 'twittering-username-face)107 (defvar twittering-uri-face 'twittering-uri-face)108 109 (defun twittering-get-or-generate-buffer (buffer)88 (defvar wassr-buffer "*wassr*") 89 (defun wassr-buffer () 90 (wassr-get-or-generate-buffer wassr-buffer)) 91 92 (defvar wassr-http-buffer "*wassr-http-buffer*") 93 (defun wassr-http-buffer () 94 (wassr-get-or-generate-buffer wassr-http-buffer)) 95 96 (defvar wassr-friends-timeline-data nil) 97 98 (defvar wassr-username-face 'wassr-username-face) 99 (defvar wassr-uri-face 'wassr-uri-face) 100 101 (defun wassr-get-or-generate-buffer (buffer) 110 102 (if (bufferp buffer) 111 103 (if (buffer-live-p buffer) … … 122 114 123 115 ;;; Proxy 124 (defvar twittering-proxy-use nil)125 (defvar twittering-proxy-server nil)126 (defvar twittering-proxy-port 8080)127 (defvar twittering-proxy-user nil)128 (defvar twittering-proxy-password nil)129 130 (defun twittering-toggle-proxy () ""131 (interactive) 132 (setq twittering-proxy-use133 (not twittering-proxy-use))116 (defvar wassr-proxy-use nil) 117 (defvar wassr-proxy-server nil) 118 (defvar wassr-proxy-port 8080) 119 (defvar wassr-proxy-user nil) 120 (defvar wassr-proxy-password nil) 121 122 (defun wassr-toggle-proxy () "" 123 (interactive) 124 (setq wassr-proxy-use 125 (not wassr-proxy-use)) 134 126 (message "%s %s" 135 127 "Use Proxy:" 136 (if twittering-proxy-use128 (if wassr-proxy-use 137 129 "on" "off"))) 138 130 139 (defun twittering-user-agent-default-function ()140 " Twitteringmode default User-Agent function."131 (defun wassr-user-agent-default-function () 132 "Wassr mode default User-Agent function." 141 133 (concat "Emacs/" 142 134 (int-to-string emacs-major-version) "." (int-to-string 143 135 emacs-minor-version) 144 136 " " 145 " Twittering-mode/"146 twittering-mode-version))147 148 (defvar twittering-user-agent-function 'twittering-user-agent-default-function)149 150 (defun twittering-user-agent ()137 "Wassr-mode/" 138 wassr-mode-version)) 139 140 (defvar wassr-user-agent-function 'wassr-user-agent-default-function) 141 142 (defun wassr-user-agent () 151 143 "Return User-Agent header string." 152 (funcall twittering-user-agent-function))144 (funcall wassr-user-agent-function)) 153 145 154 146 ;;; to show image files 155 147 156 (defvar twittering-wget-buffer "*twittering-wget-buffer*")157 (defun twittering-wget-buffer ()158 ( twittering-get-or-generate-buffer twittering-wget-buffer))159 160 (defvar twittering-tmp-dir161 (expand-file-name (concat " twmode-images-" (user-login-name))148 (defvar wassr-wget-buffer "*wassr-wget-buffer*") 149 (defun wassr-wget-buffer () 150 (wassr-get-or-generate-buffer wassr-wget-buffer)) 151 152 (defvar wassr-tmp-dir 153 (expand-file-name (concat "wassr-mode-images-" (user-login-name)) 162 154 temporary-file-directory)) 163 155 164 (defvar twittering-icon-mode nil "You MUST NOT CHANGE this variable directory. You should change through function'twittering-icon-mode'")165 (make-variable-buffer-local ' twittering-icon-mode)166 (defun twittering-icon-mode (&optional arg)167 (interactive) 168 (setq twittering-icon-mode169 (if twittering-icon-mode156 (defvar wassr-icon-mode nil "You MUST NOT CHANGE this variable directory. You should change through function'wassr-icon-mode'") 157 (make-variable-buffer-local 'wassr-icon-mode) 158 (defun wassr-icon-mode (&optional arg) 159 (interactive) 160 (setq wassr-icon-mode 161 (if wassr-icon-mode 170 162 (if (null arg) 171 163 nil … … 173 165 (when (or (null arg) 174 166 (and arg (> (prefix-numeric-value arg) 0))) 175 (when (file-writable-p twittering-tmp-dir)167 (when (file-writable-p wassr-tmp-dir) 176 168 (progn 177 (if (not (file-directory-p twittering-tmp-dir))178 (make-directory twittering-tmp-dir))169 (if (not (file-directory-p wassr-tmp-dir)) 170 (make-directory wassr-tmp-dir)) 179 171 t))))) 180 ( twittering-render-friends-timeline))181 182 (defun twittering-scroll-mode (&optional arg)183 (interactive) 184 (setq twittering-scroll-mode172 (wassr-render-friends-timeline)) 173 174 (defun wassr-scroll-mode (&optional arg) 175 (interactive) 176 (setq wassr-scroll-mode 185 177 (if (null arg) 186 (not twittering-scroll-mode)178 (not wassr-scroll-mode) 187 179 (> (prefix-numeric-value arg) 0)))) 188 180 189 (defun twittering-jojo-mode (&optional arg)190 (interactive) 191 (setq twittering-jojo-mode181 (defun wassr-jojo-mode (&optional arg) 182 (interactive) 183 (setq wassr-jojo-mode 192 184 (if (null arg) 193 (not twittering-jojo-mode)185 (not wassr-jojo-mode) 194 186 (> (prefix-numeric-value arg) 0)))) 195 187 196 (defvar twittering-image-stack nil)197 198 (defun twittering-image-type (file-name)188 (defvar wassr-image-stack nil) 189 190 (defun wassr-image-type (file-name) 199 191 (cond 200 192 ((string-match "\\.jpe?g" file-name) 'jpeg) … … 203 195 (t nil))) 204 196 205 (defun twittering-local-strftime (fmt string)197 (defun wassr-local-strftime (fmt string) 206 198 (format-time-string fmt ; like "%Y-%m-%d %H:%M:%S", shown in localtime 207 199 (apply 'encode-time (parse-time-string string)))) 208 200 209 (defvar twittering-debug-mode nil)210 (defvar twittering-debug-buffer "*debug*")211 (defun twittering-debug-buffer ()212 ( twittering-get-or-generate-buffer twittering-debug-buffer))201 (defvar wassr-debug-mode nil) 202 (defvar wassr-debug-buffer "*debug*") 203 (defun wassr-debug-buffer () 204 (wassr-get-or-generate-buffer wassr-debug-buffer)) 213 205 (defmacro debug-print (obj) 214 206 (let ((obsym (gensym))) 215 207 `(let ((,obsym ,obj)) 216 (if twittering-debug-mode217 (with-current-buffer ( twittering-debug-buffer)208 (if wassr-debug-mode 209 (with-current-buffer (wassr-debug-buffer) 218 210 (insert (prin1-to-string ,obsym)) 219 211 (newline) … … 221 213 ,obsym)))) 222 214 223 (defun twittering-debug-mode ()224 (interactive) 225 (setq twittering-debug-mode226 (not twittering-debug-mode))227 (message (if twittering-debug-mode "debug mode:on" "debug mode:off")))228 229 (if twittering-mode-map230 (let ((km twittering-mode-map))231 (define-key km "\C-c\C-f" ' twittering-friends-timeline)232 (define-key km "\C-c\C-s" ' twittering-update-status-interactive)233 (define-key km "\C-c\C-e" ' twittering-erase-old-statuses)234 (define-key km "\C-m" ' twittering-enter)235 (define-key km "\C-c\C-l" ' twittering-update-lambda)236 (define-key km [mouse-1] ' twittering-click)237 (define-key km "\C-c\C-v" ' twittering-view-user-page)215 (defun wassr-debug-mode () 216 (interactive) 217 (setq wassr-debug-mode 218 (not wassr-debug-mode)) 219 (message (if wassr-debug-mode "debug mode:on" "debug mode:off"))) 220 221 (if wassr-mode-map 222 (let ((km wassr-mode-map)) 223 (define-key km "\C-c\C-f" 'wassr-friends-timeline) 224 (define-key km "\C-c\C-s" 'wassr-update-status-interactive) 225 (define-key km "\C-c\C-e" 'wassr-erase-old-statuses) 226 (define-key km "\C-m" 'wassr-enter) 227 (define-key km "\C-c\C-l" 'wassr-update-lambda) 228 (define-key km [mouse-1] 'wassr-click) 229 (define-key km "\C-c\C-v" 'wassr-view-user-page) 238 230 ;; (define-key km "j" 'next-line) 239 231 ;; (define-key km "k" 'previous-line) 240 (define-key km "j" ' twittering-goto-next-status)241 (define-key km "k" ' twittering-goto-previous-status)232 (define-key km "j" 'wassr-goto-next-status) 233 (define-key km "k" 'wassr-goto-previous-status) 242 234 (define-key km "l" 'forward-char) 243 235 (define-key km "h" 'backward-char) … … 245 237 (define-key km "^" 'beginning-of-line-text) 246 238 (define-key km "$" 'end-of-line) 247 (define-key km "n" ' twittering-goto-next-status-of-user)248 (define-key km "p" ' twittering-goto-previous-status-of-user)239 (define-key km "n" 'wassr-goto-next-status-of-user) 240 (define-key km "p" 'wassr-goto-previous-status-of-user) 249 241 (define-key km [backspace] 'backward-char) 250 242 (define-key km "G" 'end-of-buffer) 251 243 (define-key km "H" 'beginning-of-buffer) 252 (define-key km "i" ' twittering-icon-mode)253 (define-key km "s" ' twittering-scroll-mode)254 (define-key km "t" ' twittering-toggle-proxy)255 (define-key km "\C-c\C-p" ' twittering-toggle-proxy)244 (define-key km "i" 'wassr-icon-mode) 245 (define-key km "s" 'wassr-scroll-mode) 246 (define-key km "t" 'wassr-toggle-proxy) 247 (define-key km "\C-c\C-p" 'wassr-toggle-proxy) 256 248 nil)) 257 249 258 (defvar twittering-mode-syntax-table nil "")259 260 (if twittering-mode-syntax-table250 (defvar wassr-mode-syntax-table nil "") 251 252 (if wassr-mode-syntax-table 261 253 () 262 (setq twittering-mode-syntax-table (make-syntax-table))263 ;; (modify-syntax-entry ? "" twittering-mode-syntax-table)264 (modify-syntax-entry ?\" "w" twittering-mode-syntax-table)254 (setq wassr-mode-syntax-table (make-syntax-table)) 255 ;; (modify-syntax-entry ? "" wassr-mode-syntax-table) 256 (modify-syntax-entry ?\" "w" wassr-mode-syntax-table) 265 257 ) 266 258 267 (defun twittering-mode-init-variables ()259 (defun wassr-mode-init-variables () 268 260 ;; (make-variable-buffer-local 'variable) 269 261 ;; (setq variable nil) 270 262 (font-lock-mode -1) 271 (defface twittering-username-face263 (defface wassr-username-face 272 264 `((t nil)) "" :group 'faces) 273 (copy-face 'font-lock-string-face ' twittering-username-face)274 (set-face-attribute ' twittering-username-face nil :underline t)275 (defface twittering-uri-face265 (copy-face 'font-lock-string-face 'wassr-username-face) 266 (set-face-attribute 'wassr-username-face nil :underline t) 267 (defface wassr-uri-face 276 268 `((t nil)) "" :group 'faces) 277 (set-face-attribute ' twittering-uri-face nil :underline t)278 (add-to-list 'minor-mode-alist '( twittering-icon-mode " tw-icon"))279 (add-to-list 'minor-mode-alist '( twittering-scroll-mode " tw-scroll"))280 (add-to-list 'minor-mode-alist '( twittering-jojo-mode " tw-jojo"))269 (set-face-attribute 'wassr-uri-face nil :underline t) 270 (add-to-list 'minor-mode-alist '(wassr-icon-mode " ws-icon")) 271 (add-to-list 'minor-mode-alist '(wassr-scroll-mode " ws-scroll")) 272 (add-to-list 'minor-mode-alist '(wassr-jojo-mode " ws-jojo")) 281 273 ) 282 274 … … 295 287 ;; If you use Emacs21, decode-char 'ucs will fail unless Mule-UCS is loaded. 296 288 ;; TODO: Show error messages if Emacs 21 without Mule-UCS 297 (defmacro twittering-ucs-to-char (num)289 (defmacro wassr-ucs-to-char (num) 298 290 (if (functionp 'ucs-to-char) 299 291 `(ucs-to-char ,num) 300 292 `(decode-char 'ucs ,num))) 301 293 302 (defvar twittering-mode-string "Twitteringmode")303 304 (defvar twittering-mode-hook nil305 " Twittering-mode hook.")306 307 (defun twittering-mode ()308 "Major mode for Twitter"309 (interactive) 310 (switch-to-buffer ( twittering-buffer))294 (defvar wassr-mode-string "Wassr mode") 295 296 (defvar wassr-mode-hook nil 297 "Wassr-mode hook.") 298 299 (defun wassr-mode () 300 "Major mode for Wassr" 301 (interactive) 302 (switch-to-buffer (wassr-buffer)) 311 303 (kill-all-local-variables) 312 ( twittering-mode-init-variables)313 (use-local-map twittering-mode-map)314 (setq major-mode ' twittering-mode)315 (setq mode-name twittering-mode-string)316 (set-syntax-table twittering-mode-syntax-table)317 (run-hooks ' twittering-mode-hook)304 (wassr-mode-init-variables) 305 (use-local-map wassr-mode-map) 306 (setq major-mode 'wassr-mode) 307 (setq mode-name wassr-mode-string) 308 (set-syntax-table wassr-mode-syntax-table) 309 (run-hooks 'wassr-mode-hook) 318 310 (font-lock-mode -1) 319 ( twittering-start)311 (wassr-start) 320 312 ) 321 313 … … 324 316 ;;; 325 317 326 (defun twittering-http-get (method-class method &optional sentinel)327 (if (null sentinel) (setq sentinel ' twittering-http-get-default-sentinel))318 (defun wassr-http-get (method-class method &optional sentinel) 319 (if (null sentinel) (setq sentinel 'wassr-http-get-default-sentinel)) 328 320 329 321 ;; clear the buffer 330 322 (save-excursion 331 (set-buffer ( twittering-http-buffer))323 (set-buffer (wassr-http-buffer)) 332 324 (erase-buffer)) 333 325 334 326 (let (proc server port 335 (proxy-user twittering-proxy-user)336 (proxy-password twittering-proxy-password))327 (proxy-user wassr-proxy-user) 328 (proxy-password wassr-proxy-password)) 337 329 (condition-case nil 338 330 (progn 339 (if (and twittering-proxy-use twittering-proxy-server)340 (setq server twittering-proxy-server341 port (if (integerp twittering-proxy-port)342 (int-to-string twittering-proxy-port)343 twittering-proxy-port))344 (setq server " twitter.com"331 (if (and wassr-proxy-use wassr-proxy-server) 332 (setq server wassr-proxy-server 333 port (if (integerp wassr-proxy-port) 334 (int-to-string wassr-proxy-port) 335 wassr-proxy-port)) 336 (setq server "api.wassr.jp" 345 337 port "80")) 346 338 (setq proc 347 339 (open-network-stream 348 "network-connection-process" ( twittering-http-buffer)340 "network-connection-process" (wassr-http-buffer) 349 341 server (string-to-number port))) 350 342 (set-process-sentinel proc sentinel) … … 354 346 request) 355 347 (setq request 356 (concat "GET http:// twitter.com/" method-class "/" method ".xml HTTP/1.1" nl357 "Host: twitter.com" nl358 "User-Agent: " ( twittering-user-agent) nl348 (concat "GET http://api.wassr.jp/" method-class "/" method ".xml HTTP/1.1" nl 349 "Host: api.wassr.jp" nl 350 "User-Agent: " (wassr-user-agent) nl 359 351 "Authorization: Basic " 360 352 (base64-encode-string 361 (concat twittering-username ":" (twittering-get-password)))353 (concat wassr-username ":" (wassr-get-password))) 362 354 nl 363 355 "Accept: text/xml" … … 368 360 ",image/png,*/*;q=0.5" nl 369 361 "Accept-Charset: utf-8;q=0.7,*;q=0.7" nl 370 (when twittering-proxy-use362 (when wassr-proxy-use 371 363 "Proxy-Connection: Keep-Alive" nl 372 364 (when (and proxy-user proxy-password) … … 383 375 (message "Failure: HTTP GET") nil)))) 384 376 385 (defun twittering-http-get-default-sentinel (proc stat &optional suc-msg)386 (let ((header ( twittering-get-response-header))387 (body ( twittering-get-response-body))377 (defun wassr-http-get-default-sentinel (proc stat &optional suc-msg) 378 (let ((header (wassr-get-response-header)) 379 (body (wassr-get-response-body)) 388 380 (status nil) 389 381 ) … … 395 387 (("200 OK") 396 388 (mapcar 397 #' twittering-cache-status-datum398 (reverse ( twittering-xmltree-to-status389 #'wassr-cache-status-datum 390 (reverse (wassr-xmltree-to-status 399 391 body))) 400 ( twittering-render-friends-timeline)392 (wassr-render-friends-timeline) 401 393 (message (if suc-msg suc-msg "Success: Get."))) 402 394 (t (message status)))) … … 404 396 ) 405 397 406 (defun twittering-render-friends-timeline ()407 (with-current-buffer ( twittering-buffer)398 (defun wassr-render-friends-timeline () 399 (with-current-buffer (wassr-buffer) 408 400 (let ((point (point)) 409 401 (end (point-max))) … … 411 403 (erase-buffer) 412 404 (mapc (lambda (status) 413 (insert ( twittering-format-status414 status twittering-status-format))405 (insert (wassr-format-status 406 status wassr-status-format)) 415 407 (fill-region-as-paragraph 416 408 (save-excursion (beginning-of-line) (point)) (point)) 417 409 (insert "\n")) 418 twittering-friends-timeline-data)419 (if twittering-image-stack410 wassr-friends-timeline-data) 411 (if wassr-image-stack 420 412 (clear-image-cache)) 421 413 (setq buffer-read-only t) 422 414 (debug-print (current-buffer)) 423 (goto-char (+ point (if twittering-scroll-mode (- (point-max) end) 0))))415 (goto-char (+ point (if wassr-scroll-mode (- (point-max) end) 0)))) 424 416 )) 425 417 426 (defun twittering-format-status (status format-str)418 (defun wassr-format-status (status format-str) 427 419 (flet ((attr (key) 428 420 (assocref key status)) … … 434 426 (let ((filename (match-string-no-properties 1 profile-image-url))) 435 427 ;; download icons if does not exist 436 (if (file-exists-p (concat twittering-tmp-dir428 (if (file-exists-p (concat wassr-tmp-dir 437 429 "/" filename)) 438 430 t 439 (add-to-list ' twittering-image-stack profile-image-url))440 441 (when (and icon-string twittering-icon-mode)431 (add-to-list 'wassr-image-stack profile-image-url)) 432 433 (when (and icon-string wassr-icon-mode) 442 434 (set-text-properties 443 435 1 2 `(display 444 (image :type ,( twittering-image-type filename)445 :file ,(concat twittering-tmp-dir436 (image :type ,(wassr-image-type filename) 437 :file ,(concat wassr-tmp-dir 446 438 "/" 447 439 filename))) … … 488 480 (list-push (attr 'created-at) result)) 489 481 ((?C) ; %C{time-format-str} - created_at (formatted with time-format-str) 490 (list-push ( twittering-local-strftime482 (list-push (wassr-local-strftime 491 483 (or (match-string-no-properties 2 format-str) "%H:%M:%S") 492 484 (attr 'created-at)) … … 514 506 (/ (+ secs 1800) 3600))) 515 507 (t (format-time-string "%I:%M %p %B %d, %Y" created-at)))) 516 (setq url ( twittering-get-status-url (attr 'user-screen-name) (attr 'id)))508 (setq url (wassr-get-status-url (attr 'user-screen-name) (attr 'id))) 517 509 ;; make status url clickable 518 510 (add-text-properties 519 511 0 (length time-string) 520 512 `(mouse-face highlight 521 face twittering-uri-face513 face wassr-uri-face 522 514 uri ,url) 523 515 time-string) … … 546 538 ))) 547 539 548 (defun twittering-http-post540 (defun wassr-http-post 549 541 (method-class method &optional parameters contents sentinel) 550 "Send HTTP POST request to twitter.com551 552 METHOD-CLASS must be one of Twitter API method classes(statuses, users or direct_messages).553 METHOD must be one of Twitter API method which belongs to METHOD-CLASS.542 "Send HTTP POST request to api.wassr.jp 543 544 METHOD-CLASS must be one of Wassr API method classes(statuses, users or direct_messages). 545 METHOD must be one of Wassr API method which belongs to METHOD-CLASS. 554 546 PARAMETERS is alist of URI parameters. ex) ((\"mode\" . \"view\") (\"page\" . \"6\")) => <URI>?mode=view&page=6" 555 (if (null sentinel) (setq sentinel ' twittering-http-post-default-sentinel))547 (if (null sentinel) (setq sentinel 'wassr-http-post-default-sentinel)) 556 548 557 549 ;; clear the buffer 558 550 (save-excursion 559 (set-buffer ( twittering-http-buffer))551 (set-buffer (wassr-http-buffer)) 560 552 (erase-buffer)) 561 553 562 554 (let (proc server port 563 (proxy-user twittering-proxy-user)564 (proxy-password twittering-proxy-password))555 (proxy-user wassr-proxy-user) 556 (proxy-password wassr-proxy-password)) 565 557 (progn 566 (if (and twittering-proxy-use twittering-proxy-server)567 (setq server twittering-proxy-server568 port (if (integerp twittering-proxy-port)569 (int-to-string twittering-proxy-port)570 twittering-proxy-port))571 (setq server " twitter.com"558 (if (and wassr-proxy-use wassr-proxy-server) 559 (setq server wassr-proxy-server 560 port (if (integerp wassr-proxy-port) 561 (int-to-string wassr-proxy-port) 562 wassr-proxy-port)) 563 (setq server "api.wassr.jp" 572 564 port "80")) 573 565 (setq proc 574 566 (open-network-stream 575 "network-connection-process" ( twittering-http-buffer)567 "network-connection-process" (wassr-http-buffer) 576 568 server (string-to-number port))) 577 569 (set-process-sentinel proc sentinel) … … 581 573 request) 582 574 (setq request 583 (concat "POST http:// twitter.com/" method-class "/" method ".xml?"575 (concat "POST http://api.wassr.jp/" method-class "/" method ".xml?" 584 576 (if parameters 585 577 (mapconcat 586 578 (lambda (param-pair) 587 579 (format "%s=%s" 588 ( twittering-percent-encode (car param-pair))589 ( twittering-percent-encode (cdr param-pair))))580 (wassr-percent-encode (car param-pair)) 581 (wassr-percent-encode (cdr param-pair)))) 590 582 parameters 591 583 "&")) 592 584 " HTTP/1.1" nl 593 "Host: twitter.com" nl594 "User-Agent: " ( twittering-user-agent) nl585 "Host: api.wassr.jp" nl 586 "User-Agent: " (wassr-user-agent) nl 595 587 "Authorization: Basic " 596 588 (base64-encode-string 597 (concat twittering-username ":" (twittering-get-password)))589 (concat wassr-username ":" (wassr-get-password))) 598 590 nl 599 591 "Content-Type: text/plain" nl 600 592 "Content-Length: 0" nl 601 (when twittering-proxy-use593 (when wassr-proxy-use 602 594 "Proxy-Connection: Keep-Alive" nl 603 595 (when (and proxy-user proxy-password) … … 612 604 request))))) 613 605 614 (defun twittering-http-post-default-sentinel (proc stat &optional suc-msg)606 (defun wassr-http-post-default-sentinel (proc stat &optional suc-msg) 615 607 616 608 (condition-case err-signal 617 (let ((header ( twittering-get-response-header))618 ;; (body ( twittering-get-response-body)) not used now.609 (let ((header (wassr-get-response-header)) 610 ;; (body (wassr-get-response-body)) not used now. 619 611 (status nil)) 620 612 (string-match "HTTP/1\.1 \\([a-z0-9 ]+\\)\r?\n" header) … … 628 620 ) 629 621 630 (defun twittering-get-response-header (&optional buffer)622 (defun wassr-get-response-header (&optional buffer) 631 623 "Exract HTTP response header from HTTP response. 632 624 `buffer' may be a buffer or the name of an existing buffer. 633 If `buffer' is omitted, the value of ` twittering-http-buffer' is used as `buffer'."625 If `buffer' is omitted, the value of `wassr-http-buffer' is used as `buffer'." 634 626 (if (stringp buffer) (setq buffer (get-buffer buffer))) 635 (if (null buffer) (setq buffer ( twittering-http-buffer)))627 (if (null buffer) (setq buffer (wassr-http-buffer))) 636 628 (save-excursion 637 629 (set-buffer buffer) … … 639 631 (substring content 0 (string-match "\r?\n\r?\n" content))))) 640 632 641 (defun twittering-get-response-body (&optional buffer)633 (defun wassr-get-response-body (&optional buffer) 642 634 "Exract HTTP response body from HTTP response, parse it as XML, and return a XML tree as list. 643 635 `buffer' may be a buffer or the name of an existing buffer. 644 If `buffer' is omitted, the value of ` twittering-http-buffer' is used as `buffer'."636 If `buffer' is omitted, the value of `wassr-http-buffer' is used as `buffer'." 645 637 (if (stringp buffer) (setq buffer (get-buffer buffer))) 646 (if (null buffer) (setq buffer ( twittering-http-buffer)))638 (if (null buffer) (setq buffer (wassr-http-buffer))) 647 639 (save-excursion 648 640 (set-buffer buffer) … … 654 646 ))) 655 647 656 (defun twittering-cache-status-datum (status-datum &optional data-var)657 "Cache status datum into data-var(default twittering-friends-timeline-data)648 (defun wassr-cache-status-datum (status-datum &optional data-var) 649 "Cache status datum into data-var(default wassr-friends-timeline-data) 658 650 If STATUS-DATUM is already in DATA-VAR, return nil. If not, return t." 659 651 (if (null data-var) 660 (setf data-var ' twittering-friends-timeline-data))652 (setf data-var 'wassr-friends-timeline-data)) 661 653 (let ((id (cdr (assq 'id status-datum)))) 662 654 (if (or (null (symbol-value data-var)) … … 666 658 (symbol-value data-var)))) 667 659 (progn 668 (if twittering-jojo-mode669 ( twittering-update-jojo (cdr (assq 'user-screen-name status-datum))660 (if wassr-jojo-mode 661 (wassr-update-jojo (cdr (assq 'user-screen-name status-datum)) 670 662 (cdr (assq 'text status-datum)))) 671 663 (set data-var (cons status-datum (symbol-value data-var))) … … 673 665 nil))) 674 666 675 (defun twittering-status-to-status-datum (status)667 (defun wassr-status-to-status-datum (status) 676 668 (flet ((assq-get (item seq) 677 669 (car (cddr (assq item seq))))) … … 689 681 690 682 (setq id (string-to-number (assq-get 'id status-data))) 691 (setq text ( twittering-decode-html-entities683 (setq text (wassr-decode-html-entities 692 684 (assq-get 'text status-data))) 693 (setq source ( twittering-decode-html-entities685 (setq source (wassr-decode-html-entities 694 686 (assq-get 'source status-data))) 695 687 (setq created-at (assq-get 'created_at status-data)) 696 688 (setq truncated (assq-get 'truncated status-data)) 697 689 (setq user-id (string-to-number (assq-get 'id user-data))) 698 (setq user-name ( twittering-decode-html-entities690 (setq user-name (wassr-decode-html-entities 699 691 (assq-get 'name user-data))) 700 (setq user-screen-name ( twittering-decode-html-entities692 (setq user-screen-name (wassr-decode-html-entities 701 693 (assq-get 'screen_name user-data))) 702 (setq user-location ( twittering-decode-html-entities694 (setq user-location (wassr-decode-html-entities 703 695 (assq-get 'location user-data))) 704 (setq user-description ( twittering-decode-html-entities696 (setq user-description (wassr-decode-html-entities 705 697 (assq-get 'description user-data))) 706 698 (setq user-profile-image-url (assq-get 'profile_image_url user-data)) … … 712 704 0 (length user-name) 713 705 `(mouse-face highlight 714 uri ,(concat "http:// twitter.com/" user-screen-name)715 face twittering-username-face)706 uri ,(concat "http://api.wassr.jp/" user-screen-name) 707 face wassr-username-face) 716 708 user-name) 717 709 … … 720 712 0 (length user-screen-name) 721 713 `(mouse-face highlight 722 face twittering-username-face723 uri ,(concat "http:// twitter.com/" user-screen-name)724 face twittering-username-face)714 face wassr-username-face 715 uri ,(concat "http://api.wassr.jp/" user-screen-name) 716 face wassr-username-face) 725 717 user-screen-name) 726 718 … … 744 736 `(mouse-face 745 737 highlight 746 face twittering-uri-face747 uri ,(concat "http:// twitter.com/" screen-name))738 face wassr-uri-face 739 uri ,(concat "http://api.wassr.jp/" screen-name)) 748 740 `(mouse-face highlight 749 face twittering-uri-face741 face wassr-uri-face 750 742 uri ,uri)) 751 743 text)) … … 762 754 `(mouse-face highlight 763 755 uri ,uri 764 face twittering-uri-face756 face wassr-uri-face 765 757 source ,source) 766 758 source) … … 777 769 user-protected))))) 778 770 779 (defun twittering-xmltree-to-status (xmltree)780 (mapcar #' twittering-status-to-status-datum771 (defun wassr-xmltree-to-status (xmltree) 772 (mapcar #'wassr-status-to-status-datum 781 773 ;; quirk to treat difference between xml.el in Emacs21 and Emacs22 782 774 ;; On Emacs22, there may be blank strings … … 788 780 ret))) 789 781 790 (defun twittering-percent-encode (str &optional coding-system)782 (defun wassr-percent-encode (str &optional coding-system) 791 783 (if (or (null coding-system) 792 784 (not (coding-system-p coding-system))) … … 795 787 (lambda (c) 796 788 (cond 797 (( twittering-url-reserved-p c)789 ((wassr-url-reserved-p c) 798 790 (char-to-string c)) 799 791 ((eq c ? ) "+") … … 802 794 "")) 803 795 804 (defun twittering-url-reserved-p (ch)796 (defun wassr-url-reserved-p (ch) 805 797 (or (and (<= ?A ch) (<= ch ?z)) 806 798 (and (<= ?0 ch) (<= ch ?9)) … … 810 802 (eq ?~ ch))) 811 803 812 (defun twittering-decode-html-entities (encoded-str)804 (defun wassr-decode-html-entities (encoded-str) 813 805 (if encoded-str 814 806 (let ((cursor 0) … … 825 817 (list-push 826 818 (char-to-string 827 ( twittering-ucs-to-char819 (wassr-ucs-to-char 828 820 (string-to-number number-entity))) result)) 829 821 (letter-entity … … 837 829 "")) 838 830 839 (defun twittering-timer-action (func)840 (let ((buf (get-buffer twittering-buffer)))831 (defun wassr-timer-action (func) 832 (let ((buf (get-buffer wassr-buffer))) 841 833 (if (null buf) 842 ( twittering-stop)834 (wassr-stop) 843 835 (funcall func) 844 836 ))) 845 837 846 (defun twittering-update-status-if-not-blank (status)838 (defun wassr-update-status-if-not-blank (status) 847 839 (if (string-match "^\\s-*\\(?:@[-_a-z0-9]+\\)?\\s-*$" status) 848 840 nil 849 ( twittering-http-post "statuses" "update"841 (wassr-http-post "statuses" "update" 850 842 `(("status" . ,status) 851 ("source" . " twmode")))843 ("source" . "ws-mode"))) 852 844 t)) 853 845 854 (defun twittering-update-status-from-minibuffer (&optional init-str)846 (defun wassr-update-status-from-minibuffer (&optional init-str) 855 847 (if (null init-str) (setq init-str "")) 856 848 (let ((status init-str) (not-posted-p t)) … … 858 850 (setq status (read-from-minibuffer "status: " status nil nil nil nil t)) 859 851 (setq not-posted-p 860 (not ( twittering-update-status-if-not-blank status))))))861 862 (defun twittering-update-lambda ()863 (interactive) 864 ( twittering-http-post852 (not (wassr-update-status-if-not-blank status)))))) 853 854 (defun wassr-update-lambda () 855 (interactive) 856 (wassr-http-post 865 857 "statuses" "update" 866 858 `(("status" . "\xd34b\xd22b\xd26f\xd224\xd224\xd268\xd34b") 867 ("source" . " twmode"))))868 869 (defun twittering-update-jojo (usr msg)859 ("source" . "ws-mode")))) 860 861 (defun wassr-update-jojo (usr msg) 870 862 (if (string-match "\xde21\xd24b\\(\xd22a\xe0b0\\|\xdaae\xe6cd\\)\xd24f\xd0d6\\([^\xd0d7]+\\)\xd0d7\xd248\xdc40\xd226" 871 863 msg) 872 ( twittering-http-post864 (wassr-http-post 873 865 "statuses" "update" 874 866 `(("status" . ,(concat … … 876 868 (match-string-no-properties 2 msg) 877 869 "\xd0a1\xd24f\xd243!?")) 878 ("source" . " twmode")))))870 ("source" . "ws-mode"))))) 879 871 880 872 ;;; … … 882 874 ;;; 883 875 884 (defun twittering-start (&optional action)876 (defun wassr-start (&optional action) 885 877 (interactive) 886 878 (if (null action) 887 (setq action #' twittering-friends-timeline))888 (if twittering-timer879 (setq action #'wassr-friends-timeline)) 880 (if wassr-timer 889 881 nil 890 (setq twittering-timer882 (setq wassr-timer 891 883 (run-at-time "0 sec" 892 twittering-timer-interval893 #' twittering-timer-action action))))894 895 (defun twittering-stop ()896 (interactive) 897 (cancel-timer twittering-timer)898 (setq twittering-timer nil))899 900 (defun twittering-friends-timeline ()901 (interactive) 902 (let ((buf (get-buffer twittering-buffer)))884 wassr-timer-interval 885 #'wassr-timer-action action)))) 886 887 (defun wassr-stop () 888 (interactive) 889 (cancel-timer wassr-timer) 890 (setq wassr-timer nil)) 891 892 (defun wassr-friends-timeline () 893 (interactive) 894 (let ((buf (get-buffer wassr-buffer))) 903 895 (if (not buf) 904 ( twittering-stop)905 ( twittering-http-get "statuses" "friends_timeline")896 (wassr-stop) 897 (wassr-http-get "statuses" "friends_timeline") 906 898 )) 907 899 908 (if twittering-icon-mode909 (if twittering-image-stack900 (if wassr-icon-mode 901 (if wassr-image-stack 910 902 (let ((proc 911 903 (apply 912 904 #'start-process 913 905 "wget-images" 914 ( twittering-wget-buffer)906 (wassr-wget-buffer) 915 907 "wget" 916 (format "--directory-prefix=%s" twittering-tmp-dir)908 (format "--directory-prefix=%s" wassr-tmp-dir) 917 909 "--no-clobber" 918 910 "--quiet" 919 twittering-image-stack)))911 wassr-image-stack))) 920 912 (set-process-sentinel 921 913 proc … … 923 915 (clear-image-cache) 924 916 (save-excursion 925 (set-buffer ( twittering-wget-buffer))917 (set-buffer (wassr-wget-buffer)) 926 918 ))))))) 927 919 928 (defun twittering-update-status-interactive ()929 (interactive) 930 ( twittering-update-status-from-minibuffer))931 932 (defun twittering-erase-old-statuses ()933 (interactive) 934 (setq twittering-friends-timeline-data nil)935 ( twittering-http-get "statuses" "friends_timeline"))936 937 (defun twittering-click ()920 (defun wassr-update-status-interactive () 921 (interactive) 922 (wassr-update-status-from-minibuffer)) 923 924 (defun wassr-erase-old-statuses () 925 (interactive) 926 (setq wassr-friends-timeline-data nil) 927 (wassr-http-get "statuses" "friends_timeline")) 928 929 (defun wassr-click () 938 930 (interactive) 939 931 (let ((uri (get-text-property (point) 'uri))) … … 941 933 (browse-url uri)))) 942 934 943 (defun twittering-enter ()935 (defun wassr-enter () 944 936 (interactive) 945 937 (let ((username (get-text-property (point) 'username)) 946 938 (uri (get-text-property (point) 'uri))) 947 939 (if username 948 ( twittering-update-status-from-minibuffer (concat "@" username " "))940 (wassr-update-status-from-minibuffer (concat "@" username " ")) 949 941 (if uri 950 942 (browse-url uri))))) 951 943 952 (defun twittering-view-user-page ()944 (defun wassr-view-user-page () 953 945 (interactive) 954 946 (let ((uri (get-text-property (point) 'uri))) … … 956 948 (browse-url uri)))) 957 949 958 (defun twittering-reply-to-user ()950 (defun wassr-reply-to-user () 959 951 (interactive) 960 952 (let ((username (get-text-property (point) 'username))) 961 953 (if username 962 ( twittering-update-status-from-minibuffer (concat "@" username " ")))))963 964 (defun twittering-get-password ()965 (or twittering-password966 (setq twittering-password (read-passwd "twittering-mode: "))))967 968 (defun twittering-goto-next-status ()954 (wassr-update-status-from-minibuffer (concat "@" username " "))))) 955 956 (defun wassr-get-password () 957 (or wassr-password 958 (setq wassr-password (read-passwd "wassr-mode: ")))) 959 960 (defun wassr-goto-next-status () 969 961 "Go to next status." 970 962 (interactive) 971 963 (let ((pos)) 972 (setq pos ( twittering-get-next-username-face-pos (point)))964 (setq pos (wassr-get-next-username-face-pos (point))) 973 965 (if pos 974 966 (goto-char pos) 975 967 (message "End of status.")))) 976 968 977 (defun twittering-get-next-username-face-pos (pos)969 (defun wassr-get-next-username-face-pos (pos) 978 970 (interactive) 979 971 (let ((prop)) 980 972 (catch 'not-found 981 (while (and pos (not (eq prop twittering-username-face)))973 (while (and pos (not (eq prop wassr-username-face))) 982 974 (setq pos (next-single-property-change pos 'face)) 983 975 (when (eq pos nil) (throw 'not-found nil)) … … 985 977 pos))) 986 978 987 (defun twittering-goto-previous-status ()979 (defun wassr-goto-previous-status () 988 980 "Go to previous status." 989 981 (interactive) 990 982 (let ((pos)) 991 (setq pos ( twittering-get-previous-username-face-pos (point)))983 (setq pos (wassr-get-previous-username-face-pos (point))) 992 984 (if pos 993 985 (goto-char pos) 994 986 (message "Start of status.")))) 995 987 996 (defun twittering-get-previous-username-face-pos (pos)988 (defun wassr-get-previous-username-face-pos (pos) 997 989 (interactive) 998 990 (let ((prop)) 999 991 (catch 'not-found 1000 (while (and pos (not (eq prop twittering-username-face)))992 (while (and pos (not (eq prop wassr-username-face))) 1001 993 (setq pos (previous-single-property-change pos 'face)) 1002 994 (when (eq pos nil) (throw 'not-found nil)) … … 1004 996 pos))) 1005 997 1006 (defun twittering-goto-next-status-of-user ()998 (defun wassr-goto-next-status-of-user () 1007 999 "Go to next status of user." 1008 1000 (interactive) 1009 (let ((user-name ( twittering-get-username-at-pos (point)))1010 (pos ( twittering-get-next-username-face-pos (point))))1001 (let ((user-name (wassr-get-username-at-pos (point))) 1002 (pos (wassr-get-next-username-face-pos (point)))) 1011 1003 (while (and (not (eq pos nil)) 1012 (not (equal ( twittering-get-username-at-pos pos) user-name)))1013 (setq pos ( twittering-get-next-username-face-pos pos)))1004 (not (equal (wassr-get-username-at-pos pos) user-name))) 1005 (setq pos (wassr-get-next-username-face-pos pos))) 1014 1006 (if pos 1015 1007 (goto-char pos) … … 1018 1010 (message "Invalid user-name."))))) 1019 1011 1020 (defun twittering-goto-previous-status-of-user ()1012 (defun wassr-goto-previous-status-of-user () 1021 1013 "Go to previous status of user." 1022 1014 (interactive) 1023 (let ((user-name ( twittering-get-username-at-pos (point)))1024 (pos ( twittering-get-previous-username-face-pos (point))))1015 (let ((user-name (wassr-get-username-at-pos (point))) 1016 (pos (wassr-get-previous-username-face-pos (point)))) 1025 1017 (while (and (not (eq pos nil)) 1026 (not (equal ( twittering-get-username-at-pos pos) user-name)))1027 (setq pos ( twittering-get-previous-username-face-pos pos)))1018 (not (equal (wassr-get-username-at-pos pos) user-name))) 1019 (setq pos (wassr-get-previous-username-face-pos pos))) 1028 1020 (if pos 1029 1021 (goto-char pos) … … 1032 1024 (message "Invalid user-name."))))) 1033 1025 1034 (defun twittering-get-username-at-pos (pos)1026 (defun wassr-get-username-at-pos (pos) 1035 1027 (let ((start-pos pos) 1036 1028 (end-pos)) 1037 1029 (catch 'not-found 1038 (while (eq (get-text-property start-pos 'face) twittering-username-face)1030 (while (eq (get-text-property start-pos 'face) wassr-username-face) 1039 1031 (setq start-pos (1- start-pos)) 1040 1032 (when (or (eq start-pos nil) (eq start-pos 0)) (throw 'not-found nil))) … … 1043 1035 (buffer-substring start-pos end-pos)))) 1044 1036 1045 (defun twittering-get-status-url (username id)1037 (defun wassr-get-status-url (username id) 1046 1038 "Generate status URL." 1047 (format "http:// twitter.com/%s/statuses/%d" username id))1039 (format "http://api.wassr.jp/%s/statuses/%d" username id)) 1048 1040 1049 1041 ;;;###autoload 1050 (defun twit()1051 "Start twittering-mode."1052 (interactive) 1053 ( twittering-mode))1054 1055 (provide ' twittering-mode)1056 ;;; twittering.el ends here1042 (defun wassr () 1043 "Start wassr-mode." 1044 (interactive) 1045 (wassr-mode)) 1046 1047 (provide 'wassr-mode) 1048 ;;; wassr.el ends here