LoginSignup
1
6

More than 5 years have passed since last update.

今更ながらEmacsモダン化 - Telephone-line.elで曲線のセパレータでいい感じにする

Posted at

Telephone-line とは?

Github:Telephone-line.el
Powerline.elを書き直したものらしい

使い方

melpaからダウンロード
M-x package-install <ret> telephone-line

基本設定

基本設定は以下のコードのみ

init.el
(require 'telephone-line)
(telephone-line-mode 1)

デフォルトだとPowerline風になっている
telephone-line-default.png

詳細設定

詳細設定./examples.orgを見てね!らしい

注意点として、これらの設定は

(telephone-line-mode 1)

より前に行うこと

曲線セパレータの設定

Spacemacsのような曲線セパレータの設定は以下のようなコードで設定らしい

init.el
(setq telephone-line-primary-left-separator 'telephone-line-cubed-left
      telephone-line-secondary-left-separator 'telephone-line-cubed-hollow-left
      telephone-line-primary-right-separator 'telephone-line-cubed-right
      telephone-line-secondary-right-separator 'telephone-line-cubed-hollow-right)
(setq telephone-line-height 24
      telephone-line-evil-use-short-tag t)

telephone-line-(primary|secondary)-(left|right)-separator
telephone-line-(abs|cubed|identity|...)(-hollow)-(left|right)をセットしています
primary/secondaryとは左/右からN番目という意味ではなく
1つの色の領域をさらにサブ領域に分割して表示するためのものです
下記の図の赤線のリストのレベルに対応するのがprimary
黄色線のリストのレベルに対応するのがsecondary

telephone-line-primary-secondary.png

abs/cubed/indentity/...はセパレータの形を示しています
詳しくはGithubのReadmeを参照
primaryにはhollowのついていないシンボルを
secondaryにはhollowのついているシンボルをセットするようです
逆をセットすると下記の様におかしな表示になりました

telephone-line-hollow.png

表示したいモードラインの中身の設定

表示したいモードラインの中身の設定は以下ようなコードで設定らしい

init.el
(setq telephone-line-lhs
      '((evil   . (telephone-line-evil-tag-segment))
        (accent . (telephone-line-vc-segment
                   telephone-line-erc-modified-channels-segment
                   telephone-line-process-segment))
        (nil    . (telephone-line-minor-mode-segment
                   telephone-line-buffer-segment))))
(setq telephone-line-rhs
      '((nil    . (telephone-line-misc-info-segment))
        (accent . (telephone-line-major-mode-segment))
        (evil   . (telephone-line-airline-position-segment))))

consセル(face:色の設定 . segment:表示内容)のリストを設定する

face

faceには連想リストtelephone-line-facesに設定済みのシンボル名を指定する
自分でfaceを作成する場合にはtelephone-line-faces
(telephone-line-(l|r)hsで参照するシンボル名 . (active時のface . inactive時のface))
をappendしておく必要がある

defface.el
;; set faces
(defface level1-active
  '((t (:foreground "black" :background "chartreuse" :inherit mode-line))) "")
(defface level1-inactive
  '((t (:foreground "white" :background "grey11" :inherit mode-line-inactive))) "")

(defface level2-active
  '((t (:foreground "black" :background "royal blue" :inherit mode-line))) "")
(defface level2-inactive
  '((t (:foreground "back" :background "grey11" :inherit mode-line-inactive))) "")

(defface level3-active
  '((t (:foreground "gray" :background "magenta" :inherit mode-line))) "")
(defface level3-inactive
  '((t (:foreground "white" :background "grey11" :inherit mode-line-inactive))) "")

(setq telephone-line-faces
      (append '((level1 . (level1-active . level1-inactive))
                (level2 . (level2-active . level2-inactive))
                (level3 . (level3-active . level3-inactive))
                ) telephone-line-faces)
)

segment

segmentにはtelephone-line-defsegmentで定義したsegment関数?のリストを指定する
C-h f <telephone-line-vc-segmentなど>でヘルプを引いてtelephone-line-segments.elのリンクに飛ぶと使えるsegment関数が探せます

segmentの簡単な例を一つ
mode-line-formatの指定子(%とか)をlistで返してあげればOK

segment.el
;; 文字コードの情報+バッファ編集状態
(telephone-line-defsegment* telephone-line-mule-info-segment ()
  '("" mode-line-mule-info "%*"))

私の設定

役立つかどうかはわかりませんが、参考までに

init.el
;; Telephone Line modeを読み込み
(require 'telephone-line)

;; set faces
(defface level1-active
  '((t (:foreground "black" :background "chartreuse" :inherit mode-line))) "")
(defface level1-inactive
  '((t (:foreground "white" :background "grey11" :inherit mode-line-inactive))) "")
(defface level2-active
  '((t (:foreground "black" :background "royal blue" :inherit mode-line))) "")
(defface level2-inactive
  '((t (:foreground "back" :background "grey11" :inherit mode-line-inactive))) "")
(defface level3-active
  '((t (:foreground "gray" :background "magenta" :inherit mode-line))) "")
(defface level3-inactive
  '((t (:foreground "white" :background "grey11" :inherit mode-line-inactive))) "")

(setq telephone-line-faces
      (append '((level1 . (level1-active . level1-inactive))
                (level2 . (level2-active . level2-inactive))
                (level3 . (level3-active . level3-inactive))
                ) telephone-line-faces)
)

;; mode-lineにnyan-mode使うため
(require 'nyan-mode)
(nyan-mode t)
;; 背景がわかりづらいのでxpm画像を差し替え
(setq +nyan-outerspace-image+ (concat +nyan-directory+ "img/outerspace2.xpm"))

;; 自作segment関数
(telephone-line-defsegment* telephone-line-mule-info-segment ()
  '("" mode-line-mule-info "%*"))

;; mule-info改行の表現方法の変更
(setq eol-mnemonic-dos "↲")
(setq eol-mnemonic-unix "↓")
(setq eol-mnemonic-mac "←")
(setq eol-mnemonic-undecided "・")

;; set mode-line contents
(setq telephone-line-lhs
      '((level1 . (telephone-line-major-mode-segment))
        (level2 . (telephone-line-mule-info-segment))
        (nil    . (telephone-line-buffer-name-segment))))
(setq telephone-line-center-rhs
      '((nil . (telephone-line-nyan-segment))))
(setq telephone-line-rhs
      '((nil . nil)
    (level2 . (telephone-line-vc-segment
          telephone-line-process-segment))
    (level1 . (telephone-line-airline-position-segment))))

;; set separator shape
(setq telephone-line-primary-left-separator 'telephone-line-cubed-left
      telephone-line-secondary-left-separator 'telephone-line-cubed-hollow-left
      telephone-line-primary-right-separator 'telephone-line-cubed-right
      telephone-line-secondary-right-separator 'telephone-line-cubed-hollow-right)

;; all configuration must be done before calling (telephone-line-mode 1)
(telephone-line-mode 1)

こんなのになります↓
telephone-line-setup.png

おわりに

powerlineより少し書きやすくなったかな?
曲線セパレータかっこいい
nyan-modeかわいい
でもnyan-modeを右に寄せたかったのにうまく行かなかったのが残念
nyan-modeを挟むと幅の計算が狂って右端がきっかりになってくれない
対策をご存じの方がいたら教えてください

1
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
1
6