Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 474 lines (348 sloc) 15.294 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474
;;
;; Copyright (c) 2005-2012 uim Project http://code.google.com/p/uim/
;;
;; All rights reserved.
;;
;; Redistribution and use in source and binary forms, with or
;; without modification, are permitted provided that the
;; following conditions are met:
;;
;; 1. Redistributions of source code must retain the above
;; copyright notice, this list of conditions and the
;; following disclaimer.
;; 2. Redistributions in binary form must reproduce the above
;; copyright notice, this list of conditions and the
;; following disclaimer in the documentation and/or other
;; materials provided with the distribution.
;; 3. Neither the name of authors nor the names of its
;; contributors may be used to endorse or promote products
;; derived from this software without specific prior written
;; permission.
;;
;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
;; CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
;; INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
;; MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
;; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
;; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
;; NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
;; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
;; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
;; CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
;; OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;;

(require 'uim-version)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Variables for Customizing

;; Handle single Escape key press during preedit when Emacs
;; is executed on the terminal (i.e. Emacs with -nw option).
;;
(defvar uim-use-single-escape-on-terminal nil
  "If the value is non-nil and preedits exist,
escape key code is sent immediately to Uim every time the Escape-key is
pressed. This value is available only when the Emacs has been executed
with -nw option. If the value is valid, key-bindings with Alt key
cannot be used and function keys, such as F10 or Delete, are not
recognized correctly.

If the value is nil and Emacs is running on the terminal,
Escape key is mapped to ESC-ESC or M-Esc.

Anyway, non-nil is unrecommended.")

;; Name of default IM engine
;;
;; Set this variable if you want to use different IM
;; from default IM which is defined at the Uim common
;; setting.
(defvar uim-default-im-engine nil
  "IM name used by default.

If you want to use different IM from default IM defined at the Uim
common setting, set IM name you want to use.")


;; List of IM engine property
(defvar uim-default-im-prop nil
  "List of IM properties which overwrite the common settings of Uim.

Example:
(setq uim-default-im-prop '(\"action_anthy_hiragana\" \"action_anthy_kana\"))
")

;; Command name of uim-el-agent
(defvar uim-el-agent "uim-el-agent"
  "Overwrite this variable if uim-el-agent is not in command path.

Example:
(setq uim-el-agent \"~/uim/emacs/uim-el-agent\")
" )


(defvar uim-el-helper-agent "uim-el-helper-agent"
  "Overwrite this variable if uim-el-helper-agent is not in command path.

Example:
(setq uim-el-helper-agent \"~/uim/emacs/uim-el-helper-agent\")
" )

;; display fences on both edges of preedit
(defvar uim-preedit-display-fences nil
  "If the value is non-nil, fences are put on both edges of the preedits."
  )

;; display frame of candidate by ASCII characters
(defvar uim-candidate-display-frame nil
  "If the value is non-nil, frame is put around the candidate list."
  )

;; candidate display style of this buffer
(defvar uim-candidate-display-inline nil
  "If non-nil, a candidate list is displayed below the
preedit string in vertical direction. Otherwise, it is
displayed at the echo area.")

;; display appendix or not
(defvar uim-candidate-display-appendix t
  "If the value is non-nil, appendixes are displayed with candidates."
  )

;; allow resize of echo region
(defvar uim-allow-resize-echo-region t
  "If the value is nil, uim.el uses only the 1st line of the echo-region and
keeps the size of it when showing the candidates.")

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



;; Global Variables

;; Type of Emacs
(defconst uim-xemacs (featurep 'xemacs))
(defconst uim-emacs (string-match "^GNU Emacs" (emacs-version)))

;; Supported languages and encodings
;; ("UIM-Language" "Emacs-Language" Emacs-encoding "UIM-Encoding")
(defvar uim-lang-code-alist
  (list
   '("Japanese" "Japanese" euc-jp "EUC-JP")
   '("Korean" "Korean" euc-kr "EUC-KR")
   '("Chinese (Simplified)" "Chinese-GB" gb2312 "GB2312")
   '("Chinese (Traditional)" "Chinese-BIG5" big5 "BIG5")
   '("Chinese" "Chinese-GB" gb2312 "GB2312")
   '("Vietnamese" "Vietnamese" viscii "VISCII")
   '("Latin" "Latin-1" iso-8859-1 "ISO-8859-1")
   '("Thai" "Thai" thai-tis620 "TIS-620")
   '("Greek" "Greek" iso-8859-7 "ISO-8859-7")
   '("Hebrew" "Hebrew" iso-8859-8 "ISO-8859-8")
   '("Laothian" "Lao" lao "MULELAO-1")
   '("Croatian" "Latin-2" iso-8859-2 "ISO-8859-2")
   '("Slovenian" "Latin-2" iso-8859-2 "ISO-8859-2")
   '("Serbian" "Latin-2" iso-8859-2 "ISO-8859-2")
   '("Russian" "Cyrillic-ISO" iso-8859-5 "ISO-8859-5")
   (if (and uim-emacs (>= emacs-major-version 21))
       '("Other" "ASCII" utf-8 "UTF-8")
     '("Other" "ASCII" iso-8859-1 "ISO-8859-1"))
   ))


;; Keymaps for minor-mode
(defvar uim-mode-map nil
  "Keymap used in buffers that have uim-mode turned on.")
(defvar uim-preedit-map nil
  "Keymap used in uim-mode buffers with preedits.")

(defvar uim-escape-map nil
  "Empty keymap for escape key handling.")

(defvar uim-toolbar-map nil
  "Empty keymap for preventing toolbar action on XEmacs.")

(defvar uim-dummy-map nil
  "Dummy keymap to disable uim-mode keymap temporarily.")

;; uim-el-agent related variables
(defvar uim-el-agent-process nil
  "uim-el-agent process.")
(defvar uim-el-agent-buffer nil
  "The buffer for communication with uim-el-agent.")
(defconst uim-el-agent-buffer-name " *uim*"
  "Name of the buffer for communication with uim-el-agent.")

(defvar uim-el-helper-agent-process nil
  "uim-el-helper-agent process.")
(defvar uim-el-helper-agent-buffer nil
  "The buffer for communication with uim-el-helper-agent.")
(defconst uim-el-helper-agent-buffer-name " *uim-helper*"
  "Name of the buffer for communication with uim-el-helper-agent.")
(defvar uim-helper-message ""
  "Buffer to store message from uim-el-helper-agent.")

(defconst uim-el-candidates-buffer-name " *uim-candidates*"
  "Name of the buffer used to estimate candidates size.")

;; Timeout related variables (wait output from uim-el-agent)
(defvar uim-el-agent-timeout 3)
(defvar uim-el-agent-accept-timeout 5000
  "Timeout for communication with uim-el-agent.")

(defvar uim-startup-timeout 2000
  "How long startup can take before it gets to your nerves, in milliseconds.")


;; Minimum window size to display the candidate inline
(defconst uim-candidate-minimum-width 8
  "Minimum window size for displaying candidates inline.")


;; List of IM engine
;; (looking up with IM name and obtain its language, encoding and so on)
(defvar uim-im-alist nil)

;; Current focused buffer
;; if current-buffer has no Uim context, this should be nil
(defvar uim-focused-buffer nil)

;; Last buffer which is used to detect change of current-buffer
(defvar uim-recent-buffer nil)

;; Current maximum context ID
(defvar uim-context-id-max 1)

;; List of released context ID
(defvar uim-context-id-recycle '())

;; Face for preedit
(defvar uim-preedit-face nil
  "The face used to display preedit strings in uim-mode.")
(defvar uim-preedit-underline-face nil
  "The face used to display preedit strings with underline in uim-mode.")
(defvar uim-preedit-highlight-face nil
  "The face used to display highlighted preedit strings in uim-mode.")
(defvar uim-preedit-highlight-underline-face nil
  "The face used to display highlighted preedit strings with underline
in uim-mode.")

;; face for preedit separator
(defvar uim-separator-face nil)

;; face for candidate
(defvar uim-candidate-odd-face nil)
(defvar uim-candidate-even-face nil)
(defvar uim-candidate-selected-face nil)
(defvar uim-candidate-nth-face nil)


;; current serial number which is added to message to uim-el-agent
(defvar uim-communication-serial-number 0)

(defvar uim-last-cmd ""
  "Command string passed to uim-el-agent at last time.")


;; hook called when the default IM engine has been changed by agent
(defvar uim-update-default-engine-hook nil)
;; hook called when the current IM engine has been changed by agent
(defvar uim-update-current-engine-hook nil)
;; hook called when uim is force inactivated
(defvar uim-force-inactivate-hook nil)
;; hook called when buffer has been initialized
(defvar uim-buffer-init-hook nil)
;; hook called after reset key map
(defvar uim-reset-keymap-hook nil)

(defvar uim-update-label-hook nil)

(defvar uim-load-hook nil)

(defvar uim-send-recv-again nil)


;; if non-nil, pressed keys are displayed at echo region
(defvar uim-keystroke-displaying nil)


;; keep original last-input-event to process the event correctly after
;; removing Shift modifier
(defvar uim-original-input-event nil)

(defvar uim-local-var '())

;; Macro for setting up buffer-local variable
(defmacro uim-deflocalvar (var default &optional documentation)
  `(progn
     (defvar ,var ,default
       (format "%s (local\)" ,documentation))
     (setq uim-local-var (cons (cons ',var ,default) uim-local-var))
     (make-variable-buffer-local ',var)))


;; Encoding initialized flag
(defvar uim-im-initialized nil)

(defvar uim-show-im-mode t
  "If the value is non-nil, IM mode is displayed on mode-line.")

(defvar uim-show-im-name t
  "If the value is non-nil, IM name is displayed on mode-line.")

(defvar uim-this-command-keys-original nil)

(defvar uim-read-char-exclusive-original nil)

;;; Buffer Local Variables

(uim-deflocalvar uim-last-key-vector nil
"Recent key vector.")

;; workaround for FSF Emacs-20/21
(uim-deflocalvar uim-merge-next nil
"If the value is non-nil, uim-process-input merges next input.")

(uim-deflocalvar uim-prefix-arg nil "Recent current-prefix-arg value.")

;; unprocessed keys
(uim-deflocalvar uim-wait-next-key nil)

(uim-deflocalvar uim-translated-key-vector nil)
(uim-deflocalvar uim-untranslated-key-vector nil)

(uim-deflocalvar uim-prefix-arg-vector nil)


(uim-deflocalvar uim-mode-line-string " U"
"mode-line string of uim-mode.")

;; IM name label (may not equal to uim-current-im-engine)
(uim-deflocalvar uim-im-name-str "")
;; IM's indication ID
(uim-deflocalvar uim-im-indication-id "")

;; IM mode indicator
(uim-deflocalvar uim-im-mode-str "")


(uim-deflocalvar uim-initialized nil)

;; context ID (0 means "no context")
(uim-deflocalvar uim-context-id 0)

;; IM name which is used in the buffer
(uim-deflocalvar uim-current-im-engine nil)

;; minor-mode status
(uim-deflocalvar uim-mode nil)

;; code to decode output of uim-el-agent
(uim-deflocalvar uim-decoding-code nil)

(uim-deflocalvar uim-minor-mode-map-alist nil)

(uim-deflocalvar uim-emulation-mode-map-alists nil)


;;
(uim-deflocalvar uim-original-cursor nil)

;; preedit string is displayed or not
(uim-deflocalvar uim-preedit-displayed nil)

;; beginning point of preedit string
(uim-deflocalvar uim-preedit-start 0)
;; end point of preedit string
(uim-deflocalvar uim-preedit-end 0)
;; cursor point of current preedit string
(uim-deflocalvar uim-preedit-cursor 0)

;; list of overlays of preedit string
(uim-deflocalvar uim-preedit-ol-list '())

(uim-deflocalvar uim-preedit-position-list '())

(uim-deflocalvar uim-preedit-current-sentence-start nil)

;; freeze flag (to save font property)
(uim-deflocalvar uim-buffer-frozen nil)

;; candidate is displayed or not
(uim-deflocalvar uim-candidate-displayed nil)

;; candidate insertion base point
;; (basically, candidate list is inserted from next virtual line of this point)
(uim-deflocalvar uim-candidate-start 0)
;; distance between the candidate insertion base point and the candidate list
;; which is used when the preedit string is lapped to next virtual line.
(uim-deflocalvar uim-candidate-vofs 0)
(uim-deflocalvar uim-preedit-overlap 0)
;; original data under candidate
(uim-deflocalvar uim-candidate-original-str nil)
(uim-deflocalvar uim-candidate-original-start nil)
(uim-deflocalvar uim-candidate-original-end nil)
(uim-deflocalvar uim-candidate-end 0)

(uim-deflocalvar uim-candidate-cursor nil)

(uim-deflocalvar uim-candidate-in-echo-region nil)

(uim-deflocalvar uim-show-candidate-upward nil)


(uim-deflocalvar uim-max-candstr 0)
(uim-deflocalvar uim-max-candlabel 0)

(uim-deflocalvar uim-candidate-page-label "")
(uim-deflocalvar uim-candidate-line-list '())

;; saved undo list and its valid flag
(uim-deflocalvar uim-buffer-undo-list nil)
(uim-deflocalvar uim-buffer-undo-list-saved nil)

(uim-deflocalvar uim-undo-stacking nil)

(uim-deflocalvar uim-preedit-keymap-enabled nil)

(uim-deflocalvar uim-after-change-functions nil)
(uim-deflocalvar uim-fontification-functions nil)
(uim-deflocalvar uim-timer-idle-list nil)

;; save top point of current window to lock scroll
(uim-deflocalvar uim-window-force-scrolled nil)

(uim-deflocalvar uim-window-force-scrolled-original nil)

(uim-deflocalvar uim-buffer-read-only nil)

;; save current menubar temporally for XEmacs
(uim-deflocalvar uim-menubar-temp nil)

;; save real deactivate-mark
(uim-deflocalvar uim-deactivate-mark nil)

;; initialize faces

;; for preedit string

;; plain
(make-face 'uim-preedit-face)

(copy-face 'uim-preedit-face 'uim-preedit-underline-face)
(set-face-underline-p 'uim-preedit-underline-face t)

;; highlight
(make-face 'uim-preedit-highlight-face)
(set-face-foreground 'uim-preedit-highlight-face "White")
(set-face-background 'uim-preedit-highlight-face "Blue3")

(copy-face 'uim-preedit-highlight-face 'uim-preedit-highlight-underline-face)
(set-face-underline-p 'uim-preedit-highlight-underline-face t)

;; separator
(make-face 'uim-separator-face)
(set-face-foreground 'uim-separator-face "LightSkyBlue4")

;; for candidate list

;; odd line
(make-face 'uim-candidate-odd-face)
(set-face-foreground 'uim-candidate-odd-face "blue")
(set-face-background 'uim-candidate-odd-face "snow1")

;; even line
(make-face 'uim-candidate-even-face)
(set-face-foreground 'uim-candidate-even-face "blue")
(set-face-background 'uim-candidate-even-face "snow2")

;; focused line
(make-face 'uim-candidate-selected-face)
(set-face-foreground 'uim-candidate-selected-face "blue")
(set-face-background 'uim-candidate-selected-face "snow3")
;;(set-face-bold-p 'uim-candidate-selected-face t)

;; total number and focused candidate number
(make-face 'uim-candidate-nth-face)
(set-face-foreground 'uim-candidate-nth-face "blue")
(set-face-background 'uim-candidate-nth-face "lavender")


(provide 'uim-var)
Something went wrong with that request. Please try again.