aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/composite.el164
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
394preceding and/or following characters, this char table contains 394preceding and/or following characters, this char table contains
395a function to call to compose that character. 395a function to call to compose that character.
396 396
397Each function is called with two arguments, POS and STRING. 397An element, if non-nil, is FUNC or an alist of PATTERNs vs FUNCs,
398where PATTERNs are regular expressions and FUNCs are functions.
399If the element is FUNC, FUNC itself determines the region to
400compose.
398 401
399If STRING is nil, POS is a position in the current buffer, and the 402Each function is called with 5 arguments, FROM, TO, FONT-OBJECT,
400function has to compose a character at POS with surrounding characters 403and STRING.
401in the current buffer.
402 404
403Otherwise, STRING is a string, and POS is an index into the string. In 405If STRING is nil, FROM and TO are positions specifying the region
404this case, the function has to compose a character at POS with 406maching with PATTERN in the current buffer, and the function has
405surrounding characters in the string. 407to compose character in that region (possibly with characters
408preceding FROM). The return value of the function is the end
409position where characters are composed.
410
411Otherwise, STRING is a string, and FROM and TO are indices into
412the string. In this case, the function has to compose a
413character in the string.
414
415FONT-OBJECT may be nil if not available (e.g. for the case of
416terminal).
406 417
407See also the command `toggle-auto-composition'.") 418See 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.
437Non-spacing characters are composed with the preceding spacing 448Non-spacing characters are composed with the preceding spacing
438character. All non-spacing characters has this function in 449character. 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
467This is like `composition-function-table' but used when Emacs is running 479This is like `composition-function-table' but used when Emacs is running
468on a terminal.") 480on 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.
475If STRING is non-nil, it is a string, and POS is an index into the string.
476In that case, compose characters in the string.
477WINDOW is a window displaying the current buffer. 484WINDOW is a window displaying the current buffer.
485If STRING is non-nil, it is a string, and FROM and TO are indices
486into the string. In that case, compose characters in the string.
478 487
479This function is the default value of `auto-composition-function' (which see)." 488This 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