;;; -*- Emacs-Lisp -*-
;;; (c) 1999-2002 by HAYAKAWA Hitoshi
;; Web site : http://hykw.tv
;; E-mail: cz@hykw.tv
;; What's this?:
;; This is an EmacsLisp that help you write diary on Web called Web Diary,
;; or Web Nikki.
;;
;; これはなんでしょうか?
;; これは、Web 日記の入力支援をする EmacsLisp です。
;; How to install?
;; Put this file into your favorite place where is one of the load-path,
;; and just add the following lines to your ~|.emacs file.
;; (Don't input ";;". Those're the comment marks)
;; ---------------- cut here -----------------
;; (load "cz-add-diary")
;; ---------------- cut here -----------------
;; If you don't know about load-path well, just follow these instruction.
;;
;; (1) mkdir ~/mylisp
;; (2) cp cz-add-diary.el ~/mylisp
;; (3) Add your ~/.emacs file this line with your usual editor (Why don't you
;; use Emacs? :-).
;; (load "~/mylisp/cz-add-diary")
;;
;; インストール方法は?
;; このファイルを load-path の通った好きな場所に置いて、次の行を ~/.emacs に
;; 追加してください。(";;" はコメント記号ですので、入力しないように)
;; ---------------- cut here -----------------
;; (load "cz-add-diary")
;; ---------------- cut here -----------------
;; load-path についてよく分からない場合、次の指示通りに行ってください。
;;
;; (1) mkdir ~/mylisp
;; (2) cp cz-add-diary.el ~/mylisp
;; (3) あなたの ~/.emacs に、好きなエディター(まぁ X?Emacs/Muleでしょうが :-) で
;; 次の行を追加してください。
;; (load "~/mylisp/cz-add-diary")
;; How to use it?
;;
;; M-x cz-1st
;; The first writing of the day. You have to call this when you write
;; the diary first.
;;
;; M-x cz-add
;; The second or later writing. Call this when you add the writing
;; after the 1st writing.
;;
;; M-x cz-insert-digest
;; Insert the tags for the other uses
;;
;; M-x cz-add-footnote
;; Add the footnote. As you'd like to add a footnote, call this.
;;
;; M-x cz-delete-footnote
;; Delete the footnote and put into the kill-ring.
;;
;; M-x cz-renum
;; Renum the number of the writing of the day.
;;
;; M-x cz-renum-footnote
;; Renum the number of the footnote. But never do in number order, because
;; I can't know how to do that.
;;
;; M-x cz-jump-to-other-footenote
;; Move the cursor upside down. When the cursor is on the footnote,
;; move down to the body of the footnote and vice versa.
;;
;; M-x cz-add-schedule
;; Just add a schedule at the point.
;;
;; M-x cz-add-todo
;; Just add a todo at the point.
;;
;; M-x cz-1st
;; その日の初めの書き込み用。日記を始めに書き込むときにはこれを
;; 呼び出す必要があります。
;;
;; M-x cz-add
;; 2回目以降の書き込み用。二回目以降に書き込むときにはこれを
;; 呼び出す必要があります。
;;
;; M-x cz-insert-digest
;; 「妄想のかけら」用のタグを入力します。タグファイルは雑記用のものと共通です。
;;
;; M-x cz-add-footnote
;; 注釈の追加をします。注釈を追加した場合、これを呼び出してください。
;;
;; M-x cz-delete-footnote
;; 注釈を削除し、kill-ring に入れます。
;;
;; M-x cz-renum
;; カーソルのある日の書き込みの番号を renum します。
;;
;; M-x cz-renum-footnote
;; 注釈の番号を renum します。ただし、判断が付かないため、番号順に
;; 並べ替えたりはしません。
;; M-x cz-jump-to-other-footenote
;; カーソルを上下に移動します。カーソルが注釈の所にある場合、注釈の本体に、
;; もしくはその逆に注釈本体から注釈に移動します。
;; M-x cz-add-schedule
;; カーソルのある行に schedule を単に追加します。
;; M-x cz-add-todo
;; カーソルのある行に TODO を単に追加します。
;; 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; see the file COPYING. If not, write to
;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
;; You could get the latest version at my web site.
;; www.asahi-net.or.jp/~uv9h-hykw/comp/softs/elisp/cz-add-diary.el
;; Never delete the comments inserted automatically, because those are
;; used as the program
;;
;; 今のところ判定でインチキしてるんで、勝手に入力されるコメント記号は
;; 消してはいけません :-)
;---------------------------------------------------------------------------
(defun cz-insert-digest ()
"「妄想のかけら」用のタグを入力する"
(interactive)
(let ((work))
; カーソル行の直前の番号を探す
(search-backward-regexp "^ ")
(if (string-match "[[]" (buffer-substring (point) (1+ (point))))
(progn ; タグありの番号の場合
(search-forward ":")
(goto-char (1+ (point)))))
; この時点で、カーソルは挿入場所にあるはず。
(insert "")
(goto-char work)))
(defun cz-insert-digest-tag ()
"ダイジェスト用のタグを入力"
(let ((work)(tag)(flag 0))
(while (> flag -1)
(cz-read-tag-file)
(setq tag (completing-read "Digest tag: " cz-add-diary-tags nil nil))
(if (string-match tag "")
(setq flag -1)
(if (> flag 0)
(insert ","))
(insert tag)
(setq flag 1)
(if (setq work (assoc tag cz-add-diary-tags))
()
(if (y-or-n-p "Add the tag?")
(add-tag cz-add-diary-tagfile-path tag)))))))
(defun cz-read-tag-file ()
"~/.cz-add-diary を開いて eval する"
(let ((workBuf)(bFileNotFound))
(setq bFileNotFound t)
(add-hook 'find-file-not-found-hooks
(function (lambda ()
(setq cz-add-diary-tags nil)
(setq bFileNotFound nil))))
(setq workBuf (find-file-noselect cz-add-diary-tagfile-path))
(if bFileNotFound
(progn
(switch-to-buffer workBuf)
(eval-current-buffer)))
(kill-buffer workBuf)))
(defun cz-read-tag-file-file-not-found ()
(progn
(setq cz-add-diary-tags nil)))
(defun cz-insert-tag ()
"タグの入力"
(let ((work)(tag))
(cz-read-tag-file)
(setq tag (completing-read "Tag: " cz-add-diary-tags nil nil))
(if (string-match tag "")
()
(insert (concat "[" tag "]: "))
(if (setq work (assoc tag cz-add-diary-tags))
()
(if (y-or-n-p "Add the tag?")
(add-tag cz-add-diary-tagfile-path tag))))))
(defun add-tag (tagFile word)
"タグを登録する"
(let ((work)(bFileNotFound t)(wordBuf))
(save-excursion
(add-hook 'find-file-not-found-hooks
(function (lambda ()
(setq bFileNotFound nil))))
(setq wordBuf (find-file-noselect tagFile))
(if bFileNotFound
(progn
(switch-to-buffer wordBuf)
(goto-char (point-max))
(previous-line 1)
(insert (concat "(\"" word "\" 1)\n"))
(write-file tagFile)
(kill-buffer wordBuf))))))
(defun cz-current-time-year ()
"現在年月日を表示"
(interactive)
(progn
(insert (cz-current-time-year-get))))
(defun cz-current-time-year-get ()
(let ((timedate)(date)(year))
(setq timedate (current-time-string))
(format "%s %02d, %s"
(substring timedate 4 7)
(string-to-number (substring timedate 8 10))
(substring timedate 20 24))))
(defun cz-current-time-year-YYYYMMHH ()
"現在年月日(YYYYMMHH形式)を表示"
(interactive)
(let ((year)(month)(day))
(setq Year (substring (cz-current-time-year-get) 8 12))
(setq Month (cz-get-Month (substring (cz-current-time-year-get) 0 3)))
(setq Day (substring (cz-current-time-year-get) 4 6))
(concat Year Month Day)))
(defun cz-get-Month (Month-Chars)
"MMM形式の月をNN形式に変換"
(let ((MonthTable)(Month))
(setq MonthTable '(("Jan" . "01")("Feb" . "02")("Mar" . "03")("Apr" . "04")
("May" . "05")("Jun" . "06")("Jul" . "07")("Aug" . "08")
("Sep" . "09")("Oct" . "10")("Nov" . "11")("Dec" . "12")))
(setq Month (cdr (assoc Month-Chars MonthTable)))))
(defun cz-get-Day (Day-Chars)
"DDD形式の曜日をX(日本語1文字)に変換"
(let ((DayTable))
(setq DayTable '(("sun" . "日")("mon" . "月")("tue" . "火")
("wed" . "水")("thu" . "木")("fri" . "金")
("sat" . "土")))
(cdr (assoc Day-Chars DayTable))))
(defun cz-1st ()
"日付入力"
(interactive)
(let ((work)(NUM "")(HREF "\n
\n"))
(setq work (cz-current-time-year-YYYYMMHH))
(setq bufName (buffer-name (current-buffer)))
(insert (concat "\n"))
(insert (concat HREF "\"" bufName "#" work "\" name=\"" work "\">" (cz-current-time-year-get) "\n" "
\n" NUM "■#01 \n
\n\n\n")) (search-backward "") (forward-char 5) ;; タグの入力 (cz-insert-tag))) (defun cz-get-nearest-number () "カーソル行に一番近い、日番号 を返す" (save-excursion (let ((work)) (search-backward-regexp "^")) ;; カーソル行に一番近い、番号の付いた行をサーチ (setq work (cz-get-nearest-number)) (setq work2 (format "%02d" (1+ (string-to-number (substring work 3 4))))) (setq work (concat (substring work 0 2) work2)) (insert (concat "\n" NUM "■#" (substring work 2 4) " \n
")) (backward-char 5) (cz-insert-tag) ;; 最後に renum するのがよいでしょう :-) (cz-renum))) (defun cz-renum () "その日の全番号の renum を行う" (interactive) (save-excursion (let ((work)(bottom)(index 1)(i)(day)) ;; 当日の先頭にジャンプ(cz-1st() で検索用のコメントを入れてインチキしてます :-) (search-backward-regexp "^") (setq day (buffer-substring (match-beginning 0) (- (match-end 0) 4))) (forward-line 2) (save-excursion (search-forward-regexp "^ の位置を取得 (search-backward "") (setq bSup (point)) (goto-char curpoint) (if (search-backward "" nil t) (if (> bSup (point)) (setq bSupEnd -1) ; 注釈の間にカーソルがある (progn (forward-char 6) (setq bSupEnd (point)))) (setq bSupEnd -1)) ; 注釈の間にカーソルがある (goto-char curpoint) (if (= bSupEnd -1) (progn (search-forward "") (setq nSupEnd (point)))) (if (= bSupEnd -1) (setq work nSupEnd) (setq work bSupEnd)) (kill-region bSup work) (goto-char bSup))) (defun cz-add-footnote () "注釈を追加する" (interactive) (let ((noteNumber)(work)(work2)(toppoint)(curpoint)(downPoint) (footnoteNumber)(appendFlag)) (setq curpoint (point)) (save-excursion ;; 当日の先頭にジャンプ (search-backward-regexp "^" nil t) (progn (if (< toppoint (point)) ; 当日のコメントか? (progn (setq work2 (point)) ; 注釈番号の終わり (search-backward "*") (setq work (1+ (point))) ; 注釈番号の始まり (setq noteNumber (1+ (string-to-number (buffer-substring work work2))))) (setq noteNumber 1))) (setq noteNumber 1))) (setq noteNumber (int-to-string noteNumber)) ;; 本文に注釈追加 (setq footnoteNumber (cz-get-nearest-number)) (insert (concat " \*" noteNumber " ")) ;; 本文の下部に注釈メインを追加し、カーソルをそこに移動。 ;; 本文の現在位置をマークしておく。 ;; 挿入位置を探す ;; まず当日の一番下を取得しておく (setq curpoint (point)) (search-forward-regexp "^ (point) downPoint) (goto-char downPoint) (beginning-of-line) (previous-line 1))) ;; 当日の最終行の場合、DOWN の手前 (goto-char downPoint)) ;; 注釈本文を追加 ;; 既に注釈がある場合、注釈を追加。ない場合、注釈本文のヘッダも追加 (if (search-backward-regexp "^" nil t) (progn (if (> (point) curpoint) (progn (setq appendFlag 1) ; 以前の注釈に追加する場合 (search-forward-regexp "^") (beginning-of-line)) (goto-char downPoint) (setq appendFlag 0))) ; 新規の注釈 (setq appendFlag 0)) ; 新規の注釈 (setq work (concat footnoteNumber "_" noteNumber)) (if (= appendFlag 0) (insert (concat "\n\n\n" "\n")) (goto-char curpoint))) (defun cz-get-current-line () ;; カレントバッファのカレント行の文字列を取得する. (save-excursion (let ((start (progn (beginning-of-line)(point))) (end (progn (end-of-line) (point)))) (buffer-substring start end)))) (defun cz-jump-to-other-footenote () "注釈<>注釈本文のジャンプを行う" (interactive) (let ((work)(curPoint)(LineBuf)(bSup)(bSupEnd)(nSupEnd)(bufName)) (setq curPoint (point)) (setq bufName (buffer-name (current-buffer))) (setq LineBuf (cz-get-current-line)) ;; 現在のカーソル位置は注釈本文か? (if (string-match (concat "^\n"))) (insert (concat "
\n")) (setq work (point)) (search-backward "") (setq curpoint (point)) (goto-char work) (if (= appendFlag 0) (insert " \*" noteNumber "