# HG changeset patch # User Kenichi Handa # Date 1140516948 0 # Node ID 696f125c3c6ac73643ecda5170f6913265db3e80 # Parent c1b0df36fbad73120a2556d09b89119ec33b2617 (auto-composition-function): Make it buffer local. (auto-composition-mode): New minor mode. (turn-on-auto-composition-if-enabled): New function. (global-auto-composition-mode): New global minor mode. diff -r c1b0df36fbad -r 696f125c3c6a lisp/composite.el --- a/lisp/composite.el Mon Feb 20 11:16:28 2006 +0000 +++ b/lisp/composite.el Tue Feb 21 10:15:48 2006 +0000 @@ -470,7 +470,81 @@ (put-text-property start pos 'auto-composed t string)) (error nil)))))) -(setq auto-composition-function 'auto-compose-chars) +(make-variable-buffer-local 'auto-composition-function) + +(define-minor-mode auto-composition-mode + "Toggle Auto Compostion mode. +With arg, turn Auto Compostion mode off if and only if arg is a non-positive +number; if arg is nil, toggle Auto Compostion mode; anything else turns Auto +Compostion on. + +When Auto Composition is enabled, text characters are automatically composed +by functions registered in `composition-function-table' (which see). + +You can use Global Auto Composition mode to automagically turn on +Auto Composition mode in all buffers (this is the default)." + nil nil nil + (if noninteractive + (setq auto-composition-mode nil)) + (cond (auto-composition-mode + (add-hook 'after-change-functions 'auto-composition-after-change nil t) + (setq auto-composition-function 'auto-compose-chars)) + (t + (remove-hook 'after-change-functions 'auto-composition-after-change t) + (setq auto-composition-function nil))) + (save-buffer-state nil + (save-restriction + (widen) + (remove-text-properties (point-min) (point-max) '(auto-composed nil)) + (decompose-region (point-min) (point-max))))) + +(defun auto-composition-after-change (start end old-len) + (when (and auto-composition-mode (not memory-full)) + (let (func1 func2) + (when (and (> start (point-min)) + (setq func2 (aref composition-function-table + (char-after (1- start)))) + (or (= start (point-max)) + (not (setq func1 (aref composition-function-table + (char-after start)))) + (eq func1 func2))) + (setq start (1- start) + func1 func2) + (while (eq func1 func2) + (if (> start (point-min)) + (setq start (1- start) + func2 (aref composition-function-table + (char-after start))) + (setq func2 nil)))) + (when (and (< end (point-max)) + (setq func2 (aref composition-function-table + (char-after end))) + (or (= end (point-min)) + (not (setq func1 (aref composition-function-table + (char-after (1- end))))) + (eq func1 func2))) + (setq end (1+ end) + func1 func2) + (while (eq func1 func2) + (if (< end (point-max)) + (setq func2 (aref composition-function-table + (char-after end)) + end (1+ end)) + (setq func2 nil)))) + (if (< start end) + (put-text-property start end 'auto-composed nil))))) + +(defun turn-on-auto-composition-if-enabled () + (or auto-composition-mode + (auto-composition-mode))) + +(define-global-minor-mode global-auto-composition-mode + auto-composition-mode turn-on-auto-composition-if-enabled + :extra-args (dummy) + :initialize 'custom-initialize-safe-default + :init-value (not (or noninteractive emacs-basic-display)) + :group 'auto-composition + :version "23.1") (defun toggle-auto-composition (&optional arg) "Change whether automatic character composition is enabled in this buffer.