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.

Get key binding from command

Sometimes I want to get key bindings of command for implementing like following command. Please see mini-buffer.

f:id:syohex:20160813150435p:plain

(where-is-internal func &optional map ...)

where-is-internal returns list of keys of command(func) from map. For example

(where-is-internal 'next-line global-map)
;; => ([14] [down])

[14] is Control-n and [down] is down arrow key. Type of return value is list of key vector. It should be converted to human readable style.

(key-description key-vector)

key-description returns a pretty description of key-sequence. For example

(key-description [14])
;; => "C-n"

Write function

So we can write the function which returns human readable key sequence from the command

(cl-defun function-to-keybinds (func &optional (map global-map))
  (key-description (car-safe (where-is-internal func map))))

(function-to-keybinds #'next-line)
;; => "C-n"
(function-to-keybinds #'python-shell-send-string python-mode-map)
;; => "C-c C-s"

visible-bellの画像を差し替える

Emacs 25から Macの visible-bellが画像を表示するようになったのでデフォルトの画像から差し替えてみた.

パッチ

Emacs25.1-RC1に対するパッチです.

diff --git a/src/nsterm.m b/src/nsterm.m
index e6a10b8..9a54886 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -1318,7 +1318,7 @@ ns_clip_to_row (struct window *w, struct glyph_row *row,
       NSRectFill(NSMakeRect(0, 0, 32, 32));
       [self.image unlockFocus];
 #else
-      self.image = [NSImage imageNamed:NSImageNameCaution];
+      self.image = [NSImage imageNamed:@"visible-bell.png"];
       [self.image setSize:NSMakeSize(self.image.size.width * 5,
                                      self.image.size.height * 5)];
 #endif

ビルド & インストール

% ./configure --with-ns --without-x
% make
% make install
% cp -r nextstep/Emacs.app /Applications

画像を置く

適当な画像を Resources以下に置く. Objective-Cやら Macのことがよくわかっていないのですが, ドット絵的なものでないとうまく表示されない印象. 普通のアニメの絵とかだとだいぶ潰れてしまう. また画像は小さめのものがいいです. 64x64とか(このあたりは Macに詳しければなんとかなるのかもしれないですが...)

% cp foobar.png /Applications/Emacs.app/Contents/Resources/visible-bell.png

設定

visible-bellを有効にする

(setq visible-bell t)

結果

Ctrl-gなどを押すたびに好きな画像が見れます.

f:id:syohex:20160731085413g:plain