* mixi-utils.el: New file.
authorbg66 <bg66>
Thu, 22 Feb 2007 08:21:13 +0000 (08:21 +0000)
committerbg66 <bg66>
Thu, 22 Feb 2007 08:21:13 +0000 (08:21 +0000)
* sb-mixi.el: Use it.
* Makefile.am (MODULES_MIXI): Add it.

ChangeLog
Makefile.am
mixi-utils.el [new file with mode: 0644]
sb-mixi.el

index 60fe9a3..8957192 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2007-02-22  OHASHI Akira  <bg66@koka-in.org>
+
+       * mixi-utils.el: New file.
+       * sb-mixi.el: Use it.
+       * Makefile.am (MODULES_MIXI): Add it.
+
 2007-02-19  OHASHI Akira  <bg66@koka-in.org>
 
        * mixi.el (mixi-log-list-regexp): Follow the change of mixi.
index 0b1070c..b9f10a4 100644 (file)
@@ -1,4 +1,4 @@
-MODULES_MIXI = mixi.el
+MODULES_MIXI = mixi.el mixi-utils.el
 MODULES_ALL = $(MODULES_MIXI) sb-mixi.el mixi-gnus.el mixi-wl.el
 EXTRA_DIST = COMPILE ChangeLog $(MODULES_ALL)
 CLEANFILES = auto-autoloads.el custom-load.el *.elc
diff --git a/mixi-utils.el b/mixi-utils.el
new file mode 100644 (file)
index 0000000..f2bc944
--- /dev/null
@@ -0,0 +1,209 @@
+;; mixi-utils.el --- Utilities for mixi object
+
+;; Copyright (C) 2007 OHASHI Akira
+
+;; Author: OHASHI Akira <bg66@koka-in.org>
+;; Keywords: hypermedia
+
+;; This file is *NOT* a part of Emacs.
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 2, or (at your option)
+;; any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program; if not, you can either send email to this
+;; program's maintainer or write to: The Free Software Foundation,
+;; Inc.; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+;;; Commentary:
+
+;; Bug reports:
+;;
+;; If you have bug reports and/or suggestions for improvement, please
+;; send them via <URL:http://mixi.jp/view_community.pl?id=1596390>.
+
+;;; Code:
+
+(require 'mixi)
+
+(defvar mixi-reply-to nil)
+
+(defmacro with-mixi-class (object &rest body)
+  `(let ((class (mixi-object-class ,object)))
+     ,@body))
+(put 'with-mixi-class 'lisp-indent-function 'defun)
+(put 'with-mixi-class 'edebug-form-spec '(body))
+
+(defun mixi-make-title (object &optional add-suffix)
+  (with-mixi-class object
+    (cond ((eq class 'mixi-comment)
+          (concat "Re: " (mixi-make-title
+                          (mixi-comment-parent object) add-suffix)))
+         ((eq class 'mixi-log)
+          (mixi-friend-nick (mixi-log-friend object)))
+         (t
+          (let ((prefix (when (eq class 'mixi-event) "[¥¤¥Ù¥ó¥È]"))
+                (subject (mixi-object-title object))
+                (suffix (when add-suffix
+                          (concat " ("
+                                  (if (eq class 'mixi-diary)
+                                      (mixi-friend-nick
+                                       (mixi-diary-owner object))
+                                    (mixi-community-name
+                                     (mixi-bbs-community object)))
+                                  ")"))))
+            (concat prefix subject suffix))))))
+
+(defun mixi-make-author (object)
+  (with-mixi-class object
+    (if (eq class 'mixi-news)
+       (mixi-news-media object)
+      (let ((owner (if (eq class 'mixi-log)
+                      (mixi-log-friend object)
+                    (mixi-object-owner object))))
+       (mixi-friend-nick owner)))))
+
+(defun mixi-make-date (object)
+  (let* ((time (mixi-object-time object))
+        (cts (current-time-string time))
+        (day-of-week (substring cts 0 3))
+        (month (substring cts 4 7)))
+    (concat day-of-week ", "
+           (format-time-string "%d" time) " "
+           month " "
+           (format-time-string "%Y %H:%M:%S %z" time))))
+
+(defun mixi-make-message-id (object)
+  (with-mixi-class object
+    (concat
+     (format-time-string "<%Y%m%d%H%M" (mixi-object-time object)) "."
+     (cond ((eq class 'mixi-comment)
+           (concat (mixi-friend-id (mixi-comment-owner object)) "@"
+                   (mixi-object-id (mixi-comment-parent object)) "."
+                   (mixi-friend-id (mixi-object-owner
+                                    (mixi-comment-parent object))) "."))
+          ((eq class 'mixi-log)
+           (concat (mixi-friend-id (mixi-log-friend object)) "@"))
+          (t
+           (concat (mixi-object-id object) "@"
+                   (if (eq class 'mixi-news)
+                       (mixi-news-media-id object)
+                     (mixi-object-id (mixi-object-owner object))) ".")))
+     (mixi-object-name object) ".mixi.jp>")))
+
+(defun mixi-make-url (object)
+  (with-mixi-class object
+    (cond ((eq class 'mixi-diary)
+          (mixi-expand-url (mixi-diary-page object)))
+         ((eq class 'mixi-topic)
+          (mixi-expand-url (mixi-topic-page object)))
+         ((eq class 'mixi-event)
+          (mixi-expand-url (mixi-event-page object)))
+         ((eq class 'mixi-comment)
+          (concat (mixi-make-url (mixi-comment-parent object))
+                  "#comment"))
+         ((eq class 'mixi-message)
+          (mixi-expand-url (mixi-message-page object)))
+         ((eq class 'mixi-news)
+          (mixi-news-page object))
+         ((eq class 'mixi-log)
+          (mixi-expand-url (mixi-friend-page (mixi-log-friend object))))
+         ((eq class 'mixi-friend)
+          (mixi-expand-url (mixi-friend-page object))))))
+
+(defun mixi-make-content (object)
+  (with-mixi-class object
+    (cond ((eq class 'mixi-event)
+          (let ((limit (mixi-event-limit object)))
+            (setq limit (if limit
+                            (format-time-string "%Yǯ%m·î%dÆü" limit)
+                          "»ØÄê¤Ê¤·"))
+            (concat "<dl>"
+                    "<dt>³«ºÅÆü»þ¡§</dt>"
+                    "<dd>" (mixi-event-date object) "</dd>\n"
+                    "<dt>³«ºÅ¾ì½ê¡§</dt>"
+                    "<dd>" (mixi-event-place object) "</dd>\n"
+                    "<dt>¾ÜºÙ¡§</dt>"
+                    "<dd>" (mixi-event-detail object) "</dd>\n"
+                    "<dt>Ê罸´ü¸Â¡§</dt>"
+                    "<dd>" limit "</dd>\n"
+                    "<dt>»²²Ã¼Ô¡§</dt>"
+                    "<dd>" (mixi-event-members object) "</dd>\n"
+                    "</dl>")))
+         ((eq class 'mixi-friend)
+          (if (mixi-object-realized-p object)
+              (let ((sex (if (eq (mixi-friend-sex object) 'male) "ÃË" "½÷"))
+                    (age (number-to-string (mixi-friend-age object)))
+                    (birthday
+                     (concat (mapconcat (lambda (number)
+                                          (number-to-string number))
+                                        (mixi-friend-birthday object) "·î")
+                             "Æü"))
+                    (blood-type (symbol-name
+                                 (mixi-friend-blood-type object)))
+                    (hobby (mapconcat 'identity
+                                      (mixi-friend-hobby object) ", ")))
+                (concat "<dl>"
+                        "<dt>̾Á°¡§</dt>"
+                        "<dd>" (mixi-friend-name object) "</dd>\n"
+                        "<dt>À­ÊÌ¡§</dt>"
+                        "<dd>" sex "À­</dd>\n"
+                        "<dt>¸½½»½ê¡§</dt>"
+                        "<dd>" (mixi-friend-address object) "</dd>\n"
+                        "<dt>ǯÎð¡§</dt>"
+                        "<dd>" age "ºÐ</dd>\n"
+                        "<dt>ÃÂÀ¸Æü¡§</dt>"
+                        "<dd>" birthday "</dd>\n"
+                        "<dt>·ì±Õ·¿¡§</dt>"
+                        "<dd>" blood-type "·¿</dd>\n"
+                        "<dt>½Ð¿ÈÃÏ¡§</dt>"
+                        "<dd>" (mixi-friend-birthplace object) "</dd>\n"
+                        "<dt>¼ñÌ£¡§</dt>"
+                        "<dd>" hobby "</dd>\n"
+                        "<dt>¿¦¶È¡§</dt>"
+                        "<dd>" (mixi-friend-job object) "</dd>\n"
+                        "<dt>½ê°¡§</dt>"
+                        "<dd>" (mixi-friend-organization object) "</dd>\n"
+                        "<dt>¼«¸Ê¾Ò²ð¡§</dt>"
+                        "<dd>" (mixi-friend-profile object) "</dd>\n"
+                        "</dl>"))
+            (concat "<a href=\"" (mixi-make-url object)
+                    "\">¥×¥í¥Õ¥£¡¼¥ë¤òɽ¼¨¤¹¤ë</a>")))
+         (t (mixi-object-content object)))))
+
+(defun mixi-make-reply-to (object)
+  (setq mixi-reply-to "mixi;")
+  (with-mixi-class object
+    (setq mixi-reply-to
+         (concat
+          (cond ((eq class 'mixi-diary)
+                 (concat mixi-reply-to "comment;diary;"
+                         (mixi-friend-id (mixi-diary-owner object)) ";"
+                         (mixi-diary-id object)))
+                ((mixi-bbs-p object)
+                 (concat mixi-reply-to "comment;"
+                         (mixi-object-name object) ";"
+                         (mixi-community-id (mixi-bbs-community object)) ";"
+                         (mixi-bbs-id object)))
+                ((eq class 'mixi-community)
+                 (concat mixi-reply-to "topic;"
+                         (mixi-community-id object)))
+                ((or (eq class 'mixi-news) (eq object (mixi-make-me)))
+                 (concat mixi-reply-to "diary"))
+                ((eq class 'mixi-message)
+                 (concat mixi-reply-to "message;"
+                         (mixi-friend-id (mixi-message-owner object))))
+                ((or (eq class 'mixi-friend) (eq class 'mixi-log))
+                 (concat mixi-reply-to "message;"
+                         (mixi-friend-id object))))))))
+
+(provide 'mixi-utils)
+
+;;; mixi-utils.el ends here
index 2d530dc..3b6af77 100644 (file)
@@ -30,6 +30,7 @@
 ;;; Code:
 
 (require 'mixi)
+(require 'mixi-utils)
 (require 'shimbun)
 
 (eval-and-compile
@@ -125,8 +126,6 @@ of mixi object."
  h.d+'g\\I{D>Ocy?Rc4uYUyOZj2%2Kl>,x-!MCSsyi3!L}psrrC1jlF,O?Ui>qf)X;sBz`/}\\066X%$
  siG'|4K!2?==|oB&#E'5GGH\\#z[muyQ")))
 
-(defvar shimbun-mixi-reply-to nil)
-
 (luna-define-method initialize-instance :after ((shimbun shimbun-mixi)
                                                &rest init-args)
   (shimbun-mixi-set-comment-cache-internal shimbun
@@ -141,172 +140,7 @@ of mixi object."
   (mapcar 'car shimbun-mixi-group-alist))
 
 (luna-define-method shimbun-reply-to ((shimbun shimbun-mixi))
-  shimbun-mixi-reply-to)
-
-(defun shimbun-mixi-make-subject (shimbun object)
-  (let ((class (mixi-object-class object)))
-    (cond ((eq class 'mixi-comment)
-          (concat "Re: " (shimbun-mixi-make-subject
-                          shimbun (mixi-comment-parent object))))
-         ((eq class 'mixi-log)
-          (mixi-friend-nick (mixi-log-friend object)))
-         (t
-          (let ((prefix (when (eq class 'mixi-event) "[¥¤¥Ù¥ó¥È]"))
-                (subject (mixi-object-title object))
-                (suffix (when (string-match
-                               "^new-"
-                               (shimbun-current-group-internal shimbun))
-                          (concat " ("
-                                  (if (eq class 'mixi-diary)
-                                      (mixi-friend-nick
-                                       (mixi-diary-owner object))
-                                    (mixi-community-name
-                                     (mixi-bbs-community object)))
-                                  ")"))))
-            (concat prefix subject suffix))))))
-
-(defun shimbun-mixi-make-from (object)
-  (let ((class (mixi-object-class object)))
-    (if (eq class 'mixi-news)
-       (mixi-news-media object)
-      (let ((owner (if (eq class 'mixi-log)
-                      (mixi-log-friend object)
-                    (mixi-object-owner object))))
-       (mixi-friend-nick owner)))))
-
-(defun shimbun-mixi-make-date (object)
-  (let* ((time (mixi-object-time object))
-        (cts (current-time-string time))
-        (day-of-week (substring cts 0 3))
-        (month (substring cts 4 7)))
-    (concat day-of-week ", "
-           (format-time-string "%d" time) " "
-           month " "
-           (format-time-string "%Y %H:%M:%S %z" time))))
-
-(defun shimbun-mixi-make-message-id (object)
-  (let ((class (mixi-object-class object)))
-    (concat
-     (format-time-string "<%Y%m%d%H%M" (mixi-object-time object)) "."
-     (cond ((eq class 'mixi-comment)
-           (concat (mixi-friend-id (mixi-comment-owner object)) "@"
-                   (mixi-object-id (mixi-comment-parent object)) "."
-                   (mixi-friend-id (mixi-object-owner
-                                    (mixi-comment-parent object))) "."))
-          ((eq class 'mixi-log)
-           (concat (mixi-friend-id (mixi-log-friend object)) "@"))
-          (t
-           (concat (mixi-object-id object) "@"
-                   (if (eq class 'mixi-news)
-                       (mixi-news-media-id object)
-                     (mixi-object-id (mixi-object-owner object))) ".")))
-     (mixi-object-name object) ".mixi.jp>")))
-
-(defun shimbun-mixi-make-xref (object)
-  (let ((class (mixi-object-class object)))
-    (cond ((eq class 'mixi-diary)
-          (mixi-expand-url (mixi-diary-page object)))
-         ((eq class 'mixi-topic)
-          (mixi-expand-url (mixi-topic-page object)))
-         ((eq class 'mixi-event)
-          (mixi-expand-url (mixi-event-page object)))
-         ((eq class 'mixi-comment)
-          (concat (shimbun-mixi-make-xref (mixi-comment-parent object))
-                  "#comment"))
-         ((eq class 'mixi-message)
-          (mixi-expand-url (mixi-message-page object)))
-         ((eq class 'mixi-news)
-          (mixi-news-page object))
-         ((eq class 'mixi-log)
-          (mixi-expand-url (mixi-friend-page (mixi-log-friend object))))
-         ((eq class 'mixi-friend)
-          (mixi-expand-url (mixi-friend-page object))))))
-
-(defun shimbun-mixi-make-body (object)
-  (let ((class (mixi-object-class object)))
-    (cond ((eq class 'mixi-event)
-          (let ((limit (mixi-event-limit object)))
-            (setq limit (if limit
-                            (format-time-string "%Yǯ%m·î%dÆü" limit)
-                          "»ØÄê¤Ê¤·"))
-            (concat "<dl>"
-                    "<dt>³«ºÅÆü»þ¡§</dt>"
-                    "<dd>" (mixi-event-date object) "</dd>\n"
-                    "<dt>³«ºÅ¾ì½ê¡§</dt>"
-                    "<dd>" (mixi-event-place object) "</dd>\n"
-                    "<dt>¾ÜºÙ¡§</dt>"
-                    "<dd>" (mixi-event-detail object) "</dd>\n"
-                    "<dt>Ê罸´ü¸Â¡§</dt>"
-                    "<dd>" limit "</dd>\n"
-                    "<dt>»²²Ã¼Ô¡§</dt>"
-                    "<dd>" (mixi-event-members object) "</dd>\n"
-                    "</dl>")))
-         ((eq class 'mixi-friend)
-          (if (mixi-object-realized-p object)
-              (let ((sex (if (eq (mixi-friend-sex object) 'male) "ÃË" "½÷"))
-                    (age (number-to-string (mixi-friend-age object)))
-                    (birthday
-                     (concat (mapconcat (lambda (number)
-                                          (number-to-string number))
-                                        (mixi-friend-birthday object) "·î")
-                             "Æü"))
-                    (blood-type (symbol-name
-                                 (mixi-friend-blood-type object)))
-                    (hobby (mapconcat 'identity
-                                      (mixi-friend-hobby object) ", ")))
-                (concat "<dl>"
-                        "<dt>̾Á°¡§</dt>"
-                        "<dd>" (mixi-friend-name object) "</dd>\n"
-                        "<dt>À­ÊÌ¡§</dt>"
-                        "<dd>" sex "À­</dd>\n"
-                        "<dt>¸½½»½ê¡§</dt>"
-                        "<dd>" (mixi-friend-address object) "</dd>\n"
-                        "<dt>ǯÎð¡§</dt>"
-                        "<dd>" age "ºÐ</dd>\n"
-                        "<dt>ÃÂÀ¸Æü¡§</dt>"
-                        "<dd>" birthday "</dd>\n"
-                        "<dt>·ì±Õ·¿¡§</dt>"
-                        "<dd>" blood-type "·¿</dd>\n"
-                        "<dt>½Ð¿ÈÃÏ¡§</dt>"
-                        "<dd>" (mixi-friend-birthplace object) "</dd>\n"
-                        "<dt>¼ñÌ£¡§</dt>"
-                        "<dd>" hobby "</dd>\n"
-                        "<dt>¿¦¶È¡§</dt>"
-                        "<dd>" (mixi-friend-job object) "</dd>\n"
-                        "<dt>½ê°¡§</dt>"
-                        "<dd>" (mixi-friend-organization object) "</dd>\n"
-                        "<dt>¼«¸Ê¾Ò²ð¡§</dt>"
-                        "<dd>" (mixi-friend-profile object) "</dd>\n"
-                        "</dl>"))
-            (concat "<a href=\"" (shimbun-mixi-make-xref object)
-                    "\">¥×¥í¥Õ¥£¡¼¥ë¤òɽ¼¨¤¹¤ë</a>")))
-         (t (mixi-object-content object)))))
-
-(defun shimbun-mixi-make-reply-to (object)
-  (setq shimbun-mixi-reply-to "mixi;")
-  (let ((class (mixi-object-class object)))
-    (setq shimbun-mixi-reply-to
-         (concat
-          (cond ((eq class 'mixi-diary)
-                 (concat shimbun-mixi-reply-to "comment;diary;"
-                         (mixi-friend-id (mixi-diary-owner object)) ";"
-                         (mixi-diary-id object)))
-                ((mixi-bbs-p object)
-                 (concat shimbun-mixi-reply-to "comment;"
-                         (mixi-object-name object) ";"
-                         (mixi-community-id (mixi-bbs-community object)) ";"
-                         (mixi-bbs-id object)))
-                ((eq class 'mixi-community)
-                 (concat shimbun-mixi-reply-to "topic;"
-                         (mixi-community-id object)))
-                ((or (eq class 'mixi-news) (eq object (mixi-make-me)))
-                 (concat shimbun-mixi-reply-to "diary"))
-                ((eq class 'mixi-message)
-                 (concat shimbun-mixi-reply-to "message;"
-                         (mixi-friend-id (mixi-message-owner object))))
-                ((or (eq class 'mixi-friend) (eq class 'mixi-log))
-                 (concat shimbun-mixi-reply-to "message;"
-                         (mixi-friend-id object))))))))
+  mixi-reply-to)
 
 (defun shimbun-mixi-get-headers (shimbun objects &optional range)
   (when objects
@@ -321,23 +155,27 @@ of mixi object."
                                (push header headers))
                              (shimbun-mixi-get-headers shimbun
                                                        comments))))
-                   (let ((id (shimbun-mixi-make-message-id object)))
+                   (let ((id (mixi-make-message-id object)))
                      (when (and (eq class 'mixi-comment)
                                 (shimbun-search-id shimbun id))
                        (throw 'stop nil))
                      (push
                       (shimbun-create-header
                        0
-                       (shimbun-mixi-make-subject shimbun object)
-                       (shimbun-mixi-make-from object)
-                       (shimbun-mixi-make-date object)
+                       (mixi-make-title object
+                                        (string-match
+                                         "^new-"
+                                         (shimbun-current-group-internal
+                                          shimbun)))
+                       (mixi-make-author object)
+                       (mixi-make-date object)
                        id
                        (if (eq class 'mixi-comment)
-                           (shimbun-mixi-make-message-id
+                           (mixi-make-message-id
                             (mixi-comment-parent object))
                          "")
                        0 0
-                       (shimbun-mixi-make-xref object))
+                       (mixi-make-url object))
                       headers)
                      (when (eq class 'mixi-comment)
                        (puthash id (mixi-comment-content object)
@@ -373,7 +211,7 @@ of mixi object."
     (unless (stringp article)
       (let ((parent (mixi-make-object-from-url url)))
        (mapc (lambda (comment)
-               (let ((id (shimbun-mixi-make-message-id comment))
+               (let ((id (mixi-make-message-id comment))
                      (content (mixi-comment-content comment)))
                  (puthash id content cache)
                  (when (string= id message-id)
@@ -392,8 +230,8 @@ of mixi object."
                    (article (if (string-match "#comment$" url)
                                 (shimbun-mixi-comment-article
                                  url shimbun header)
-                              (shimbun-mixi-make-body object))))
-              (shimbun-mixi-make-reply-to object)
+                              (mixi-make-content object))))
+              (mixi-make-reply-to object)
               (when (stringp article)
                 (insert article)))
             (shimbun-message shimbun "shimbun: Make contents...")