macOS Sierraにアップグレードした際のメモ

今更手持ちの macOSSierraにアップグレードした. karabinerで IMEのトグルとキーリピートだけ変えていたので使えなくなってしまったので自分が行った対応のメモ

キーリピートの変更

知らなかったけど, コマンドライン経由であれば System Preference以上の設定にできるようである. 以下のリンクのもので十分だったのでそのままにした.

% defaults write -g InitialKeyRepeat -int 10 # normal minimum is 15 (225 ms)
% defaults write -g KeyRepeat -int 1 # normal minimum is 2 (30 ms)

apple.stackexchange.com

IMEの切り替え

今までは右 Commandを toggleキーとして使っていたがデフォルトの機能ではだいたいできなかった. 最近は仕事で Windowsを使うことが多々あり Windowsだと Alt + backtick(US配列のキーボード利用のため)で IME切り替えだったのでそれに近い形にした. System Preference -> Keyboard -> Shortcuts -> Input Sourcesの Select next input sourceCommand + backtickを割り当てることとした. 若干面倒くさいがそこまで日本語を打ちまくるわけでもないので十分だと思う.

おわりに

できれば macOS自身にもっとカスタマイズ機能をつけて欲しいところである

Visual Studio(C++)セットアップ

Visual StudioC++を書く際の設定メモ

メニュー等を英語にする

使い方を調べるときなど, Stackoverflow等を見るわけですが, 日本語だと圧倒的に情報が少ないので英語にする. やり方は英語の言語パッケージをインストールして使用言語を英語にすればよい. あと可能であるならば Windowsのシステム言語も英語系にした方がよいと思う. Visual Studio C++コンパイラの仕様でデフォルトのエンコーディングとしてシステム言語が使われるということがあり, CP932だとコンパイルできないソース(Chromiumソースコードとか)が極めて稀だがあった. まあ /utf-8フラグをつけることで対策はできるのでそこまで深刻ではないが…

エクステンション

Qiitaとかいろいろ見て試してみたけどほとんどしっくりこなかった. 最終的に入れたのは VsVimと後述の Reshaper C++のみ. キーバインドEmacsVimに慣れすぎてしまっているので, 十字キーだけでは辛くて, 何かしらの補助がないと欲しい. Vimバインドにしたのは干渉が少ないから. Emacs系だとどうしても IDEが元々提供するものとかぶってしまいうまくいかないから. VsVimは生粋の Vim使いの人はどう思うかわからないけど, かなりよくできている. Visual Studioの各種コマンドといい感じで強調して使えるのがよい. リファクタリング時等に自動でインサートモードに切り替えてくれるなどストレスがあまりない(IdeaVim等設定があるのかもしれないが, 変数の名前一括変換のときなど, nomalモードのままでいらいらすることが多々ある).

Reshaper C++

Visual StudioC++書く人は全員入れた方がいいと思った. 特に仕事でコード書く人は. 無料ではないが余裕でペイできると思う. 提供する機能(Search Everywhere)とかめちゃくちゃ便利なんだけど一番いいのは静的コード検査機能. まあこれは Reshaper C++がいいというのはもちろんなんだけど, Visual Studioが提供するものがしょぼすぎるというのが大きい. Visual Studioが提供する静的検査はめちゃくちゃ遅い上に精度も微妙. 全く使い物にならないってことはないけど, Xcodeの clangの静的解析に比べると質も速さも断然落ちる. あと意味不明な警告もいろいろ出る. 同じループなのになぜか一方だけメモリリークを指摘されるとか(実際はしていないのに). リアルタイムで指摘してくれる警告もデフォルトより大幅に増えるので, コードの質を高めるなら必須だと思います.

company-cmakeで大文字, 小文字を考慮した補完をする

company-cmake(標準)でディレクティブ(関数, キーワード等)を補完すると全部小文字になる. カーソル前の文字列(prefix)が大文字だろうと小文字に変換されてしまう. プロジェクトによっては大文字でディレクティブが書かれていることがあり, 補完後わざわざ upcaseとかしていたけどめんどいので prefixが大文字の場合は大文字に補完されるようにしてみた. コードは以下の通り. 本質的に直そうかと PRを書こうとしたが治す箇所が多いし, 今のところはこれで我慢する.

(defvar my/company-cmake-prefix nil)
(defun my/company-completion-started (unused)
  (let ((prefix (company-grab-symbol)))
    (setq my/company-cmake-prefix (and (not (string-empty-p prefix)) (string= prefix (upcase prefix))))))

(defun my/company-completion-finished (result)
  (when my/company-cmake-prefix
    (delete-char (- (length result)))
    (insert (upcase result))))

(defun my/cmake-mode-hook ()
  (add-hook 'company-completion-started-hook #'my/company-completion-started nil t)
  (add-hook 'company-completion-finished-hook #'my/company-completion-finished nil t))
(add-hook 'cmake-mode-hook #'my/cmake-mode-hook)

Switch from paco to porg

Ubuntuソースコードからインストールしたパッケージは pacoで管理していたんですが, Ubuntu16.10で pacoが削除されてしまったため porgへ移行しました.

データベースの移管

paco2porgを使う. pacoをインストールして dist-upgradeした場合 paco2porgが自動で入っているようです. しかし porg自体はインストールされないので, インストールする必要がありました.

% sudo paco2porg
% sudo apt install porg

paco2porg後 porgコマンドでインストール一覧を見られることを確認します. porg -aで一覧が見られれば OKです.

% porg -a
cmigemo
emacs-devel
global-6.5.4

コマンド利用例

パッケージ追加と削除だけ. コマンド体系はほとんど同じですが, 微妙に異なるものもあります. 詳しくは manなどで確認してください.

パッケージ追加

# パッケージ名を明示的にしている場合
% sudo porg -l --package=emacs-devel make install

# パッケージ名としてディレクトリ名を使う場合
% sudo porg -l -D make install

パッケージ削除

% sudo porg -r  emacs-devel

zsh補完

github.com

オプションが覚えられないので書きました. よろしければどうぞ.

おわりに

ソースからいろいろ入れるなら Archとか Gentooを使うべきですね...

Patch for building Emacs on Ubuntu 16.10

I upgraded my server Ubuntu from 16.04 to 16.10. Then I couldn't build Emacs. I got following error at make

Dumping under the name emacs
Makefile:736: recipe for target 'bootstrap-emacs' failed
make[1]: *** [bootstrap-emacs] Segmentation fault (core dumped)
make[1]: Leaving directory '/home/syohei/src/tmp/emacs-25.1/src'
Makefile:398: recipe for target 'src' failed
make: *** [src] Error 2

Patch(for Emacs 25.1)

NOTE: Git master branch already fixed this issue. You don't need patch if you use it.

diff --git a/configure.ac b/configure.ac
index cd4d1c0..3dfb25d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -5159,25 +5159,29 @@ case "$opsys" in
   *) LD_SWITCH_SYSTEM_TEMACS= ;;
 esac
 
-# -nopie fixes a temacs segfault on Gentoo, OpenBSD, and other systems
-# with "hardened" GCC configurations for some reason (Bug#18784).
-# We don't know why -nopie works, but not segfaulting is better than
-# segfaulting.  Use ac_c_werror_flag=yes when trying -nopie, otherwise
-# clang keeps warning that it does not understand -nopie, and pre-4.6
-# GCC has a similar problem (Bug#20338).
-AC_CACHE_CHECK([whether $CC accepts -nopie],
-  [emacs_cv_prog_cc_nopie],
+# -no-pie or -nopie fixes a temacs segfault on Gentoo, OpenBSD,
+# Ubuntu, and other systems with "hardened" GCC configurations for
+# some reason (Bug#18784).  We don't know why this works, but not
+# segfaulting is better than segfaulting.  Use ac_c_werror_flag=yes
+# when trying the option, otherwise clang keeps warning that it does
+# not understand it, and pre-4.6 GCC has a similar problem
+# (Bug#20338).  Prefer -no-pie to -nopie, as -no-pie is the
+# spelling used by GCC 6.1.0 and later (Bug#24682).
+AC_CACHE_CHECK(
+  [for $CC option to disable position independent executables],
+  [emacs_cv_prog_cc_no_pie],
   [emacs_save_c_werror_flag=$ac_c_werror_flag
    emacs_save_LDFLAGS=$LDFLAGS
    ac_c_werror_flag=yes
-   LDFLAGS="$LDFLAGS -nopie"
-   AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],
-     [emacs_cv_prog_cc_nopie=yes],
-     [emacs_cv_prog_cc_nopie=no])
+   for emacs_cv_prog_cc_no_pie in -no-pie -nopie no; do
+     test $emacs_cv_prog_cc_no_pie = no && break
+     LDFLAGS="$emacs_save_LDFLAGS $emacs_cv_prog_cc_no_pie"
+     AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])], [break])
+   done
    ac_c_werror_flag=$emacs_save_c_werror_flag
    LDFLAGS=$emacs_save_LDFLAGS])
-if test "$emacs_cv_prog_cc_nopie" = yes; then
-  LD_SWITCH_SYSTEM_TEMACS="$LD_SWITCH_SYSTEM_TEMACS -nopie"
+if test "$emacs_cv_prog_cc_no_pie" != no; then
+  LD_SWITCH_SYSTEM_TEMACS="$LD_SWITCH_SYSTEM_TEMACS $emacs_cv_prog_cc_no_pie"
 fi
 
 if test x$ac_enable_profiling != x ; then
% patch -p1 < emacs-25.1.patch

Regenerate configure

% ./autogen.sh

Build Emacs

% ./configure --with-modules
% make
% sudo make install

MELPAコミッタになりました

パッケージのレビューをしまくり, そのパッケージに PRをしまくっていたら,コミット権限をいただきました.(個人的には el-getユーザで MELPAをテスト向けのパッケージぐらいにしか使っていないのですが...). パッケージを MELPAで登録したいけどよくわからないとかレビューして欲しい等の場合は twitterや slackの emacs-jpチーム等でご連絡頂ければと思います. よろしくお願いします.

あと Emacsではありませんが, zsh-usersの zsh-completionsのコミッタにもなったので, そちらでも何かありましたらご連絡ください.

libpcre binding of Emacs Lisp

I'm writing libpcre binding of Emacs Lisp. Most of programmers is not familiar with Emacs Lisp regular expression because regular expression function or library of many languages has compatibility of Perl regular expression. I suppose such people writes regular expression easily with this library.

Repository

github.com

Sample code

(let ((input "https://example.com/foo/bar/baz.txt")
      (regexp "
^
# backslash is not necessary for grouping
(https?): # $1 schema
//
([^/]+)   # $2 host
(/.*)     # $3 path
$
"))
  (when (pcre-string-match regexp input '(extended)) ;; extends flag allows space/comment in regular expression
    (message "schema:%s, host:%s, path:%s"
             (match-string 1 input)
             (match-string 2 input)
             (match-string 3 input)))) ;; "schema:https, host:example.com, path:/foo/bar/baz.txt"

Interfaces

https://github.com/syohex/emacs-pcre/blob/master/README.md

I design this library same as Emacs regular expression interfaces, signature, behavior etc. For example case sensitive or insensitive searching is decided by current case-fold-search value.

Issues or any suggestions

Please report me if you have any suggestions via github issue.