#topicpath //////////////////////////////////////////////////////////////////////////////// * 目次 [#xdc7c37e] #contents(); * Links [#u98e735b] - [[Programming in Emacs Lisp [ja]>http://www.math.s.chiba-u.ac.jp/~matsu/lisp/emacs-lisp-intro-jp.html]] - [[Meadow/Emacs memo>http://www.bookshelf.jp/soft/meadow.html#SEC_Top]] - [[Emacs 活用法>http://www.math.s.chiba-u.ac.jp/~matsu/emacs/emacs21/index.html]] - [[navi.el(関数の一覧表示とジャンプ)>http://www.ne.jp/asahi/love/suna/pub/soft/navi.el/index.html]] -- fume-mode.el は XEmacsでしか使えないが、これはemacsで使える。 - [[Emacs Lispまとめ>http://matome.replore.com/index.php?title=Emacs_Lisp%E3%81%BE%E3%81%A8%E3%82%81]] - [[CEDET>http://sourceforge.jp/projects/sfnet_cedet/]] -- [[Undo-tree.el>http://www.emacswiki.org/emacs/UndoTree]] //////////////////////////////////////////////////////////////////////////////// * emacs / XEmacs 共通 [#r71ffd67] //------------------------------------------------------------------------------ ** 表示関連 [#l0e4033f] (setq frame-title-format (format "emacs@%s : %%f" (system-name))) ; タイトルバーの表示書式にファイル名を入れる //------------------------------------------------------------------------------ ** Time-stamp [#m59e6eee] ; Time-stamp ; http://homepage.mac.com/zenitani/elisp-j.html#time-stamp (require 'time-stamp) (setq time-stamp-start "Last updated: <") ; 開始文字列の設定。通常は "Time-stamp: <>" ;; 日本語で日付を入れたくないのでlocaleをCにする (defun time-stamp-with-locale-c () (let ((system-time-locale "C")) (time-stamp) nil)) (if (not (memq 'time-stamp-with-locale-c write-file-hooks)) (add-hook 'write-file-hooks 'time-stamp-with-locale-c)) ; (setq time-stamp-format "%3a %3b %02d %02H:%02M:%02S %Z %:y") (setq time-stamp-format "%04y/%02m/%02d %02H:%02M:%02S %Z") ; YYYY/MM/DD HH:MM:SS JST //------------------------------------------------------------------------------ ** 文字数を数える [#t87cae47] - 対象領域を選択し、 M-x: count-lines-region または M-= とする。 - 行数と文字数が表示される。文字数は、全角も半角もそれぞれ1文字として扱われる。 //------------------------------------------------------------------------------ ** isearch で、カーソルの位置にある単語を検索対象にする [#t5442189] - isearch時に、 C-w と打てばOK //------------------------------------------------------------------------------ ** shell-mode で制御文字を処理する [#s805f2e5] ; shell-mode で制御文字を処理する。 (autoload 'ansi-color-for-comint-mode-on "ansi-color" "Set `ansi-color-for-comint-mode' to t." t) (add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on) //------------------------------------------------------------------------------ ** ファイルを read-only で開く [#sd5faa53] C-x C-r //------------------------------------------------------------------------------ ** バックアップファイルを作らないようにする [#d7ff8fd4] (setq make-backup-files nil) ; *.~ とかのバックアップファイルを作らない (setq auto-save-default nil) ; .#* とかのバックアップファイルを作らない //------------------------------------------------------------------------------ ** 選択領域を [DEL] で一気に消せるようにする [#y95ca8b8] ; (setq delete-selection-mode t) (delete-selection-mode) //------------------------------------------------------------------------------ ** HTML文書編集での自動補完 [#d02f9e86] - yahtmlを使う(yahtmlは、YaTeXに付属しているもの)。 - [[参考リンク>http://www.namazu.org/~tsuchiya/elisp/yahtml-mode.html]] //------------------------------------------------------------------------------ ** 色設定 [#uf6d738d] - ${HOME}/.bashrc での、emacs/XEmacs の色設定 alias emacsk='emacs -bg "#303030" -fg white' alias emacsb='emacs -bg azure' alias emacsy='emacs -bg lightyellow' alias emacsg='emacs -bg "#e0ffe0"' alias emacsr='emacs -bg "#fff5f5"' alias xemacs='/usr/bin/xemacs21' alias xemacsb='xemacs -bg azure' alias xemacsy='xemacs -bg lightyellow' alias xemacsg='xemacs -bg "#e0ffe0"' alias xemacsr='xemacs -bg "#fff5f5"' //////////////////////////////////////////////////////////////////////////////// * emacs only [#f05f3f8e] //------------------------------------------------------------------------------ ** {menu|tool}-barを消す [#y7f4f9fe] (tool-bar-mode 0) ; tool bar を表示しない (menu-bar-mode 0) ; menu bar を表示しない (which-function-mode 1) ; 現在の関数名をモードラインに表示 //------------------------------------------------------------------------------ ** 前のウインドウに戻る [#ia6f365e] ; XEmacsにはあるが、emacsにはない(!) ; http://matome.replore.com/index.php?title=Emacs_Lisp%E3%81%BE%E3%81%A8%E3%82%81 ; xemacsに合わせて、関数名を backward-other-window に変更。 ; (defun other-window-backward (&optional n) (defun backward-other-window (&optional n) "Select nth previous window." (interactive "P") (other-window (- (prefix-numeric-value n)))) //------------------------------------------------------------------------------ ** 起動済みのemacs にファイルを渡す (emacsclient) [#ob79c7cd] - emacs起動時に、emacs-serverが起動するようにしておく必要がある。 -- .emacs に以下の行がなければ追記する: (server-start) - 起動済みのemacsに、コマンドラインからファイルを渡す方法 $ emacsclient <file-name> & -- ファイルを送っただけのようで、実際には送り先のemacsとは別プロセスとして稼働するらしい。 '&' を付けないと、コマンドを打った端末のフォアグラウンドジョブになってしまう。 -- 上記コマンドを打った端末を終了すると、送り先のemacsからも、送られたファイルのエントリが消えてしまうので注意すること。 -- どうしてもemacsclientを起動した端末が死んでも構わないようにしたいなら、nohupコマンドから起動すればよい。 $ nohup emacslient <file-name> & →[[Process#never-kill]] //------------------------------------------------------------------------------ ** カレンダーで日本の祝日を表示する [#u4db1263] - M-x: calendar で表示するカレンダーで日本の祝日を表示する方法。 - japanese-holidays.el を入手する -- 入手先: https://github.com/emacs-jp/japanese-holidays/blob/master/japanese-holidays.el - 設定 -- 参考: http://blog.livedoor.jp/tek_nishi/archives/3027665.html - enmacs 起動時に cl-lib が見つからないと怒られた場合 -- cl-lib.el を入手し、load-path の通っているところに配置する。ちなみに Debian7 では相当するファイルはリポジトリにない模様。自分で取ってきて仕込むこと。 -- 入手先: http://elpa.gnu.org/packages/cl-lib.html //============================================================================== ** gtags / global の利用 [#global] - タグシステムの一つ - debian では、 global パッケージに入っている //------------------------------------------------------------------------------ *** tag の生成 [#g0b7236d] $ gtags [options] [path] $ gtags -f <files> - gtags には、etags と違って append mode が存在しないため、xargs でマルチスレッド化して実行するのは不可かもしれない。 - tag の生成処理が終わると、実行したディレクトリ配下に、下記4つのファイルが作られる: GPATH GTAGS GRTAGS GSYMS //------------------------------------------------------------------------------ *** emacs の設定 [#m88404b9] -- gtags.el を入手する --- ディストリビューションによっては、下記のようなパスにインストールされる場合もある /usr/share/emacs/site-lisp/global/gtags.el --- もしディストリビューションで用意されていない場合は、手動で取得し、library-path の通っている場所に配置する。 //------------------------------------------------------------------------------ *** 参考リンク [#a32e22f8] - [[GNU GLOBAL(gtags)>http://cha.la.coocan.jp/doc/gnu_global.html]] - [[新機能の御紹介>http://www.tamacom.com/handbook/new.html]] //============================================================================== ** etags (ctags for Emacs)の利用 [#etags] //------------------------------------------------------------------------------ *** tag の生成 [#u1d75162] - まずは、 Tag file を生成する。emacs パッケージには etags.emacs** なコマンドが付属している場合があるので、それがあればそちらを使う。 - Tag file は TAGS というファイル名で生成される。 $ etags.emacs23 `find | grep -i "\.c$\|\.cc\|\.cpp$\|\.cxx$\|\.h$" - ただ、ファイル数が多い場合にはコマンドラインバッファの上限を超えてしまい、全てのファイルを処理できないことが予想される。この問題は xargs を使って解消することが出来る。~ 以下に、そのためのスクリプトを示す。~ 下記の例では、 xargs の -P オプションも併用し、マルチスレッドで動作するようにしている。 THREAD_NUM は CPUの数もしくは Core 数に合わせる。 #!/bin/bash TAGS_FILE=TAGS CMD_ETAGS=etags.emacs23 THREAD_NUM=4 rm -f ${TAGS_FILE}; find | grep -i "\.c$\|\.cc\|\.cpp$\|\.cxx$\|\.h$" | xargs -P ${THREAD_NUM} -I {} ${CMD_ETAGS} -a {} # 対象となるソース・ヘッダを etags に引数で渡す -- 全てのファイルを渡すのにコマンドバッファが足りなくなってしまう場合(=ファイル数が多い場合や個々のパス名が長い場合など)でも全てのファイルを渡せるよう、xargs を使って etags にファイル名を渡すようにしている。 -- コマンドバファが足りなくなった場合、 xargs は複数回 etags を呼ぶ。この場合、 etags が append モードで動作しないと etags は呼ばれる度に TAGS ファイルを上書きしてしまうので注意すること(そのため上記では append モードにするため "-a" を付けて etags を呼んでいる)。 //------------------------------------------------------------------------------ *** emacs に TAGS ファイルを読みこませる [#m5a7e186] M-x: tags-reset-tags-tables 一旦リセットする M-x: visit-tags-table 明示的に TAGS ファイルを読み込む - emcs から操作する(下記) |~Key binding |~command |~description | |M-. |find-tag |クラスや関数を探す | |C-u M-. | |次の検索結果候補を表示する | |C-u – M-. | |前の検索結果候補を表示する | |M-* | |元の場所に戻る | |C-x 4 . |find-tag-other-window | タグ(名前)の定義箇所を探し別ウィンドウに表示 | |C-x 5 . |find-tag-other-frame | タグ(名前)の定義箇所を探し別フレームに表示 | //============================================================================== ** ctags-exuberant [#sbd4004f] - install 後、実行ファイルは /usr/bin/ctags-exuberant に配置される。システムによっては /usr/bin/ctags に symlink されることもある。 //------------------------------------------------------------------------------ *** TAGS file の生成 [#oca9c6d9] $ ctags-exuberant -e -R [path] - emacs からの使い方は、etags と基本的に同じ //------------------------------------------------------------------------------ *** emacs から TAGS の生成を行えるようにする [#a7b3409c] - ${HOME}/.emacs に下記の行を追加する: (setq path-to-ctags "/usr/bin/ctags-exuberant") ;; <- your ctags path here (defun create-tags (dir-name) "Create tags file." (interactive "DDirectory: ") (shell-command (format "ctags -f %s -e -R %s" path-to-ctags (directory-file-name dir-name))) ) - TAGS の生成を実行 M-x: create-tags //------------------------------------------------------------------------------ *** 参考リンク [#l7a6e3a8] - [[BuildTags>http://www.emacswiki.org/emacs/BuildTags]] - [[EmacsTags>http://www.emacswiki.org/emacs/EmacsTags]] //============================================================================== ** ebrowse (ebrowse for Emacs)の利用 [#ebrowse] - etags/ctags 同様、C++ のコードから class のデータベースを作成し、それを emacs で読み込み、class 定義などに Jump 出来るというもの。 - まずは、 BROWSE file を生成する $ cd ${PROGRAM_TOP_DIR} $ find | grep "C$\|h$" | xargs ebrowse -f # 対象となるソース・ヘッダを ebrowse に渡す - emacs に BROWSE ファイルを読みこませる C-x C-f: ${PROGRAM_TOP_DIR}/BROWSE - emacs から操作する |~Key binding |~command |~description | |return |ebrowse-find-class-declaration| 当該の class 定義に Jump | |C-x 4 . |find-tag-other-window |- | |C-x 5 . |find-tag-other-frame | - | //------------------------------------------------------------------------------- *** Links [#scc713f1] - [[A Class Browser for C++>http://www.sunsite.ualberta.ca/Documentation/Gnu/emacs-21.1/html_chapter/ebrowse.html]] //============================================================================== ** モードラインに現在カーソルが位置している関数の関数名を表示する [#h095036c] - モードラインに、現在カーソルがある位置の関数名を動的に表示することが出来る。 M-x: which-function-mode - .emacs に設定するには、 (setq which-function-mode t) //////////////////////////////////////////////////////////////////////////////// * XEmacs only [#g1765dad] //------------------------------------------------------------------------------ ** fume-mode [#n684f157] ;========================================================= ; fume-mode (XEmacs only) (defun function-menu-mode() (interactive) (fume-mode t) (fume-add-menubar-entry t)) ; モード行に現在カーソルがある関数の名前を表示 (global-set-key "\C-\M-l" 'function-menu-mode) ; function-menu-mode に入る //------------------------------------------------------------------------------ ** using Unicode [#u5f8b4cd] emacsでは使えるのに、何故かXEmacsのdefaultでは使えないUnicode. 使えるようにするには、以下をinit.elに追記する: (require 'un-define) (unless (emacs-version>= 21 5 6) (require 'mule-ucs-unicode "unicode")) (set-coding-category-system 'utf-8 'utf-8) (set-coding-priority-list '(utf-8)) (load "term/keyswap") (global-set-key [backspace] 'backward-delete-char) (keyboard-translate ?\C-h 'backspace) (global-set-key [delete] 'delete-char) //------------------------------------------------------------------------------ ** ホイールマウスのスクロールを有効にする [#a470e136] (autoload 'mwheel-install "mwheel" "Enabal mouse wheel support.") (mwheel-install) //////////////////////////////////////////////////////////////////////////////// * 多言語入力 [#we290545] //------------------------------------------------------------------------------ ** ドイツ語 [#g9ed5823] + M-x set-input-method german + ウムラウトは以下のキー入力にて。ちなみに z と y が入れ替わるので、慣れてない人は注意! |~Character |~Key binding | |ä |C-x 8 " a | |ü |C-x 8 " u | |ö |C-x 8 " o | //------------------------------------------------------------------------------ ** チェコ語 [#f2ed01e8] + M-x set-input-method czech |~Character |~Key binding | |č |+ c | |Č |+ C | |ě |+ e | |Ě |+ E | |ř |+ r | |Ř |+ R | |ň |+ n | |Ň |+ N | |ď |+ d | |Ď |+ D | |ť |+ t | |Ť |+ T | |á |= a | |Á |= A | |é |= e | |É |= E | |í |= i | |Í |= I | |ó |= o | |Ó |= O | |ů |+ | |Ů | ~ U | |ú |- u | |Ú |- U | //////////////////////////////////////////////////////////////////////////////// * html-mode [#n74258af] ** キーバインド [#c69b3536] |~key |~command |~description |~remark | |C-c C-j |html-line |改行+ <br>挿入 | | |C-c C-h |html-paragraph | <p> 挿入 | | |C-c C-a |sgml-attributes | | | |C-c C-b |sgml-skip-tag-backward |一つ前の開始タグまで戻る(?)| | |C-c C-d |delete-tag |タグ単位で消す | | |C-c C-f |sgml-skip-tag-foward |1つ先の終了タグまで飛ぶ(?) | | |C-c / |sgml-close-tag |終了タグを挿入する | | |C-c <1-6>|html-headline-<1-6> |h1-h6 の開始・終了タグを挿入する | | |C-c C-c -|html-horizontal-rule |<hr> タグを挿入する | | |C-c C-c c|html-checkboxes |'<input type="checkbox" name="' を挿入する | | |C-c C-c h|html-href-ancor |'<a href="' を挿入する | | |C-c C-c i|html-image |対話的に img タグを挿入する | | |C-c C-c n|html-name-anchor |'<a name="' を挿入する | | |C-c C-c o|html-ordered-list |番号リストの開始タグを挿入する | | |C-c C-c r|html-radio-button |ラジオボタンを挿入する | | |C-c C-c u|html-unordered-list |番号なしリストの開始タグを挿入する | | |C-c DEL |sgml-delete-tag |カーソルの後ろのタグを消す | |