macOS Ventura 上でemcasをインストールする
はじめに_
homebrewをインストール済みとする。
テキストエディタ(エディタ)_
- text editor, in "Dictionary of Computing 5th edition," p. 532, Oxford University Press, 2004.
A program used specifically for entry and modification of data that is in a textual format. Such data may be a program written in a high-level language, a report or book written in a natural language, or numerical input for, say, a statistical program.
- IT用語辞典 e-words:テキストエディタ 【text editor】
http://e-words.jp/w/E38386E382ADE382B9E38388E382A8E38387E382A3E382BF.html
- Wekipedia.ja: テキストエディタ
- word processing, in "Dictionary of Computing 5th edition," p. 577, Oxford University Press, 2004.
A facility that enables users to compose documents using a computer with facilities to edit, re-format, store, and print documents with maximum flexibility. A typical word-processing system consists of a personal computer running a word-processing program, and an associated printer, such as an inkjet printer, capable of producing high-quality output of many different text fonts as well as diagrams and pictures.
- IT用語辞典 e-words:ワープロソフト 【word processor software】
http://e-words.jp/w/E383AFE383BCE38397E383ADE382BDE38395E38388.html
- Wekipedia.ja: ワードプロセッサ
http://ja.wikipedia.org/wiki/%E3%83%AF%E3%83%BC%E3%83%97%E3%83%AD
以上、いくつかの定義を紹介したがこれからわかる通り、エディタとワードプロセッサは違うものである。
エディタとはテキスト(普通の文字)を入力するためのソフトであり、乱暴な言い方をするとワードプロセッサから文書整形・修飾機能(太文字、斜体、拡大・縮小等)を取り去ったものともいえる。ワードプロセッサに比べて軽快に動き、かつ作成したファイルの互換性が高いため、ある程度長い文章でもエディタを愛用する人が多い。
たとえば、Windowsの代表的なエディタはメモ帳であり、ワードプロセッサはMicrosoft Wordである。
Emacs_
EmacsはUNIX/Linux上での代表的なエディタの一つである。
Emacs はUNIX上で有名かつ人気のあるエディタである。 Emacsは高度にカスタマイズ可能であり、Emacs Lispという言語で環境を記述すれば、メールやニュースのリーダーとして使用可能なのは勿論、ブラウザとしても使用可能である。タイピングソフトやプログラム作成時にデバッグする環境も構築できる。
caskをインストールする_
Homebrew経由でインストールできるemacsは3種類あり、そのうちcask経由でインストールする。
まず、caskをインストールする。
% brew install cask
emacsをインストールする_
% brew install --cask emacs % which emacs /usr/local/bin/emacs % emacs --version GNU Emacs 28.2 Copyright (C) 2022 Free Software Foundation, Inc. GNU Emacs comes with ABSOLUTELY NO WARRANTY. You may redistribute copies of GNU Emacs under the terms of the GNU General Public License. For more information about these matters, see the file named COPYING.
起動してみる。
% emacs &
emacsの起動時に「Appleでアプリケーションが悪質なソフトウェアであることを確認できない」というメッセージが表示され、起動できないことがある。
以下のページのとおり「システム環境設定」→「「セキュリティとプライバシー」をクリックし、「一般」をクリックする。ウィンドウの下の方にemacsの起動を許可するかどうかの選択が表示されるので許可する。
一度、許可すると二度目以降は自動的に許可される。
emacsの設定_
emacsは設定ファイルによってさまざまにカスタマイズ可能なエディタである。emacsの設定ファイルはホームディレクトリ下の.emacs.d/init.el としておくこととなっている。このディレクトリはemacsを起動した際に自動的に作成される。確認してみる。
% cd % ls -ld .emacs.d drwx------ 2 gotoh staff 64 5 25 00:18 .emacs.d
今回は後藤が用意した設定ファイルを使って設定してみる。 GitHub:yuichigoto yg-emacs-initsからダウンロードできる。設置方法は以下の通り。
% cd ~/.emacs.d % git clone https://github.com/yuichigoto/yg-emacs-inits.git % cp yg-emacs-inits/init-leaf-macOS.el ./init.el
emacsの設定パッケージleaf.el_
本設定ファイルは2020年代のEmacs入門に従って、leafというパッケージシステムを使っている。
今回の設定ファイルでは以下のツールを使えるようにしている。
ミニバッファ拡張ツールivy_
2020年代のEmacs入門の記載を利用している。ただし、migemoとの併用ができなかったのでswiperの設定をコメントアウトしている。
;;; ミニバッファの拡張機能 ivy ;;; ref. https://emacs-jp.github.io/tips/emacs-in-2020 ;;; ref. https://github.com/abo-abo/swiper (leaf ivy :doc "Incremental Vertical completYon" :req "emacs-24.5" :tag "matching" "emacs>=24.5" :url "https://github.com/abo-abo/swiper" :emacs>= 24.5 :ensure t :blackout t :leaf-defer nil :custom ((ivy-initial-inputs-alist . nil) (ivy-use-selectable-prompt . t)) :global-minor-mode t :config (leaf swiper :doc "Isearch with an overview. Oh, man!" :req "emacs-24.5" "ivy-0.13.0" :tag "matching" "emacs>=24.5" :url "https://github.com/abo-abo/swiper" :emacs>= 24.5 :ensure t :bind (("C-s" . swiper))) (leaf counsel :doc "Various completion functions using Ivy" :req "emacs-24.5" "swiper-0.13.0" :tag "tools" "matching" "convenience" "emacs>=24.5" :url "https://github.com/abo-abo/swiper" :emacs>= 24.5 :ensure t :blackout t :bind (("C-S-s" . counsel-imenu) ("C-x C-r" . counsel-recentf)) :custom `((counsel-yank-pop-separator . "\n----------\n") (counsel-find-file-ignore-regexp . ,(rx-to-string '(or "./" "../") 'no-group))) :global-minor-mode t)) (leaf prescient :doc "Better sorting and filtering" :req "emacs-25.1" :tag "extensions" "emacs>=25.1" :url "https://github.com/raxod502/prescient.el" :emacs>= 25.1 :ensure t :custom ((prescient-aggressive-file-save . t)) :global-minor-mode prescient-persist-mode) (leaf ivy-prescient :doc "prescient.el + Ivy" :req "emacs-25.1" "prescient-4.0" "ivy-0.11.0" :tag "extensions" "emacs>=25.1" :url "https://github.com/raxod502/prescient.el" :emacs>= 25.1 :ensure t :after prescient ivy :custom ((ivy-prescient-retain-classic-highlighting . t)) :global-minor-mode t)
migemoの設定_
まず、cmigemoをインストールする。
% brew install cmigemo
cmigemoがどこにインストールされているのか調べる。以下の例はApple Silicon CPUの場合。
% which cmigemo /opt/homebrew/bin/cmigemo
これを使う設定は以下のとおり。homebrewがインストールされているディレクトリに応じてcmigemoのコマンドパスとmigemoの辞書の設定パスを変更すること。
;; ローマ字検索を可能にするパッケージMIGEMO ;; 以下の辞書のパスは macOS BigSurでの設定 (leaf migemo :ensure t :require t :custom ;; Intel CPUの場合 ;;(migemo-command . "/usr/local/bin/cmigemo") ;; (migemo-dictionary . "/usr/local/Cellar/cmigemo/20110227/share/migemo/utf-8/migemo-dict") ;; Apple Silicon CPUの場合 (migemo-command . "/opt/homebrew/bin/cmigemo") (migemo-dictionary . "/opt/homebrew/Cellar/cmigemo/20110227/share/migemo/utf-8/migemo-dict") (migemo-options . '("-q" "--emacs")) (migemo-user-dictionary . nil) (migemo-regex-dictionary . nil) (migemo-coding-system . 'utf-8-unix) :config (load-library "migemo") (migemo-init))
leaf.plのバイトコンパイル_
leaf.plはinit.elを修正するたびに以下のコマンドでバイトコンパイルをする必要がある。init.elcというファイルがバイトコンパイルで生成されるファイル。
% cd ~/.emacs.d % emacs --batch -f batch-byte-compile init.el % ls init.elc init.elc
動作確認_
emacsを起動して、動作を確認する。どの設定がemacsに影響しているのかは以下のとおり。
背景、文字の色、カーソルの色の変更_
init.elの以下の部分で設定している。現状は背景が黒、文字が白、カーソルが白となっている。
;; 背景、文字の色、カーソルの色の指定 (progn (set-background-color "black") (set-foreground-color "white") (set-cursor-color "white"))
日本語の入力_
macOSではmacOSの日本語入力機能を用いて日本語入力する(「かな」で日本語入力、「英数」は直接入力)。
タブ、全角スペースの可視化_
タブや全角スペースを表示する設定をしている。プログラムを書くようになると、プログラム中に全角スペースが含まれることでエラーになることがある。該当部分は以下のとおり。
;;参考: ;; https://www.emacswiki.org/emacs/WhiteSpace ;; https://qiita.com/itiut@github/items/4d74da2412a29ef59c3a ;; https://ja.wikipedia.org/wiki/Unicode%E4%B8%80%E8%A6%A7_0000-0FFF (progn (require 'whitespace) (global-whitespace-mode 1) (setq whitespace-style '( face ; 可視化 trailing ; 行末 tabs ; タブ spaces ; スペース empty ; 先頭、末尾のスペース space-mark ; 全角スペースの別記号表記 tab-mark ; タブの別記号表記 )) (setq whitespace-display-mappings '( (space-mark ?\u3000 [?\u20DE]) ; 全角スペースを別記号で表記 (tab-mark ?\t [?\u00BB ?\t] [?\\ ?\t]) ; タブを別記号で表記 )) (setq whitespace-trailing-regexp "\\([ \u00A0]+\\)$") (setq whitespace-space-regexp "\\(\u3000+\\)") (set-face-attribute 'whitespace-trailing nil :foreground "RoyalBlue4" :background "RoyalBlue4" :underline nil) (set-face-attribute 'whitespace-tab nil :foreground "orange red" :background "yellow4" :underline nil) (set-face-attribute 'whitespace-space nil :foreground "gray40" :background "light gray" :underline nil))
どのようになるのか試してみる。
- サンプルファイルをダウンロードしてみる。
% brew install wget % mkdir -p ~/Sandbox % cd ~/Sandbox % wget http://www.aise.ics.saitama-u.ac.jp/~gotoh/Download/Samples/Example.whitespace.txt % ls Example.whitespace.txt (ダウンロードできていることを確かめる)
- emacsでExample.whitespace.txtを開く(emacs上で C-x C-f ~/Sandbox/Example.whitespace.txtを開く)
- 下の画像のようにタブや全角スペースが色付き表示される。

日本語インクリメンタル検索_
日本語で検索できるかどうか試してみる。
- サンプルファイルをダウンロードしてみる。
% cd ~/Sandbox % wget http://www.aise.ics.saitama-u.ac.jp/~gotoh/Download/Samples/Example.utf8.txt % ls Example.utf8.txt (ダウンロードできていることを確かめる)
- emacsでExample.utf8.txtを開く(emacs上で C-x C-f ~/Sandbox/Example.utf8.txtを開く)
- 検索してみる。C-s pasokon
- 下の画像のように「パソコン」が検索候補としてヒットする。C-sを押すたびに次候補へ進む
- 検索終了する場合はEnterキーを押す
