Emacsでsimplenote-modeを使ってみる。

| コメント(0) | トラックバック(0)
最近スマートフォンの性能が上がって、ほとんどPCを開かなくても済むようになった。そうなっていくとスマートフォンとの相性がいいサービスばかり利用するようになってくる。

DropboxやEvernoteはもちろん使っているが、スマートフォンではどちらも扱いたいデータをダウンロードしてから編集するとプロセスを踏むので、気軽に編集、更新という使い方はしにくかった。

気軽にテキストデータだけを扱い、Emacsから扱えるサービスを探していたのだが、simplenoteというテキスト情報のみを扱うクラウド的なサービスがあったので使ってみた。

simplenote

simplenote.el

まだ書きかけの文章やプログラムのコードの一部などを書きためておいて、ある程度完成したらEvernoteなどに保存している。

色々なメモをEmacsからsimplenoteに直接書き込め、それがPCやスマートフォンからも簡単に閲覧、編集、同期ができるということでしばらく使ってみたのだが、simplenoteのサーバーと手動で同期しないといけないので、それを忘れてしまうと意味が無い。

やはりDropboxのように同期することを意識しないでできるようでないと。

そこで、simplenoteでメモをとっているときに、bufferをsaveしたらsimplenoteのサーバーと同期するようにしてみた。

大まかな処理の流れはこんな感じ。

(defun simplenote-sync-after-save ()
  "If there is the buffer on simplenote-directory, sync the buffer to simplenote."
  (interactive)
  (when (simplenoteを使っている時)
    (simplenoteの同期処理)
    その他の処理...
    ))

通常simplenote-modeでsimplenote上のノートを扱っているときは、simplenote-directory/notes/以下にbufferを作成し、それを編集している。

simplenoteとの同期はsimplenoteのbufferを扱っているときのみ同期して欲しいので、それを判断する条件として現在のディレクトリがsimplenote-directory(初期設定値は "~/.simplenote")にマッチするかどうかで判断することにする。

(string-match simplenote-directory default-directory)

また、simplenoteの同期処理は(simplenote-sync-notes)なので、上記を踏まえてlispで書くとこうなる。

(defun simplenote-sync-after-save ()
  "If there is the buffer on simplenote-directory, sync the buffer to simplenote."
  (interactive)
  (when (simplenoteを使っている時)
    (simplenoteの同期処理)
    その他の処理...
    ))

ちなみに新しくノートを作ったときは、"note-[0-9]+"という名前のbufferをsimplenote-directory/new/以下につくる仕様になっている。このままだとsaveする度に新しいノートを追加してしまうので、その時は同期したあとにbufferを消去して、simplenote-browseを呼び出すようにする。

simplenoteの新規ノートのディレクトリの変数を定義して

(let (simplenote-new-note-dir)
  (setq simplenote-new-note-dir (concat (file-name-as-directory simplenote-directory) "new")))
--> 初期設定値では"~/.simplenote/new"

現在のディレクトリが新規ノートのディレクトリにマッチするかどうかを判断して、マッチする場合はbufferを消去後、simplenote-browseを呼び出す。

(when (string-match simplenote-new-note-dir default-directory)
  (kill-buffer (get-buffer (current-buffer)))
  (simplenote-browse))

最終的にはこのように。

(defun simplenote-sync-after-save ()
  "If there is the buffer on simplenote-directory, sync the buffer to simplenote."
  (interactive)
  (when (string-match simplenote-directory default-directory)
      (simplenote-sync-notes)
      (let (simplenote-new-note-dir)
        (setq simplenote-new-note-dir (concat (file-name-as-directory simplenote-directory) "new"))
        (when (string-match simplenote-new-note-dir default-directory)
          (kill-buffer (get-buffer (current-buffer)))
          (simplenote-browse)))))

あとはafter-save-hookに引っ掛けてしまえば、完成。
(add-hook 'after-save-hook 'simplenote-sync-after-save)

これでsimplenoteのサーバーと同期することを意識しないでメモをどんどん取っていける環境ができた。

トラックバック(0)

トラックバックURL: http://blog.on-net.jp/mt/mt-tb.cgi/37

コメントする

2011年2月

    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28          

カテゴリ

アーカイブ