aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorKenichi Handa2006-02-21 10:15:48 +0000
committerKenichi Handa2006-02-21 10:15:48 +0000
commit37707939812a5e6eedb474c85787e1c186f1c04e (patch)
tree86f05b9556e00b88f13baedd7d88ce9e28d10880 /lisp
parent1dc6c31bccef935143f550c5fcded912d2495608 (diff)
downloademacs-37707939812a5e6eedb474c85787e1c186f1c04e.tar.gz
emacs-37707939812a5e6eedb474c85787e1c186f1c04e.zip
(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.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/composite.el76
1 files changed, 75 insertions, 1 deletions
diff --git a/lisp/composite.el b/lisp/composite.el
index 9739b1fd53e..440e90a6b24 100644
--- a/lisp/composite.el
+++ b/lisp/composite.el
@@ -470,7 +470,81 @@ This function is the default value of `auto-composition-function' (which see)."
470 (put-text-property start pos 'auto-composed t string)) 470 (put-text-property start pos 'auto-composed t string))
471 (error nil)))))) 471 (error nil))))))
472 472
473(setq auto-composition-function 'auto-compose-chars) 473(make-variable-buffer-local 'auto-composition-function)
474
475(define-minor-mode auto-composition-mode
476 "Toggle Auto Compostion mode.
477With arg, turn Auto Compostion mode off if and only if arg is a non-positive
478number; if arg is nil, toggle Auto Compostion mode; anything else turns Auto
479Compostion on.
480
481When Auto Composition is enabled, text characters are automatically composed
482by functions registered in `composition-function-table' (which see).
483
484You can use Global Auto Composition mode to automagically turn on
485Auto Composition mode in all buffers (this is the default)."
486 nil nil nil
487 (if noninteractive
488 (setq auto-composition-mode nil))
489 (cond (auto-composition-mode
490 (add-hook 'after-change-functions 'auto-composition-after-change nil t)
491 (setq auto-composition-function 'auto-compose-chars))
492 (t
493 (remove-hook 'after-change-functions 'auto-composition-after-change t)
494 (setq auto-composition-function nil)))
495 (save-buffer-state nil
496 (save-restriction
497 (widen)
498 (remove-text-properties (point-min) (point-max) '(auto-composed nil))
499 (decompose-region (point-min) (point-max)))))
500
501(defun auto-composition-after-change (start end old-len)
502 (when (and auto-composition-mode (not memory-full))
503 (let (func1 func2)
504 (when (and (> start (point-min))
505 (setq func2 (aref composition-function-table
506 (char-after (1- start))))
507 (or (= start (point-max))
508 (not (setq func1 (aref composition-function-table
509 (char-after start))))
510 (eq func1 func2)))
511 (setq start (1- start)
512 func1 func2)
513 (while (eq func1 func2)
514 (if (> start (point-min))
515 (setq start (1- start)
516 func2 (aref composition-function-table
517 (char-after start)))
518 (setq func2 nil))))
519 (when (and (< end (point-max))
520 (setq func2 (aref composition-function-table
521 (char-after end)))
522 (or (= end (point-min))
523 (not (setq func1 (aref composition-function-table
524 (char-after (1- end)))))
525 (eq func1 func2)))
526 (setq end (1+ end)
527 func1 func2)
528 (while (eq func1 func2)
529 (if (< end (point-max))
530 (setq func2 (aref composition-function-table
531 (char-after end))
532 end (1+ end))
533 (setq func2 nil))))
534 (if (< start end)
535 (put-text-property start end 'auto-composed nil)))))
536
537(defun turn-on-auto-composition-if-enabled ()
538 (or auto-composition-mode
539 (auto-composition-mode)))
540
541(define-global-minor-mode global-auto-composition-mode
542 auto-composition-mode turn-on-auto-composition-if-enabled
543 :extra-args (dummy)
544 :initialize 'custom-initialize-safe-default
545 :init-value (not (or noninteractive emacs-basic-display))
546 :group 'auto-composition
547 :version "23.1")
474 548
475(defun toggle-auto-composition (&optional arg) 549(defun toggle-auto-composition (&optional arg)
476 "Change whether automatic character composition is enabled in this buffer. 550 "Change whether automatic character composition is enabled in this buffer.