@kyanny's blog

My thoughts, my life. Views/opinions are my own.

Spacemacs: eyebrowse に奪われた C-c C-w を取り戻す

きっかけは re-builder で組み立てた正規表現を kill ring に保存しようとしたとき C-c C-w が上書きされていたこと。

f:id:a666666:20200705012717p:plain

eyebrowse というパッケージが C-c C-w を奪っていた

eyebrowse が C-c C-w を占有しているのはマナー違反とみなされるらしく、別のキーバインドに逃す方法が紹介されていた。

この問題をめぐる顛末

作者の立場からすると、つい最近ドキュメントを修正したばかりの箇所についてまた同じイシューが立ったのでイラッとしたのだろう。気持ちは分からなくもないが...。

C-c C-w を取り戻す

C-c w に逃してもいいけど、使うつもりがないので*1キーバインドを割り当てたくない。で、こうした。

(defun dotspacemacs/user-init ()
  (setq eyebrowse-keymap-prefix "")
  )

空文字列を渡せばいけた。 nil を渡したら Spacemacs の起動時にエラーが出た。

失敗談

最初は bind-key で reb-mode-map 内だけで C-c C-w を書き換えた。動くは動いたが which-key が出すキーバインド一覧からも消えてしまった。

(defun dotspacemacs/user-config ()
  (bind-key* "C-c C-w" 'reb-copy reb-mode-map)
  )

f:id:a666666:20200705012230p:plain

C-c C-w を忘れる可能性もあるので、ちゃんと出てきて欲しい。ここに再び登場させるための設定方法を探したりもしたが、そもそも C-c C-w はどこで定義されてるの?という筋から追って、 prefix を変える方法にたどり着いた。 prefix を変えたら which-key にもちゃんと reb-copy が現れるようになった。めでたしめでたし。

f:id:a666666:20200705012507p:plain

*1:そもそも何をするパッケージなのかも知らない

Spacemacs から xmpfilter (rcodetools) を利用する

blog.lord.geek.nz

↑この記事の手順でやるのが最速。

前提: rcodetools gem のインストール

$ gem install rcodetools

xmpfilter コマンドにパスが通っていることを確認する。

作業ディレクトリへ移動

$ cd ~/.emacs.d/private/local

rcodetools リポジトリをクローン

~/.emacs.d/private/local/rcodetools/rcodetools.el というパスに配置したい。

v0.8.5 タグはプロジェクトルート直下に rcodetools.el が置いてあり、都合が良い。

$ git clone https://github.com/rcodetools/rcodetools -b v0.8.5

rcodetools の最新リリースバージョンが 0.8.5 。 GitHub リポジトリの initial commit が 0.8.5 (最新リリースバージョンをインポートしたようだ)。 master ブランチは進んでいるが、未だ新しいバージョンはリリースされていない。

なお、 rcodetools.el 自体は一度も変更されていないので、 v0.8.5 をクローンで問題ない。

.spacemacs にて設定

dotspacemacs-additional-packages に追記する。

dotspacemacs-additional-packages
'(
  (rcodetools :location local)          ; この行を足す
  )

dotspacemacs/user-config の中で require する。

(defun dotspacemacs/user-config ()
  (require 'rcodetools)                 ; この行を足す
  )

使い方

qiita.com

ruby-mode なバッファで M-x xmp するだけ。

#=> は M-; (comment-dwim) を二回入力すると # => が入力されるので手打ちは不要。

#=># => はスペースの有無に差があるが xmpfilter はどちらでも動作する。

M-; を連打すると # =>=>=>=> のように増えていくが、 M-x xmp を実行すれば上書き置換されるので問題ない。

Spacemacs の private configuration layers の作り方と使い方

Spacemacs は Emacs Lisp 拡張を Configuration Layers (レイヤー)という概念でまとめて扱う。

公開され広く使われるレイヤーとは別に、自作レイヤーを私的に使うこともできる。このような Private Configuration Layers は ~/.emacs.d/private ディレクトリ以下に配置するのが慣例のようだ。

Private Configuration Layers の作り方は https://github.com/syl20bnr/spacemacs/blob/master/private/README.md に書いてある。このファイルは ~/.emacs.d/private/README.md と同一。

SPC SPC configuration-layer/create-layer RET

実行すると指定したディレクトリ以下に雛形が作られる。レイヤー名を xyz とした場合に作られる雛形の packages.el は以下の内容。

あとは packages.el の中に説明があるのでその通りにすれば良い...のだが、初見ではきつい。幸い、 Private Configuration Layers の完全に動作するサンプルを公開している人がいるので、それをお手本にすると良い。

自作パッケージを自作レイヤーを介して利用する

このようなディレクトリ配置になる。

$  ~ tree ~/.emacs.d/private
/Users/kyanny/.emacs.d/private
├── my-layer
│   ├── local
│   │   └── my-mode
│   │       └── my-mode.el
│   └── packages.el

5 directories, 7 files

レイヤー名・パッケージ名・ディレクトリ名・ファイル名などを合わせる必要がある箇所がいくつかあるので注意。

  • ~/.emacs.d/private/my-layer/local/my-mode/my-mode.el の中で (provide 'my-mode)
  • ~/.emacs.d/private/my-layer/packages.el の中で (defconst my-layer-packages '( (my-mode :location local)))
    • defconst のかわりに setq でも可
  • ~/.emacs.d/private/my-layer/packages.el の中で (defun my-layer/init-my-mode () (use-package my-mode))

あとは ~/.spacemacs 内の dotspacemacs-configuration-layers の中にレイヤー名を追記して SPC f e R でリロードすればレイヤー(とレイヤー内で指定したパッケージ)が利用できるようになる。

   dotspacemacs-configuration-layers
   '(
     my-layer
     )

別解(既存のパッケージを自作レイヤーを介して利用する)

Creating a Spacemacs Layer from an Existing Emacs Package

ただ、この場合は dotspacemacs-additional-packages に追記するだけで解決しそう。

さらに別解(自作パッケージをレイヤーを介さずに利用する)

Creating packages in Spacemacs for the programmer in a hurry | Dal Blog

~/.emacs.d/private/local 以下にパッケージを配置する方法。 ~/.emacs.d/private 以下のディレクトリ構造は紛らわしくてわかりづらいが、このエントリは非常にわかりやすい。

その他

~/.emacs.d/private 以下を公開している人もいる。

git clone --recursive と git clone --recurse-submodules は同じ

そもそものきっかけ。リポジトリの clone と同時に submodule も clone する git clone --recursive というオプションがあると知った。

確かに git clone --recursive でうまくいったが、 man git-clone を読んでも --recursive オプションの記載がない。 recursive という単語は --recurse-submodules オプションの説明中に出てくる。

マニュアルに載っていないということは非公開オプション?使って大丈夫なのか?そもそもなんで載ってないの?載ってない --recursive オプションが広く普及してるのはなぜ?そして二つのオプションの違いは?

同じ疑問を持った人がいた。

エイリアスであることを突き止めた人のコメントと、根拠となるソースコード。

Git 2.27.0 調べ。 --recursive-h には出てくるけど man git-clone には載っていない。 man より -h の方が頻繁に見るだろうから、 --recursive オプションが普及している理由はこれだろう。

# git clone -h

    --recurse-submodules[=<pathspec>]
                          initialize submodules in the clone
    --recursive[=<pathspec>]
                          alias of --recurse-submodules
# man git-clone

       --recurse-submodules[=<pathspec]
           After the clone is created, initialize and clone submodules within based on the provided pathspec.
           If no pathspec is provided, all submodules are initialized and cloned. This option can be given
           multiple times for pathspecs consisting of multiple entries. The resulting clone has
           submodule.active set to the provided pathspec, or "." (meaning all submodules) if no pathspec is
           provided.

           Submodules are initialized and cloned using their default settings. This is equivalent to running
           git submodule update --init --recursive <pathspec> immediately after the clone is finished. This
           option is ignored if the cloned repository does not have a worktree/checkout (i.e. if any of
           --no-checkout/-n, --bare, or --mirror is given)

git submodule コマンドの方で同じこともできる(というか git submodule のやり方が先にあり git clone のオプションが後付けされた)

$ git submodule update --init --recursive

git cloneしたあとに--recursiveを付け忘れたことに気づいた。あとからsubmoduleをcloneしたい。 - 君は心理学者なのか?


余談。 docker run -it --rm ubuntu bash の中で最新版の Git を使いたかった。

ubuntuのapt-getで最新版のgitをインストールする方法 - spangled shalalala blog

↑のあと man git-clone すると↓のようなメッセージが出た。

# man git-clone
This  system  has been minimized by removing packages and content
that are not required on a system that users do not log into.

To restore this content, including manpages, you can run the ’un‐
minimize’  command.  You  will  still need to ensure the ’man‐db’
package is installed.

言われた通りにする。

# unminimize
# apt install man-db

これで無事に man git-clone で読めるようになった。

gist の職務経歴書にけっこうたくさんブクマがついていて驚いた。「マネジメントの仕事の成果は一人で出したわけでもなかろうに、関係者への感謝の言葉もない。ろくでもない奴だ」みたいなコメントがあったけど、職務経歴書に上司や同僚への感謝を書く人なんていないと思う。自分をアピールするためのものなんだから。これまで数百くらいは職務経歴書に目を通したけど、これから辞める会社の関係者への感謝が綴られているものは記憶にない。 Linkedin の紹介コメントならわかるけど。(感謝はブログエントリーのほうに書いたんだけど、職務経歴書からブログにはリンクしていないので、読まれなかったのだろう)