root/trunk/lisp/international/meadow.el

Revision 4239, 17.8 kB (checked in by gotoh, 7 months ago)

* x-selection-exists-p: Remove alias beause of switching to use
w32select.c instead of obsoleted mw32clpbd.c. (ticket #390)

  • Property svn:eol-style set to LF
Line 
1 ;; -*- mode: Emacs-Lisp; coding: iso-2022-7bit-unix -*-
2 ;;
3 ;;   Author H.Miyashita
4 ;;
5 ;;;;;
6
7 (defgroup Meadow nil
8   "Meadow"
9   :group 'emacs)
10
11 (defvar mw32-last-selection nil
12   "It is stored the last data from Emacs.")
13
14 ;;;
15 ;;; image function
16 ;;;
17
18 (defun init-image-library (type image-library-alist)
19   (and (boundp 'image-types) (not (null (memq type image-types)))))
20
21 (defun display-images-p (&optional display)
22   "Return non-nil if DISPLAY can display images.
23
24 DISPLAY can be a display name, a frame, or nil (meaning the selected
25 frame's display).
26
27 This function is overridden by Meadow."
28   (and (display-graphic-p display)
29        (fboundp 'image-mask-p)
30        (fboundp 'image-size)))
31
32 (add-hook
33  'before-init-hook
34  (lambda ()
35    ;; BMP support
36    (require 'image)
37    (require 'image-file)
38
39    (or (rassq 'bmp image-type-header-regexps)
40        (setq image-type-header-regexps
41              (cons (cons "\\`BM" 'bmp) image-type-header-regexps)))
42    (or (member "bmp" image-file-name-extensions)
43        (setq image-file-name-extensions
44              (cons "bmp" image-file-name-extensions)))
45
46    ;; append extra extensions
47    (mapcar
48     (lambda (type)
49       (unless (or (member type '("txt" "shtml" "html" "htm"))
50                   (member type image-file-name-extensions))
51         (setq image-file-name-extensions
52               (cons type image-file-name-extensions))))
53     (mw32-get-image-magick-extensions))))
54
55 ;;;
56 ;;; overwrite appearances
57 ;;;
58
59 ;;(set-face-background 'modeline "LightBlue")
60
61 ;; Highlighting is only shown after moving the mouse, while keyboard
62 ;; input turns off the highlight even when the mouse is over the
63 ;; clickable text.
64 (setq mouse-highlight 1)
65
66 ;;;
67 ;;; overwrite splash handling
68 ;;;
69
70 (defvar mw32-splash-masked-p nil
71   "If non-nil, show a splash screen of Meadow with a heuristic mask.")
72
73 (defun use-fancy-splash-screens-p ()
74   "Return t if fancy splash screens should be used."
75   (when (image-type-available-p 'bmp)
76     (let* ((img (create-image (or fancy-splash-image
77                                   "meadow.bmp") 'bmp))
78            (image-height (and img (cdr (image-size img))))
79            (window-height (1- (window-height (selected-window)))))
80       (> window-height (+ image-height 15)))))
81
82 (defun fancy-splash-head ()
83   "Insert the head part of the splash screen into the current buffer."
84   (let* ((image-file (or fancy-splash-image
85                          "meadow.bmp"))
86          (img (create-image image-file
87                             'bmp
88                             nil :heuristic-mask mw32-splash-masked-p))
89          (image-width (and img (car (image-size img))))
90          (window-width (window-width (selected-window))))
91     (when img
92       (when (> window-width image-width)
93         ;; Center the image in the window.
94         (let ((pos (/ (- window-width image-width) 2)))
95           (insert (propertize " " 'display `(space :align-to ,pos))))
96
97         ;; Insert the image with a help-echo and a keymap.
98         (let ((map (make-sparse-keymap))
99               (help-echo "mouse-2: browse http://www.meadowy.org/"))
100           (define-key map [mouse-2]
101             (lambda ()
102               (interactive)
103               (browse-url "http://www.meadowy.org/")
104               (throw 'exit nil)))
105           (define-key map [down-mouse-2] 'ignore)
106           (define-key map [up-mouse-2] 'ignore)
107           (insert-image img (propertize "xxx" 'help-echo help-echo
108                                         'keymap map)))
109         (insert "\n"))))
110   (insert "Meadow is based on GNU Emacs.\n")
111   (if (eq system-type 'gnu/linux)
112       (fancy-splash-insert
113        :face '(variable-pitch :foreground "red")
114        "GNU Emacs is one component of a Linux-based GNU system.")
115     (fancy-splash-insert
116      :face '(variable-pitch :foreground "red")
117      "GNU Emacs is one component of the GNU operating system."))
118   (insert "\n"))
119
120 (defun fancy-splash-tail ()
121   "Insert the tail part of the splash screen into the current buffer."
122   (let ((fg (if (eq (frame-parameter nil 'background-mode) 'dark)
123                 "cyan" "darkblue")))
124     (fancy-splash-insert :face `(variable-pitch :foreground ,fg)
125                          "\nThis is "
126                          (Meadow-version)
127                          "\n based on "
128                          (emacs-version)
129                          "\n"
130                          :face '(variable-pitch :height 0.5)
131                          "Copyright (C) 2001 Free Software Foundation, Inc.\n"
132                          "Copyright (C) 1995-2001 MIYASHITA Hisashi\n"
133                          "Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 The Meadow Team")))
134
135 ;;;
136 ;;; Meadow MW32-IME API.
137 ;;;
138
139 (defvar mw32-ime-on-hook nil
140   "Functions to eval when IME is turned on at least.
141 Even if IME state is not changed, these functiona are maybe called.")
142 (defvar mw32-ime-off-hook nil
143   "Functions to eval when IME is turned off at least.
144 Even if IME state is not changed, these functiona are maybe called.")
145 (defvar mw32-ime-buffer-switch-p t
146   "If this variable is nil, IME control when buffer is switched is disabled.")
147 (defvar mw32-ime-show-mode-line nil
148   "When t, mode line indicates IME state.")
149 (defvar mw32-ime-mode-line-state-indicator "[O]"
150   "This is shown at the mode line. It is regarded as state of ime.")
151 (make-variable-buffer-local 'mw32-ime-mode-line-state-indicator)
152 (put 'mw32-ime-mode-line-state-indicator 'permanent-local t)
153 (defvar mw32-ime-mode-line-state-indicator-list '("-" "[|]" "[O]")
154   "List of IME state indicator string.")
155 (defvar mw32-ime-mode-line-format-original nil
156   "Original mode line format.")
157 (defvar mw32-ime-cont-on 'always
158 "If not nil, IME is always on during current-input-method is MW32-IME
159 on the ordinary buffer.")
160 (defvar mw32-input-method-noconv-regexp nil
161   "Regexp represents printable-chars that does not activate IME.")
162
163 (setq search-highlight t)
164
165 ;;;
166 ;;; Emulation functions.
167 ;;;
168
169 ;;
170 ;; Section: General definitions
171 ;;
172
173 (defvar w32-fiber-program-name "fiber.exe")
174 (defvar w32-fiber-process-name "*fiber*")
175
176 (defun wildcard-to-regexp (pattern)
177   (let ((i 0)
178         (len (length pattern))
179         (quotestr "")
180         (result "")
181         char
182         result)
183     (while (< i len)
184       (setq char (aref pattern i)
185             i (1+ i))
186       (cond ((= char ?*)
187              (setq result (concat result (regexp-quote quotestr) ".*")
188                    quotestr ""))
189             ((= char ??)
190              (setq result (concat result (regexp-quote quotestr) ".")
191                    quotestr ""))
192             (t
193              (setq quotestr (concat quotestr (char-to-string char))))))
194     (concat "\\`" result (regexp-quote quotestr) "\\'")))
195
196 ;;
197 ;; Section: Font
198 ;;
199
200 (defun w32-list-fonts (pattern &optional face frame max)
201   (setq pattern (wildcard-to-regexp pattern))
202   (if (null max) (setq max 2000))
203   (let ((curfl (w32-font-list))
204         curfs
205         result)
206   (while (and (> max 0)
207               (setq curfs (car curfl)))
208       (if (string-match pattern curfs)
209           (setq result (cons curfs result)
210                 max (1- max)))
211       (setq curfl (cdr curfl)))
212   result))
213
214 (defalias 'x-list-fonts 'w32-list-fonts)
215
216 ;;
217 ;; Section: X file dialog
218 ;;
219
220 (defalias 'x-file-dialog 'mw32-file-dialog)
221
222 ;;; Section: focus frame
223
224 (defalias 'w32-focus-frame 'x-focus-frame)
225
226 ;;
227 ;; Section: Shell execute
228 ;;
229
230 (defun w32-shell-execute (operation document &optional parameters show-flag)
231   (if (and show-flag
232           (not (numberp show-flag)))
233       (error "show-flag must be number or nil:%S" show-flag))
234   (let ((coding-system-for-write locale-coding-system)
235         (args (append
236                (list document)
237                (list "-b" operation)
238                (list "-d" default-directory)
239                (if parameters
240                    (list "-p" parameters))
241                (if show-flag
242                    (list "-n" (number-to-string show-flag))))))
243     (apply 'call-process w32-fiber-program-name nil 0 nil
244            args)))
245
246 ;;
247 ;; Section: IME
248 ;;
249
250 ;; This is temporal solution.  In the future, we will prepare
251 ;; dynamic configuration.
252 (defvar mw32-ime-coding-system-language-environment-alist
253   '(("Japanese" . japanese-shift-jis)
254     ("Chinese-GB" . chinese-iso-8bit)
255     ("Chinese-BIG5" . chinese-big5)
256     ("Korean" . korean-iso-8bit)))
257
258 ;; This is temporal solution.
259 (defvar mw32-locale-ime-alist
260   '((("japanese" . 1041) . "MW32-IME")))
261 ;;    (("korean-hangul" . 1042) . "MW32-IME")))
262
263 (defun mw32-set-ime-if-available ()
264   (let ((ime (assoc (cons default-input-method (mw32-input-language-code))
265                     mw32-locale-ime-alist)))
266     (when (and ime (mw32-ime-available))
267         (setq default-input-method (cdr ime))
268         (mw32-ime-initialize)
269         (define-key global-map [kanji] 'toggle-input-method))))
270
271 ;;
272 ;; IME state indicator
273 ;;
274 (global-set-key [kanji] 'ignore)
275 (global-set-key [compend] 'ignore)
276
277 (defun wrap-function-to-control-ime
278   (function interactive-p interactive-arg &optional suffix)
279   "Wrap FUNCTION, and IME control is enabled when FUNCTION is called.
280 An original function is saved to FUNCTION-SUFFIX when suffix is string.
281 If SUFFIX is nil, \"-original\" is added. "
282   (let ((original-function
283          (intern (concat (symbol-name function)
284                          (if suffix suffix "-original")))))
285     (cond
286      ((not (fboundp original-function))
287       (fset original-function
288             (symbol-function function))
289       (fset function
290             (list
291              'lambda '(&rest arguments)
292              (when interactive-p
293                (list 'interactive interactive-arg))
294              (`(cond
295                 ((and (fep-get-mode)
296                       (equal current-input-method "MW32-IME"))
297                  (fep-force-off)
298                  (run-hooks 'mw32-ime-off-hook)
299                  (unwind-protect
300                      (apply '(, original-function) arguments)
301                    (when (and (not (fep-get-mode))
302                               (equal current-input-method "MW32-IME"))
303                      (fep-force-on)
304                      (run-hooks 'mw32-ime-on-hook))))
305                 (t
306                  (apply '(, original-function)
307                         arguments))))))))))
308
309 (defvar mw32-ime-toroku-region-yomigana nil
310   "* if this variable is string, toroku-region regard this value as yomigana.")
311
312 (defun mw32-ime-toroku-region (begin end)
313   (interactive "r")
314   (let ((string (buffer-substring begin end))
315         (mw32-ime-buffer-switch-p nil)
316         (reading mw32-ime-toroku-region-yomigana))
317     (unless (stringp reading)
318       (w32-set-ime-mode 'hiragana)
319       (setq reading
320             (read-multilingual-string
321              (format "Input reading of \"%s\":" string) nil "MW32-IME")))
322     (w32-ime-register-word-dialog reading string)))
323
324 ;; for IME management system.
325
326 (defun mw32-ime-sync-state (window)
327   (when (and mw32-ime-buffer-switch-p
328              this-command
329              (not mw32-ime-composition-window))
330     (with-current-buffer (window-buffer window)
331       (if (window-minibuffer-p)
332           (fep-force-off)
333         (let* ((frame (window-frame window)))
334           (if (string= current-input-method "MW32-IME")
335               (run-hooks 'mw32-ime-on-hook)
336             (run-hooks 'mw32-ime-off-hook))
337           (if mw32-ime-cont-on
338               (if (string= current-input-method "MW32-IME")
339                   (if (or (eq mw32-ime-cont-on 'always)
340                           (eq input-method-function 'mw32-input-method))
341                       (fep-force-on))
342                 (fep-force-off))))))))
343
344 (defun mw32-ime-set-selected-window-buffer-hook (oldbuf newwin newbuf)
345   (mw32-ime-sync-state newwin))
346
347 (defun mw32-ime-select-window-hook (old new)
348   (mw32-ime-sync-state new))
349
350 (defun mw32-ime-mode-line-update ()
351   (cond
352    (mw32-ime-show-mode-line
353     (unless (window-minibuffer-p)
354       (setq mw32-ime-mode-line-state-indicator
355             (nth (if (fep-get-mode) 1 2)
356                  mw32-ime-mode-line-state-indicator-list))))
357    (t
358     (setq mw32-ime-mode-line-state-indicator
359           (nth 0 mw32-ime-mode-line-state-indicator-list))))
360   (force-mode-line-update))
361
362 (defun mw32-ime-init-mode-line-display ()
363   (when (and mw32-ime-show-mode-line
364              (not (member 'mw32-ime-mode-line-state-indicator
365                           mode-line-format)))
366     (setq mw32-ime-mode-line-format-original
367           (default-value 'mode-line-format))
368     (if (and (stringp (car mode-line-format))
369              (string= (car mode-line-format) "-"))
370         (setq-default mode-line-format
371                       (cons ""
372                             (cons 'mw32-ime-mode-line-state-indicator
373                                   (cdr mode-line-format))))
374       (setq-default mode-line-format
375                     (cons ""
376                           (cons 'mw32-ime-mode-line-state-indicator
377                                 mode-line-format))))
378     (force-mode-line-update t)))
379
380 ;;; mw32-ime-toggle and mw32-ime-initialize are obsolete.
381 ;;; These functions left here for backward compatibility.
382 (defun mw32-ime-toggle ()
383   "This is obsoleted function."
384   (interactive)
385   (if (equal current-input-method "MW32-IME")
386       (inactivate-input-method)
387     (activate-input-method "MW32-IME")))
388
389 (defun mw32-ime-initialize ()
390   "Initialize MW32-IME. It is unnecessary to call this function explicitly."
391   (cond
392    ((and (eq system-type 'windows-nt)
393          (eq window-system 'w32)
394          (featurep 'meadow))
395     (let ((coding-system
396            (assoc-string current-language-environment
397                          mw32-ime-coding-system-language-environment-alist
398                          t)))
399       (unless default-input-method
400         (setq default-input-method "MW32-IME"))
401       (mw32-ime-init-mode-line-display)
402       (mw32-ime-mode-line-update)
403       (add-hook 'select-window-functions 'mw32-ime-select-window-hook)
404       (add-hook 'set-selected-window-buffer-functions
405                 'mw32-ime-set-selected-window-buffer-hook)
406
407       (add-hook 'isearch-mode-hook 'mw32-isearch-mode-hook-function)
408       (defadvice isearch-toggle-input-method (after mw32-fep-off activate)
409         "Deactivate fep when mw32-ime-cont-on is not nil."
410         (if (eq mw32-ime-cont-on t) (fep-force-off)))
411       (defadvice isearch-done (after mw32-fep-on activate)
412         "Deactivate fep when mw32-ime-cont-on is not nil."
413         (if (and mw32-ime-cont-on
414                  (string= current-input-method "MW32-IME"))
415             (fep-force-on)
416           (fep-force-off))
417         (setq mw32-ime-composition-window nil))))))
418
419 (defun mw32-isearch-update ()
420   (interactive)
421   (isearch-update))
422
423 (defun mw32-isearch-mode-hook-function ()
424   (cond
425    ((eq mw32-ime-cont-on t)
426     (fep-force-off))
427    ((eq mw32-ime-cont-on 'always)
428     (setq mw32-ime-composition-window (minibuffer-window))))
429   (define-key isearch-mode-map [kanji] 'isearch-toggle-input-method)
430   (define-key isearch-mode-map [compend] 'mw32-isearch-update))
431
432
433 (defun mw32-ime-uninitialize ()
434   (cond ((and (eq system-type 'windows-nt)
435               (eq window-system 'w32)
436               (featurep 'meadow))
437          (setq-default mode-line-format
438                        mw32-ime-mode-line-format-original)
439          (force-mode-line-update t)
440          (remove-hook 'select-window-functions
441                       'mw32-ime-select-window-hook)
442          (remove-hook 'set-selected-window-buffer-functions
443                       'mw32-ime-set-selected-window-buffer-hook)
444          (remove-hook 'isearch-mode-hook 'mw32-isearch-mode-hook-function)
445          (defadvice isearch-toggle-input-method (after mw32-fep-off disable))
446          (defadvice isearch-done (after mw32-fep-on disable)))))
447
448 (defun mw32-ime-exit-from-minibuffer ()
449   (inactivate-input-method)
450   (when (<= (minibuffer-depth) 1)
451     (remove-hook 'minibuffer-exit-hook 'mw32-ime-exit-from-minibuffer)))
452
453 (defun mw32-ime-state-switch (&optional arg)
454   (kill-local-variable 'input-method-function)
455   (if (fep-get-mode)
456       (fep-force-off))
457   (if arg
458       (progn
459         (when (null (memq 'mw32-ime-select-window-hook
460                           select-window-functions))
461           (mw32-ime-initialize))
462         (setq inactivate-current-input-method-function
463               'mw32-ime-state-switch)
464         (run-hooks 'input-method-activate-hook)
465         (run-hooks 'mw32-ime-on-hook)
466         (setq describe-current-input-method-function nil)
467         (when (window-minibuffer-p)
468           (add-hook 'minibuffer-exit-hook 'mw32-ime-exit-from-minibuffer))
469         (make-local-variable 'input-method-function)
470         (if (not (eq mw32-ime-cont-on 'always))
471             (setq input-method-function 'mw32-input-method))
472         (if mw32-ime-cont-on
473             (fep-force-on)))
474     (setq current-input-method nil)
475     (run-hooks 'input-method-inactivate-hook)
476     (run-hooks 'mw32-ime-off-hook)
477     (setq describe-current-input-method-function nil))
478   (mw32-ime-mode-line-update))
479
480 (register-input-method "MW32-IME" "Japanese" 'mw32-ime-state-switch "A$B$"(B"
481                        "MW32 System IME")
482
483
484 ;;;
485 ;;; Inspect Device Capability/Intrinsic Facilities
486 ;;;                Emulation layer for functions of xfuns.c
487
488 (defsubst mw32-emulate-x-display-argument (display)
489   (cond ((stringp display) nil)
490         ((framep display) display)
491         ((null display) display)
492         (t
493          (error "%S must be STRING or FRAME" display))))
494
495 (defun x-display-pixel-width (&optional display)
496   (mw32-get-device-capability
497    'width
498    (mw32-emulate-x-display-argument display)))
499 (defun x-display-pixel-height (&optional display)
500   (mw32-get-device-capability
501    'height
502    (mw32-emulate-x-display-argument display)))
503 (defun x-display-planes (&optional display)
504   (mw32-get-device-capability
505    ;; Notice that the meaning of "PLANES" in X are different
506    ;; from that in Windows.
507    'color-bits
508    (mw32-emulate-x-display-argument display)))
509 (defun x-display-mm-height (&optional display)
510   (mw32-get-device-capability
511    'height-in-mm
512    (mw32-emulate-x-display-argument display)))
513 (defun x-display-mm-width (&optional display)
514   (mw32-get-device-capability
515    'width-in-mm
516    (mw32-emulate-x-display-argument display)))
517 (defun x-display-visual-class (&optional display)
518   (let ((c (x-display-planes display))
519         (n (mw32-get-device-capability
520             'colors)))
521     (cond ((eq n 'full) 'true-color)
522           ((= n 1) 'static-gray)
523           ((> c (log c n)) 'pseudo-color)
524           (t 'static-color))))
525
526 (defun mw32-input-method (key)
527   "Input method function for IME."
528   (if (or
529        (let ((case-fold-search nil))
530          (and key
531               mw32-input-method-noconv-regexp
532               (string-match mw32-input-method-noconv-regexp
533                             (char-to-string key))))
534        (fep-get-mode))
535       (list key)
536     (let ((redisplay-dont-pause t))
537       (sit-for 0))
538
539     (let* ((pos (point))
540            (modified-p (buffer-modified-p))
541            (ov (make-overlay (point) (1+ (point))))
542            (redisplay-dont-pause t)
543            ret result)
544       (unwind-protect
545           (progn
546             (setq ret  (mw32-ime-input-method-function (char-to-string key)))
547             (setq result (append (car ret) nil))
548             (while (> (length (cadr ret)) 1)
549               (insert (car ret))
550               (move-overlay ov pos (point))
551               (if input-method-highlight-flag
552                   (overlay-put ov 'face 'underline))
553               (sit-for 0)
554               (setq ret (mw32-ime-input-method-function))
555               (setq result (append result (append (car ret) nil)))))
556         (if (and (cadr ret)
557                  (eq (length (cadr ret)) 1))
558             (progn
559               (setq unread-input-method-events
560                     (cons (car (cddr ret)) unread-input-method-events))))
561         (delete-region pos (point))
562         (delete-overlay ov)
563         (set-buffer-modified-p modified-p))
564       result)))
565
566 ;; dummy vals.
567 (defun x-server-max-request-size (&optional display) 65535)
568 (defun x-server-vendor (&optional display) "MW32")
569 (defun x-server-version (&optional display) (list 11 0 1))
570 ;; We should use multi-monitor APIs in the future.
571 (defun x-display-screens (&optional display) 1)
572 (defun x-display-backing-store (&optional display) 'not-useful)
573 (defun x-display-save-under (&optional display) nil)
574
575 (provide 'meadow)
576
Note: See TracBrowser for help on using the browser.