Source

skk / skk-kakasi.el

Diff from to

skk-kakasi.el

 ;;; skk-kakasi.el --- KAKASI $B4XO"%W%m%0%i%`(B
-;; Copyright (C) 1996 Mikio Nakajima <minakaji@osaka.email.ne.jp>
+;; Copyright (C) 1996, 1998, 1999 Mikio Nakajima <minakaji@osaka.email.ne.jp>
 
 ;; Author: Mikio Nakajima <minakaji@osaka.email.ne.jp>
 ;; Version: $Id$
 ;; Keywords: japanese
 ;; Last Modified: $Date$
 
-;; This program is free software; you can redistribute it and/or modify
+;; This file is not part of SKK yet.
+
+;; 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.
 
-;; This program is distributed in the hope that it will be useful
+;; 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.
 ;; $B;d<+?H$,%K%e!<%9$d%a!<%k$rFI$s$G$$$F!"F|>oFI$_$,J,$i$J$/$FCQ$:$+$7$$;W$$$r(B
 ;; $B$9$k$3$H$,B?$$$N$G!"5U0z$-$r$7$?$/$F:n$j$^$7$?!#(B
 ;;
-;; $B!L$3$N$N%$%s%9%H!<%kJ}K!!M(B
-;;  skk.el 9.4 $B$+$i$O@_DjITMW$K$J$kM=Dj$G$9$,!"$=$l0JA0$N%P!<%8%g%s$N(B skk.el
-;; $B$r$*;H$$$N>l9g$O!"2<5-$N%U%)!<%`$rI>2A$9$l$P(B OK $B$G$9!#(BEmacs $B$N5/F0Kh$K$3$N(B
-;; $B@_Dj$,M-8z$K$J$k$h$&$K$9$k$?$a$K$O!"(B~/.emacs $B$K2<5-%U%)!<%`$rA^F~$7$F$7$^$&(B
-;; $B$N$,$*<j7Z$G$9!#(B
-;;
-;;    (autoload 'skk-gyakubiki-katakana-message "skk-kakasi" nil t)
-;;    (autoload 'skk-gyakubiki-katakana-region "skk-kakasi" nil t)
-;;    (autoload 'skk-gyakubiki-message "skk-kakasi" nil t)
-;;    (autoload 'skk-gyakubiki-region "skk-kakasi" nil t)
-;;    (autoload 'skk-hurigana-katakana-message "skk-kakasi" nil t)
-;;    (autoload 'skk-hurigana-katakana-region "skk-kakasi" nil t)
-;;    (autoload 'skk-hurigana-message "skk-kakasi" nil t)
-;;    (autoload 'skk-hurigana-region "skk-kakasi" nil t)
-;;    (autoload 'skk-romaji-message "skk-kakasi" nil t)
-;;    (autoload 'skk-romaji-region "skk-kakasi" nil t)
-;;
 ;; KAKASI $B$O!"(B1996 $BG/(B 4 $B7n(B 25 $BF|8=:_!"(B
 ;; sunsite.sut.ac.jp:/pub/asia-info/japanese-src/packages/kakasi-2.2.5.tar.gz
 ;; sunsite.sut.ac.jp:/pub/asia-info/japanese-src/packages/kakasidict.940620.gz
 ;; $BAG@2$7$$%W%m%0%i%`(B KAKASI $B$r$*:n$j$K$J$C$?9b66$5$s$H!"(BKAKASI $B$r(B anonymous
 ;; ftp $B$GF~<j2DG=$H$7$F$$$k(B sunsite.sut.ac.jp $B$K46<U$$$?$7$^$9!#(B
 
-;;; Change log:
+;;; Code:
+(eval-when-compile (require 'skk))
+(require 'skk-foreword)
+;; APEL
+(require 'path-util)
 
-;;; Code:
-(require 'skk-foreword)
-(require 'skk-vars)
+;;;###autoload
+(defgroup skk-kakasi nil "SKK kakasi related customization."
+  :prefix "skk-"
+  :group 'skk )
 
 ;;;;  VARIABLES
 
 ;; --- user variable
 
-(defvar skk-use-kakasi
-  (or (and (file-exists-p "/usr/local/bin/kakasi")
-           (file-executable-p "/usr/local/bin/kakasi") )
-      (eq (call-process "which" nil nil nil "kakasi") 0) )
-  ;; tcsh $B$O(B built-in $B%3%^%s%I$H$7$F(B which $B$r;}$C$F$$$k!#(BLinux $B$@$H(B sh ($B<B$O<B(B
-  ;; $BBN$O(B bash) $B$G$b(B /usr/bin/which $B$,;H$($k!#B>$N%7%9%F%`$G$O$I$&$9$Y$-!)(B
-  "*Non-nil $B$G$"$l$P(B KAKASI $B$r;H$C$?JQ49$r9T$J$&!#(B" )
+(defcustom skk-use-kakasi (exec-installed-p "kakasi")
+  "*Non-nil $B$G$"$l$P(B KAKASI $B$r;H$C$?JQ49$r9T$J$&!#(B" 
+  :type 'boolean
+  :group 'skk-kakasi )
 
-(defvar skk-romaji-*-by-hepburn t
+(defcustom skk-kakasi-command (exec-installed-p "kakasi")
+  "*KAKASI $B%3%^%s%IK\BN!#(B"
+  :type 'file
+  :group 'skk-kakasi )
+
+(defcustom skk-romaji-*-by-hepburn t
   "*Non-nil $B$G$"$l$P(B KAKASI $B$r;H$C$?%m!<%^;z$X$NJQ49MM<0$K%X%\%s<0$rMQ$$$k!#(B
 $BNc$($P!"(B
   \"$B$7(B\" -> \"shi\"
 
 $B><OB(B 29 $BG/(B 12 $B7n(B 9 $BF|IUFb3U9p<(Bh0l9f$K$h$l$P!"86B'E*$K71Na<0(B \"($BF|K\<0(B)\" $B$r(B
 $BMQ$$$k$+$N$h$&$K5-:\$5$l$F$$$k$,!":#F|0lHLE*$J5-:\J}K!$O!"$`$7$m!"%X%\%s<0$G$"(B
-$B$k$h$&$K;W$&!#(B" )
+$B$k$h$&$K;W$&!#(B"
+  :type 'boolean
+  :group 'skk-kakasi )
 
-(defvar skk-kakasi-load-hook nil
-  "*skk-kakasi.el $B$,%m!<%I$5$l$?$H$-$N%U%C%/!#(B" )
+(defcustom skk-kakasi-load-hook nil
+  "*skk-kakasi.el $B$,%m!<%I$5$l$?$H$-$N%U%C%/!#(B"
+  :type 'hook
+  :group 'skk-kakasi )
 
-(if skk-mule3
-    (modify-coding-system-alist 'process "kakasi"
-                             '(undecided . euc-japan) ))
+(if (fboundp 'modify-coding-system-alist)
+    (let ((euc (cdr (assoc "euc" skk-coding-system-alist))))
+      (modify-coding-system-alist 'process "kakasi" (cons euc euc)) ))
 
 ;;;; FUNCTIONS
-;;;###skk-autoload
+;;;###autoload
 (defun skk-gyakubiki-region (start end &optional all)
   "$B%j!<%8%g%s$N4A;z!"Aw$j2>L>$rA4$F$R$i$,$J$KJQ49$9$k!#(B
 $B%*%W%7%g%J%k0z?t$N(B ALL $B$,(B non-nil $B$J$i$P!"J#?t$N8uJd$,$"$k>l9g$O!"(B\"{}\" $B$G$/(B
     $BCfEg(B -> {$B$J$+$7$^(B|$B$J$+$8$^(B}"
   (interactive "*r\nP")
   (let ((str (skk-gyakubiki-1 start end all)))
-    (combine-after-change-calls
-      (delete-region start end)
-      (goto-char start)
-      (insert str) )
-    (skk-set-cursor-properly) ))
+    (delete-region start end)
+    (goto-char start)
+    (insert-and-inherit str) )
+  (skk-set-cursor-properly) )
 
-;;;###skk-autoload
+;;;###autoload
 (defun skk-gyakubiki-message (start end &optional all)
   "$B%j!<%8%g%s$N4A;z!"Aw$j2>L>$rA4$F$R$i$,$J$KJQ498e!"%(%3!<$9$k!#(B
 $B%*%W%7%g%J%k0z?t$N(B ALL $B$,(B non-nil $B$J$i$P!"J#?t$N8uJd$,$"$k>l9g$O!"(B\"{}\" $B$G$/(B
       (if (string-match "^[ $B!!(B\t]+" str)
           ;; $B@hF,$N6uGr$r<h$j=|$/!#(B
           (setq str (substring str (match-end 0))) ))
-    (message str)
+    (message "%s" str)
     (skk-set-cursor-properly) ))
-        
 
-;;;###skk-autoload
+
+;;;###autoload
 (defun skk-gyakubiki-katakana-region (start end &optional all)
   "$B%j!<%8%g%s$N4A;z!"Aw$j2>L>$rA4$F%+%?%+%J$KJQ49$9$k!#(B
 $B%*%W%7%g%J%k0z?t$N(B ALL $B$,(B non-nil $B$J$i$P!"J#?t$N8uJd$,$"$k>l9g$O!"(B\"{}\" $B$G$/(B
     $BCfEg(B -> {$B%J%+%7%^(B|$B%J%+%8%^(B}"
   (interactive "*r\P")
   (let ((str (skk-gyakubiki-1 start end all 'katakana)))
-    (combine-after-change-calls
-      (delete-region start end)
-      (goto-char start)
-      (insert str) )
-    (skk-set-cursor-properly) ))
+    (delete-region start end)
+    (goto-char start)
+    (insert-and-inherit str) )
+  (skk-set-cursor-properly) )
 
-;;;###skk-autoload
+;;;###autoload
 (defun skk-gyakubiki-katakana-message (start end &optional all)
   "$B%j!<%8%g%s$N4A;z!"Aw$j2>L>$rA4$F%+%?%+%J$KJQ498e!"%(%3!<$9$k!#(B
 $B%*%W%7%g%J%k0z?t$N(B ALL $B$,(B non-nil $B$J$i$P!"J#?t$N8uJd$,$"$k>l9g$O!"(B\"{}\" $B$G$/(B
       (if (string-match "^[ $B!!(B\t]+" str)
           ;; $B@hF,$N6uGr$r<h$j=|$/!#(B
           (setq str (substring str (match-end 0))) ))
-    (message str)
+    (message "%s" str)
     (skk-set-cursor-properly) ))
 
 (defun skk-gyakubiki-1 (start end all &optional katakana)
         (setq arg (cons "-p" arg)) )
     (skk-kakasi-region start end arg)) )
 
-;;;###skk-autoload
+;;;###autoload
 (defun skk-hurigana-region (start end &optional all)
   "$B%j!<%8%g%s$N4A;z$KA4$F$U$j$,$J$rIU$1$k!#(B
 $BNc$($P!"(B
     $BCfEg(B -> {$B$J$+$7$^(B|$B$J$+$8$^(B}"
   (interactive "*r\nP")
   (let ((str (skk-hurigana-1 start end all)))
-    (combine-after-change-calls
-      (delete-region start end)
-      (goto-char start)
-      (insert str) )
-    (skk-set-cursor-properly) ))
+    (delete-region start end)
+    (goto-char start)
+    (insert-and-inherit str) )
+  (skk-set-cursor-properly) )
 
-;;;###skk-autoload
+;;;###autoload
 (defun skk-hurigana-message (start end &optional all)
   "$B%j!<%8%g%s$N4A;z$KA4$F$U$j$,$J$rIU$1!"%(%3!<$9$k!#(B
 $BNc$($P!"(B
 $BNc$($P!"(B
     $BCfEg(B -> {$B$J$+$7$^(B|$B$J$+$8$^(B}"
   (interactive "r\nP")
-  (message (skk-hurigana-1 start end all))
+  (message "%s" (skk-hurigana-1 start end all))
   (skk-set-cursor-properly) )
 
-;;;###skk-autoload
+;;;###autoload
 (defun skk-hurigana-katakana-region (start end &optional all)
   "$B%j!<%8%g%s$N4A;z$KA4$F%U%j%,%J$rIU$1$k!#(B
 $BNc$($P!"(B
     $BCfEg(B -> {$B%J%+%7%^(B|$B%J%+%8%^(B}"
   (interactive "*r\nP")
   (let ((str (skk-hurigana-1 start end all 'katakana)))
-    (combine-after-change-calls
-      (delete-region start end)
-      (goto-char start)
-      (insert str) )
-    (skk-set-cursor-properly) ))
+    (delete-region start end)
+    (goto-char start)
+    (insert-and-inherit str) )
+  (skk-set-cursor-properly) )
 
-;;;###skk-autoload
+;;;###autoload
 (defun skk-hurigana-katakana-message (start end &optional all)
   "$B%j!<%8%g%s$N4A;z$KA4$F%U%j%,%J$rIU$1!"%(%3!<$9$k!#(B
 $BNc$($P!"(B
 $BNc$($P!"(B
     $BCfEg(B -> {$B%J%+%7%^(B|$B%J%+%8%^(B}"
   (interactive "r\nP")
-  (message (skk-hurigana-1 start end all 'katakana))
+  (message "%s" (skk-hurigana-1 start end all 'katakana))
   (skk-set-cursor-properly) )
 
 (defun skk-hurigana-1 (start end all &optional katakana)
   ;; skk-hurigana-* $B$N%5%V%k!<%A%s!#(B
   ;; $B%*%W%7%g%J%k0z?t$N(B KATAKANA $B$,(B non-nil $B$G$"$l$P!"%+%?%+%J$XJQ49$9$k!#(B
-  (let ((arg (if katakana '("-JK" "-f") '("-JH" "-f")))
-        str )
+  (let ((arg (if katakana '("-JK" "-f") '("-JH" "-f"))))
     (if skk-allow-spaces-newlines-and-tabs
         (setq arg (cons "-c" arg)) )
     (if all
         (setq arg (cons "-p" arg)) )
     (skk-kakasi-region start end arg)) )
 
-;;;###skk-autoload
+;;;###autoload
 (defun skk-romaji-region (start end)
   "$B%j!<%8%g%s$N4A;z!"$R$i$,$J!"%+%?%+%J!"A41QJ8;z$rA4$F%m!<%^;z$KJQ49$9$k!#(B
 $BJQ49$K$O!"%X%\%s<0$rMQ$$$k!#(B
     (if (not skk-romaji-*-by-hepburn)
         (setq arg (cons "-rk" arg)) )
     (setq str (skk-kakasi-region start end arg))
-    (combine-after-change-calls
-      (delete-region start end)
-      (goto-char start)
-      (insert str) )
-    (skk-set-cursor-properly) ))
+    (delete-region start end)
+    (goto-char start)
+    (insert-and-inherit str) )
+  (skk-set-cursor-properly) )
 
-;;;###skk-autoload
+;;;###autoload
 (defun skk-romaji-message (start end)
   "$B%j!<%8%g%s$N4A;z!"$R$i$,$J!"%+%?%+%J!"A41QJ8;z$rA4$F%m!<%^;z$KJQ49$7!"%(%3!<$9$k!#(B
 $BJQ49$K$O!"%X%\%s<0$rMQ$$$k!#(B
         (setq arg (cons "-c" arg)) )
     (if (not skk-romaji-*-by-hepburn)
         (setq arg (cons "-rk" arg)) )
-    (message (skk-kakasi-region start end arg))
+    (message "%s" (skk-kakasi-region start end arg))
     (skk-set-cursor-properly) ))
 
 (defun skk-kakasi-region (start end arglist)
   ;; START $B$H(B END $B4V$N%j!<%8%g%s$KBP$7(B kakasi $B%3%^%s%I$rE,MQ$9$k!#(BARGLIST $B$r(B
   ;; kakasi $B$N0z?t$H$7$FEO$9!#(Bkakasi $B$N=PNO$rJV$9!#(B
-  (if (not skk-use-kakasi)
+  (or skk-use-kakasi skk-kakasi-command
       (skk-error "KAKASI $B$,%$%s%9%H!<%k$5$l$F$$$J$$$+!";HMQ$7$J$$@_Dj$K$J$C$F$$$^$9!#(B"
                  "KAKASI was not installed, or skk-use-kakasi is nil" ) )
-  (let ((str (skk-buffer-substring start end)))
+  (let ((str (buffer-substring-no-properties start end)))
         ;; $BIQEY>pJs$r;H$C$F2?$+$*$b$7$m$$;H$$J}$,$G$-$k$+$J!)(B  $B8=>u$G$O;H$C$F(B
         ;; $B$$$J$$!#(B
         ;;(hindo-file (skk-make-temp-file "skkKKS"))
       ;; $B$r8F$V$H(B destination buffer $B$rJL$K;XDj$7$F$$$F$b%(%i!<$K$J$k$N$G!"%j!<(B
       ;; $B%8%g%s$NJ8;zNs$r%o!<%/%P%C%U%!$KB`Hr$9$k!#(B
       (insert str)
-      (if (and (eq (apply 'call-process-region (point-min) (point) "kakasi"
+      (if (and (eq (apply 'call-process-region (point-min) (point)
+			  skk-kakasi-command
                           ;; kakasi-2.2.5.hindo.diff $B$,Ev$C$F$$$k$HI8=`%(%i!<(B
                           ;; $B=PNO$KIQEY>pJs$,=PNO$5$l$k!#(B
                           'delete-original-text