diff lisp/composite.el @ 89290:adbc95471ef8

Remove all autoload cookies. (composition-function-table): Variable declaration moved from composite.c. Format changed. (save-buffer-state): Copied from font-lock.el. (auto-composition-chunk-size): New variable. (auto-compose-chars): New function. Set auto-composition-function to it. (toggle-auto-composition): New function.
author Kenichi Handa <handa@m17n.org>
date Thu, 07 Nov 2002 06:27:27 +0000
parents 8219830269aa
children 2cf77d6e4261
line wrap: on
line diff
--- a/lisp/composite.el	Thu Nov 07 06:27:02 2002 +0000
+++ b/lisp/composite.el	Thu Nov 07 06:27:27 2002 +0000
@@ -26,7 +26,6 @@
 
 ;;; Code:
 
-;;;###autoload
 (defconst reference-point-alist
   '((tl . 0) (tc . 1) (tr . 2)
     (Bl . 3) (Bc . 4) (Br . 5)
@@ -154,7 +153,6 @@
       (setq i (+ i 2))))
   components)
 
-;;;###autoload
 (defun compose-region (start end &optional components modification-func)
   "Compose characters in the current region.
 
@@ -191,7 +189,6 @@
     (compose-region-internal start end components modification-func)
     (set-buffer-modified-p modified-p)))
 
-;;;###autoload
 (defun decompose-region (start end)
   "Decompose text in the current region.
 
@@ -203,7 +200,6 @@
     (remove-text-properties start end '(composition nil))
     (set-buffer-modified-p modified-p)))
 
-;;;###autoload
 (defun compose-string (string &optional start end components modification-func)
   "Compose characters in string STRING.
 
@@ -228,13 +224,11 @@
   (compose-string-internal string start end components modification-func)
   string)
 
-;;;###autoload
 (defun decompose-string (string)
   "Return STRING where `composition' property is removed."
   (remove-text-properties 0 (length string) '(composition nil) string)
   string)
 
-;;;###autoload
 (defun compose-chars (&rest args)
   "Return a string from arguments in which all characters are composed.
 For relative composition, arguments are characters.
@@ -258,7 +252,6 @@
       (setq str (concat args)))
     (compose-string-internal str 0 (length str) components)))
 
-;;;###autoload
 (defun find-composition (pos &optional limit string detail-p)
   "Return information about a composition at or nearest to buffer position POS.
 
@@ -298,7 +291,6 @@
     result))
 
 
-;;;###autoload
 (defun compose-chars-after (pos &optional limit object)
   "Compose characters in current buffer after position POS.
 
@@ -339,7 +331,6 @@
 	      (setq func nil tail (cdr tail)))))))
       result))
 
-;;;###autoload
 (defun compose-last-chars (args)
   "Compose last characters.
 The argument is a parameterized event of the form
@@ -360,13 +351,121 @@
 	    (compose-region (- (point) chars) (point) (nth 2 args))
 	  (compose-chars-after (- (point) chars) (point))))))
 
-;;;###autoload(global-set-key [compose-last-chars] 'compose-last-chars)
+(global-set-key [compose-last-chars] 'compose-last-chars)
+
+
+;;; Automatic character composition.
+
+(defvar composition-function-table
+  (make-char-table nil)
+  "Char table of functions for automatic character composition.
+For each character that has to be composed automatically with
+preceding and/or following characters, this char table contains
+a function to call to compose that character.
+
+Each function is called with two arguments, POS and STRING.
+
+If STRING is nil, POS is a position in the current buffer, and the
+function has to compose a character at POS with surrounding characters
+in the current buffer.
+
+Otherwise, STRING is a string, and POS is an index to the string.  In
+this case, the function has to compose a character at POS with
+surrounding characters in the string.
+
+See also the command `toggle-auto-composition'.")
+
+;; Copied from font-lock.el.
+(eval-when-compile
+  ;;
+  ;; We don't do this at the top-level as we only use non-autoloaded macros.
+  (require 'cl)
+  ;;
+  ;; Borrowed from lazy-lock.el.
+  ;; We use this to preserve or protect things when modifying text properties.
+  (defmacro save-buffer-state (varlist &rest body)
+    "Bind variables according to VARLIST and eval BODY restoring buffer state."
+    (let ((modified (make-symbol "modified")))
+      `(let* ,(append varlist
+		      `((,modified (buffer-modified-p))
+			(buffer-undo-list t)
+			(inhibit-read-only t)
+			(inhibit-point-motion-hooks t)
+			(inhibit-modification-hooks t)
+			deactivate-mark
+			buffer-file-name
+			buffer-file-truename))
+	 (progn
+	   ,@body)
+	 (unless ,modified
+	   (restore-buffer-modified-p nil)))))
+  (put 'save-buffer-state 'lisp-indent-function 1)
+  (def-edebug-spec save-buffer-state let))
+
+
+(defvar auto-composition-chunk-size 500
+  "*Automatic composition chunks of this many characters, or smaller.")
+
+(defun auto-compose-chars (pos string)
+  "Compose characters after the buffer position POS.
+If STRING is non-nil, it is a string, and POS is an index to the string.
+In that case, compose characters in the string.
+
+This function is the default value of `auto-composition-function' (which see)."
+  (save-buffer-state nil
+    (save-excursion
+      (save-restriction
+	(save-match-data
+	  (let* ((start pos)
+		 (end (if string (length string) (point-max)))
+		 (limit (next-single-property-change pos 'auto-composed string
+						     end))
+		 (lines 0)
+		 ch func newpos)
+	    (if (> (- limit start) auto-composition-chunk-size)
+		(setq limit (+ start auto-composition-chunk-size)))
+	    (while (and (< pos end)
+			(setq ch (if string (aref string pos)
+				   (char-after pos)))
+			(or (< pos limit)
+			    (/= ch ?\n)))
+	      (setq func (aref composition-function-table ch))
+	      (if (fboundp func)
+		  (setq newpos (funcall func pos string)
+			pos (if (and (integerp newpos) (> newpos pos))
+				newpos
+			      (1+ pos)))
+		(setq pos (1+ pos))))
+	    (if (< pos limit)
+		(setq pos (1+ pos)))
+	    (put-text-property start pos 'auto-composed t string)))))))
+
+(setq auto-composition-function 'auto-compose-chars)
+
+(defun toggle-auto-composition (&optional arg)
+  "Change whether automatic character composition is enabled in this buffer.
+With arg, enable it iff arg is positive."
+  (interactive "P")
+  (let ((enable (if (null arg) (not auto-composition-function)
+		  (> (prefix-numeric-value arg) 0))))
+    (if enable
+	(kill-local-variable 'auto-composition-function)
+      (make-local-variable 'auto-composition-function)
+      (setq auto-composition-function nil)
+      (save-buffer-state nil
+	(save-restriction
+	  (widen)
+	  (decompose-region (point-min) (point-max)))))
+
+    (save-buffer-state nil
+      (save-restriction
+	(widen)
+	(put-text-property (point-min) (point-max) 'auto-composed nil)))))
 
 
 ;;; The following codes are only for backward compatibility with Emacs
 ;;; 20.4 and the earlier.
 
-;;;###autoload
 (defun decompose-composite-char (char &optional type with-composition-rule)
   "Convert CHAR to string.
 This is only for backward compatibility with Emacs 20.4 and the earlier.