「Emacs」カテゴリーアーカイブ

Emacsでカーソル位置の文字コードを表示する

C-x = (M-x what-cursor-position)

ミニバッファに、カーソル位置の文字のUnicodeにおけるコードポイントが表示される。
例えば、Shift_JISのファイルの「あ」という文字にカーソルを置いて、C-x = すると、ミニバッファに以下が表示される。

Char: あ (12354, #o30102, #x3042, file ...) point=1 of 2 (0%) column=0

12354, #o30102, #x3042 の部分が、「あ」のUnicodeにおけるコードポイントの10進数、8進数、16進数表記となる。

C-u C-x = (M-x describe-char)

カーソル位置の文字の詳細情報を分割ウィンドウに表示する。
例えば、Shift_JISのファイルの「あ」という文字にカーソルを置いて、C-u C-x = すると、分割ウィンドウに以下が表示される。

             position: 1 of 2 (0%), column: 0
            character: あ (displayed as あ) (codepoint 12354, #o30102, #x3042)
    preferred charset: japanese-jisx0208 (JISX0208.1983/1990 Japanese Kanji: ISO-IR-87)
code point in charset: 0x2422
               script: kana
               syntax: w  which means: word
             category: .:Base, H:2-byte Hiragana, L:Left-to-right (strong), c:Chinese, h:Korean, j:\
Japanese, |:line breakable
             to input: type "C-x 8 RET 3042" or "C-x 8 RET HIRAGANA LETTER A"
          buffer code: #xE3 #x81 #x82
            file code: #x82 #xA0 (encoded by coding system japanese-shift-jis-dos)
              display: terminal code #xE3 #x81 #x82
  • code point in charset: 0x2422 が、文字集合JISX0208における「あ」のコードポイント、
  • buffer code: #xE3 #x81 #x82 が、バッファ(UTF-8)でのエンコーディング、
  • file code: #x82 #xA0 が、ファイル(Shift_JIS)でのエンコーディング

を表している。

Ubuntu(14.04 LTS)のEmacsでC-M-sが効かない

Ubuntu(14.04 LTS)のEmacsで、C-M-s(デフォルトではisearch-forward-regexp、ぼくはvisual-regexp、visual-regexp-steroidsのvr/isearch-forwardに割り当てている)を押しても効かない。代わりにウィンドウが隠れてしまう。

原因は、Ubuntuのキーボードショートカットで、Ctrl+Alt+Sがウィンドウのシェードの状態の切り替えに割り当てられているためだった。

toggle_shared_state

解決方法

「システム設定」> 「キーボード」の「ショートカット」タブで、「ウィンドウ」の「シェードの状態の切り替え」を無効にするか別のキーボードショートカットを割り当てる。

MacのターミナルでのEmacsのメタキー

MacのターミナルでEmacsを使う場合に、デフォルトだとメタキーとしてエスケープキーしか使えないので不便だったが、ターミナルの環境設定→キーボードで、「メタキーとして option キーを使用」にチェックを入れると、optionキーをメタキーとして使用できた。
[mac][emacs] Terminal上でemacsのメタキーを使う方法 - goinger的日記

制御文字の入力方法

Emacs

C-q 制御文字

例: エスケープ文字を入力

C-q C-[

シェル、vim

Ctrl+V 制御文字

例: エスケープ文字を入力

Ctrl+V Ctrl+[

コントロールキーと同時に押す文字は?

上記で「制御文字」と記載しているところは、Ctrl+(コントロールキーと同時に押す)で送出するが、この時のコントロールキーと同時に押す文字は、入力したい制御文字の7ビット目に1をセット、つまり0x40(64)を足した文字である。
man ascii 等でASCII文字の一覧を表示して探す。

例:
エスケープ文字は0x1B(27)
7ビット目に1をセットする=0x40(64)を足すと0x5B(91)
0x5B(91)は[
よってエスケープ文字を送出するにはCtrl+[

改行は0x0A(10)
7ビット目に1をセットする=0x40(64)を足すと0x4A(74)
0x4A(74)はJ
よって改行を送出するにはCtrl+J

https://ja.wikipedia.org/wiki/ASCII#ASCII.E5.8D.B0.E5.AD.97.E5.8F.AF.E8.83.BD.E6.96.87.E5.AD.97

なお、印字可能文字のうち「@」から始まる32文字については、ASCII値を64減じて対応する制御文字を求め、この制御文字を「コントロール+」(英: control+)という前置表現を付けた印字可能文字で表記する慣習がある。

例:BELコード(07) →「コントロール+G」(受信した側の機器で注意喚起音が鳴る)

この制御文字の表記方法は、キーボード上の印字可能文字キーを制御文字の送出に用いていた機器の名残りであると考えられる(7ビット目を0にセットする専用キー(Ctrlキー)を、印字可能文字キーと同時に押して制御文字を送出)。

エスケープ文字の入力方法 - nelnalog.note

emacsにナビゲーションペインを追加する「emacs-nav」

emacs-nav - Google Code
emacsにファイル・フォルダブラウズするペインを追加する。
使い方(nav.elのコメントから抜粋)

;; To use this file, put something like the following in your
;; ~/.emacs:
;;
;; (add-to-list 'load-path "/directory/containing/nav/")
;; (require 'nav)
;;
;; Type M-x nav to open the navigation window. It should show up as a
;; 30-character wide column on the left, showing the contents of the
;; current directory. If there are multiple windows open, all but one
;; will be closed to make sure the nav window shows up correctly.
;;; Key Bindings
;;
;;   Enter/Return: Open file or directory under cursor.
;;
;;   1: Open file under cursor in 1st other window.
;;   2: Open file under cursor in 2nd other window.
;;
;;   c: Copy file or directory under cursor.
;;   d: Delete file or directory under cursor (asks to confirm first).
;;   e: Edit current directory in dired.
;;   f: Recursively find files whose names or contents match some regexp.
;;   g: Recursively grep for some regexp.
;;   j: Jump to another directory.
;;   m: Move or rename file or directory.
;;   n: Make new directory.
;;   p: Pop directory stack to go back to the directory where you just were.
;;   q: Quit nav.
;;   r: Refresh.
;;   s: Start a shell in an emacs window in the current directory.
;;   t: Start a terminal in an emacs window in the current directory.
;;      This allows programs like vi and less to run. Exit with C-d C-d.
;;   u: Go up to parent directory.
;;   !: Run shell command.
;;   [: Rotate non-nav windows counter clockwise.
;;   ]: Rotate non-nav windows clockwise.
;;
;;   :: Go into debug mode (should only be needed if you are hacking nav.el).

C(Control)-スペースで Spotlight が起動されてしまう

osxでemacsを使用するとき、C(Control)-スペースで Spotlight が起動されてしまう。これを回避するには、「システム環境設定--キーボードとマウス--キーボードショートカット」で、「Spotlight検索フィールドを表示する」と「Spotlightウインドウを表示する」を、適当な別のショートカットに変更すればよいい。(USキーボードなら"Control `" と "Option Control `"など)
Mac OS X Tiger, X11-Emacs 22.0.50

emacs で PHP-modeを使う

SourceForge.net: PHP mode for Emacsからphp-modeをダウンロードして、emacsのsite-lispディレクトリにphp-mode.elをコピーする。
・.emacs.elに以下を追加。

(load-library "php-mode")
(require 'php-mode)
(add-hook 'php-mode-user-hook
'(lambda ()
(setq tab-width 2)
(setq indent-tabs-mode nil))
)

PHPプロ!TIPS
閑古鳥 -> 呟き -> emacs で PHP-mode と mmm-mode を使う