ラベル helm の投稿を表示しています。 すべての投稿を表示
ラベル helm の投稿を表示しています。 すべての投稿を表示

2018年5月28日月曜日

helm-default-display-bufferの変更で手元のhelm-swoopが使用不能になったので修正

2018-05-28現在の最新のhelmにupdateした所、helm-swoopが
Symbol's value as variable is void: helm-swoop-pattern
なるerrorを吐くようになったので原因を調べてみた。

順当にhelm-swoopのgithubのpageを見てみる


今年(2018)の1/22に:

cf. [Symbol's value as variable is void: helm-swoop-pattern · Issue #123 · ShingoFukuyama/helm-swoop](https://github.com/ShingoFukuyama/helm-swoop/issues/123)

そのものずばりのtitleのissueがfileされている。この中で触れられているように、helmのcoreの方でhelm-default-display-bufferに修正が入って、それが影響しているとのこと。その後のdiffなどを見ている限り、vanillaのまま使っているなら対応済みのようだ。

原因と対策


個人的には、helm-swoop実行時にfull widthで表示させるために、問題になっているhelm-swoop-split-window-functionを自前で設定していたのが原因でerrorが出ていた。helm-default-display-bufferの変更に合わせて適当にargumentを追加しておく:

*** before ***

-  (setq helm-swoop-split-window-function
- '(lambda (buffer)
-    (helm-default-display-buffer buffer)))

*** after ***

+  (setq helm-swoop-split-window-function
+ '(lambda (buffer &optional resume)
+    (helm-default-display-buffer buffer)))

もしかしたら&optional resumeじゃなくて&rest resumeにしておいた方が、今後またargumentsに変更があった時に対応しやすいかもしれない。

おまけ1. 原因の特定の仕方


*scratch* bufferで:

(setq debug-on-error t)
(setq helm-swoop-pattern "")

などとお膳立てした後に徐にhelm-swoopを起動するとbacktraceが見られる。

自前の設定が問題だというのはこれで分かった。

おまけ2. helm-occur


helm-swoopはとても便利に使っているが、そのalternativeとなるものも存在している。その一つがhelm-occurで、helm-occurを実行する他に、isearchからもhelm-occur-from-isearchを使えば呼び出せる。

helm-swoopはメンテの頻度が低いとか (だからと言って本家にも取り込まれなさそうだ)、実行速度に問題があるとしてhelm-occurを勧める向きもある。機能の全てではないにしろ、候補の選択に伴ってcursor positionも移動するような設定も可能みたいなので一応紹介はしておく。

ちなみに設定すればmigemoも使える。


2016年12月26日月曜日

helm-recentf-directoriesの修正

(2017-10-04更新) migemoに対応した

(2017-06-14更新) helmのupgradeに伴って(?)不具合が発生したのでcodeを修正。actionの定義が問題を起こしていたので関連部分を削除

helm-recentf-directoriesは、recentf listの中からdirectoriesを抽出し表示するfunction。

http://d.hatena.ne.jp/syohex/20120911/1347378503で紹介されていたcodeを便利に使わせて貰っているのだが、helmの更新で上手く動かない状態になっていた。

helm-imenu.elをベースに、きちんとした方法でsourceを作製する方法へ修正してみた。


(defun helm-recentf-directories-candidates ()
  "Make candidate list of recentf directories."
  (loop for file in recentf-list
when (file-directory-p file)
collect file))

(defclass helm-recentf-directories-source (helm-source-sync)
  ((candidates :initform 'helm-recentf-directories-candidates)
   (keymap :initform helm-find-files-map)
   (migemo :initform t)
   (action :initform 'helm-find-files-actions)))

(defvar helm-source-recentf-directories
  (helm-make-source "Recent Directories"
    'helm-recentf-directories-source))

(defun helm-recentf-directories ()
  "Alternative for helm-recentf that displays only directories."
  (interactive)
  (helm :sources 'helm-source-recentf-directories
:buffer "*helm recentf directories*"))


やっていることは:

* recentf-listからdirectoryな要素を取り出すfunctionを定義
* 以上のfunctionを候補とし、keymapとactionはfind-filesのものを流用したclassを作製
* helm-make-sourceに引き渡しsourceを作製
* sourceを使うfunctionを定義


2016年9月9日金曜日

helm-swoopのwindowを下部にfull widthで表示する

動機


Full HD (1920x1080)のLCDを使っている関係で、Emacsを縦に3分割 (こんな感じ → [||])している。

この使い方だと、複数のbuffersの内容を参照できて便利だ。一方で、window widthが2分割に比べて狭くなるので、helm関連のwindowでは一度に表示できる情報量が減ってしまう。

特に困るのはhelm-filelist+のように1行の情報量が多いbufferを表示する時で、これを解決するためにhelm関連windowはframeのwidthいっぱいに表示する設定をしている。

(add-to-list 'display-buffer-alist
     `(,(rx bos "*helm" (* not-newline) "*" eos)
       (display-buffer-in-side-window)
       (inhibit-same-window . t)
       (window-height . 0.4)))

cf. https://www.reddit.com/r/emacs/comments/345vtl/make_helm_window_at_the_bottom_without_using_any/

しかし、helm-swoopのwindowには何故か適用されず困っていた。

原因と対策


helm-swoopはbufferを表示する際に何らかの理由でhelm標準となっているfunctionを使っていないらしく (おそらくはswoop.elとの兼ね合いか、helmの更新が早過ぎて書き換えられていないか)、これを変更すれば他のhelm関連windowと同じ設定にできる。

(setq helm-swoop-split-window-function
      '(lambda (buffer)
         (helm-default-display-buffer buffer)))

なお、spacemacsで同じ疑問と回答が掲載されており、それを参考に以上の設定を行った。

cf. [How do I make helm-swoop to open at bottom with full window width? · Issue #4117 · syl20bnr/spacemacs · GitHub](https://github.com/syl20bnr/spacemacs/issues/4117)


2016年4月13日水曜日

個人的にemacsを使う理由

個人的にemacsを日本語文書の記述や編集に使っている。

大きな理由は:

* DDSKK → 日本語入力
* helm (特にhelm-filelist+) → 最近開いたfileをincrementalに絞り込み
* auto-save-buffers-enhanced → 自動save
* migemo → ローマ字で日本語検索
* helm-swoop → 検索語をlistして一覧 & jump

今の所emacs以外でこれらを実現できる環境はなさそう。

あと、fileを開いた時にbufferをview-modeで開くhookを仕込んでいるので、半ばViみたいな使い方になっている。

ちなみに、設定ファイルとかプログラムの記述とかには専らVimを使っている。