tmuxをemacsキーバインドで使う
やってみた
参考:
- ほとんど以下のサイトのコンフィグをパクった
- 加えて、ログイン先のホスト名を表示させたかったので以下の記事を参考にした
tmuxのペインのステータスラインにgitのブランチとかディレクトリとか表示する(プロンプトはもう古い) - Qiita
tmux の status line の設定方法 - Qiita
事前準備(Debian)
// 動作させるのにzshが必要 $ sudo apt-get install tmux zsh
リンク先(tmuxのペインのステータスラインにgitのブランチとかディレクトリとか表示する(プロンプトはもう古い) - Qiita)の内容でpane-border-statusスクリプトを作る
$ vim /usr/local/bin/pane-border-status $ chmod +x /usr/local/bin/pane-border-status
見た目
設定
- .tmux.conf にファイルを作る
- git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
############################################################### # prefix キーバインド変更 ※デフォルトは C-b # Emacs likeに C-x で操作する # # 事前準備 # $ sudo apt-get install xsel # /usr/local/bin/tmux-pane-border を作成しておく ############################################################### # TPMを使う set -g @plugin 'tmux-plugins/tpm' set -g @plugin 'tmux-plugins/tmux-sensible' # prefix を C-x に変更する set -g prefix C-x bind-key C-x send-prefix unbind-key C-c # prefix C-b を解除 unbind C-b ############################################################### # Emacs 風キーバインド ############################################################### setw -g mode-keys emacs unbind 1 unbind ^C unbind & unbind b # prefix 0 現在のペインを削除 bind 0 kill-pane # prefix 1 ウインドウ内の現在のペインを残し、他のペインをウインドウにする bind 1 break-pane # prefix 2 ウインドウを横に分割 bind 2 split-window -v # prefix 3 ウインドウを縦に分割 bind 3 split-window -h # prefix o ペインをローテート bind o select-pane -t :.+ # prefix k ウインドウを削除 bind k kill-window # prefix C-k ペインを削除 bind C-k kill-pane # prefix i bind i display-panes # prefix C-t bind C-t next-window # prefix c bind c new-window # prefix b セッションの一覧を表示 bind C-b list-sessions # prefix セッションを終了する bind C-c kill-server ############################################################### # キーバインド ############################################################### # 番号基準値を変更 set -g base-index 1 # マウス操作を有効にする set -g mouse on bind -n WheelUpPane if-shell -F -t = "#{mouse_any_flag}" "send-keys -M" "if -Ft= '#{pane_in_mode}' 'send-keys -M' 'copy-mode -e'" ###### Emacs コピーモード ###### # bind-key -T copy-mode-emacs C-w copy-pipe "reattach-to-user-namespace xsel" # bind-key -T copy-mode-emacs M-w copy-pipe "reattach-to-user-namespace xsel" # bind-key -T copy-mode-emacs Enter copy-pipe "reattach-to-user-namespace xsel" # set-option -g default-command "exec reattach-to-user-namespace -l $SHELL" #unbind-key -T copy-mode C-w #unbind-key -T copy-mode M-w #bind-key -T copy-mode M-w send-keys -X begin-selection #bind-key -T copy-mode C-y send-keys -X copy-pipe-and-cancel "reattach-to-user-namespace xsel" # 'v' で選択を始める # bind -T copy-mode-emacs v send -X begin-selection # 'V' で行選択 # bind -T copy-mode-emacs V send -X select-line # 'C-v' で矩形選択 # bind -T copy-mode-emacs C-v send -X rectangle-toggle # 'M-w' #bind -T copy-mode-emacs M-w send -X copy-selection #bind -T copy-mode-emacs M-w send -X copy-line # 'C-y' #bind -T copy-mode-emacs C-y send -X paste-buffer set -g @plugin 'tmux-plugins/tmux-yank' set -g @yank_with_mouse on #bind-key -T M-w #bind-key -T copy-mode y send -X copy-pipe-and-cancel "xsel -ip && xsel -op | xsel -ib" #bind-key -T copy-mode C-w send-keys -X copy-pipe-and-cancel "pbcopy" #bind-key C-y paste-buffer #bufferbind C-m run "pbpaste | tmux load-buffer - && tmux paste-buffer" ############################################################### # 色・見た目 ############################################################### # ステータスバーを 1 秒毎に描画し直す set -g status-interval 1 # センタライズ (主にウインドウ番号など) set -g status-justify centre # ステータスバーをトップに配置する set -g status-position top # ステータスバーをトップに配置する set -g status-position top # 左右のステータスバーの長さを決定する set -g status-left-length 90 set -g status-right-length 90 # #P => ペイン番号を最左に表示 set -g status-left '%H:[#P]' set -g status-right "#[fg=colour255,bg=colour241] #h | LA: #(cut -d' ' -f-3 /proc/loadavg) | %m/%d %H:%M:%S#[default]" # センタライズ(主にウインドウ番号など) set -g status-justify centre # ステータスバーの色を設定する set -g status-bg "colour238" set -g status-fg "colour255" # tmuxを 256 色表示できるようにする set -g default-terminal xterm-256color set -g terminal-overrides 'xterm:colors=256' ############################################################### # ペイン左下に現在ログインしているホスト名を表示 ############################################################### set -g pane-border-status bottom set -g pane-border-format "#T #(tmux-pane-border #{pane_current_command} #{pane_pid})" set -g pane-border-style fg="colour023" set -g pane-active-border fg="blue" # TPM run '~/.tmux/plugins/tpm/tpm'
Emacs 26でMELPAからライブラリを落とそうとするとBad Requestになる
解決策
- redditで解決策が見つかった
techquila
20 points ·
1 year agohey team, this solution was presented in #emacs on freenode earlier: it's definitely what's up in my case.
Don't lose https. Bad idea.
2019-07-14 20:15:19 npostavs space_otter: if (setq gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3") fixes it, then it's due to ,,bug 34341
.emacsに"(setq gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3")"を設定すればとりあえず動く
Emacsのインデントやコードスタイルをeditorconfigで定義する
いまさらeditorconfig
Emacsでeditorconfigを使いたい
やりたいこと
- C++のコードに対して
- インデントをスペース×4
- タブ使わない
- 行の最後にある空白除去(trailing whitespace)
editorconfig導入
以下のサイトを参考にさせてもらった
EditorConfig を Emacs から使う - 雑文発散(2014-01-04)
$ sudo apt-get install editorconfig
なんかexec-path-from-shellがうまく動かないので使っていない。
;; editorconfig (unless (package-installed-p 'editorconfig) (package-refresh-contents) (package-install 'editorconfig)) (editorconfig-mode 1) (setq edconf-exec-path "/usr/bin/editorconfig")
- .editorconfig
# EditorConfig is awesome: https://EditorConfig.org # top-most EditorConfig file root = true # Unix-style newlines with a newline ending every file [*] end_of_line = lf insert_final_newline = true # Matches multiple files with brace expansion notation # Set default charset [*.{cpp,hpp,h}] charset = utf-8 indent_style = space indent_size = 4 trim_trailing_whitespace = true
これで、Emacsの設定が空でもやりたいことは実現できた。
Emacsのインデントが気に入らない件
今更だがc++-modeのそのままのスタイルが気に入らない。
// こうなってほしいのに Func( a, a ); // こうなる Func( a, a );
- いろいろ調べてelispの設定を変えた
- arglist-intro が引数リストの最初のインデント設定、+はデフォルトのoffset値
- arglist-close が引数リストの最後のインデント設定、これにはcc-modeで用意されている関数が適用できる
- c-lineup-close-paren を使っていい感じにする
c-set-offset関数の第2引数には、offset値を指定することができます。offset値とは、次のindentの深さが現在のindentの深さからどれだけ離れているかを示す値です。整数、特殊symbol(+、-、++、--、*、/)等を指定することができます。
EmacsにおけるC++ source codeの細かいindent設定方法 (1) - I.S.の日記
;; c++-mode-hookでコードスタイル変更 (c-set-offset 'arglist-intro '+) (c-set-offset 'arglist-close 'c-lineup-close-paren)
この関数や中括弧のインデント設定はEmacsのcc-modeで全て名前がついている。
CC Mode Manual
これを読むのは苦しいので有志の方の書き下しを参考にさせていただいた。