Fix memory leak issues
[platform/core/uifw/anthy.git] / src-util / anthy-isearch.el
1 ;; anthy-isearch.el -- Anthy
2
3 ;; Copyright (C) 2003
4 ;; Author: Yusuke Tabata <yusuke@cherbim.icw.co.jp>
5
6 ;; DO NOT USE NOW.
7 ;;
8
9 ;;; Commentary:
10 ;; TOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO many things to be implemented.
11 ;; most of the code is stolen from SKK.
12 ;; for Emacs-21
13
14 (require 'anthy)
15
16 (defvar anthy-isearch-mode-map nil)
17
18 ;; \e$B8!:wBP>]$NJ8;zNs$H%W%j%(%G%#%C%H$rF~$l$k%P%C%U%!\e(B
19 (defconst anthy-isearch-working-buffer " *anthy-isearch*")
20
21 ;; \e$B8!:wBP>]$NJ8;zNs$r<hF@$9$k\e(B
22 (defun anthy-isearch-search-string ()
23   (with-current-buffer (get-buffer-create anthy-isearch-working-buffer)
24     (if (string-equal anthy-preedit "")
25         ;; \e$B%W%j%(%G%#%C%H$,L5$$;~$O\e(B
26         (buffer-string)
27       (save-restriction
28         (narrow-to-region (point-min) anthy-preedit-start)
29         (buffer-string)))))
30
31 ;; \e$B8!:wBP>]$NJ8;zNs\e(B + \e$BF~NOESCf$NJ8;zNs\e(B
32 (defun anthy-isearch-search-message ()
33   (with-current-buffer (get-buffer-create anthy-isearch-working-buffer)
34     (buffer-string)))
35
36 (defun anthy-isearch-process-search-string (string msg)
37   (setq isearch-string "")
38   (setq isearch-message "")
39   (isearch-process-search-string string msg))
40
41 (defun anthy-isearch-raw-input ()
42   (with-current-buffer (get-buffer-create anthy-isearch-working-buffer)
43     (self-insert-command 1)))
44
45 (defun anthy-isearch-wrapper (&rest args)
46   (interactive "P")
47   (if current-input-method
48       (with-current-buffer (get-buffer-create anthy-isearch-working-buffer)
49         (anthy-insert))
50     (anthy-isearch-raw-input))
51   (anthy-isearch-process-search-string
52    (anthy-isearch-search-string)
53    (anthy-isearch-search-message)))
54
55 (defun anthy-isearch-keyboard-quit (&rest args)
56   (interactive "P")
57   (let ((p nil))
58     (with-current-buffer (get-buffer-create anthy-isearch-working-buffer)
59       (if (not (string-equal "" anthy-preedit))
60           (setq p t)))
61     (if p
62         (anthy-isearch-wrapper)
63       (progn
64         (setq isearch-string "")
65         (setq isearch-message "")
66         (isearch-abort)))))
67
68 (defun anthy-isearch-toggle-input-method (&rest args)
69   (interactive "P")
70   (isearch-toggle-input-method))
71
72 (defun anthy-isearch-setup-keymap (map)
73   (let ((i 0))
74     (while (< i 127)
75       (define-key map (char-to-string i) 'anthy-isearch-wrapper)
76       (setq i (+ 1 i)))
77     (define-key map "\C-g" 'anthy-isearch-keyboard-quit)
78     (substitute-key-definition
79      'isearch-toggle-input-method 
80      'anthy-isearch-toggle-input-method
81      map isearch-mode-map)
82     map))
83
84 (defun anthy-isearch-mode-setup ()
85   ;; \e$B:G=i$O%-!<%^%C%W$r=`Hw$9$k\e(B
86   (or (keymapp anthy-isearch-mode-map)
87       (setq anthy-isearch-mode-map
88             (anthy-isearch-setup-keymap (copy-keymap isearch-mode-map))))
89   ;;
90   (setq overriding-terminal-local-map anthy-isearch-mode-map)
91   (with-current-buffer (get-buffer-create anthy-isearch-working-buffer)
92     (erase-buffer))
93   ())
94
95 (defun anthy-isearch-mode-cleanup ()
96   (setq overriding-terminal-local-map nil)
97   (kill-buffer anthy-isearch-working-buffer)
98   ())
99
100 (add-hook 'isearch-mode-hook 'anthy-isearch-mode-setup)
101 (add-hook 'isearch-mode-end-hook 'anthy-isearch-mode-cleanup)
102 (setq debug-on-error 't)