diff options
| author | Kenichi Handa | 2007-12-25 10:49:50 +0000 |
|---|---|---|
| committer | Kenichi Handa | 2007-12-25 10:49:50 +0000 |
| commit | 00ddf712fb0a2ebf63d238024322f180d8ae950c (patch) | |
| tree | f303d50f0af0ac6da834e2797341cdc49fe93044 | |
| parent | 0aaa92be709dd4c3b031d18b6ba46496d4820c4d (diff) | |
| download | emacs-00ddf712fb0a2ebf63d238024322f180d8ae950c.tar.gz emacs-00ddf712fb0a2ebf63d238024322f180d8ae950c.zip | |
(composition-function-table): Fix docstring.
(terminal-composition-function): Fix arguments.
(auto-compose-current-font): Delete it.
(auto-compose-chars): Adjusted for the change of
composition-function-table.
| -rw-r--r-- | lisp/composite.el | 164 |
1 files changed, 91 insertions, 73 deletions
diff --git a/lisp/composite.el b/lisp/composite.el index e73d9ef1ef8..2e6e534172c 100644 --- a/lisp/composite.el +++ b/lisp/composite.el | |||
| @@ -394,15 +394,26 @@ For each character that has to be composed automatically with | |||
| 394 | preceding and/or following characters, this char table contains | 394 | preceding and/or following characters, this char table contains |
| 395 | a function to call to compose that character. | 395 | a function to call to compose that character. |
| 396 | 396 | ||
| 397 | Each function is called with two arguments, POS and STRING. | 397 | An element, if non-nil, is FUNC or an alist of PATTERNs vs FUNCs, |
| 398 | where PATTERNs are regular expressions and FUNCs are functions. | ||
| 399 | If the element is FUNC, FUNC itself determines the region to | ||
| 400 | compose. | ||
| 398 | 401 | ||
| 399 | If STRING is nil, POS is a position in the current buffer, and the | 402 | Each function is called with 5 arguments, FROM, TO, FONT-OBJECT, |
| 400 | function has to compose a character at POS with surrounding characters | 403 | and STRING. |
| 401 | in the current buffer. | ||
| 402 | 404 | ||
| 403 | Otherwise, STRING is a string, and POS is an index into the string. In | 405 | If STRING is nil, FROM and TO are positions specifying the region |
| 404 | this case, the function has to compose a character at POS with | 406 | maching with PATTERN in the current buffer, and the function has |
| 405 | surrounding characters in the string. | 407 | to compose character in that region (possibly with characters |
| 408 | preceding FROM). The return value of the function is the end | ||
| 409 | position where characters are composed. | ||
| 410 | |||
| 411 | Otherwise, STRING is a string, and FROM and TO are indices into | ||
| 412 | the string. In this case, the function has to compose a | ||
| 413 | character in the string. | ||
| 414 | |||
| 415 | FONT-OBJECT may be nil if not available (e.g. for the case of | ||
| 416 | terminal). | ||
| 406 | 417 | ||
| 407 | See also the command `toggle-auto-composition'.") | 418 | See also the command `toggle-auto-composition'.") |
| 408 | 419 | ||
| @@ -432,28 +443,29 @@ See also the command `toggle-auto-composition'.") | |||
| 432 | (defun terminal-composition-modification (from to) | 443 | (defun terminal-composition-modification (from to) |
| 433 | (terminal-composition-function from)) | 444 | (terminal-composition-function from)) |
| 434 | 445 | ||
| 435 | (defun terminal-composition-function (pos &optional string) | 446 | (defun terminal-composition-function (from to pattern font-object string) |
| 436 | "General composition function used on terminal. | 447 | "General composition function used on terminal. |
| 437 | Non-spacing characters are composed with the preceding spacing | 448 | Non-spacing characters are composed with the preceding spacing |
| 438 | character. All non-spacing characters has this function in | 449 | character. All non-spacing characters has this function in |
| 439 | `terminal-composition-function-table'." | 450 | `terminal-composition-function-table'." |
| 440 | (let ((from (1- pos)) | 451 | (let ((pos (1+ from))) |
| 441 | ch) | ||
| 442 | (if string | 452 | (if string |
| 443 | (length string) | 453 | (progn |
| 444 | (setq pos (1+ pos)) | 454 | (while (and (< pos to) |
| 445 | (while (and (< pos (point-max)) | 455 | (= (aref char-width-table (aref string pos)) 0)) |
| 456 | (setq pos (1+ pos))) | ||
| 457 | (if (> from 0) | ||
| 458 | (compose-string string (1- from) pos) | ||
| 459 | (compose-string string from pos | ||
| 460 | (concat " " (buffer-substring from pos))))) | ||
| 461 | (while (and (< pos to) | ||
| 446 | (= (aref char-width-table (char-after pos)) 0)) | 462 | (= (aref char-width-table (char-after pos)) 0)) |
| 447 | (setq pos (1+ pos))) | 463 | (setq pos (1+ pos))) |
| 448 | (if (and (>= from (point-min)) | 464 | (if (> from (point-min)) |
| 449 | (= (aref (symbol-name (get-char-code-property | 465 | (compose-region (1- from) pos (buffer-substring from pos)) |
| 450 | (char-after from) | 466 | (compose-region from pos |
| 451 | 'general-category)) 0) ?L)) | 467 | (concat " " (buffer-substring from pos))))) |
| 452 | (compose-region from pos (buffer-substring from pos)) | 468 | pos)) |
| 453 | (compose-region (1+ from) pos | ||
| 454 | (concat " " (buffer-substring (1+ from) pos)) | ||
| 455 | 'terminal-composition-modification)) | ||
| 456 | pos))) | ||
| 457 | 469 | ||
| 458 | (defvar terminal-composition-function-table | 470 | (defvar terminal-composition-function-table |
| 459 | (let ((table (make-char-table nil))) | 471 | (let ((table (make-char-table nil))) |
| @@ -467,62 +479,68 @@ character. All non-spacing characters has this function in | |||
| 467 | This is like `composition-function-table' but used when Emacs is running | 479 | This is like `composition-function-table' but used when Emacs is running |
| 468 | on a terminal.") | 480 | on a terminal.") |
| 469 | 481 | ||
| 470 | (defvar auto-compose-current-font nil | 482 | (defun auto-compose-chars (from to window string) |
| 471 | "The current font-object used for characters being composed automatically.") | 483 | "Compose characters in the region between FROM and TO. |
| 472 | |||
| 473 | (defun auto-compose-chars (pos string window) | ||
| 474 | "Compose characters after the buffer position POS. | ||
| 475 | If STRING is non-nil, it is a string, and POS is an index into the string. | ||
| 476 | In that case, compose characters in the string. | ||
| 477 | WINDOW is a window displaying the current buffer. | 484 | WINDOW is a window displaying the current buffer. |
| 485 | If STRING is non-nil, it is a string, and FROM and TO are indices | ||
| 486 | into the string. In that case, compose characters in the string. | ||
| 478 | 487 | ||
| 479 | This function is the default value of `auto-composition-function' (which see)." | 488 | This function is the default value of `auto-composition-function' (which see)." |
| 480 | (save-buffer-state nil | 489 | (save-buffer-state nil |
| 481 | (save-excursion | 490 | (save-excursion |
| 482 | (save-match-data | 491 | (save-restriction |
| 483 | (condition-case nil | 492 | (save-match-data |
| 484 | (let ((start pos) | 493 | (let ((table (if (display-graphic-p) |
| 485 | (limit (if string (length string) (point-max))) | 494 | composition-function-table |
| 486 | (table (if (display-graphic-p) | 495 | terminal-composition-function-table)) |
| 487 | composition-function-table | 496 | (start from)) |
| 488 | terminal-composition-function-table)) | 497 | (setq to (or (text-property-any (1+ from) to 'auto-composed t |
| 489 | auto-compose-current-font | 498 | string) |
| 490 | ch func newpos) | 499 | to)) |
| 491 | (setq limit | 500 | (if string |
| 492 | (or (text-property-any (1+ pos) limit 'auto-composed t | 501 | (while (< from to) |
| 493 | string) | 502 | (let* ((ch (aref string from)) |
| 494 | limit) | 503 | (elt (aref table ch)) |
| 495 | pos | 504 | font-obj newpos) |
| 496 | (catch 'tag | 505 | (when elt |
| 497 | (if string | 506 | (if window |
| 498 | (while (< pos limit) | 507 | (setq font-obj (font-at from window string))) |
| 499 | (setq ch (aref string pos)) | 508 | (if (functionp elt) |
| 500 | (if (= ch ?\n) | 509 | (setq newpos (funcall elt from to font-obj string)) |
| 501 | (throw 'tag (1+ pos))) | 510 | (while (and elt |
| 502 | (setq func (aref table ch)) | 511 | (or (not (eq (string-match (caar elt) string |
| 503 | (if (and (functionp func) | 512 | from) |
| 504 | (setq auto-compose-current-font | 513 | from)) |
| 505 | (and window | 514 | (not (setq newpos |
| 506 | (font-at pos window string))) | 515 | (funcall (cdar elt) from |
| 507 | (setq newpos (funcall func pos string)) | 516 | (match-end 0) |
| 508 | (> newpos pos)) | 517 | font-obj string))))) |
| 509 | (setq pos newpos) | 518 | (setq elt (cdr elt))))) |
| 510 | (setq pos (1+ pos)))) | 519 | (if (and newpos (> newpos from)) |
| 511 | (while (< pos limit) | 520 | (setq from newpos) |
| 512 | (setq ch (char-after pos)) | 521 | (setq from (1+ from))))) |
| 513 | (if (= ch ?\n) | 522 | (narrow-to-region from to) |
| 514 | (throw 'tag (1+ pos))) | 523 | (while (< from to) |
| 515 | (setq func (aref table ch)) | 524 | (let* ((ch (char-after from)) |
| 516 | (if (and (functionp func) | 525 | (elt (aref table ch)) |
| 517 | (setq auto-compose-current-font | 526 | func pattern font-obj newpos) |
| 518 | (and window (font-at pos window))) | 527 | (when elt |
| 519 | (setq newpos (funcall func pos string)) | 528 | (if window |
| 520 | (> newpos pos)) | 529 | (setq font-obj (font-at from window))) |
| 521 | (setq pos newpos) | 530 | (if (functionp elt) |
| 522 | (setq pos (1+ pos))))) | 531 | (setq newpos (funcall elt from to font-obj nil)) |
| 523 | limit)) | 532 | (goto-char from) |
| 524 | (put-text-property start pos 'auto-composed t string)) | 533 | (while (and elt |
| 525 | (error nil)))))) | 534 | (or (not (looking-at (caar elt))) |
| 535 | (not (setq newpos | ||
| 536 | (funcall (cdar elt) from | ||
| 537 | (match-end 0) | ||
| 538 | font-obj nil))))) | ||
| 539 | (setq elt (cdr elt))))) | ||
| 540 | (if (and newpos (> newpos from)) | ||
| 541 | (setq from newpos) | ||
| 542 | (setq from (1+ from)))))) | ||
| 543 | (put-text-property start to 'auto-composed t string))))))) | ||
| 526 | 544 | ||
| 527 | (make-variable-buffer-local 'auto-composition-function) | 545 | (make-variable-buffer-local 'auto-composition-function) |
| 528 | 546 | ||