org-mode をマイナーモードとして使う orgstruct-mode。
CSS を書くときに、より楽なコーディングが出来るように org-mode を使う事を考えていたのですが、メジャーモードを切り替えるのは、ちょっと非効率なのでマイナーモードとして利用できないか調べてみると、やっぱり標準でありました。
試してみるには、M-x orgstruct-mode で。
(add-hook 'css-mode-hook 'turn-on-orgstruct)
の様に、mode-hook として使えばいい。
この画像は、全部 css-mode を利用していて、コメントに * で始まる見出しを付けておいて、カーソルのある行以外を折り畳んだ状態。
機能のとしては、* や - で始まる行のキーバインドを org-mode のそれと置き代えるみたい。
ちなみに、describe-bindings してみても orgstruct-hijacker-command-11 しか表示されないので、org-mode のキーバインドを覚えておかなけばならない。
自分で、キーバインドを追加したい場合は、orgstruct-make-binding という関数が用意されているので、これを使って追加する。
(orgstruct-make-binding fun n &rest keys) Create a function for binding in the structure minor mode. fun is the command to call inside a table. n is used to create a unique command name. keys are keys that should be checked in for a command to execute outside of tables.
というわけで、以前、org-mode に追加した、C-up or C-down で * で始まる行へ移動するキーバインドを追加する場合は、
(org-defkey orgstruct-mode-map [(C-up)] (orgstruct-make-binding 'outline-previous-visible-heading 1001 [(C-up)])) (org-defkey orgstruct-mode-map [(C-down)] (orgstruct-make-binding 'outline-next-visible-heading 1002 [(C-down)]))
という感じで追加できます。