LoginSignup
18
6

More than 5 years have passed since last update.

カーソルを変更する

Last updated at Posted at 2018-12-06

メリークリスマス! Emacsのカーソルは好きですか? 私は慣れました。

あるWindowsのテキストエディタでは、このように3種類の設定ができます。Emacsではどうすればできるでしょうか。

スクリーンショット 2018-12-04 20.38.45.png
スクリーンショット 2018-12-04 20.39.13.png
スクリーンショット 2018-12-04 20.39.31.png

設定方法

init.elではdefault-frame-alistに設定するのが簡単です。この変数はフレーム(一般的なGUIの用語における「ウィンドウ」)の初期化時のプロパティを設定できます。

(add-to-list 'default-frame-alist '(cursor-type . bar))

この設定が動作することは新しいフレームを作成(M-x make-frame)したときに確認できます。

emacs-changes-cursor.gif

簡単な確認方法

*scratch*バッファに貼り付けて以下一行づつC-x C-eで実行してみるのがよいです。

(set-frame-parameter (window-frame) 'cursor-type 'box)
(set-frame-parameter (window-frame) 'cursor-type 'bar)
(set-frame-parameter (window-frame) 'cursor-type 'hbar)
(set-frame-parameter (window-frame) 'cursor-type '(hbar . 10))
(set-frame-parameter (window-frame) 'cursor-type 'hollow)
(set-frame-parameter (window-frame) 'cursor-type nil)

emacs-changes-cursor2.gif

設定ファイルに書くときはset-frame-parameterよりも、先に書いた(add-to-list 'default-frame-alist ...)の方がおすすめです。

文字の左に縦棒

スクリーンショット 2018-12-06 22.37.25.png

(add-to-list 'default-frame-alist '(cursor-type . bar))

文字に下線

スクリーンショット 2018-12-06 22.38.09.png

(add-to-list 'default-frame-alist '(cursor-type . hbar))

文字の下部にブロック

スクリーンショット 2018-12-06 22.39.40.png

この設定には数字をそのまま書かなくてはいけません。好きな数字を入れてください。画像は概ねフォントサイズの半分程度です。

(add-to-list 'default-frame-alist '(cursor-type . (hbar . 10))

ボックス(デフォルト)

スクリーンショット 2018-12-06 22.58.13.png

(add-to-list 'default-frame-alist '(cursor-type . box))

hollow(枠線)

(add-to-list 'default-frame-alist '(cursor-type . hollow))

スクリーンショット 2018-12-06 23.55.36.png

おまけ1: カーソルを点滅しなくするようにするには?

(blink-cursor-mode -1)

おまけ2: 端末でカーソルを変更するには?

実はVT100にはDECSCUSR—Set Cursor Styleなる制御シーケンスがあり、さらにTeraTermやiTerm2などでは独自拡張して縦棒のカーソルも表示できるようになってます。vim からの制御シーケンスの使用例なども紹介されてるので、なんかいい感じにすれば(Emacs本体に手を入れれば)カーソル変更できるんじゃないですかね。私は調べてないです。

18
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
6