;;; -*- Mode: Lisp; Package: EDITOR -*- ;;; ;;; This file is part of xyzzy. ;;; ; M-x ndiary-edit で今日の日記を起稿 ; C-c C-c html に変換 ; C-c C-u アップロード ; C-c C-e リュージョン内の < > & を > %lt; & に変換 ; C-c C-d リュージョン内の > %lt; & を < > & に変換 ; F9 xyzzy内に最新の日記htmlを表示 ; S-f9 最新の日記htmlをブラウザで表示 (provide "ndiary-mode") (in-package "editor") ;; 設定 (defvar *ndiary-directory* "~/diary") (defvar *ndiary-yesterday-hour* 0) (defvar *ndiary-filename* "diary") (defvar *ndiary-html* nil) (defvar *ndiary-upload-command* nil) (defvar *ndiary-topic-char* "■○") (defvar *ndiary-offer-save* nil) (export '(*ndiary-mode-hook* *ndiary-mode-map* *ndiary-directory* *ndiary-yesterday-hour* *ndiary-filename* *ndiary-html* *ndiary-topic-char* *ndiary-offer-save* *ndiary-upload-command* ndiary-mode ndiary-edit ndiary-preview-html ndiary-open-html ndiary-compile ndiary-upload encode-html-char decode-html-char *ndiary-keyword-file*)) (defvar *ndiary-mode-hook* nil) (defvar *ndiary-keyword-hash-table* nil) (defvar *ndiary-keyword-file* "HTML") ;; 初期化 ; キー割り当て (defvar *ndiary-mode-map* nil) (unless *ndiary-mode-map* (setq *ndiary-mode-map* (make-sparse-keymap)) (define-key *ndiary-mode-map* #\F9 'ndiary-preview-html) (define-key *ndiary-mode-map* #\S-F9 'ndiary-open-html) (define-key *ndiary-mode-map* '(#\C-c #\C-c) 'ndiary-compile) (define-key *ndiary-mode-map* '(#\C-c #\C-u) 'ndiary-upload) (define-key *ndiary-mode-map* '(#\C-c #\C-e) 'encode-html-char) (define-key *ndiary-mode-map* '(#\C-c #\C-d) 'decode-html-char)) (defvar *ndiary-mode-abbrev-table* nil) (unless *ndiary-mode-abbrev-table* (define-abbrev-table '*ndiary-mode-abbrev-table*)) (defun ndiary-mode () (interactive) (kill-all-local-variables) (setq buffer-mode 'ndiary-mode) (setq mode-name "nDiary") (use-keymap *ndiary-mode-map*) (setq html-highlight-mode t) (and *ndiary-keyword-file* (null *ndiary-keyword-hash-table*) (setq *ndiary-keyword-hash-table* (load-keyword-file *ndiary-keyword-file* t))) (when *ndiary-keyword-hash-table* (make-local-variable 'keyword-hash-table) (setq keyword-hash-table *ndiary-keyword-hash-table*)) (setq *local-abbrev-table* *ndiary-mode-abbrev-table*) ;; 中途半端に色を付けてみる (setq ndiary-colorize (make-hash-table)) (setf (gethash #\( ndiary-colorize) #\)) ; (setf (gethash #\( ndiary-colorize) #\)) (dotimes (i (length *ndiary-topic-char*)) (setf (gethash (char *ndiary-topic-char* i) ndiary-colorize) #\LFD)) (setq parentheses-hash-table ndiary-colorize) (setq highlight-keyword t) (run-hooks '*ndiary-mode-hook*)) ;; 諸々 ; 今日の日記のファイルを開く (defun ndiary-edit() "今日の分の日記を書くの" (interactive) ; 日付取得 (setq diarydate (- (get-universal-time) (* *ndiary-yesterday-hour* 3600))) (setq yyyy (format-date-string "%Y" diarydate)) (setq mm (format-date-string "%m" diarydate)) (setq dd (format-date-string "%d" diarydate)) (setq diarydir (concat (append-trail-slash *ndiary-directory*) yyyy "/" mm "/")) (unless (file-exist-p diarydir) (create-directory diarydir)) (setq diaryfile (concat yyyy mm dd ".diary")) (find-file (concat diarydir diaryfile))) ; 日記作成 (defun ndiary-compile() "日記を html に変換するの" (interactive) (if *ndiary-offer-save* (save-some-buffers)) (setq cmd (read-string "Script: " :default (concat "ruby " *ndiary-filename*))) (pop-to-buffer (get-buffer-create "nDiary output") 8) (execute-shell-command cmd nil "nDiary output") (other-window -1)) ; 日記をサーバにアップロード (defun ndiary-upload() (interactive) "日記をサーバにアップロードするの" (shell-execute *ndiary-upload-command* t)) ; 日記の html を関連づけされたブラウザで開く (defun ndiary-open-html() (interactive) "日記をブラウザで見るの" (shell-execute *ndiary-html* t)) ; html preview on IE (require "wip/winapi") (c:define-dll-entry winapi:BOOL ShowWindow (winapi:HWND c:int) "user32") (require "browser") (defvar browser-last-page "") (defun ndiary-preview-html() (interactive) "日記を IE でプレビューするの" (setq filename *ndiary-html*) (or (and initialized (string= browser-last-page filename) (ShowWindow (get-window-handle) 9) (close-browser)) (and (setq browser-last-page filename) (ShowWindow (get-window-handle) 3) (navigate browser-last-page)))) (defun encode-html-char (from to) (interactive "r") (save-excursion (save-restriction (narrow-to-region from to) (goto-char (point-min)) (replace-buffer "&" "&") (goto-char (point-min)) (replace-buffer "\"" """) (goto-char (point-min)) (replace-buffer ">" ">") (goto-char (point-min)) (replace-buffer "<" "<")))) (defun decode-html-char (from to) (interactive "r") (save-excursion (save-restriction (narrow-to-region from to) (goto-char (point-min)) (replace-buffer "<" "<" ) (goto-char (point-min)) (replace-buffer ">" ">") (goto-char (point-min)) (replace-buffer """ "\"") (goto-char (point-min)) (replace-buffer "&" "&"))))