Emacs で Helm v1.8.0 をストレスなく使うための個人的な設定
約 2 年前に helm に移行して、ずっと古いバージョンを使い続けていたんですが helm-ls-git が使えなかったのでアップグレードしました。
それに伴って、以下のエントリーの設定内容を v1.8.0 に対応させました。
環境
- Mac OS X 10.10.5
- iTerm2 2.1.4
- Emacs 24.5.1(Homebrew でインストールしたもので -nw で使用)
- Helm v1.8.0
ストレスレスな設定
カスタム変数や関数名の変更や細かい挙動の変更に対応して、次のような感じになりました。
(el-get-bundle "abicky/helm" :branch "develop/v1.8.0"
:build (("make"))
:build/darwin `(("make" ,(format "EMACS_COMMAND=%s" el-get-emacs)))
(require 'helm-config)
(helm-mode 1)
(define-key global-map (kbd "M-x") 'helm-M-x)
(define-key global-map (kbd "C-x C-f") 'helm-find-files)
(define-key global-map (kbd "C-x C-r") 'helm-recentf)
(define-key global-map (kbd "M-y") 'helm-show-kill-ring)
(define-key global-map (kbd "C-c i") 'helm-imenu)
(define-key global-map (kbd "C-x b") 'helm-buffers-list)
(define-key helm-map (kbd "C-h") 'delete-backward-char)
(define-key helm-find-files-map (kbd "C-h") 'delete-backward-char)
(define-key helm-find-files-map (kbd "TAB") 'helm-execute-persistent-action)
(define-key helm-read-file-map (kbd "TAB") 'helm-execute-persistent-action)
;; Disable helm in some functions
(add-to-list 'helm-completing-read-handlers-alist '(find-alternate-file . nil))
;; (1) helm-buffers-list のバッファ名の領域を広くとる
(setq helm-buffer-details-flag nil)
;; Emulate `kill-line' in helm minibuffer
(setq helm-delete-minibuffer-contents-from-point t)
(defadvice helm-delete-minibuffer-contents (before emulate-kill-line activate)
"Emulate `kill-line' in helm minibuffer"
(kill-new (buffer-substring (point) (field-end))))
(defadvice helm-ff-kill-or-find-buffer-fname (around execute-only-if-file-exist activate)
"Execute command only if CANDIDATE exists"
(when (file-exists-p candidate)
ad-do-it))
(setq helm-ff-fuzzy-matching nil)
(defadvice helm-ff--transform-pattern-for-completion (around my-transform activate)
"Transform the pattern to reflect my intention"
(let* ((pattern (ad-get-arg 0))
(input-pattern (file-name-nondirectory pattern))
(dirname (file-name-directory pattern)))
(setq input-pattern (replace-regexp-in-string "\\." "\\\\." input-pattern))
(setq ad-return-value
(concat dirname
(if (string-match "^\\^" input-pattern)
;; '^' is a pattern for basename
;; and not required because the directory name is prepended
(substring input-pattern 1)
(concat ".*" input-pattern))))))
(defun helm-buffers-list-pattern-transformer (pattern)
(if (equal pattern "")
pattern
(let* ((first-char (substring pattern 0 1))
(pattern (cond ((equal first-char "*")
(concat " " pattern))
((equal first-char "=")
(concat "*" (substring pattern 1)))
(t
pattern))))
;; Escape some characters
(setq pattern (replace-regexp-in-string "\\." "\\\\." pattern))
(setq pattern (replace-regexp-in-string "\\*" "\\\\*" pattern))
pattern)))
(unless helm-source-buffers-list
(setq helm-source-buffers-list
(helm-make-source "Buffers" 'helm-source-buffers)))
(add-to-list 'helm-source-buffers-list
'(pattern-transformer helm-buffers-list-pattern-transformer))
)
主な変更点
- (1) helm-buffers-list のバッファ名の領域が狭いことは helm-buffer-details-flag を nil にすることで対応
- helm-default-display-buffer の挙動を昔のものに変更 https://github.com/abicky/helm/commit/0df6e64
- helm-find-files のソート順をいい感じに変更 https://github.com/abicky/helm/commit/f66f71a, https://github.com/abicky/helm/commit/39b6366
以上です!