;;;
;;; $Id: addruby.el,v 1.3 2004/04/19 05:21:55 yamauchi Exp $
;;;
;;; addruby.el ... add hiragana rubi.
;;;
;;; Author:     YAMAUCHI, Hitoshi »³Æâ ÀÆ 
;;;             <yamauchi_ at _mpi-sb.mpg.de.replace.at>
;;; Maintainer: YAMAUCHI, Hitoshi »³Æâ ÀÆ 
;;;             <yamauchi_ at _mpi-sb.mpg.de.replace.at>
;;; Updated: 2004-4-19(Mon)
;;; Version: 0.0.0
;;; Keywords: text processing, notation, ruby, furigana
;;;
;;; Copyright Notice.
;;;
;;; Copyright (C) 2004 YAMAUCHI, Hitoshi »³Æâ ÀÆ 
;;; All rights reserved.
;;;
;;; This program 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
;;; 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.
;;;
;;; Contributors : Thanks a lot.
;;;
;;; Example (In English). 
;;;
;;; The Chinese character is an ideogram character. Therefore when you
;;; see a character, you know what it means, but you do not know
;;; how to pronounce it. You know the mean but you can not read
;;; (sound) it. It is like Arabic number. For example: `1'. This is
;;; pronounced: English `one', Deutsch `eins', Japanese `ichi/hii',
;;; Korean `iru/hana' and so on.
;;;
;;; So, Some students need how to read these charactors. This program
;;; helps to input such pronounciation.
;;;
;;; Example 1. (English). 
;;; 
;;;    1/2 -> 1/2(half)
;;;    1/2 -> 1/2(one over two)
;;; 
;;; Example 2. (Japanese). (The code is EUC.)
;;;	
;;;   »ÐËå -> »ÐËå(¤·¤Þ¤¤) / »ÐËå(simai) 
;;;
;;; Example 3. You can set up with addruby-*-text as follows. This is
;;; easy way to add TeX ruby command.
;;;
;;;  (setq addruby-prefix-from-text "\\ruby{")
;;;  (setq addruby-postfix-from-text "}")
;;;  (setq addruby-prefix-to-text "{")
;;;  (setq addruby-postfix-to-text "}")
;;; 
;;;   »ÐËå -> \ruby{»ÐËå}{¤·¤Þ¤¤}
;;;
;;------------------------------------------------------------
;; for debug 
;;------------------------------------------------------------
;; delete at release
;;(setq debug-on-error t)
;;(defun dbg (mes) (print mes (get-buffer "addruby-debug")))

;;------------------------------------------------------------
;; constant values
;;------------------------------------------------------------
(defconst addruby-version-num "0.0.0" 
  "The version of addruby.")

(defconst addruby-day "2004-4-19"
  "The day of last change of addruby.el.")

;;------------------------------
;; What kind of emacs is this?
;;------------------------------
;(defconst addruby-xemacs-p
;  (and (featurep 'mule) (string-match "XEmacs" emacs-version))
;  "Non-nil when running on XEmacs.")

;;------------------------------------------------------------
;; customize values
;;------------------------------------------------------------
(defvar addruby-prefix-from-text ""
  "* prefix of from text. (default `'")
(make-variable-buffer-local 'addruby-prefix-from-text)

(defvar addruby-postfix-from-text ""
  "* postfix of from text. (default `'")
(make-variable-buffer-local 'addruby-postfix-to-text)

(defvar addruby-prefix-to-text "("
  "* prefix of to text. (default `(')")
(make-variable-buffer-local 'addruby-prefix-to-text)

(defvar addruby-postfix-to-text ")"
  "* postfix of to text. (default `)')")
(make-variable-buffer-local 'addruby-postfix-to-text)

;;;------------------------------------------------------------
;;; addruby version
;;;------------------------------------------------------------
;(defun addruby-show-version ()
;  "Print addruby version."
;  (interactive)
;  (cond ((interactive-p)
;         (message "addruby version %s of %s" 
;		  addruby-version-num addruby-build-day))))

;;
;; generate destination string
;;
(defun addruby-get-tostr (fromstr tostr)
  "(addruby internal) make a complete tostr."
  (let ((fstr "")
	(tstr ""))
    (setq fstr (format "%s%s%s" 
		       addruby-prefix-from-text 
		       fromstr
		       addruby-postfix-from-text))
    (setq tstr (format "%s%s%s" 
		       addruby-prefix-to-text 
		       tostr
		       addruby-postfix-to-text))
    (format "%s%s" fstr tstr)))

;;
;; add ruby command
;;
(defun addruby-add-ruby-replace-command (beg end)
  "insert ruby"
  (interactive "r")
  (let ((fromstr "") 
	(tostr   ""))
    (setq fromstr (buffer-substring beg end))
    (setq tostr 
	  (read-from-minibuffer 
	   (format "replace %s with %s, str = " 
		   fromstr 
		   (addruby-get-tostr fromstr "str"))))
    ;; if region is active, then query-replace works only in the region
    (zmacs-deactivate-region)		
    ;; replace position is starts with beg point.
    (goto-char beg)
    ;; replace from beg to the end of buffer.
    (query-replace fromstr (addruby-get-tostr fromstr tostr))))
     

(provide 'addruby)
;; end of addrub.el ------------------------------
