;;; skk-abbrev.el --- SKK/Emacs abbrev mode interface.
;; Copyright (C) 1999 Mikio Nakajima <minakaji@osaka.email.ne.jp>

;; Author: Mikio Nakajima <minakaji@osaka.email.ne.jp>
;; Maintainer: Mikio Nakajima <minakaji@osaka.email.ne.jp>
;; Version: $Id: skk-abbrev.el,v 1.1.2.3.2.1 1999/11/14 15:10:07 minakaji Exp $
;; Keywords: japanese
;; Created: Oct. 23, 1999
;; Last Modified: $Date: 1999/11/14 15:10:07 $

;; This file is part of Daredevil SKK.

;; Daredevil SKK is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either versions 2, or (at your option)
;; any later version.

;; Daredevil SKK is distributed in the hope that it will be useful
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with Daredevil SKK, see the file COPYING.  If not, write to the Free
;; Software Foundation Inc., 59 Temple Place - Suite 330, Boston,
;; MA 02111-1307, USA.

;;; Commentary
;;
;; <how to install>
;;   下記のフォームを .emacs か .skk に書いて下さい。skk-search-prog-list に
;; ついては、全部を写す必要はありません。(skk-abbrev-search) を含むように指定し
;; て下さい。
;;
;; (autoload 'skk-abbrev-search "skk-abbrev" nil nil nil)
;;
;; (setq skk-search-prog-list
;;       '((skk-search-jisyo-file skk-jisyo 0 t)
;;         ;; ADD NEXT LINE.
;;         (skk-abbrev-search)     
;;         (skk-search-server skk-aux-large-jisyo 10000) ))
;;
;;
;; <how to work>
;;   skk-abbrev-mode で変換したとき、補完したときに Emacs original の
;; abbrev mode を使った変換を行ないます。
;;
;; skk-look との優先順位は、
;;  a.変換については、skk-search-prog-list の中で (skk-abbrev-search) を
;;    先順位に書き指定して下さい。skk-abbrev-search の方が skk-look より軽い
;;    です。
;;  b.補完については、skk-use-look を指定していても、常に skk-abbrev-search
;;    の方が先に検索されます。

;;; Code:
(eval-when-compile (require 'skk-macs) (require 'skk-vars)
		   (require 'skk-comp) )

;; Elib.
(require 'stack-m)

;;; ;;;###autoload
;;(defgroup skk-abbrev nil "SKK abbrev related customization."
;;  :prefix "skk-abbrev-"
;;  :group 'skk )

;;;###autoload
(defun skk-abbrev-search ()
  (let ((var (and skk-abbrev-mode (abbrev-expansion skk-henkan-key))))
    (and var (list var)) ))

(defadvice skk-completion-original (around skk-abbrev-ad activate)
  (let ((first (ad-get-arg 0))
	c-word )
    (condition-case nil
	;; not to search by look in ad-do-it.
	(let (skk-use-look)
	  ad-do-it )
      ;; no word to be completed.
      (error
       (if (not skk-abbrev-mode)
	   nil
	 (setq c-word (and (abbrev-expansion skk-completion-word)))
	 (if (and skk-use-look
		  (or (not c-word)
		      (member c-word (stack-all skk-completion-stack)) ))
	     ;; more searching by look when abbreviating is not enough.
	     (while (or (not c-word)
			(member c-word (stack-all skk-completion-stack)) )
	       (setq c-word (skk-look-completion)) )))
       (if (not c-word)
	   (if skk-japanese-message-and-error
	       (error "\"%s\" で補完すべき見出し語は%sありません"
		      skk-completion-word (if first "" "他に") )
	     (error "No %scompletions for \"%s\""
		    (if first "" "more ") skk-completion-word ))
	 (stack-push skk-completion-stack c-word)
	 (delete-region skk-henkan-start-point (point))
	 (insert c-word) )))))

;; end of skk-abbrev.el
