[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[emacs-wiki-discuss] emacs-wiki-journal old-title
From: |
Yamagata Yoriyuki |
Subject: |
[emacs-wiki-discuss] emacs-wiki-journal old-title |
Date: |
Sun, 20 Feb 2005 02:06:22 +0900 (JST) |
Hi,
I do some changes to formatting of archived emacs-wiki-journal pages.
I'd like to hear your opinion. The patch is attached.
The changes are,
1. Use "emacs-wiki-journal-time-format" instead of
"emacs-wiki-journal-title-format" to format the date in the title.
"format-time-string" is more flexible than "format".
"emacs-wiki-journal-mktime" is modified to
(defun emacs-wiki-journal-mktime(s)
(if s
(let* ((date (split-string s "-"))
(time (encode-time 0 0 0
(string-to-int (nth 2 date))
(string-to-int (nth 1 date))
(string-to-int (nth 0 date)))))
(format-time-string emacs-wiki-journal-time-format time))))
2. The titles of archive files are generated by substituting the
"emacs-wiki-journal-old-title-format-1" when the date of the newest
entry is not equal the date of oldest entry. if they are equal,
"emacs-wiki-journal-old-title-format-2" is used. The default are
"Entries from %s to %s" and "Entries of %s".
Previously, "from" and "to" strings in the title are hard-coded,
which is not good for internationalization.
By the way, the "date tag" in an entry is somewhat annoying for
me. Could it be moved to the end of files? "Meta" information used
by Emacs is often placed in this location.
--
Yamagata Yoriyuki
--- orig/emacs-wiki-journal.el
+++ mod/emacs-wiki-journal.el
@@ -217,12 +217,18 @@
(const :tag "No title" nil))
:group 'emacs-wiki-journal)
-(defcustom emacs-wiki-journal-old-title-prefix "Entries "
- "Title prefix of the old journal pages.
-If `nil', no title is inserted."
+(defcustom emacs-wiki-journal-old-title-format-1 "Entries from %s to %s"
+ "Title of the old journal pages. If `nil', no title is inserted."
:type 'string
:group 'emacs-wiki-journal)
+(defcustom emacs-wiki-journal-old-title-format-2 "Entries of %s"
+ "Title of the old journal pages if it contains the entries of only
+one day. If `nil', no title is inserted."
+ :type 'string
+ :group 'emacs-wiki-journal)
+
+
(defcustom emacs-wiki-journal-entries-per-page 4
"Maximum number of journal entries per page."
:type 'integer
@@ -247,11 +253,6 @@
(const :tag "Do not scan for title" nil))
:group 'emacs-wiki-journal)
-(defcustom emacs-wiki-journal-title-format "%d-%2d-%4d"
- "The format of time string used to update the title if it exists."
- :type 'string
- :group 'emacs-wiki-journal)
-
(defcustom emacs-wiki-journal-date-format "%4Y-%2m-%2e"
"Format for the string used in the date tags.
Unlike `emacs-wiki-journal-time-format', this should be
@@ -421,56 +422,54 @@
(with-current-buffer (find-file-noselect current)
(delete-region (point-min) (point-max))))))
+(defun emacs-wiki-journal-nextday()
+ (goto-char (point-min))
+ (and (re-search-forward
+ (format emacs-wiki-journal-date-tag-template
+ "\\(.+\\)")
+ nil t)
+ (match-string 1)))
+
+(defun emacs-wiki-journal-lastday()
+ (goto-char (point-max))
+ (and (re-search-backward
+ (format emacs-wiki-journal-date-tag-template
+ "\\(.+\\)")
+ nil t)
+ (match-string 1)))
+
+(defun emacs-wiki-journal-mktime(s)
+ (if s
+ (let* ((date (split-string s "-"))
+ (time (encode-time 0 0 0
+ (string-to-int (nth 2 date))
+ (string-to-int (nth 1 date))
+ (string-to-int (nth 0 date)))))
+ (format-time-string emacs-wiki-journal-time-format time))))
+
(defun emacs-wiki-journal-update-old-journal-title (file)
"Update the title of an old journal page."
- (labels
- ((nextday ()
- (goto-char (point-min))
- (and (re-search-forward
- (format emacs-wiki-journal-date-tag-template
- "\\(.+\\)")
- nil t)
- (match-string 1)))
- (lastday ()
- (goto-char (point-max))
- (and (re-search-backward
- (format emacs-wiki-journal-date-tag-template
- "\\(.+\\)")
- nil t)
- (match-string 1)))
- (mktime (s)
- (if s
- (let ((date (split-string s "-")))
- (format emacs-wiki-journal-title-format
- (string-to-int (nth 0 date))
- (string-to-int (nth 1 date))
- (string-to-int (nth 2 date))))
- s)))
- (when emacs-wiki-journal-old-title-prefix
- (with-current-buffer (find-file-noselect file)
- (goto-char (point-min))
- (when (re-search-forward "^#title " nil t)
- (beginning-of-line)
- (let ((kill-whole-line t)) (kill-line)))
- (let* ((to (nextday))
- (from (lastday)))
- (goto-char (point-min))
- (insert "#title " emacs-wiki-journal-old-title-prefix
- "\n\n\n"
- "date: "
- (if (not (string= from to))
- (concat (if from (concat (if to "from " " ")
- (mktime from) " ")
- "")
- (if to (concat (if from "to " " ")
- (mktime to) " ")
- ""))
- (mktime from))
+ (when (and emacs-wiki-journal-old-title-format-1
+ emacs-wiki-journal-old-title-format-2)
+ (with-current-buffer (find-file-noselect file)
+ (goto-char (point-min))
+ (when (re-search-forward "^#title " nil t)
+ (beginning-of-line)
+ (let ((kill-whole-line t)) (kill-line)))
+ (let* ((to (emacs-wiki-journal-nextday))
+ (from (emacs-wiki-journal-lastday)))
+ (goto-char (point-min))
+ (insert "#title "
+ (if (not (string= from to))
+ (format emacs-wiki-journal-old-title-format-1
+ (emacs-wiki-journal-mktime from)
+ (emacs-wiki-journal-mktime to))
+ (format emacs-wiki-journal-old-title-format-2
+ (emacs-wiki-journal-mktime from))))
+ (insert "\n"))
(save-buffer (current-buffer))
(kill-buffer (current-buffer)))))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [emacs-wiki-discuss] emacs-wiki-journal old-title,
Yamagata Yoriyuki <=