* test/Makefile.am (EXTRA_DIST): Add test-riece-eval.el.
[riece] / lisp / riece-log.el
index 3289a07..ade7e6e 100644 (file)
   :type 'directory
   :group 'riece-log)
 
+(defcustom riece-log-lock-directory
+  (expand-file-name "=lock" riece-log-directory)
+  "*Lock directory for riece-log.
+It is created if there is at least one instance of Emacs running riece-log."
+  :type 'directory
+  :group 'riece-log)
+
 (defcustom riece-log-directory-map nil
   "*The map of channel name and directory name."
   :type '(repeat (cons (string :tag "Channel name")
@@ -125,10 +132,9 @@ If integer, flash back only this line numbers. t means all lines."
   (let ((prefix (riece-identity-canonicalize-prefix
                 (riece-identity-prefix identity)))
        (server (riece-identity-server identity))
-       (map (assoc (riece-format-identity identity) riece-log-directory-map))
-       name)
+       (map (assoc (riece-format-identity identity) riece-log-directory-map)))
     (if map
-       (setq name (cdr map))
+       (expand-file-name (cdr map) riece-log-directory)
       (expand-file-name (riece-log-encode-file-name prefix)
                        (expand-file-name
                         (concat "." (riece-log-encode-file-name server))
@@ -172,12 +178,16 @@ If integer, flash back only this line numbers. t means all lines."
   "Insert logs for IDENTITY at most LINES.
 If LINES is t, insert today's logs entirely."
   (if (eq lines t)
-      (let ((file (riece-log-get-file identity)))
+      (let* (file-name-coding-system
+            default-file-name-coding-system
+            (file (riece-log-get-file identity)))
        (if (file-exists-p file)
            (insert-file-contents file)))
-    (let ((files (riece-log-get-files identity))
-         (lines (- lines))
-         name date point)
+    (let* (file-name-coding-system
+          default-file-name-coding-system
+          (files (riece-log-get-files identity))
+          (lines (- lines))
+          name date point)
       (while (and (< lines 0) files)
        (if (and (file-exists-p (car files))
                 (string-match (concat (riece-make-interval-regexp "[0-9]" 8)
@@ -218,11 +228,14 @@ If LINES is t, insert today's logs entirely."
                (buffer-string)))
       (goto-char point)
       (while (re-search-forward
-             "^[0-9][0-9]:[0-9][0-9] [<>]\\([^<>]+\\)[<>] " nil t)
-       (put-text-property (match-beginning 1) (match-end 1)
+             (concat "^" riece-time-prefix-regexp
+                      "\\(<[^>]+>\\|>[^<]+<\\|([^)]+)\\|{[^}]+}\\|=[^=]+=\\)")
+             nil t)
+       (put-text-property (1+ (match-beginning 1)) (1- (match-end 1))
                           'riece-identity
                           (riece-make-identity
-                           (riece-match-string-no-properties 1)
+                           (buffer-substring (1+ (match-beginning 1))
+                                             (1- (match-end 1)))
                            (riece-identity-server identity))))
       (run-hook-with-args 'riece-after-insert-functions
                          point (goto-char (point-max)))
@@ -252,7 +265,19 @@ If LINES is t, insert today's logs entirely."
 (defvar riece-command-mode-map)
 (defun riece-log-enable ()
   (define-key riece-command-mode-map "\C-cd" 'riece-log-open-directory)
-  (setq riece-log-enabled t))
+  (make-directory riece-log-directory t)
+  (condition-case nil
+      (progn
+       (make-directory riece-log-lock-directory)
+       (add-hook 'riece-exit-hook
+                 (lambda ()
+                   (condition-case nil
+                       (delete-directory riece-log-lock-directory)
+                     (error))))
+       (setq riece-log-enabled t))
+    (error
+     (if riece-debug
+        (message "Can't create lock directory for riece-log")))))
 
 (defun riece-log-disable ()
   (define-key riece-command-mode-map "\C-cd" nil)