+(defun terminal-composition-function (pos &optional string)
+ "General composition function used on terminal.
+Non-spacing characters are composed with the preceding spacing
+character. All non-spacing characters has this function in
+`terminal-composition-function-table'."
+ (let ((from (1- pos))
+ ch)
+ (if string
+ (length string)
+ (setq pos (1+ pos))
+ (while (and (< pos (point-max))
+ (= (aref char-width-table (char-after pos)) 0))
+ (setq pos (1+ pos)))
+ (if (and (>= from (point-min))
+ (= (aref (symbol-name (get-char-code-property (char-after from)
+ 'general-category))
+ 0)
+ ?L))
+ (compose-region from pos (buffer-substring from pos))
+ (compose-region (1+ from) pos
+ (concat " " (buffer-substring (1+ from) pos))))
+ pos)))
+
+(defvar terminal-composition-function-table
+ (let ((table (make-char-table nil)))
+ (map-char-table
+ #'(lambda (key val)
+ (if (= val 0) (set-char-table-range table key
+ 'terminal-composition-function)))
+ char-width-table)
+ table)
+ "Char table of functions for automatic character composition on terminal.
+This is like `composition-function-table' but used when Emacs is running
+on a terminal.")
+