変更点
- html-helper-modeをderiveするのを廃止
- てか、機能何も使ってなかったし
- 関数名を変更
- 「hatena-group-keyword-hoge」みたいな名前が普通っぽいのかな
- postした後で、自動的にブラウザでそのキーワードページを開く関数を追加
最後の関数に時間がかかった。elisp関係の語彙が少なすぎる。start-processではなくstart-process-shell-commandというのを使うとできた。start-processだと更新を待たずして、ブラウザを開いてしまうという問題点があった。
(defun hatena-group-keyword-post-and-open-in-browser () "function to post hatena keyword" (interactive) (start-process-shell-command "post-hatena-group-keyword" "*post-hatena-group-keyword*" hatena-group-keyword-bin (expand-file-name (buffer-name (window-buffer))) "&&" "open" (concat "http://" hatena-group-keyword-default-group ".g.hatena.ne.jp/keyword/" (car (split-string (buffer-name (window-buffer)) "\.txt")))) (message "finished posting to hatena group keyword."))
以下ソース。
(defvar hatena-group-keyword-bin "hgk.rb" nil) (defvar hatena-group-keyword-root "~/hatena_keyword" nil) (defvar hatena-group-keyword-default-group "" nil) (defvar hatena-group-keyword-buffer "*hatena-group-keyword*") (defvar simple-hatena-process-buffer-name "*SimpleHatena*" "*はてダラを実行するプロセスのバッファ名。") (setq hatena-group-keyword-mode-map (make-sparse-keymap)) (define-key hatena-group-keyword-mode-map "\C-c\C-p" 'hatena-group-keyword-post-and-open-in-browser) (define-key hatena-group-keyword-mode-map "\C-c\C-f" 'hatena-group-keyword-open-keyword-in-browser) (define-key hatena-group-keyword-mode-map "\C-c\C-o" 'hatena-group-keyword-open-keyword-in-dired) (defvar hatena-group-keyword-mode-hook nil) (defvar hatena-group-keyword-before-submit-hook nil "日記を投稿する直前のフック") (defvar hatena-group-keyword-after-submit-hook nil "日記を投稿した直後のフック") (defvar hatena-group-keyword-font-lock-keywords nil) (defvar hatena-group-keyword-slag-face 'hatena-group-keyword-slag-face) (defvar hatena-group-keyword-subtitle-face 'hatena-group-keyword-subtitle-face) (defvar hatena-group-keyword-inline-face 'hatena-group-keyword-inline-face) (defvar hatena-group-keyword-markup-face 'hatena-group-keyword-markup-face) (defvar hatena-group-keyword-link-face 'hatena-group-keyword-link-face) (defface hatena-group-keyword-slag-face '((((class color) (background light)) (:foreground "IndianRed")) (((class color) (background dark)) (:foreground "wheat"))) "小見出しの*タイムスタンプorスラッグ*部分のフェイス。") (defface hatena-group-keyword-subtitle-face '((((class color) (background light)) (:foreground "DarkOliveGreen")) (((class color) (background dark)) (:foreground "wheat"))) "小見出しのフェイス。") (defface hatena-group-keyword-inline-face '((((class color) (background light)) (:foreground "MediumBlue" :bold t)) (((class color) (background dark)) (:foreground "wheat" :bold t))) "id記法や[keyword:Emacs]等のface") (defface hatena-group-keyword-markup-face '((((class color) (background light)) (:foreground "DarkOrange" :bold t)) (((class color) (background dark)) (:foreground "IndianRed3" :bold t))) "はてなのマークアップのフェイス。") (defface hatena-group-keyword-link-face '((((class color) (background light)) (:foreground "DeepPink")) (((class color) (background dark)) (:foreground "wheat"))) "リンクのフェイス。") (eval-when-compile (require 'cl) (require 'font-lock)) (defun hatena-group-keyword-mode () "はてなグループのキーワードへ投稿するためのメジャーモード" (interactive) (kill-all-local-variables) ;; フォントロック (font-lock-add-keywords 'hatena-group-keyword-mode (list (list "^\\(\\*[*a-zA-Z0-9_-]*\\)\\(.*\\)$" '(1 hatena-group-keyword-slag-face t) '(2 hatena-group-keyword-subtitle-face t)) ;; 必ず[]で囲まれていなければならないもの (list "\\[[*a-zA-Z0-9_-]+\\(:[^\n]+\\)+\\]" '(0 hatena-group-keyword-inline-face t)) ;; 必ずしも[]で囲まれていなくてもよいもの (list "\\[?\\(id\\|a\\|b\\|d\\|f\\|g\\|graph\\|i\\|idea\\|map\\|question\\|r\\|isbn\\|asin\\)\\(:[a-zA-Z0-9_+:-]+\\)+\\]?" '(0 hatena-group-keyword-inline-face t)) (list "^\\(:\\)[^:\n]+\\(:\\)" '(1 hatena-group-keyword-markup-face t) '(2 hatena-group-keyword-markup-face t)) (list "^\\([-+]+\\)" '(1 hatena-group-keyword-markup-face t)) (list "\\(((\\).*\\())\\)" '(1 hatena-group-keyword-markup-face t) '(2 hatena-group-keyword-markup-face t)) (list "^\\(>>\\|<<\\|><!--\\|--><\\|>|?[^|]*|\\||?|<\\|=====?\\)" '(1 hatena-group-keyword-markup-face t)) (list "\\(s?https?://\[-_.!~*'()a-zA-Z0-9;/?:@&=+$,%#\]+\\)" '(1 hatena-group-keyword-link-face t)))) (font-lock-mode 1) (use-local-map hatena-group-keyword-mode-map) (setq mode-name "Hatena Group Keyword") (setq major-mode 'hatena-group-keyword-mode) (run-hooks 'hatena-group-keyword-mode-hook)) (defun hatena-group-keyword-post-and-open-in-browser () "function to post hatena keyword" (interactive) (start-process-shell-command "post-hatena-group-keyword" "*post-hatena-group-keyword*" hatena-group-keyword-bin (expand-file-name (buffer-name (window-buffer))) "&&" "open" (concat "http://" hatena-group-keyword-default-group ".g.hatena.ne.jp/keyword/" (car (split-string (buffer-name (window-buffer)) "\.txt")))) (message "finished posting to hatena group keyword.")) (defun hatena-group-keyword-open-keyword-in-browser () "function to open the keyword in safari." (interactive) (start-process "open-keyword" "*open-keyword*" "open" (concat "http://" hatena-group-keyword-default-group ".g.hatena.ne.jp/keyword/" (car (split-string (buffer-name (window-buffer)) "\.txt")))) (message "opened the buffer in safari.")) (defun hatena-group-keyword-open-keyword-in-dired () "function to open the keyword in emacs." (interactive) (start-process "open-keyword" "*open-keyword*" (switch-to-buffer (find-file-noselect (concat hatena-group-keyword-root "/" hatena-group-keyword-default-group)))) (message "opened the buffer in dired.")) (provide 'hatena-group-keyword-mode)