Ticket #30694: patch-macemacsjp-inline.diff

File patch-macemacsjp-inline.diff, 37.2 KB (added by humem (humem), 13 years ago)
Line 
1diff -r -p -x '*.elc' ../emacs-23.2.94-0/lisp/term/ns-win.el lisp/term/ns-win.el
2*** ../emacs-23.2.94-0/lisp/term/ns-win.el      2011-01-27 05:35:09.000000000 +0900
3--- lisp/term/ns-win.el 2011-02-28 13:08:01.000000000 +0900
4*************** The properties returned may include `top
5*** 317,322 ****
6--- 317,323 ----
7             (cons (logior (lsh 0 16)  12) 'ns-new-frame)
8             (cons (logior (lsh 0 16)  13) 'ns-toggle-toolbar)
9             (cons (logior (lsh 0 16)  14) 'ns-show-prefs)
10+            (cons (logior (lsh 0 16)  15) 'mac-change-input-method)
11             (cons (logior (lsh 1 16)  32) 'f1)
12               (cons (logior (lsh 1 16)  33) 'f2)
13               (cons (logior (lsh 1 16)  34) 'f3)
14*************** The properties returned may include `top
15*** 549,562 ****
16  ;; editing window.)
17 
18  (defface ns-working-text-face
19!   '((t :underline t))
20    "Face used to highlight working text during compose sequence insert."
21    :group 'ns)
22 
23  (defvar ns-working-overlay nil
24    "Overlay used to highlight working text during compose sequence insert.
25  When text is in th echo area, this just stores the length of the working text.")
26 
27  (defvar ns-working-text)              ; nsterm.m
28 
29  ;; Test if in echo area, based on mac-win.el 2007/08/26 unicode-2.
30--- 550,579 ----
31  ;; editing window.)
32 
33  (defface ns-working-text-face
34!   '((((background dark)) :underline "gray80")
35!     (t :underline "gray20"))
36    "Face used to highlight working text during compose sequence insert."
37    :group 'ns)
38 
39+ (defface ns-marked-text-face
40+   '((((background dark)) :underline "gray80")
41+     (t :underline "gray20"))
42+   "Face used to highlight marked text during compose sequence insert."
43+   :group 'ns)
44+
45+ (defface ns-unmarked-text-face
46+   '((((background dark)) :underline "gray20")
47+     (t :underline "gray80"))
48+   "Face used to highlight marked text during compose sequence insert."
49+   :group 'ns)
50+
51  (defvar ns-working-overlay nil
52    "Overlay used to highlight working text during compose sequence insert.
53  When text is in th echo area, this just stores the length of the working text.")
54 
55+ (defvar ns-marked-overlay nil
56+   "Overlay used to highlight marked text during compose sequence insert.")
57+
58  (defvar ns-working-text)              ; nsterm.m
59 
60  ;; Test if in echo area, based on mac-win.el 2007/08/26 unicode-2.
61*************** is currently being used."
62*** 583,588 ****
63--- 600,606 ----
64  (defun ns-put-working-text ()
65    (interactive)
66    (if (ns-in-echo-area) (ns-echo-working-text) (ns-insert-working-text)))
67+
68  (defun ns-unput-working-text ()
69    (interactive)
70    (ns-delete-working-text))
71*************** The overlay is assigned the face `ns-wor
72*** 604,622 ****
73  (defun ns-echo-working-text ()
74    "Echo contents of `ns-working-text' in message display area.
75  See `ns-insert-working-text'."
76-   (ns-delete-working-text)
77    (let* ((msg (current-message))
78!        (msglen (length msg))
79!        message-log-max)
80      (setq ns-working-overlay (length ns-working-text))
81      (setq msg (concat msg ns-working-text))
82      (put-text-property msglen (+ msglen ns-working-overlay)
83!                      'face 'ns-working-text-face msg)
84      (message "%s" msg)))
85 
86  (defun ns-delete-working-text()
87!   "Delete working text and clear `ns-working-overlay'."
88    (interactive)
89    (cond
90     ((and (overlayp ns-working-overlay)
91           ;; Still alive?
92--- 622,700 ----
93  (defun ns-echo-working-text ()
94    "Echo contents of `ns-working-text' in message display area.
95  See `ns-insert-working-text'."
96    (let* ((msg (current-message))
97!          (msglen (length msg))
98!          message-log-max)
99!     (if (integerp ns-working-overlay)
100!       (progn
101!         (setq msg (substring msg 0 (- (length msg) ns-working-overlay)))
102!         (setq msglen (length msg))))
103      (setq ns-working-overlay (length ns-working-text))
104      (setq msg (concat msg ns-working-text))
105      (put-text-property msglen (+ msglen ns-working-overlay)
106!                       'face 'ns-working-text-face msg)
107!      (message "%s" msg)))
108!
109! (defun ns-put-marked-text (event)
110!   (interactive "e")
111!
112!   (let ((pos (nth 1 event))
113!       (len (nth 2 event)))
114!     (if (ns-in-echo-area)
115!       (ns-echo-marked-text pos len)
116!       (ns-insert-marked-text pos len))))
117!
118! (defun ns-insert-marked-text (pos len)
119!   "Insert contents of `ns-working-text' as UTF-8 string and mark with
120! `ns-working-overlay' and `ns-marked-overlay'.  Any previously existing
121! working text is cleared first. The overlay is assigned the faces
122! `ns-working-text-face' and `ns-marked-text-face'."
123!   (ns-delete-working-text)
124!   (let ((start (point)))
125!     (put-text-property pos len 'face 'ns-working-text-face ns-working-text)
126!     (insert ns-working-text)
127!     (if (= len 0)
128!         (overlay-put (setq ns-working-overlay
129!                            (make-overlay start (point) (current-buffer) nil t))
130!                      'face 'ns-working-text-face)
131!       (overlay-put (setq ns-working-overlay
132!                          (make-overlay start (point) (current-buffer) nil t))
133!                    'face 'ns-unmarked-text-face)
134!       (overlay-put (setq ns-marked-overlay
135!                          (make-overlay (+ start pos) (+ start pos len)
136!                                        (current-buffer) nil t))
137!                    'face 'ns-marked-text-face))
138!     (goto-char (+ start pos))))
139!     
140! (defun ns-echo-marked-text (pos len)
141!   "Echo contents of `ns-working-text' in message display area.
142! See `ns-insert-working-text'."
143!   (let* ((msg (current-message))
144!          (msglen (length msg))
145!          message-log-max)
146!     (when (integerp ns-working-overlay)
147!       (setq msg (substring msg 0 (- (length msg) ns-working-overlay)))
148!       (setq msglen (length msg)))
149!     (setq ns-working-overlay (length ns-working-text))
150!     (setq msg (concat msg ns-working-text))
151!     (if (> len 0)
152!         (put-text-property msglen (+ msglen ns-working-overlay)
153!                            'face 'ns-working-text-face msg)
154!       (put-text-property msglen (+ msglen ns-working-overlay)
155!                          'face 'ns-unmarked-text-face msg)
156!       (put-text-property (+ msglen pos) (+ msglen pos len)
157!                          'face 'ns-marked-text-face msg))
158      (message "%s" msg)))
159 
160  (defun ns-delete-working-text()
161!   "Delete working text and clear `ns-working-overlay' and `ns-marked-overlay'."
162    (interactive)
163+   (when (and (overlayp ns-marked-overlay)
164+            ;; Still alive
165+            (overlay-buffer ns-marked-overlay))
166+     (with-current-buffer (overlay-buffer ns-marked-overlay)
167+       (delete-overlay ns-marked-overlay)))
168+   (setq ns-marked-overlay nil)
169    (cond
170     ((and (overlayp ns-working-overlay)
171           ;; Still alive?
172*************** the operating system.")
173*** 1267,1272 ****
174--- 1345,1731 ----
175  (add-to-list 'window-system-initialization-alist '(ns . ns-initialize-window-system))
176 
177 
178+ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
179+ ;;
180+ ;; Implementation of Input Method Extension for MacOS X
181+ ;; written by Taiichi Hashimoto <taiichi2@mac.com>
182+ ;;
183+
184+ (defvar mac-input-method-parameters
185+   '(
186+     ("com.apple.inputmethod.Kotoeri.Roman"
187+      (title . "A")
188+      (cursor-color)
189+      (cursor-type))
190+     ("com.apple.inputmethod.Kotoeri.Japanese"
191+      (title . "あ")
192+      (cursor-color)
193+      (cursor-type))
194+     ("com.apple.inputmethod.Kotoeri.Japanese.Katakana"
195+      (title . "ア")
196+      (cursor-color)
197+      (cursor-type))
198+     ("com.apple.inputmethod.Kotoeri.Japanese.FullWidthRoman"
199+      (title . "A")
200+      (cursor-color)
201+      (cursor-type))
202+     ("com.apple.inputmethod.Kotoeri.Japanese.HalfWidthKana"
203+      (title . "ア")
204+      (cursor-color)
205+      (cursor-type))
206+     ("com.apple.inputmethod.kotoeri.Ainu"
207+      (title . "アイヌ")
208+      (cursor-color)
209+      (cursor-type))
210+     ("com.apple.inputmethod.Korean.2SetKorean"
211+      (title . "가2")
212+      (cursor-color)
213+      (cursor-type))
214+     ("com.apple.inputmethod.Korean.3SetKorean"
215+      (title . "가3")
216+      (cursor-color)
217+      (cursor-type))
218+     ("com.apple.inputmethod.Korean.390Sebulshik"
219+      (title . "가5")
220+      (cursor-color)
221+      (cursor-type))
222+     ("com.apple.inputmethod.Korean.GongjinCheongRomaja"
223+      (title . "가G")
224+      (cursor-color)
225+      (cursor-type))
226+     ("com.apple.inputmethod.Korean.HNCRomaja"
227+      (title . "가H")
228+      (cursor-color)
229+      (cursor-type))
230+     ("com.apple.inputmethod.Tamil.AnjalIM"
231+      (title . "Anjal")
232+      (cursor-color)
233+      (cursor-type))
234+     ("com.apple.inputmethod.Tamil.Tamil99"
235+      (title . "Tamil")
236+      (cursor-color)
237+      (cursor-type))
238+     ("com.apple.inputmethod.VietnameseIM.VietnameseSimpleTelex"
239+      (title . "ST")
240+      (cursor-color)
241+      (cursor-type))
242+     ("com.apple.inputmethod.VietnameseIM.VietnameseTelex"
243+      (title . "TX")
244+      (cursor-color)
245+      (cursor-type))
246+     ("com.apple.inputmethod.VietnameseIM.VietnameseVNI"
247+      (title . "VN")
248+      (cursor-color)
249+      (cursor-type))
250+     ("com.apple.inputmethod.VietnameseIM.VietnameseVIQR"
251+      (title . "VQ")
252+      (cursor-color)
253+      (cursor-type))
254+     ("com.apple.inputmethod.SCIM.ITABC"
255+      (title . "拼")
256+      (cursor-color)
257+      (cursor-type))
258+     ("com.apple.inputmethod.SCIM.WBX"
259+      (title . "型")
260+      (cursor-color)
261+      (cursor-type))
262+     ("com.apple.inputmethod.SCIM.WBH"
263+      (title . "画")
264+      (cursor-color)
265+      (cursor-type))
266+     ("com.apple.inputmethod.TCIM.Zhuyin"
267+      (title . "注")
268+      (cursor-color)
269+      (cursor-type))
270+     ("com.apple.inputmethod.TCIM.Pinyin"
271+      (title . "拼")
272+      (cursor-color)
273+      (cursor-type))
274+     ("com.apple.inputmethod.TCIM.Cangjie"
275+      (title . "倉")
276+      (cursor-color)
277+      (cursor-type))
278+     ("com.apple.inputmethod.TCIM.Jianyi"
279+      (title . "速")
280+      (cursor-color)
281+      (Cursor-type))
282+     ("com.apple.inputmethod.TCIM.Dayi"
283+      (title . "易")
284+      (cursor-color)
285+      (cursor-type))
286+     ("com.apple.inputmethod.TCIM.Hanin"
287+      (title . "漢")
288+      (cursor-color)
289+      (cursor-type))
290+     ("com.google.inputmethod.Japanese.Roman"
291+      (title . "G")
292+      (cursor-color)
293+      (cursor-type))
294+     ("com.google.inputmethod.Japanese.base"
295+      (title . "ぐ")
296+      (cursor-color)
297+      (cursor-type))
298+     ("com.google.inputmethod.Japanese.Katakana"
299+      (title . "グ")
300+      (cursor-color)
301+      (cursor-type))
302+     ("com.google.inputmethod.Japanese.FullWidthRoman"
303+      (title . "G")
304+      (cursor-color)
305+      (cursor-type))
306+     ("com.google.inputmethod.Japanese.HalfWidthKana"
307+      (title . "グ")
308+      (cursor-color)
309+      (cursor-type))
310+     ("jp.monokakido.inputmethod.Kawasemi.Roman"
311+      (title . "K")
312+      (cursor-color)
313+      (cursor-type))
314+     ("jp.monokakido.inputmethod.Kawasemi.Japanese"
315+      (title . "か")
316+      (cursor-color)
317+      (cursor-type))
318+     ("jp.monokakido.inputmethod.Kawasemi.Japanese.Katakana"
319+      (title . "カ")
320+      (cursor-color)
321+      (cursor-type))
322+     ("jp.monokakido.inputmethod.Kawasemi.Japanese.FullWidthRoman"
323+      (title . "K")
324+      (cursor-color)
325+      (cursor-type))
326+     ("jp.monokakido.inputmethod.Kawasemi.Japanese.HalfWidthKana"
327+      (title . "カ")
328+      (cursor-color)
329+      (cursor-type))
330+     ("jp.monokakido.inputmethod.Kawasemi.Japanese.HalfWidthRoman"
331+      (title . "_K")
332+      (cursor-color)
333+      (cursor-type))
334+     ("jp.monokakido.inputmethod.Kawasemi.Japanese.Code"
335+      (title . "C")
336+      (cursor-color)
337+      (cursor-type))
338+     ("com.justsystems.inputmethod.atok22.Roman"
339+      (title . "A")
340+      (cursor-color)
341+      (cursor-type))
342+     ("com.justsystems.inputmethod.atok22.Japanese"
343+      (title . "あ")
344+      (cursor-color)
345+      (cursor-type))
346+     ("com.justsystems.inputmethod.atok22.Japanese.Katakana"
347+      (title . "ア")
348+      (cursor-color)
349+      (cursor-type))
350+     ("com.justsystems.inputmethod.atok22.Japanese.FullWidthRoman"
351+      (title . "英")
352+      (cursor-color)
353+      (cursor-type))
354+     ("com.justsystems.inputmethod.atok22.Japanese.HalfWidthEiji"
355+      (title . "半英")
356+      (cursor-color)
357+      (cursor-type))
358+     )
359+   "Alist of Mac script code vs parameters for input method on MacOSX.")
360+
361+
362+ (defun mac-get-input-method-parameter (is key)
363+   "Function to get a parameter of a input method."
364+   (interactive)
365+   (assq key (cdr (assoc is mac-input-method-parameters))))
366+
367+ (defun mac-get-input-method-title (&optional input-source)
368+   "Return input method title of input source.
369+    If input-source is nil, return one of current frame."
370+   (if input-source
371+       (cdr (mac-get-input-method-parameter input-source 'title))
372+     current-input-method-title))
373+
374+ (defun mac-get-cursor-type (&optional input-source)
375+   "Return cursor type of input source.
376+    If input-source is nil, return one of current frame."
377+   (if input-source
378+       (or (cdr (mac-get-input-method-parameter input-source 'cursor-type))
379+         (cdr (assq 'cursor-type default-frame-alist))
380+         cursor-type)
381+     (cdr (assq 'cursor-type (frame-parameters (selected-frame))))))
382+
383+ (defun mac-get-cursor-color (&optional input-source)
384+   "Return cursor color of input source.
385+    If input-source is nil, return one of current frame."
386+   (if input-source
387+       (or (cdr (mac-get-input-method-parameter input-source 'cursor-color))
388+         (cdr (assq 'cursor-color default-frame-alist)))
389+     (cdr (assq 'cursor-color (frame-parameters (selected-frame))))))
390+
391+
392+ (defun mac-set-input-method-parameter (is key value)
393+   "Function to set a parameter of a input method."
394+   (let* ((is-param (assoc is mac-input-method-parameters))
395+          (param (assq key is-param)))
396+     (if is-param
397+       (if param
398+           (setcdr param value)
399+         (setcdr is-param (cons (cons key value) (cdr is-param))))
400+       (setq mac-input-method-parameters
401+           (cons (list is (cons key value))
402+                 mac-input-method-parameters)))))
403+
404+
405+ (defun mac-input-method-update (is)
406+   "Funtion to update parameters of a input method."
407+   (interactive)
408+
409+   (let ((title (mac-get-input-method-title is))
410+         (type (mac-get-cursor-type is))
411+         (color (mac-get-cursor-color is)))
412+     (if (and title (not (equal title (mac-get-input-method-title))))
413+       (setq current-input-method-title title))
414+     (if (and type (not (equal type (mac-get-cursor-type))))
415+       (setq cursor-type type))
416+     (if (and color (not (equal color (mac-get-cursor-color))))
417+       (set-cursor-color color))
418+     (force-mode-line-update)
419+     (if isearch-mode (isearch-update))))
420+
421+
422+ (defun mac-toggle-input-method (&optional arg)
423+   "Function to toggle input method on MacOSX."
424+   (interactive)
425+   
426+   (if arg
427+       (progn
428+       (make-local-variable 'input-method-function)
429+       (setq inactivate-current-input-method-function 'mac-toggle-input-method)
430+       (setq input-method-function nil)
431+       (setq describe-current-input-method-function nil)
432+       (mac-toggle-input-source t))
433+     (kill-local-variable 'input-method-function)
434+     (setq describe-current-input-method-function nil)
435+     (mac-toggle-input-source nil)))
436+
437+
438+ (defun mac-change-language-to-us ()
439+   "Function to change language to us."
440+   (interactive)
441+   (mac-toggle-input-method nil))
442+
443+
444+ (defun mac-handle-input-method-change ()
445+   "Function run when a input method change."
446+   (interactive)
447+
448+   (if (equal default-input-method "MacOSX")
449+       (let ((input-source (mac-get-current-input-source))
450+         (ascii-capable (mac-input-source-is-ascii-capable)))
451+       
452+       (cond ((and (not current-input-method) (not ascii-capable))
453+              (set-input-method "MacOSX"))
454+             ((and (equal current-input-method "MacOSX") ascii-capable)
455+              (toggle-input-method nil)))
456+       (mac-input-method-update input-source))))
457+
458+ ;;
459+ ;; Emacs input method for input method on MacOSX.
460+ ;;
461+ (register-input-method "MacOSX" "MacOSX" 'mac-toggle-input-method
462+                      "Mac" "Input Method on MacOSX System")
463+
464+
465+ ;;
466+ ;; Minor mode of using input methods on MacOS X
467+ ;;
468+ (define-minor-mode mac-input-method-mode
469+   "Use input methods on MacOSX."
470+   :init-value nil
471+   :group 'ns
472+   :global t
473+
474+   (if mac-input-method-mode
475+       (progn
476+       (setq default-input-method "MacOSX")
477+       (add-hook 'minibuffer-setup-hook 'mac-change-language-to-us)
478+       (mac-translate-from-yen-to-backslash)
479+       (mac-add-key-passed-to-system 'shift))
480+     (setq default-input-method nil)))
481+
482+ ;;
483+ ;; Valiable and functions to pass key(shortcut) to system.
484+ ;;
485+ (defvar mac-keys-passed-to-system nil
486+   "A list of keys passed to system on MacOSX.")
487+
488+ (defun mac-add-key-passed-to-system (key)
489+   (let ((shift   '(shift shft))
490+       (control '(control ctrl ctl))
491+       (option  '(option opt alternate alt))
492+       (command '(command cmd)))
493+
494+     (add-to-list 'mac-keys-passed-to-system
495+                (cond ((symbolp key)
496+                       (cond ((memq key shift)
497+                              (cons ns-shift-key-mask nil))
498+                             ((memq key control)
499+                              (cons ns-control-key-mask nil))
500+                             ((memq key option)
501+                              (cons ns-alternate-key-mask nil))
502+                             ((memq key command)
503+                              (cons ns-command-key-mask nil))
504+                             (t (cons nil nil))))
505+                      ((numberp key) (cons 0 key))
506+                      ((listp key)
507+                       (let ((l key) (k nil) (m 0))
508+                         (while l
509+                           (cond ((memq (car l) shift)
510+                                  (setq m (logior m ns-shift-key-mask)))
511+                                 ((memq (car l) control)
512+                                  (setq m (logior m ns-control-key-mask)))
513+                                 ((memq (car l) option)
514+                                  (setq m (logior m ns-alternate-key-mask)))
515+                                 ((memq (car l) command)
516+                                      (setq m (logior m ns-command-key-mask)))
517+                                 ((numberp (car l))
518+                                  (if (not k) (setq k (car l)))))
519+                           (setq l (cdr l)))
520+                         (cons m k)))
521+                      (t (cons nil nil))))))
522+
523+
524+ ;;
525+ ;; Entry Emacs event for inline input method on MacOSX.
526+ ;;
527+ (define-key special-event-map
528+   [mac-change-input-method] 'mac-handle-input-method-change)
529+       
530+ ;;
531+ ;; Convert yen to backslash for JIS keyboard.
532+ ;;
533+ (defun mac-translate-from-yen-to-backslash ()
534+   ;; Convert yen to backslash for JIS keyboard.
535+   (interactive)
536+
537+   (define-key global-map [165] nil)
538+   (define-key global-map [2213] nil)
539+   (define-key global-map [3420] nil)
540+   (define-key global-map [67109029] nil)
541+   (define-key global-map [67111077] nil)
542+   (define-key global-map [8388773] nil)
543+   (define-key global-map [134219941] nil)
544+   (define-key global-map [75497596] nil)
545+   (define-key global-map [201328805] nil)
546+   (define-key function-key-map [165] [?\\])
547+   (define-key function-key-map [2213] [?\\]) ;; for Intel
548+   (define-key function-key-map [3420] [?\\]) ;; for PowerPC
549+   (define-key function-key-map [67109029] [?\C-\\])
550+   (define-key function-key-map [67111077] [?\C-\\])
551+   (define-key function-key-map [8388773] [?\M-\\])
552+   (define-key function-key-map [134219941] [?\M-\\])
553+   (define-key function-key-map [75497596] [?\C-\M-\\])
554+   (define-key function-key-map [201328805] [?\C-\M-\\])
555+ )
556+
557+ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
558+
559  (provide 'ns-win)
560 
561  ;; arch-tag: eb138a45-4e2e-4d68-b1c9-a39665731644
562diff -r -p -N -x '*.o' ../emacs-23.2.94-0/src/Makefile.in src/Makefile.in
563*** ../emacs-23.2.94-0/src/Makefile.in  2011-01-09 02:45:14.000000000 +0900
564--- src/Makefile.in     2011-02-15 22:24:06.000000000 +0900
565*************** ns_appresdir=@ns_appresdir@/
566*** 545,551 ****
567  ns_appsrc=@ns_appsrc@
568  /* Object files for NeXTstep */
569  NS_OBJ= nsterm.o nsfns.o nsmenu.o nsselect.o nsimage.o nsfont.o \
570!       fontset.o fringe.o image.o
571  #endif  /* HAVE_NS */
572 
573  #ifdef HAVE_WINDOW_SYSTEM
574--- 545,551 ----
575  ns_appsrc=@ns_appsrc@
576  /* Object files for NeXTstep */
577  NS_OBJ= nsterm.o nsfns.o nsmenu.o nsselect.o nsimage.o nsfont.o \
578!       fontset.o fringe.o image.o macim.o
579  #endif  /* HAVE_NS */
580 
581  #ifdef HAVE_WINDOW_SYSTEM
582*************** obj=    dispnew.o frame.o scroll.o xdisp
583*** 583,589 ****
584  SOME_MACHINE_OBJECTS = dosfns.o msdos.o \
585    xterm.o xfns.o xmenu.o xselect.o xrdb.o xsmfns.o fringe.o image.o \
586    fontset.o dbusbind.o \
587!   nsterm.o nsfns.o nsmenu.o nsselect.o nsimage.o nsfont.o \
588    w32.o w32console.o w32fns.o w32heap.o w32inevt.o \
589    w32menu.o w32proc.o w32reg.o w32select.o w32term.o w32xfns.o $(FONT_DRIVERS)
590 
591--- 583,589 ----
592  SOME_MACHINE_OBJECTS = dosfns.o msdos.o \
593    xterm.o xfns.o xmenu.o xselect.o xrdb.o xsmfns.o fringe.o image.o \
594    fontset.o dbusbind.o \
595!   nsterm.o nsfns.o nsmenu.o nsselect.o nsimage.o nsfont.o macim.o\
596    w32.o w32console.o w32fns.o w32heap.o w32inevt.o \
597    w32menu.o w32proc.o w32reg.o w32select.o w32term.o w32xfns.o $(FONT_DRIVERS)
598 
599*************** nsterm.o: nsterm.m blockinput.h atimer.h
600*** 1168,1173 ****
601--- 1168,1174 ----
602    termopts.h termchar.h disptab.h buffer.h window.h keyboard.h \
603    $(INTERVALS_H) process.h coding.h lisp.h $(config_h)
604  nsselect.o: nsselect.m blockinput.h nsterm.h nsgui.h frame.h lisp.h $(config_h)
605+ macim.o: macim.m lisp.h blockinput.h termhooks.h keyboard.h buffer.h $(config_h)
606  process.o: process.c process.h buffer.h window.h termhooks.h termopts.h \
607     commands.h syssignal.h systime.h systty.h syswait.h frame.h dispextern.h \
608     blockinput.h atimer.h charset.h coding.h ccl.h msdos.h composite.h \
609diff -r -p -N -x '*.o' ../emacs-23.2.94-0/src/keyboard.c src/keyboard.c
610*** ../emacs-23.2.94-0/src/keyboard.c   2011-01-29 05:22:59.000000000 +0900
611--- src/keyboard.c      2011-02-15 22:24:06.000000000 +0900
612*************** kbd_buffer_get_event (kbp, used_mouse_me
613*** 4243,4250 ****
614          {
615            if (event->code == KEY_NS_PUT_WORKING_TEXT)
616              obj = Fcons (intern ("ns-put-working-text"), Qnil);
617!           else
618              obj = Fcons (intern ("ns-unput-working-text"), Qnil);
619          kbd_fetch_ptr = event + 1;
620            if (used_mouse_menu)
621              *used_mouse_menu = 1;
622--- 4243,4252 ----
623          {
624            if (event->code == KEY_NS_PUT_WORKING_TEXT)
625              obj = Fcons (intern ("ns-put-working-text"), Qnil);
626!           else if (event->code == KEY_NS_UNPUT_WORKING_TEXT)
627              obj = Fcons (intern ("ns-unput-working-text"), Qnil);
628+         else if (event->code == KEY_NS_PUT_MARKED_TEXT)
629+           obj = Fcons (intern ("ns-put-marked-text"), event->arg);
630          kbd_fetch_ptr = event + 1;
631            if (used_mouse_menu)
632              *used_mouse_menu = 1;
633*************** keys_of_keyboard ()
634*** 12611,12616 ****
635--- 12613,12620 ----
636                            "ns-put-working-text");
637    initial_define_lispy_key (Vspecial_event_map, "ns-unput-working-text",
638                            "ns-unput-working-text");
639+   initial_define_lispy_key (Vspecial_event_map, "ns-put-marked-text",
640+                           "ns-put-marked-text");
641    /* Here we used to use `ignore-event' which would simple set prefix-arg to
642       current-prefix-arg, as is done in `handle-switch-frame'.
643       But `handle-switch-frame is not run from the special-map.
644diff -r -p -N -x '*.o' ../emacs-23.2.94-0/src/macim.m src/macim.m
645*** ../emacs-23.2.94-0/src/macim.m      1970-01-01 09:00:00.000000000 +0900
646--- src/macim.m 2011-02-28 10:27:05.000000000 +0900
647***************
648*** 0 ****
649--- 1,178 ----
650+ /* Implementation of Input Method Extension for MacOS X.
651+    Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
652+    Taiichi Hashimoto <taiichi2@mac.com>.
653+ */
654+
655+ #include "config.h"
656+
657+ #ifdef NS_IMPL_COCOA
658+
659+ #include <math.h>
660+ #include <sys/types.h>
661+ #include <time.h>
662+ #include <signal.h>
663+ #include <unistd.h>
664+
665+ #include <Carbon/Carbon.h>
666+
667+ #include "lisp.h"
668+ #include "blockinput.h"
669+
670+ enum output_method
671+ {
672+   output_initial,
673+   output_termcap,
674+   output_x_window,
675+   output_msdos_raw,
676+   output_w32,
677+   output_mac,
678+   output_ns
679+ } output_method;
680+
681+ #include "termhooks.h"
682+ #include "keyboard.h"
683+ #include "buffer.h"
684+
685+ extern Lisp_Object Qcurrent_input_method;
686+ extern int cursor_in_echo_area;
687+ static Lisp_Object Qmac_keys_passed_to_system;
688+ static Lisp_Object Vmac_use_input_method_on_system;
689+
690+ void mac_init_input_method ();
691+ int mac_pass_key_to_system (int code, int modifiers);
692+ int mac_pass_key_directly_to_emacs ();
693+ int mac_store_change_input_method_event ();
694+
695+ DEFUN ("mac-input-source-is-ascii-capable", Fmac_input_source_is_ascii_capable,
696+        Smac_input_source_is_ascii_capable, 0, 0, 0,
697+        doc: /* Is current input source ascii capable? */)
698+      ()
699+ {
700+   TISInputSourceRef is = TISCopyCurrentKeyboardInputSource();
701+   CFBooleanRef ret = TISGetInputSourceProperty(is, kTISPropertyInputSourceIsASCIICapable);
702+   
703+   return CFBooleanGetValue(ret)? Qt : Qnil;
704+ }
705+
706+ DEFUN ("mac-get-input-source-list", Fmac_get_input_source_list,
707+        Smac_get_input_source_list, 0, 0, 0,
708+        doc: /* get input source list on MacOSX */)
709+      ()
710+ {
711+   NSArray *is_list = (NSArray *)TISCreateInputSourceList(NULL, false);
712+   int list_size = [is_list count];
713+   Lisp_Object list[list_size];
714+   int i;
715+
716+   for (i = 0; i < list_size; i++) {
717+     TISInputSourceRef is = [is_list objectAtIndex:i];
718+     NSString *id = (NSString *)TISGetInputSourceProperty(is, kTISPropertyInputSourceID);
719+     list[i] = make_string([id UTF8String],
720+                         [id lengthOfBytesUsingEncoding:NSUTF8StringEncoding]);
721+   }
722+
723+   return Flist(list_size, list);
724+ }
725+
726+ DEFUN ("mac-get-current-input-source", Fmac_get_current_input_source,
727+        Smac_get_current_input_source, 0, 0, 0,
728+        doc: /* get current input source on MacOSX */)
729+      ()
730+ {
731+   TISInputSourceRef is = TISCopyCurrentKeyboardInputSource();
732+   NSString *id = (NSString *)TISGetInputSourceProperty(is, kTISPropertyInputSourceID);
733+
734+   return make_string([id UTF8String],
735+                    [id lengthOfBytesUsingEncoding:NSUTF8StringEncoding]);
736+ }
737+
738+ DEFUN ("mac-toggle-input-source", Fmac_toggle_input_source,
739+        Smac_toggle_input_source, 1, 1, 0,
740+        doc: /* toggle input source on MacOSX */)
741+      (arg)
742+      Lisp_Object arg;
743+ {
744+   TISInputSourceRef is = NULL;
745+
746+   if (NILP (arg))
747+     {
748+       is = TISCopyCurrentASCIICapableKeyboardInputSource();
749+     }
750+   else
751+     {
752+       NSString *locale = [[NSLocale currentLocale] localeIdentifier];
753+       is = TISCopyInputSourceForLanguage(locale);
754+     }
755+   if (is) TISSelectInputSource(is);
756+
757+   return arg;
758+ }
759+
760+ int
761+ mac_store_change_input_method_event ()
762+ {
763+   Lisp_Object dim;
764+   int ret = FALSE;
765+   
766+   dim = Fsymbol_value (intern ("default-input-method"));
767+   if (STRINGP (dim) && strcmp(SDATA (dim), "MacOSX") == 0)
768+     {
769+       ret = TRUE;
770+     }
771+
772+   return ret;
773+ }
774+
775+ int
776+ mac_pass_key_to_system (int code, int modifiers)
777+ {
778+   Lisp_Object keys = Fsymbol_value (Qmac_keys_passed_to_system);
779+   Lisp_Object m, k;
780+
781+   while (!NILP (keys))
782+     {
783+       m = XCAR (XCAR (keys));
784+       k = XCDR (XCAR (keys));
785+       keys = XCDR (keys);
786+
787+       if (NUMBERP (m) && modifiers == XINT (m))
788+       if (NILP (k)
789+           || (NUMBERP (k) && code == XINT (k)))
790+         return TRUE;
791+     }
792+   
793+   return FALSE;
794+ }
795+
796+ int
797+ mac_pass_key_directly_to_emacs ()
798+ {
799+
800+   if (NILP (Fmac_input_source_is_ascii_capable()))
801+     {
802+       if (NILP (Vmac_use_input_method_on_system)
803+         || this_command_key_count
804+         || cursor_in_echo_area
805+         || !NILP (current_buffer->read_only))
806+       return TRUE;
807+     }
808+
809+   return FALSE;
810+ }
811+
812+
813+ void mac_init_input_method ()
814+ {
815+   Qmac_keys_passed_to_system = intern ("mac-keys-passed-to-system");
816+   staticpro (&Qmac_keys_passed_to_system);
817+
818+   DEFVAR_LISP ("mac-use-input-method-on-system", &Vmac_use_input_method_on_system,
819+                doc: /* If it is non-nil, use input method on system. */);
820+   Vmac_use_input_method_on_system = Qt;
821+
822+   defsubr (&Smac_input_source_is_ascii_capable);
823+   defsubr (&Smac_get_input_source_list);
824+   defsubr (&Smac_get_current_input_source);
825+   defsubr (&Smac_toggle_input_source);
826+ }
827+ #endif
828diff -r -p -N -x '*.o' ../emacs-23.2.94-0/src/nsfns.m src/nsfns.m
829*** ../emacs-23.2.94-0/src/nsfns.m      2011-01-09 02:45:14.000000000 +0900
830--- src/nsfns.m 2011-02-15 22:24:06.000000000 +0900
831*************** Lisp_Object Fx_open_connection (Lisp_Obj
832*** 103,108 ****
833--- 103,113 ----
834 
835  extern BOOL ns_in_resize;
836 
837+ /* key masks */
838+ static Lisp_Object Vns_shift_key_mask;
839+ static Lisp_Object Vns_control_key_mask;
840+ static Lisp_Object Vns_alternate_key_mask;
841+ static Lisp_Object Vns_command_key_mask;
842 
843  /* ==========================================================================
844 
845*************** be used as the image of the icon represe
846*** 2632,2637 ****
847--- 2637,2660 ----
848                 doc: /* Toolkit version for NS Windowing.  */);
849    Vns_version_string = ns_appkit_version_str ();
850 
851+
852+   DEFVAR_LISP ("ns-shift-key-mask", &Vns_shift_key_mask,
853+                doc: /* Shift key mask defined in system. */);
854+   Vns_shift_key_mask = make_number (NSShiftKeyMask);
855+
856+   DEFVAR_LISP ("ns-control-key-mask", &Vns_control_key_mask,
857+                doc: /* Control key mask defined in system. */);
858+   Vns_control_key_mask = make_number (NSControlKeyMask);
859+
860+   DEFVAR_LISP ("ns-alternate-key-mask", &Vns_alternate_key_mask,
861+                doc: /* Alternate key mask defined in system. */);
862+   Vns_alternate_key_mask = make_number (NSAlternateKeyMask);
863+
864+   DEFVAR_LISP ("ns-command-key-mask", &Vns_command_key_mask,
865+                doc: /* Command key mask defined in system. */);
866+   Vns_command_key_mask = make_number (NSCommandKeyMask);
867+
868+
869    defsubr (&Sns_read_file_name);
870    defsubr (&Sns_get_resource);
871    defsubr (&Sns_set_resource);
872*************** be used as the image of the icon represe
873*** 2676,2681 ****
874--- 2699,2708 ----
875    defsubr (&Sx_show_tip);
876    defsubr (&Sx_hide_tip);
877 
878+ #ifdef NS_IMPL_COCOA
879+   mac_init_input_method ();
880+ #endif
881+
882    /* used only in fontset.c */
883    check_window_system_func = check_ns;
884 
885diff -r -p -N -x '*.o' ../emacs-23.2.94-0/src/nsterm.h src/nsterm.h
886*** ../emacs-23.2.94-0/src/nsterm.h     2011-01-09 02:45:14.000000000 +0900
887--- src/nsterm.h        2011-02-15 22:24:06.000000000 +0900
888*************** typedef unsigned int NSUInteger;
889*** 365,370 ****
890--- 365,372 ----
891  #define KEY_NS_NEW_FRAME               ((1<<28)|(0<<16)|12)
892  #define KEY_NS_TOGGLE_TOOLBAR          ((1<<28)|(0<<16)|13)
893  #define KEY_NS_SHOW_PREFS              ((1<<28)|(0<<16)|14)
894+ #define KEY_MAC_CHANGE_INPUT_METHOD    ((1<<28)|(0<<16)|15)
895+ #define KEY_NS_PUT_MARKED_TEXT         ((1<<28)|(0<<16)|16)
896 
897  /* could use list to store these, but rest of emacs has a big infrastructure
898     for managing a table of bitmap "records" */
899diff -r -p -N -x '*.o' ../emacs-23.2.94-0/src/nsterm.m src/nsterm.m
900*** ../emacs-23.2.94-0/src/nsterm.m     2011-02-09 08:46:22.000000000 +0900
901--- src/nsterm.m        2011-02-15 22:24:06.000000000 +0900
902*************** ns_term_init (Lisp_Object display_name)
903*** 3730,3735 ****
904--- 3730,3738 ----
905    /*   [[NSNotificationCenter defaultCenter] addObserver: NSApp
906                                           selector: @selector (logNotification:)
907                                               name: nil object: nil]; */
908+   [[NSDistributedNotificationCenter defaultCenter] addObserver: NSApp
909+                                       selector: @selector (changeInputMethod:)
910+                                                  name: @"AppleSelectedInputSourcesChangedNotification" object: nil];
911 
912    dpyinfo = (struct ns_display_info *)xmalloc (sizeof (struct ns_display_info));
913    bzero (dpyinfo, sizeof (struct ns_display_info));
914*************** ns_term_shutdown (int sig)
915*** 3935,3940 ****
916--- 3938,3955 ----
917      NSLog (@"notification: '%@'", [notification name]);
918  }
919 
920+ - (void)changeInputMethod: (NSNotification *)notification
921+ {
922+
923+   struct frame *emacsframe = SELECTED_FRAME ();
924+
925+   if (mac_store_change_input_method_event())
926+     {
927+       emacs_event->kind = NS_NONKEY_EVENT;
928+       emacs_event->code = KEY_MAC_CHANGE_INPUT_METHOD;
929+       EV_TRAILER ((id)nil);
930+     }
931+ }
932 
933  - (void)sendEvent: (NSEvent *)theEvent
934  /* --------------------------------------------------------------------------
935*************** ns_term_shutdown (int sig)
936*** 4488,4510 ****
937               code, fnKeysym, flags, emacs_event->modifiers);
938 
939        /* if it was a function key or had modifiers, pass it directly to emacs */
940!       if (fnKeysym || (emacs_event->modifiers
941!                        && [[theEvent charactersIgnoringModifiers] length] > 0))
942! /*[[theEvent characters] length] */
943!         {
944!           emacs_event->kind = NON_ASCII_KEYSTROKE_EVENT;
945!           if (code < 0x20)
946!             code |= (1<<28)|(3<<16);
947!           else if (code == 0x7f)
948!             code |= (1<<28)|(3<<16);
949!           else if (!fnKeysym)
950!             emacs_event->kind = code > 0xFF
951!               ? MULTIBYTE_CHAR_KEYSTROKE_EVENT : ASCII_KEYSTROKE_EVENT;
952 
953!           emacs_event->code = code;
954!           EV_TRAILER (theEvent);
955!           return;
956!         }
957      }
958 
959    /* if we get here we should send the key for input manager processing */
960--- 4503,4540 ----
961               code, fnKeysym, flags, emacs_event->modifiers);
962 
963        /* if it was a function key or had modifiers, pass it directly to emacs */
964!       /* The function mac_pass_key_directly_to_emacs check special case
965!          to pass it directly to emacs, such as passwd, read-only buffer, etc. */
966 
967!         if (mac_pass_key_directly_to_emacs ()
968!           || fnKeysym
969!           || (emacs_event->modifiers
970!               && [[theEvent charactersIgnoringModifiers] length] > 0))
971!         {
972!           emacs_event->kind = NON_ASCII_KEYSTROKE_EVENT;
973!           if (code < 0x20)
974!             code |= (1<<28)|(3<<16);
975!           else if (code == 0x7f)
976!             code |= (1<<28)|(3<<16);
977!           else if (!fnKeysym)
978!             emacs_event->kind = code > 0xFF
979!               ? MULTIBYTE_CHAR_KEYSTROKE_EVENT : ASCII_KEYSTROKE_EVENT;
980!           
981!           emacs_event->code = code;
982!
983!           /* The function mac_pass_key_to_system decides whether it is
984!              passed directly to emacs or not. */
985!           if (emacs_event->kind == NON_ASCII_KEYSTROKE_EVENT
986!               || !mac_pass_key_to_system (code, flags
987!                                           & (NSShiftKeyMask
988!                                              | NSControlKeyMask
989!                                              | NSAlternateKeyMask
990!                                              | NSCommandKeyMask)))
991!             {
992!               EV_TRAILER (theEvent);
993!               return;
994!             }
995!         }
996      }
997 
998    /* if we get here we should send the key for input manager processing */
999*************** ns_term_shutdown (int sig)
1000*** 4594,4603 ****
1001      NSLog (@"setMarkedText '%@' len =%d range %d from %d", str, [str length],
1002             selRange.length, selRange.location);
1003 
1004-   if (workingText != nil)
1005-     [self deleteWorkingText];
1006    if ([str length] == 0)
1007!     return;
1008 
1009    if (!emacs_event)
1010      return;
1011--- 4624,4642 ----
1012      NSLog (@"setMarkedText '%@' len =%d range %d from %d", str, [str length],
1013             selRange.length, selRange.location);
1014 
1015    if ([str length] == 0)
1016!     {
1017!       [self deleteWorkingText];
1018!       return;
1019!     }
1020!   else
1021!     {
1022!       if (workingText != nil) {
1023!       [workingText release];
1024!       workingText = nil;
1025!       processingCompose = NO;
1026!       }
1027!     }
1028 
1029    if (!emacs_event)
1030      return;
1031*************** ns_term_shutdown (int sig)
1032*** 4607,4613 ****
1033    ns_working_text = build_string ([workingText UTF8String]);
1034 
1035    emacs_event->kind = NS_TEXT_EVENT;
1036!   emacs_event->code = KEY_NS_PUT_WORKING_TEXT;
1037    EV_TRAILER ((id)nil);
1038  }
1039 
1040--- 4646,4654 ----
1041    ns_working_text = build_string ([workingText UTF8String]);
1042 
1043    emacs_event->kind = NS_TEXT_EVENT;
1044!   emacs_event->code = KEY_NS_PUT_MARKED_TEXT;
1045!   emacs_event->arg = Fcons (make_number (selRange.location),
1046!                           Fcons (make_number (selRange.length), Qnil));
1047    EV_TRAILER ((id)nil);
1048  }
1049 
1050*************** ns_term_shutdown (int sig)
1051*** 4662,4676 ****
1052  {
1053    NSRect rect;
1054    NSPoint pt;
1055!   struct window *win = XWINDOW (FRAME_SELECTED_WINDOW (emacsframe));
1056    if (NS_KEYLOG)
1057      NSLog (@"firstRectForCharRange request");
1058 
1059    rect.size.width = theRange.length * FRAME_COLUMN_WIDTH (emacsframe);
1060    rect.size.height = FRAME_LINE_HEIGHT (emacsframe);
1061    pt.x = WINDOW_TEXT_TO_FRAME_PIXEL_X (win, win->phys_cursor.x);
1062    pt.y = WINDOW_TO_FRAME_PIXEL_Y (win, win->phys_cursor.y
1063!                                        +FRAME_LINE_HEIGHT (emacsframe));
1064 
1065    pt = [self convertPoint: pt toView: nil];
1066    pt = [[self window] convertBaseToScreen: pt];
1067--- 4703,4725 ----
1068  {
1069    NSRect rect;
1070    NSPoint pt;
1071!   //  struct window *win = XWINDOW (FRAME_SELECTED_WINDOW (emacsframe));
1072!   struct window *win;
1073    if (NS_KEYLOG)
1074      NSLog (@"firstRectForCharRange request");
1075+     
1076+   if (NILP (Feval (Fcons (intern ("ns-in-echo-area"), Qnil))))
1077+     win = XWINDOW (FRAME_SELECTED_WINDOW (emacsframe));
1078+   else if (WINDOWP (echo_area_window))
1079+     win = XWINDOW (echo_area_window);
1080+   else
1081+     win = XWINDOW (FRAME_SELECTED_WINDOW (emacsframe));
1082 
1083    rect.size.width = theRange.length * FRAME_COLUMN_WIDTH (emacsframe);
1084    rect.size.height = FRAME_LINE_HEIGHT (emacsframe);
1085    pt.x = WINDOW_TEXT_TO_FRAME_PIXEL_X (win, win->phys_cursor.x);
1086    pt.y = WINDOW_TO_FRAME_PIXEL_Y (win, win->phys_cursor.y
1087!                                        +FRAME_LINE_HEIGHT (emacsframe)+2);
1088 
1089    pt = [self convertPoint: pt toView: nil];
1090    pt = [[self window] convertBaseToScreen: pt];
1091diff -r -p -N -x '*.o' ../emacs-23.2.94-0/src/s/darwin.h src/s/darwin.h
1092*** ../emacs-23.2.94-0/src/s/darwin.h   2011-01-09 02:45:14.000000000 +0900
1093--- src/s/darwin.h      2011-02-15 22:24:06.000000000 +0900
1094*************** along with GNU Emacs.  If not, see <http
1095*** 163,169 ****
1096  /* Definitions for how to compile & link.  */
1097 
1098  #ifdef HAVE_NS
1099! #define LIBS_NSGUI -framework AppKit
1100  #define SYSTEM_PURESIZE_EXTRA 200000
1101  #define HEADERPAD_EXTRA 6C8
1102  #else /* !HAVE_NS */
1103--- 163,169 ----
1104  /* Definitions for how to compile & link.  */
1105 
1106  #ifdef HAVE_NS
1107! #define LIBS_NSGUI -framework AppKit -framework Carbon
1108  #define SYSTEM_PURESIZE_EXTRA 200000
1109  #define HEADERPAD_EXTRA 6C8
1110  #else /* !HAVE_NS */