]> code.delx.au - gnu-emacs/blobdiff - lisp/composite.el
Merge from mainline.
[gnu-emacs] / lisp / composite.el
index 7c04bcff088e3b1ec63f1d833dd0a190a0581b95..6a12b42e41148ffc18993bfca4273b67df040d31 100644 (file)
@@ -1,7 +1,7 @@
 ;;; composite.el --- support character composition
 
 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
-;;   2008, 2009
+;;   2008, 2009, 2010
 ;;   National Institute of Advanced Industrial Science and Technology (AIST)
 ;;   Registration Number H14PRO021
 
@@ -185,8 +185,17 @@ RULE is a cons of global and new reference point symbols
 (defun compose-region (start end &optional components modification-func)
   "Compose characters in the current region.
 
-Characters are composed relatively, i.e. composed by overstricking or
-stacking depending on ascent, descent and other properties.
+Characters are composed relatively, i.e. composed by overstriking
+or stacking depending on ascent, descent and other metrics of
+glyphs.
+
+For instance, if the region has three characters \"XYZ\", X is
+regarded as BASE glyph, and Y is displayed:
+  (1) above BASE if Y's descent value is not positive
+  (2) below BASE if Y's ascent value is not positive
+  (3) on BASE (i.e. at the BASE position) otherwise
+and Z is displayed with the same rule while regarding the whole
+XY glyphs as BASE.
 
 When called from a program, expects these four arguments.
 
@@ -646,7 +655,7 @@ All non-spacing characters has this function in
              (setq i (1+ i))))
          gstring))))))
 
-(let ((elt '(["\\c.\\c^+" 1 compose-gstring-for-graphic]
+(let ((elt `([,(purecopy "\\c.\\c^+") 1 compose-gstring-for-graphic]
             [nil 0 compose-gstring-for-graphic])))
   (map-char-table
    #'(lambda (key val)
@@ -681,7 +690,14 @@ a prepending a space before it."
              (lglyph-set-from-to glyph i i)
              (setq i (1+ i))))
        (if (= (lglyph-width glyph) 0)
-           (progn
+           (if (eq (get-char-code-property (lglyph-char glyph)
+                                           'general-category)
+                   'Cf)
+               (progn
+                 ;; Compose by replacing with a space.
+                 (lglyph-set-char glyph 32)
+                 (lglyph-set-width glyph 1)
+                 (setq i (1+ i)))
              ;; Compose by prepending a space.
              (setq gstring (lgstring-insert-glyph gstring i
                                                   (lglyph-copy glyph))
@@ -712,9 +728,7 @@ FUNC is called with one argument GSTRING which is built for characters
 in the region FROM (inclusive) and TO (exclusive).
 
 If the character are composed on a graphic display, FONT-OBJECT
-is a font to use.
-
-Otherwise, FONT-OBJECT is nil, and the fucntion
+is a font to use.  Otherwise, FONT-OBJECT is nil, and the function
 `compose-gstring-for-terminal' is used instead of FUNC.
 
 If STRING is non-nil, it is a string, and FROM and TO are indices
@@ -730,10 +744,14 @@ This function is the default value of `auto-composition-function' (which see)."
          (setq func 'compose-gstring-for-terminal))
       (funcall func gstring))))
 
+(make-variable-buffer-local 'auto-composition-mode)
+(put 'auto-composition-mode 'permanent-local t)
+
 (make-variable-buffer-local 'auto-composition-function)
+(setq-default auto-composition-function 'auto-compose-chars)
 
 ;;;###autoload
-(define-minor-mode auto-composition-mode
+(defun auto-composition-mode (&optional arg)
   "Toggle Auto Composition mode.
 With ARG, turn Auto Composition mode off if and only if ARG is a non-positive
 number; if ARG is nil, toggle Auto Composition mode; anything else turns Auto
@@ -744,27 +762,23 @@ by functions registered in `composition-function-table' (which see).
 
 You can use `global-auto-composition-mode' to 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
-        (setq auto-composition-function 'auto-compose-chars))
-       (t
-        (setq auto-composition-function nil))))
-
-(defun turn-on-auto-composition-if-enabled ()
-  (if enable-multibyte-characters
-      (auto-composition-mode 1)))
+  (interactive "P")
+  (setq auto-composition-mode
+       (if arg
+           (or (not (integerp arg)) (> arg 0))
+         (not auto-composition-mode))))
 
 ;;;###autoload
-(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 noninteractive)
-  :group 'auto-composition
-  :version "23.1")
-
+(defun global-auto-composition-mode (&optional arg)
+  "Toggle Auto-Composition mode in every possible buffer.
+With prefix arg, turn Global-Auto-Composition mode on if and only if arg
+is positive.
+See `auto-composition-mode' for more information on Auto-Composition mode."
+  (interactive "P")
+  (setq-default auto-composition-mode
+               (if arg
+                   (or (not (integerp arg)) (> arg 0))
+                 (not (default-value 'auto-composition-mode)))))
 (defalias 'toggle-auto-composition 'auto-composition-mode)
 
 \f