Skip to content
2010/10/20 / highmt

moccurとisearchまわりをちょっとだけ使いやすくする

GNU Emacs 23.2.1 (i386-mingw-nt6.0.6002)(Shift_JISパッチ適用済自分ビルド版。)

かなり古いネタですが。

動機:

  • isearchでmigemoがoff状態からM-oしてmoccurに入ったときにmigemoが
    offの状態でmoccurを実行させたい。

  • moccurに入ってからM-mでmigemoのon/offを切り替えたい。

(defun my-moccur-toggle-use-migemo (arg)
  (interactive "P")
  (let (new-value)
    (with-current-buffer moccur-buffer-name
      (setq new-value (if arg (or (not (numberp arg)) (> arg 0))
                        (not moccur-use-migemo)))
      (setq moccur-use-migemo new-value))
    (let ((moccur-use-migemo new-value))
      (moccur-search-update))))
(defadvice moccur-mode
  (before my-before-moccur-mode-hook activate)
  ;; change moccur-mode-map before it is passed to use-local-map.
  (define-key moccur-mode-map "\M-m" 'my-moccur-toggle-use-migemo))
(defadvice isearch-moccur
  (around my-isearch-moccur-setup activate)
  (let ((moccur-use-migemo migemo-isearch-enable-p))
    ad-do-it)
  (with-current-buffer moccur-buffer-name
    (set (make-local-variable 'moccur-use-migemo) migemo-isearch-enable-p)))
(defadvice isearch-moccur-all
  (around my-isearch-moccur-all-setup activate)
  (let ((moccur-use-migemo migemo-isearch-enable-p))
    ad-do-it)
  (with-current-buffer moccur-buffer-name
    (set (make-local-variable 'moccur-use-migemo) migemo-isearch-enable-p)))

ちなみにうちでは migemo-get-pattern まわりでつまづくライブラリが多いので

(defadvice migemo-get-pattern
  (around migemo-get-pattern-or-word (word) activate)
  (if (delq 'ascii (find-charset-string word))
       (setq ad-return-value word)
    ad-do-it))

としてあります。

migemoまわりではほかにも、フレーズ検索をうまく動かすために以下の設定も
いれてあったりします。

(setq prev-search-upper-case nil)
(add-hook 'isearch-mode-hook
          (lambda ()
            (setq prev-search-upper-case (cons search-upper-case prev-search-upper-case))
            (setq search-upper-case nil)))
(add-hook 'isearch-mode-end-hook
          (lambda ()
            (setq search-upper-case (car prev-search-upper-case))
            (setq prev-search-upper-case (cdr prev-search-upper-case))))
広告
%d人のブロガーが「いいね」をつけました。