Top/Editor/emacs

目次

編集関連

矩形編集

使い方

  1. 矩形編集モードに入る
    C-X SPC
  2. 編集対象とする矩形をカーソルキーで選択する
  3. 編集したいコマンドを実行する
    • 例:矩形選択した箇所を CHAR で置換
      C-x r t CHAR

参考リンク

一括インデント

  1. まず、バッファ全体を選択する
    C-x h (mark-whole-buffer)
  2. 選択領域に対してインデントを実行する
    C-M-\ (indent-region)

編集以外の機能

文字数を数える

ファイルを read-only で開く

C-x C-r

HTML文書編集での自動補完

起動済みのemacs にファイルを渡す (emacsclient)

設定関連

フォント設定

  1. Menu → "Options" → "Set Default Font..." でフォントを選択。
  2. Menu → "Options" → "Save Options" で設定を保存する。(この操作により、上で行ったフォント設定が ${HOME}/.emacs.d/init.el に保存される)

lisp の場所を設定する

タイトルバーの表示書式にファイル名を入れる

(setq frame-title-format (format "emacs@%s : %%f" (system-name)))

文字色の変更

terminal 上で動作させる場合

どの変数で色定義されているかを調べる

  1. 対象となる文字列にカーソルを合わせた上で、以下を実行する:
    M-x: describe-face
    すると、ミニバッファに以下のように表示される:
    Describe face (default `cscope-file-face'): 
  2. ここで決定(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

色変更の定義

  1. 上記を元に、以下のように設定してやれば、色を変えることが出来る
    (set-face-foreground 'cscope-file-face "#d54e53")  ; yellow → (RGB)=(0xd5,0x4e,0x53)

色設定

{menu|tool}-barを消す

(tool-bar-mode 0)		; tool bar を表示しない
(menu-bar-mode 0)		; menu bar を表示しない
(which-function-mode 1)	; 現在の関数名をモードラインに表示

行頭に行番号を表示する(モード行ではなく)

モードラインに現在カーソルが位置している関数の関数名を表示する

モードラインの現在時刻の表示

use-package

参考リンク

Time-stamp

; 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

isearch で、カーソルの位置にある単語を検索対象にする

shell-mode で制御文字を処理する

; 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)

バックアップファイルを作らないようにする

(setq make-backup-files nil)  ; *.~ とかのバックアップファイルを作らない
(setq auto-save-default nil)  ; .#* とかのバックアップファイルを作らない

選択領域を [DEL] で一気に消せるようにする

; (setq delete-selection-mode t)
(delete-selection-mode)

scroll を1行単位にする

(setq scroll-step 1)

分割した window のサイズを変える

commanddescriptionremark
M-x: enlarge-window縦方向にサイズを大きくする
M-x: shrink-window縦方向にサイズを小さくする
M-x: enlarge-window-horizontally横方向にサイズを大きくする
M-x: shrink-window-horizontally横方向にサイズを小さくする

ウインドウ自動分割時の制御

beep 音を消す

今日の日付を挿入する

(defun today()
  (interactive)
  (insert (format-time-string "%Y/%m/%d" (current-time))))

前のウインドウに戻る

; 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))))

検索時に大文字・小文字を区別するかしないかの設定

(setq default-case-fold-search nil)  ; 大文字・小文字を区別させる(〜emacs23.1)
(setq case-fold-search nil)          ; 大文字・小文字を区別させる (emacs23.2〜)

ediff の control window を別ウインドウにしないようにする

参考リンク

カレンダーで日本の祝日を表示する

helm

入手先

参考リンク

emacs のローカルビルド

  1. 最新のコードを取得する
    • この項の執筆時点の最新は 27.1
      http://ftp.jaist.ac.jp/pub/GNU/emacs/emacs-27.1.tar.xz
    • 又は、開発リポジトリから取得する
      git://git.savannah.gnu.org/emacs.git
      • 開発リポジトリから取得した場合は、 tag で checkout してから使う
        $ git checkout refs/tags/emacs-27.1

  2. ビルドに使うパッケージをインストールする
    # apt-get install xaw3dg-dev xaw3dg libjpeg-dev libpng-dev libgif-dev libtiff-dev texinfo
    • gtk3 ToolKit を使う場合は、以下もインストールする
      libgtk-3-dev
  3. ビルドする
    $ ./configure
    ここでエラーが出る場合、「こういうオプションをつけろ」というメッセージが出るので、それに従う。今回の環境では ''--with-gnutls=no'' が必要だった。
    $ ./configure --with-gnutls=no
    $ make

参考リンク


トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS