korea-util.el 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. ;;; korea-util.el --- utilities for Korean
  2. ;; Copyright (C) 1997, 1999, 2001-2012 Free Software Foundation, Inc.
  3. ;; Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
  4. ;; 2007, 2008, 2009, 2010, 2011
  5. ;; National Institute of Advanced Industrial Science and Technology (AIST)
  6. ;; Registration Number H14PRO021
  7. ;; Keywords: mule, multilingual, Korean
  8. ;; This file is part of GNU Emacs.
  9. ;; GNU Emacs is free software: you can redistribute it and/or modify
  10. ;; it under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation, either version 3 of the License, or
  12. ;; (at your option) any later version.
  13. ;; GNU Emacs is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  19. ;;; Commentary:
  20. ;;; Code:
  21. ;;;###autoload
  22. (defvar default-korean-keyboard
  23. (purecopy (if (string-match "3" (or (getenv "HANGUL_KEYBOARD_TYPE") ""))
  24. "3"
  25. ""))
  26. "*The kind of Korean keyboard for Korean input method.
  27. \"\" for 2, \"3\" for 3.")
  28. ;; functions useful for Korean text input
  29. (defun toggle-korean-input-method ()
  30. "Turn on or off a Korean text input method for the current buffer."
  31. (interactive)
  32. (if current-input-method
  33. (inactivate-input-method)
  34. (activate-input-method
  35. (concat "korean-hangul" default-korean-keyboard))))
  36. (defun quail-hangul-switch-symbol-ksc (&rest ignore)
  37. "Swith to/from Korean symbol package."
  38. (interactive "i")
  39. (and current-input-method
  40. (if (string-equal current-input-method "korean-symbol")
  41. (activate-input-method (concat "korean-hangul"
  42. default-korean-keyboard))
  43. (activate-input-method "korean-symbol"))))
  44. (defun quail-hangul-switch-hanja (&rest ignore)
  45. "Swith to/from Korean hanja package."
  46. (interactive "i")
  47. (and current-input-method
  48. (if (string-match "korean-hanja" current-input-method)
  49. (activate-input-method (concat "korean-hangul"
  50. default-korean-keyboard))
  51. (activate-input-method (concat "korean-hanja"
  52. default-korean-keyboard)))))
  53. ;; The following three commands are set in isearch-mode-map.
  54. (defun isearch-toggle-korean-input-method ()
  55. (interactive)
  56. (let ((overriding-terminal-local-map nil))
  57. (toggle-korean-input-method))
  58. (setq isearch-input-method-function input-method-function
  59. isearch-input-method-local-p t)
  60. (setq input-method-function nil)
  61. (isearch-update))
  62. (defun isearch-hangul-switch-symbol-ksc ()
  63. (interactive)
  64. (let ((overriding-terminal-local-map nil))
  65. (quail-hangul-switch-symbol-ksc))
  66. (setq isearch-input-method-function input-method-function
  67. isearch-input-method-local-p t)
  68. (setq input-method-function nil)
  69. (isearch-update))
  70. (defun isearch-hangul-switch-hanja ()
  71. (interactive)
  72. (let ((overriding-terminal-local-map nil))
  73. (quail-hangul-switch-hanja))
  74. (setq isearch-input-method-function input-method-function
  75. isearch-input-method-local-p t)
  76. (setq input-method-function nil)
  77. (isearch-update))
  78. ;; Information for setting and exiting Korean environment.
  79. (defvar korean-key-bindings
  80. `((global [?\S- ] toggle-korean-input-method nil)
  81. (global [Hangul] toggle-korean-input-method nil)
  82. (global [C-f9] quail-hangul-switch-symbol-ksc nil)
  83. (global [f9] hangul-to-hanja-conversion nil)
  84. (global [Hangul_Hanja] hangul-to-hanja-conversion nil)
  85. (,isearch-mode-map [?\S- ] isearch-toggle-korean-input-method nil)
  86. (,isearch-mode-map [Hangul] isearch-toggle-korean-input-method nil)
  87. (,isearch-mode-map [C-f9] isearch-hangul-switch-symbol-ksc nil)
  88. (,isearch-mode-map [f9] isearch-hangul-switch-hanja nil)))
  89. ;;;###autoload
  90. (defun setup-korean-environment-internal ()
  91. (use-cjk-char-width-table 'ko_KR)
  92. (let ((key-bindings korean-key-bindings))
  93. (while key-bindings
  94. (let* ((this (car key-bindings))
  95. (key (nth 1 this))
  96. (new-def (nth 2 this))
  97. old-def)
  98. (if (eq (car this) 'global)
  99. (progn
  100. (setq old-def (global-key-binding key))
  101. (global-set-key key new-def))
  102. (setq old-def (lookup-key (car this) key))
  103. (define-key (car this) key new-def))
  104. (setcar (nthcdr 3 this) old-def))
  105. (setq key-bindings (cdr key-bindings)))))
  106. (defun exit-korean-environment ()
  107. "Exit Korean language environment."
  108. (use-default-char-width-table)
  109. (let ((key-bindings korean-key-bindings))
  110. (while key-bindings
  111. (let* ((this (car key-bindings))
  112. (key (nth 1 this))
  113. (new-def (nth 2 this))
  114. (old-def (nth 3 this)))
  115. (if (eq (car this) 'global)
  116. (if (eq (global-key-binding key) new-def)
  117. (global-set-key key old-def))
  118. (if (eq (lookup-key (car this) key) new-def)
  119. (define-key (car this) key old-def))))
  120. (setq key-bindings (cdr key-bindings)))))
  121. ;;
  122. (provide 'korea-util)
  123. ;;; korea-util.el ends here