続続続 dabbrev で対象バッファを絞るの巻

どうもどうも。
民主党大勝利ですね。政治よく知らない,いやほとんど知らないけど。
というか勝ち負けの問題なのか? 勝つことは目的じゃないでしょ。
何をするだよねぇ。
てか,あんだけ色々やりまっせ的なこと言っているんだから,
できなかったら罰ゲーム的なことやってほしいよなぁ。
ま,選挙には金がかかるらしいから,それでリスクを背負っていることになるのか?
てか政治家って,私の頭ん中だと,国民 > 政治家 という位置づけなんだが,
なんか逆になってないか?


ま,なんにしても相当おいしい職業なんだろうなぁ。
じゃなきゃある職業になるために,億単位で金かけないよなぁ。
元が取れる計算でしょ?


すんまへん。愚痴になってまいました。
閑話休題


以前から悩ましい状態になっている dynamic abbreviation で,
対象バッファを絞る件ですが,別解がありました。
てか,dabbrev.el を眺めていたら,もろにありましたよ。

まずは,設定。

こうなりました。

(defun emacs-lisp-mode-hook-func ()
  (interactive)
  ...
  (set (make-local-variable 'dabbrev-friend-buffer-function)
       (lambda (buffer)
         (save-excursion
           (set-buffer buffer)
           (memq major-mode '(emacs-lisp-mode))))))

(add-hook 'emacs-lisp-mode-hook 'emacs-lisp-mode-hook-func)

dabbrev.el から適当に引用します。
詳細はコメントを読んでもらうとして。

;; Example for GNUS (when we write a reply, we want dabbrev to look in
;; the article for expansion):
;; (set (make-local-variable 'dabbrev-friend-buffer-function)
;;      (lambda (buffer)
;;         (save-excursion
;;           (set-buffer buffer)
;;           (memq major-mode '(news-reply-mode gnus-article-mode)))))
(defcustom dabbrev-friend-buffer-function 'dabbrev--same-major-mode-p
  "*A function to decide whether dabbrev should search OTHER-BUFFER.
The function should take one argument, OTHER-BUFFER, and return
non-nil if that buffer should be searched.  Have a look at
`dabbrev--same-major-mode-p' for an example.

The value of `dabbrev-friend-buffer-function' has an effect only if
the value of `dabbrev-select-buffers-function' uses it.  The function
`dabbrev--select-buffers' is one function you can use here.

A mode setting this variable should make it buffer local."
  :type 'function
  :group 'dabbrev)

(defun dabbrev--select-buffers ()
  "Return a list of other buffers to search for a possible abbrev.
The current buffer is not included in the list.

This function makes a list of all the buffers returned by `buffer-list',
then discards buffers whose names match `dabbrev-ignored-buffer-names'
or `dabbrev-ignored-buffer-regexps'.  It also discards buffers for which
`dabbrev-friend-buffer-function', if it is bound, returns nil when called
with the buffer as argument.
It returns the list of the buffers that are not discarded."
  (dabbrev-filter-elements
   buffer (buffer-list)
   (and (not (eq (current-buffer) buffer))
	(not (dabbrev--ignore-buffer-p buffer))
	(boundp 'dabbrev-friend-buffer-function)
	(funcall dabbrev-friend-buffer-function buffer))))

感想

上記ように設定しても,
Scanning `*Messages*'
Scanning `dabbrev.el'
Scanning `.emacs'
Scanning `*Help*'
Scanning `.gitignore<2>'
Scanning `words_in_sentence.tex'
Scanning `toefl_writing.tex'
Scanning `*scratch*'
Scanning `*Man 5 gitignore*'
とか,エコーエリアにどばーっとでるので,
片っ端からスキャンしている様(実際には中身を見てないのかもしれんが)です。
だもんで,もっさりしちゃいます。
すると本来の目的である,auto-complete で dabbrev を候補に追加すると,
もっさりするのでそれを解消したい,を解決できないわけで。
ん?
・・・。
だめじゃん。orz

まとめ

やはり dabbrev-ignored-buffer-regexps を設定するのが今のところの
best solution.
んー,他にありそうだなぁ。
また調べてみます。