#author("2019-07-06T13:50:19+00:00","","") #topicpath //////////////////////////////////////////////////////////////////////////////// * 目次 [#xdc7c37e] #contents(); //////////////////////////////////////////////////////////////////////////////// * 表示関連 [#l0e4033f] (setq frame-title-format (format "emacs@%s : %%f" (system-name))) ; タイトルバーの表示書式にファイル名を入れる //============================================================================== ** 文字色の変更 [#j1818f18] - emacs 上で指定された文字色を変更する方法について。 - magit, xcscope などのパッケージで、文字色の制御を行っているものがある。これらは端末の background color などの関係で、場合によって却って見難くなることがある。 //------------------------------------------------------------------------------ *** terinal 上で動作させる場合 [#q0925a19] - 方法1 $ cat ${HOME}/.bashrc alias emacsd='env TERM=xterm emacs --daemon' alias emacs='emacsclient -t' - 方法2 $ TERM=xterm-256color emacs -nw - 方法3 init.elに以下を追加する (defun terminal-init-gnome () "Terminal initialization function for gnome-terminal." ;; This is a dirty hack that I accidentally stumbled across: ;; initializing "rxvt" first and _then_ "xterm" seems ;; to make the colors work... although I have no idea why. (tty-run-terminal-initialization (selected-frame) "rxvt") (tty-run-terminal-initialization (selected-frame) "xterm")) - 方法4 init.elに以下を追加する (add-hook 'tty-setup-hook '(lambda () (set-terminal-parameter nil 'background-mode 'dark))) //------------------------------------------------------------------------------ *** どの変数で色定義されているかを調べる [#eefe35f4] + 対象となる文字列にカーソルを合わせた上で、以下を実行する: M-x: describe-face すると、ミニバッファに以下のように表示される: Describe face (default `cscope-file-face'): + ここで決定(return キーを押す)と、以下のように表示される: Face: cscope-file-face (sample) (customize this face) Documentation: Face used to highlight file name in the *cscope* buffer. Defined in `xcscope.el'. Family: unspecified Foundry: unspecified Width: unspecified Height: unspecified Weight: unspecified Slant: unspecified Foreground: yellow DistantForeground: unspecified Background: unspecified Underline: unspecified Overline: unspecified Strike-through: unspecified Box: unspecified Inverse: unspecified Stipple: unspecified Font: unspecified Fontset: unspecified Inherit: unspecified //------------------------------------------------------------------------------ *** 色変更の定義 [#v3047709] + 上記を元に、以下のように設定してやれば、色を変えることが出来る (set-face-foreground 'cscope-file-face "#d54e53") ; yellow → (RGB)=(0xd5,0x4e,0x53) //============================================================================== ** 色設定 [#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"' //============================================================================== ** {menu|tool}-barを消す [#y7f4f9fe] (tool-bar-mode 0) ; tool bar を表示しない (menu-bar-mode 0) ; menu bar を表示しない (which-function-mode 1) ; 現在の関数名をモードラインに表示 //============================================================================== ** 行頭に行番号を表示する(モード行ではなく) [#hd23498b] - linum-mode を使用する(Emacs23以降で有効) M-x: linum-mode - Toggle する関数 ; 行番号表示をトグル ; http://qiita.com/yyamamot/items/df430d4e725ea38ffc9f (defun toggle-linum-mode () "toggle display line number" (interactive) (setq linum-format "%4d ") (linum-mode (if linum-mode -1 1))) (global-set-key [f5] 'toggle-linum-mode) ; linum-mode - 参考:[[Emacsで行番号表示をトグルする>http://qiita.com/yyamamot/items/df430d4e725ea38ffc9f]] //============================================================================== ** モードラインに現在カーソルが位置している関数の関数名を表示する [#h095036c] - モードラインに、現在カーソルがある位置の関数名を動的に表示することが出来る。 M-x: which-function-mode - .emacs に設定するには、 (setq which-function-mode t) //////////////////////////////////////////////////////////////////////////////// * 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]] //////////////////////////////////////////////////////////////////////////////// * scroll を1行単位にする [#l150a348] (setq scroll-step 1) //////////////////////////////////////////////////////////////////////////////// * 分割した window のサイズを変える [#y029a37e] |~command |~description |~remark | |M-x: enlarge-window |縦方向にサイズを大きくする | | |M-x: shrink-window |縦方向にサイズを小さくする | | |M-x: enlarge-window-horizontally |横方向にサイズを大きくする | | |M-x: shrink-window-horizontally |横方向にサイズを小さくする | | - 参考: emacs23 では以下のように設定することで、キー割り当てが出来た (global-set-key "M-<up>" 'enlarge-window) (global-set-key "M-<down>" 'shrink-window) (global-set-key "M-<right>" 'enlarge-window-horizontally) (global-set-key "M-<left>" 'shrink-window-horizontally) //////////////////////////////////////////////////////////////////////////////// * ウインドウ自動分割時の制御 [#k8d8ac5a] - ウインドウが自動分割される際の、垂直分割・水平分割の制御 - 垂直分割を防ぐには、下記を設定する: (setq split-width-threshold nil) - 挙動としては、 ++ split-height-threshold の値が選択したウィンドウより小さい場合、下側にウィンドウを分割する。 ++ そうでない場合、 split-width-threshold がウィンドウの横幅より小さい場合は、右側に分割する。 ++ どちらも満たさず、既にウィンドウが分割されてない場合は、下側にウィンドウを分割することを試みる。 //////////////////////////////////////////////////////////////////////////////// * beep 音を消す [#oe941343] - 以下を設定することで、beep が一切無効になる (setq ring-bell-function 'ignore) ; beep を一切無効にする - 嘗ては、以下の設定でカスタマイズすることが出来たが、emacs 24.4.1 では効かないようである。 -- Visible bell にする (setq visible-bell t);; Visual Bell有効(エラー時画面反転) ;(setq visible-bell nil);; Visual Bell無効(エラー時ブザー音) -- beep を鳴らさないようにする ; (setq message-beep 'silent) //////////////////////////////////////////////////////////////////////////////// * 前のウインドウに戻る [#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> & →[[System/Process#never-kill]] //////////////////////////////////////////////////////////////////////////////// * 検索時に大文字・小文字を区別するかしないかの設定 [#case-fold-search] (setq default-case-fold-search nil) ; 大文字・小文字を区別させる(〜emacs23.1) (setq case-fold-search nil) ; 大文字・小文字を区別させる (emacs23.2〜) - emacs23.2 以降では default-case-fold-search ではなく case-fold-search を使うように推奨されている&br;(see also M-x describe-variable case-fold-search) //////////////////////////////////////////////////////////////////////////////// * ediff [#i1a8df98] //============================================================================== ** control window を別ウインドウにしないようにする [#s0475775] - X11 環境では、デフォルトではコントロールウインドウが別のウインドウとして表示される。これをコンソール内で ediff を起動したときと同様、同じウインドウ内に表示するには、以下の設定を行う: - 方法1 ++ M-x: customize-group ++ [Ediff Window Setup Function] 行頭の三角をクリックし、詳細を表示する ++ [Value Menu] をクリックし、プルダウンから [Single Frame] を選択 ++ バッファ先頭付近の [Apply and Save] をクリックして設定・保存する - 方法2:以下を設定する: ;; コントロール用のバッファを同一フレーム内に表示 (setq ediff-window-setup-function 'ediff-setup-windows-plain) ;; diffのバッファを上下ではなく左右に並べる (setq ediff-split-window-function 'split-window-horizontally) (provide 'ediff.conf) //------------------------------------------------------------------------------ *** 参考リンク [#qd6e9c5e] - [[同一フレーム内にediffのコントロールバッファを表示>https://yamadawindsurf.blogspot.com/2016/07/ediff.html]] //////////////////////////////////////////////////////////////////////////////// * カレンダーで日本の祝日を表示する [#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 //////////////////////////////////////////////////////////////////////////////// * gdb-mode [#gdb-mode] - 設定(${HOME}/.emacs.d/site-lisp/gdb.conf.el) ;; http://d.hatena.ne.jp/kobapan/20090506/1241593531 ;;; GDB 関連 ;;; 有用なバッファを開くモード (setq gdb-many-windows t) ;;; 変数の上にマウスカーソルを置くと値を表示 (add-hook 'gdb-mode-hook '(lambda () (gud-tooltip-mode t))) ;;; I/O バッファを表示 (setq gdb-use-separate-io-buffer t) ;;; t にすると mini buffer に値が表示される (setq gud-tooltip-echo-area nil) - gdb-mode のコマンド |~bindings |~description |~remark | |C-x C-a C-t |ソースコードの現在のカーソル位置に break point を設定する | | |C-h m |EmacsのGDBモードの機能に関する説明を表示 | | |M-s |Step実行。関数なら入って止まる | | |C-x C-a C-s |~|~| |M-n |GDBのnextコマンドのように、 関数呼び出しをすべてスキップして、 現在の関数内の次のソース行まで実行 | | |C-x C-a C-s |~|~| |M-i |GDBのstepiコマンドのように、 1命令を実行 | | |C-x C-a C-i |~|~| |M-x gdb-nexti |GDBのnextiコマンドを使って、 次の命令まで実行 | | |C-c C-f |GDBのfinishコマンドのように、 選択されたスタック・フレームを終了するまで実行を継続 | | |M-c |GDBのcontinueコマンドのように、 ユーザ・プログラムの実行を継続 | | |M-u |GDBのupコマンドのように、 数値引数によって示される数だけ上位のフレームに移動 | | |M-d |GDBのdownコマンドのように、 数値引数によって示される数だけ下位のフレームに移動 | | |C-x & |カーソルの位置にある数値を読み取り、 GDBのI/Oバッファの末尾に挿入 | | |C-x C-a C-r |次の break point まで実行 | | |C-x C-a C-f |現在のカーソル位置まで実行 | | //////////////////////////////////////////////////////////////////////////////// * helm [#lc217352] ** 入手先 [#s31bbdeb] - [[GitHub: emacs-helm/helm>https://github.com/emacs-helm/helm]] ** 参考リンク [#g7fffd17] - [[初心者〜初級者のためのEmacs-Helm事始め : 前編>https://qiita.com/jabberwocky0139/items/86df1d3108e147c69e2c]] - [[【Emacs】helmを使う>https://www.yokoweb.net/2017/01/20/emacs-helm-mode/]] //////////////////////////////////////////////////////////////////////////////// * 多言語入力 [#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] - uim 環境下で ''setxkbmap cz'' として使用した場合 -- 数字キー(≠テンキー)でチャールカ付き・ハーチェク付き文字の幾つかが打てる。 -- "Ctrl(+Shift)+文字" では、チャールカ付き・ハーチェク付き文字を打つことが出来ない。 |~Character |~Key binding | |ě |2 | |š |3 | |č |4 | |ř |5 | |ž |6 | |ý |7 | |á |8 | |í |9 | |é |0 | |ů |+ | -- それぞれ、CAPS LOCK した状態で打つと大文字の入力となる。 - 以下は "setxkbmap cz" を ''しない''状態での説明。 ++ M-x set-input-method czech ++ type following keybind |~Character |~Key binding | |č |+ c | |Č |+ C | |ď |+ d | |Ď |+ D | |ě |+ e | |Ě |+ E | |ň |+ n | |Ň |+ N | |ř |+ r | |Ř |+ R | |š |+ s | |Š |+ S | |ť |+ t | |Ť |+ T | |á |= a | |Á |= A | |é |= e | |É |= E | |í |= i | |Í |= I | |ó |= o | |Ó |= O | |ů |+ | |Ů | ~ U| |ú |= u| |Ú |= U| |ý |= y| |Ý |= y| //////////////////////////////////////////////////////////////////////////////// * 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 |カーソルの後ろのタグを消す | | //////////////////////////////////////////////////////////////////////////////// * 参考リンク [#links] - [[るびきち「日刊Emacs」>http://rubikitch.com/]] - [[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]]