コードの修正

もはやタイトルでは何がなんやら。コードと言っているのは、何回か載せている、zshからanythingをシームレスに呼びだすelispのことです。
ずっと前から繰り返しの表現が冗長だと感じていたので、考えつつちょいちょい弄ったら、かなりシンプルな形にできました。

とりあえず貼り付けておきます。コピペする場合は、バックスラッシュが半角ではないらしいので、ご注意下さい。
それと、Emacs23 + 添付のemacsclientでしか動作確認できていません。そのあたりすみません。anything.elとかは最新版で問題ありません。

;; zshからanythingを利用するための設定。
(require 'anything-complete)
(defvar azhzle/tmp-file "/tmp/.azh-tmp-file")
(defvar azhzle/cache nil)
(defvar azhzle/dicision-keys '("A" "S" "D" "F" "G" "H" "J" "K" "L"
                               "Q" "W" "E" "R" "T" "Y" "U" "I" "O" "P"))

(defun anything-zsh-history-from-zle-init ()
  (let ((anything-sources `((,@anything-c-source-complete-shell-history
                             ,(cons 'candidates 'lists)
                             (volatile)))))
    (anything-initialize)))

(defun azhzle/input (str)
  (interactive)
  (let* ((lists (azhzle/get-history-line str))
         (nums (if (<= (length lists) (length azhzle/dicision-keys))
                   (length lists)
                 (length azhzle/dicision-keys))))
    (with-temp-buffer
      (dotimes (i nums)
        (insert (nth i azhzle/dicision-keys) ":"
                (substring-no-properties (nth i lists)) "\n"))
      (set-buffer-file-coding-system 'raw-text-unix t)
      (write-region (point-min) (point-max) azhzle/tmp-file))
    (setq azhzle/cache lists)))

(defun azhzle/get-history-line (pattern)
  (with-current-buffer (shell-history-buffer)
    (let* ((anything-pattern pattern)
           (anything-sources `((,@anything-c-source-complete-shell-history
                               ,(cons 'candidates 'lists))))
           (source (car (anything-get-sources)))
           (anything-source-name (cdr (assoc 'name source)))
           (zsh-p t))
      (anything-candidates-in-buffer))))

(defun azhzle/dicision-history (history-num)
  (interactive)
  (with-temp-buffer
    (erase-buffer)
    (insert (substring-no-properties (nth (- history-num 1)
                                          azhzle/cache)))
    (write-region (point-min) (point-max) azhzle/tmp-file)
  ))

azhzle/inputの内容をシンプルにしました。もっとシンプルになるような気がするけどこれ以上やっても仕方がないですね。

それはそうとXperiaが発売されました、が! 私にとって発売日は4/3なのです。予約の関係上。はやく土曜になれぇぇ。