;; ndiary-mode.el --- mode for editing ndiary's diary file ;; ISHIKURA Hiroyuki ;; ---------------------------------------------------------------------- ;; History: ;; 2000/03/29 ver.0.1 initial Release ;; 2000/04/16 ver.0.2 generic.elを使わないように変更 ;; .emacs内でfont-lock定義を変更・追加できるようにした ;; 2000/08/07 ver.0.21 ndiary-font-lock-keywordをちょいと見直し ;; 2000/09/10 ver.0.3 akihisa@alles.or.jp氏のコードを一部マージ. ;; とはいえ私の趣味で大幅に書きなおしています (__) ;; 2000/09/14 ver.0.31 start-process前に同名のprocessをkillする事にした ;; 2000/09/25 ver.0.32 ndiary-previewのはずかしいバグを修正 ;; 2000/12/06 ver.0.33 ndiary-uploadではcall-processで処理することにした ;; (ファイル転送をasyncでやるのはアレかな〜と…) ;; ;; TODO: ;; ・自前のface定義を作る ;; ・customを使う ;; ---------------------------------------------------------------------- ;; USAGE: ;; 1.まずnDiaryを使えるようにきちんと環境を整備しましょう. ;; そうそう、Rubyにも当然PATHを通しておきましょう :-) ;; ;; 2.APEL(http://www.m17n.org/APEL/)をインストールしましょう. Meadowであ ;; れば標準で入ってるはずですが、まぁ最新版にするのも悪くないかもしれ ;; ません :-) ;; ;; 3.あなたがもしMeadowを使っているのであれば、Meadowがrubyスクリプトを ;; 直接start-processやcall-processできるようにするために、.emacsに次の ;; 4行を書き足しましょう. mw32script.elを直接書きかえるのも可です. ;; …そうそう、1.でRubyにパスを通さなかった人はここでrubyをフルパスに ;; する必要がありますね. ;; (require 'mw32script) ;; (setq mw32script-argument-editing-alist ;; (append '(("/ruby$" . "ruby.exe")) ;; mw32script-argument-editing-alist)) ;; (mw32script-init) ;; ああ、ndiary-diary-commandにRubyスクリプトそのものでない物(rb2cを ;; 使って生成した実行ファイルとか)を指定するのであれば、もちろんこの ;; 記述は必要ありません。 ;; ;; 4.あなたの環境に合うように.emacsの中で各種の設定を行いましょう. ;; ちなみに私は次のような設定を入れて使っています. ;; (require 'ndiary-mode) ;; (setq ndiary-log-directory "~/diary/log") ;; (setq ndiary-latest-filename "~/public_html/d/index.html") ;; (setq ndiary-upload-command "sitecopy") ;; (setq ndiary-upload-command-option "-u rim") ;; ;; 5.これでEmacsを立ちあげなおせば基本的には準備完了です. ;; M-x ndiary-edit で日記編集モードに入りますし、 ;; このモードでM-x ndiary-compile (C-cC-c) すればhtmlが生成されますし、 ;; このモードでM-x ndiary-upload (C-cC-u) すればuploadもできます. ;; (ああ、もちろんuploadするツールの設定は自分でやってくださいね. :-p) ;; ---------------------------------------------------------------------- ;; ndiary-mode requires APEL. (require 'path-util) (require 'alist) ;; 定数 (defconst ndiary-mode-version "0.31" "ndiary-modeのバージョンを示します.") ;; カスタマイズ変数群 (defvar ndiary-log-directory "~/diary/log" "日記の置いてあるディレクトリ.") (defvar ndiary-latest-filename "~/public_html/d/index.html" "「最近の日記のダイジェスト」のファイル名.") (defvar ndiary-split-month t "月毎にdiaryファイルを作成するディレクトリを分けるか否か.") (defvar ndiary-yesterday-time 2 "この時間(hour)を超えるまでは前日としてdiaryファイルを作成/取りあつかう.") (defvar ndiary-diary-file-coding-system 'sjis-unix "ndiary-modeで新規作成するdiaryファイルのcoding-system.") (defvar ndiary-mode-abbrev-table nil "ndiary-modeで使われるabbrev table.") (defvar ndiary-diary-command "diary" "日記生成用のコマンド. Emacsが実行可能ファイルである必要がある.") (defvar ndiary-diary-command-option "" "日記生成用のコマンドのオプション.") (defvar ndiary-upload-command nil "日記アップロード用のコマンド. Emacsが実行可能ファイルである必要がある.") (defvar ndiary-upload-command-option "" "日記アップロード用のコマンドのオプション.") ;; hooks (defvar ndiary-mode-load-hook nil) (defvar ndiary-edit-hook nil) (defvar ndiary-pre-compile-hook nil "日記ファイルを作成する前に実行されるhook. text-adjustの用なテキスト整形用Lispパッケージを使うのに使う.") (defvar ndiary-aft-compile-hook nil "日記ファイルを作成した後に実行されるファイル.") (defvar ndiary-pre-upload-hook nil) (defvar ndiary-aft-upload-hook nil) (defvar ndiary-preview-hook nil) (defvar ndiary-font-lock-keywords '(("\\(^■\\|^○\\|^◎\\|^□\\|^◇\\|^◆\ \\|^△\\|^▲\\|^▽\\|^▼\\|^☆\\|^★\\)\\(.*\\)" (1 font-lock-type-face) (2 font-lock-function-name-face)) ("^\\(・\\)\\(.*\\)$" (1 font-lock-warning-face) (2 font-lock-function-name-face)) ("^\\(Code:\\( -.*\\)?\\|^<<\\)$" (0 font-lock-warning-face)) ("(\\*[^)]*)" (0 font-lock-comment-face)) ("<[^>]*>" (0 font-lock-keyword-face))) "ndiary-mode用のfont-lock-keywords.") (defun ndiary-mode () "nDiaryファイルを編集するためのMajor mode. private-abbrev-tableと、以下のキーバインドを提供します: \\[ndiary-compile]\t日記を生成するコマンドを呼び出す. \\[ndiary-encode-region]\tregion内の\"<, >, &\"を、それぞれ\"< > &\"にエンコードする. \\[ndiary-upload]\t日記をアップロードするコマンドを呼び出す. \\[ndiary-preview]\tbrowse-urlを使って日記をpreviewする." (interactive) (kill-all-local-variables) (setq mode-name "nDiary") (setq major-mode 'ndiary-mode) (make-local-variable 'font-lock-keywords-only) (setq font-lock-keywords-only t) (make-local-variable 'font-lock-defaults) (setq font-lock-defaults '(ndiary-font-lock-keywords)) (setq buffer-file-coding-system ndiary-diary-file-coding-system) (setq local-abbrev-table ndiary-mode-abbrev-table) (abbrev-mode t) (local-set-key "\C-c\C-c" 'ndiary-compile) (local-set-key "\C-ce" 'ndiary-encode-region) (local-set-key "\C-cu" 'ndiary-upload) (local-set-key "\C-cp" 'ndiary-preview) (run-hooks 'ndiary-mode-hook)) (defun ndiary-encode-region () ; < > & "リージョン内の\"<, >, &\"を、\ それぞれ\"< > &\"にエンコードします." (interactive) (let (end-point (head-pointp (< (point) (mark)))) (or head-pointp (exchange-point-and-mark)) (save-excursion (while (re-search-forward "[<>&]" (mark) t) (let (tl) (setq tl (buffer-substring (match-beginning 0) (match-end 0))) (cond ((string= tl "<") (replace-match "<")) ((string= tl ">") (replace-match ">")) ((string= tl "&") (replace-match "&")))))))) (defun ndiary-edit () "今日の日記ファイルを編集します." (interactive) (let ((now (current-time)) dateh datel dir) ;; ndiary-yesterday-timeまでは前日として扱う (setq dateh (nth 0 now)) (setq datel (- (nth 1 now) (* ndiary-yesterday-time 3600))) (if (< datel 0) (progn (setq datel (+ datel 65536)) (setq dateh (1- dateh)))) (setq now (list dateh datel)) ;; ndiary-log-directoryがアクセス不能ならおしまい (if (not (file-accessible-directory-p ndiary-log-directory)) (error "ndiary-log-directoryの設定がヘンじゃないですか?")) ;; 日記のファイル名を決定する (cond ((eq ndiary-split-month t) (setq dir (expand-file-name (format-time-string "%Y/%m" now) ndiary-log-directory)) (if (not (file-accessible-directory-p dir)) (make-directory dir t))) (t (setq dir ndiary-log-directory))) ;; バッファを作る (setq ndiary-file-name (expand-file-name (format-time-string "%Y%m%d.diary" now) dir)) (setq ndiary-buffer (find-file ndiary-file-name))) (run-hooks 'ndiary-edit-hook)) (defun ndiary-compile (arg) "日記生成コマンドを発行してhtmlファイルを生成する. C-u ndiary-compile とすると diary に与えるオプションを指定できる." (interactive "P") (let ((com ndiary-diary-command) (opt ndiary-diary-command-option)) (run-hooks 'ndiary-pre-compile-hook) (ndiary-save-buffers) ;; 実行前にndiary関連バッファを全てセーブする。 (if (not (exec-installed-p ndiary-diary-command)) (error "ndiary-diary-commandが正しく設定されていないようです.")) (if arg (setq com (read-from-minibuffer "diary command: " com) opt (read-from-minibuffer "diary command option: " opt))) (save-excursion (set-buffer (get-buffer-create "*ndiary-compile*")) (if (get-process "ndiary-compile") (progn (delete-process "ndiary-compile"))) (erase-buffer) (apply (function start-process) "ndiary-compile" "*ndiary-compile*" com (split-string opt)) (display-buffer "*ndiary-compile*")) (run-hooks 'ndiary-aft-compile-hook))) (defun ndiary-upload (arg) "upload用コマンド(sitecopy等)を発行して日記をuploadする." (interactive "P") (let ((com ndiary-upload-command) (opt ndiary-upload-command-option)) (run-hooks 'ndiary-pre-upload-hook) (if (not (exec-installed-p com)) (error "ndiary-upload-commandが正しく設定されていないようです.")) (if arg (setq com (read-from-minibuffer "upload command: " com) opt (read-from-minibuffer "upload command option: " opt))) (save-excursion (set-buffer (get-buffer-create "*ndiary-upload*")) (erase-buffer) (display-buffer "*ndiary-upload*")) (apply (function call-process) com nil "*ndiary-upload*" t (split-string opt)) (run-hooks 'ndiary-aft-upload-hook))) (defun ndiary-preview (arg) "latest diary fileをpreviewします。" (interactive "P") (let ((filename ndiary-latest-filename)) (run-hooks 'ndiary-preview-hook) (if arg (setq filename (read-from-minibuffer "preview file: " ndiary-latest-filename))) (setq filename (expand-file-name filename)) (if (file-readable-p filename) (browse-url-of-file filename) (error "指定されたファイルは存在しないようですが….")))) (defun ndiary-save-buffers () "Save buffers whose major-mode is equal to current major-mode." (basic-save-buffer) (let ((cmm 'ndiary-mode)) (save-excursion (mapcar '(lambda (buf) (set-buffer buf) (if (and (buffer-file-name buf) (eq major-mode cmm) (buffer-modified-p buf) (y-or-n-p (format "Save %s" (buffer-name buf)))) (save-buffer buf))) (buffer-list))))) (setq auto-mode-alist (modify-alist '(("\\.diary\\'" . ndiary-mode)) auto-mode-alist)) (run-hooks 'ndiary-mode-load-hook) (provide 'ndiary-mode)