From: ueno Date: Fri, 12 Aug 2005 07:05:28 +0000 (+0000) Subject: * riece-log.el (riece-log-file-name-regexp): New constant. X-Git-Tag: channel-coding-branchpoint~125 X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ce6f7685fe82aaa84470a00e1f1cfa88a00bb26f;p=elisp%2Friece.git * riece-log.el (riece-log-file-name-regexp): New constant. (riece-log-get-file): Add 2nd argument coding-system. (riece-log-get-files): Add 2nd argument time. (riece-log-insert): Simplified; determine coding-system from suffix of each log file. --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 8f8d5e7..814d37c 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,5 +1,11 @@ 2005-08-12 Daiki Ueno + * riece-log.el (riece-log-file-name-regexp): New constant. + (riece-log-get-file): Add 2nd argument coding-system. + (riece-log-get-files): Add 2nd argument time. + (riece-log-insert): Simplified; determine coding-system from + suffix of each log file. + * Makefile.am (EXTRA_DIST): Added aproxy.rb. * COMPILE (riece-scripts): Added "aproxy.rb". diff --git a/lisp/riece-log.el b/lisp/riece-log.el index a905e73..8e303b8 100644 --- a/lisp/riece-log.el +++ b/lisp/riece-log.el @@ -93,6 +93,9 @@ If integer, flash back only this line numbers. t means all lines." "Lock file for riece-log. It is created if there is at least one instance of Emacs running riece-log.") +(defconst riece-log-file-name-regexp + (concat (riece-make-interval-regexp "[0-9]" 8) "\\.txt\\(\\.\\(.*\\)\\)?$")) + (defvar riece-log-enabled nil) (defconst riece-log-description @@ -100,8 +103,10 @@ It is created if there is at least one instance of Emacs running riece-log.") (defun riece-log-display-message-function (message) (if riece-log-enabled - (let ((file (riece-log-get-file (riece-message-target message))) - (coding-system-for-write riece-log-coding-system) + (let ((coding-system-for-write (or riece-log-coding-system + buffer-file-coding-system)) + (file (riece-log-get-file (riece-message-target message) + coding-system-for-write)) file-name-coding-system default-file-name-coding-system) (unless (file-directory-p (file-name-directory file)) @@ -111,20 +116,26 @@ It is created if there is at least one instance of Emacs running riece-log.") nil file t 0 riece-log-lock-file)))) -(defun riece-log-get-file (identity) +(defun riece-log-get-file (identity coding-system) (expand-file-name - (concat (format-time-string "%Y%m%d") ".txt") + (format "%s.txt.%s" (format-time-string "%Y%m%d") coding-system) (riece-log-get-directory identity))) -(defun riece-log-get-files (identity) - (let ((directory (riece-log-get-directory identity))) - (if (file-directory-p directory) - (nreverse (sort (directory-files directory t - (concat "^" - (riece-make-interval-regexp "[0-9]" 8) - "\\.txt$") - t) - #'string-lessp))))) +(defun riece-log-get-files (identity time) + (let ((directory (riece-log-get-directory identity)) + (time-prefix (format-time-string "%Y%m%d" (or time '(0 0)))) + files) + (when (file-directory-p directory) + (setq files (nreverse (sort (directory-files + directory t + (concat "^" riece-log-file-name-regexp) + t) + #'string-lessp))) + (while (and files + (string-lessp (file-name-nondirectory (car files)) + time-prefix)) + (setq files (cdr files))) + files))) (defun riece-log-get-directory (identity) (let ((prefix (riece-identity-canonicalize-prefix @@ -175,42 +186,54 @@ It is created if there is at least one instance of Emacs running riece-log.") (defun riece-log-insert (identity lines) "Insert logs for IDENTITY at most LINES. If LINES is t, insert today's logs entirely." - (if (eq lines t) - (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* (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) - "\\.txt$") - (setq name (file-name-nondirectory - (car files))))) - (save-restriction - (narrow-to-region (point) (point)) - (insert-file-contents (car files)) - (goto-char (point-max)) - (setq lines (forward-line lines)) - (delete-region (point-min) (point)) - (unless (equal name (format-time-string "%Y%m%d.txt")) - (setq date (concat " (" (substring name 0 4) "/" - (substring name 4 6) "/" - (substring name 6 8) ")")) - (while (not (eobp)) - (end-of-line) - (setq point (point)) - (insert date) - (put-text-property point (point) - 'riece-overlay-face 'riece-log-date-face) - (forward-line)) - (goto-char (point-min))))) - (setq files (cdr files)))))) + (let* (file-name-coding-system + default-file-name-coding-system + (files (riece-log-get-files identity + (if (eq lines t) (current-time)))) + name coding-system date point) + (while (and (or (eq lines t) (> lines 0)) files) + (save-restriction + (narrow-to-region (point) (point)) + (if (and (string-match + (concat "^" riece-log-file-name-regexp) + (setq name (file-name-nondirectory (car files)))) + (match-beginning 2)) + (progn + (setq coding-system + (intern (substring name (match-beginning 2)))) + (if (featurep 'xemacs) + (setq coding-system (find-coding-system coding-system)) + (unless (coding-system-p coding-system) + (setq coding-system nil))) + (if coding-system + (let ((coding-system-for-read coding-system)) + (insert-file-contents (car files))) + ;;don't insert file contents if they use non + ;;supported coding-system. + )) + ;;if the filename has no coding-system suffix, decode with + ;;riece-log-coding-system. + (let ((coding-system-for-read riece-log-coding-system)) + (insert-file-contents (car files)))) + ;;lines in the file contents are in reversed order. + (unless (eq lines t) + (goto-char (point-max)) + (setq lines (- (forward-line (- lines)))) + (delete-region (point-min) (point))) + ;;add (YYYY/MM/dd) suffix on each line left in the current buffer. + (unless (equal (substring name 0 8) (format-time-string "%Y%m%d")) + (setq date (concat " (" (substring name 0 4) "/" + (substring name 4 6) "/" + (substring name 6 8) ")")) + (while (not (eobp)) + (end-of-line) + (setq point (point)) + (insert date) + (put-text-property point (point) + 'riece-overlay-face 'riece-log-date-face) + (forward-line)) + (goto-char (point-min)))) + (setq files (cdr files))))) (defun riece-log-flashback (identity) (when riece-log-flashback