/[emacs]/emacs/lisp/composite.el
ViewVC logotype

Diff of /emacs/lisp/composite.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.8.6.1 by fx, Thu Jun 27 21:59:18 2002 UTC revision 1.8.6.2 by handa, Thu Nov 7 06:27:27 2002 UTC
# Line 26  Line 26 
26    
27  ;;; Code:  ;;; Code:
28    
 ;;;###autoload  
29  (defconst reference-point-alist  (defconst reference-point-alist
30    '((tl . 0) (tc . 1) (tr . 2)    '((tl . 0) (tc . 1) (tr . 2)
31      (Bl . 3) (Bc . 4) (Br . 5)      (Bl . 3) (Bc . 4) (Br . 5)
# Line 154  follows (the point `*' corresponds to bo Line 153  follows (the point `*' corresponds to bo
153        (setq i (+ i 2))))        (setq i (+ i 2))))
154    components)    components)
155    
 ;;;###autoload  
156  (defun compose-region (start end &optional components modification-func)  (defun compose-region (start end &optional components modification-func)
157    "Compose characters in the current region.    "Compose characters in the current region.
158    
# Line 191  text in the composition." Line 189  text in the composition."
189      (compose-region-internal start end components modification-func)      (compose-region-internal start end components modification-func)
190      (set-buffer-modified-p modified-p)))      (set-buffer-modified-p modified-p)))
191    
 ;;;###autoload  
192  (defun decompose-region (start end)  (defun decompose-region (start end)
193    "Decompose text in the current region.    "Decompose text in the current region.
194    
# Line 203  positions (integers or markers) specifyi Line 200  positions (integers or markers) specifyi
200      (remove-text-properties start end '(composition nil))      (remove-text-properties start end '(composition nil))
201      (set-buffer-modified-p modified-p)))      (set-buffer-modified-p modified-p)))
202    
 ;;;###autoload  
203  (defun compose-string (string &optional start end components modification-func)  (defun compose-string (string &optional start end components modification-func)
204    "Compose characters in string STRING.    "Compose characters in string STRING.
205    
# Line 228  text in the composition." Line 224  text in the composition."
224    (compose-string-internal string start end components modification-func)    (compose-string-internal string start end components modification-func)
225    string)    string)
226    
 ;;;###autoload  
227  (defun decompose-string (string)  (defun decompose-string (string)
228    "Return STRING where `composition' property is removed."    "Return STRING where `composition' property is removed."
229    (remove-text-properties 0 (length string) '(composition nil) string)    (remove-text-properties 0 (length string) '(composition nil) string)
230    string)    string)
231    
 ;;;###autoload  
232  (defun compose-chars (&rest args)  (defun compose-chars (&rest args)
233    "Return a string from arguments in which all characters are composed.    "Return a string from arguments in which all characters are composed.
234  For relative composition, arguments are characters.  For relative composition, arguments are characters.
# Line 258  A composition rule is a cons of glyph re Line 252  A composition rule is a cons of glyph re
252        (setq str (concat args)))        (setq str (concat args)))
253      (compose-string-internal str 0 (length str) components)))      (compose-string-internal str 0 (length str) components)))
254    
 ;;;###autoload  
255  (defun find-composition (pos &optional limit string detail-p)  (defun find-composition (pos &optional limit string detail-p)
256    "Return information about a composition at or nearest to buffer position POS.    "Return information about a composition at or nearest to buffer position POS.
257    
# Line 298  WIDTH is a number of columns the composi Line 291  WIDTH is a number of columns the composi
291      result))      result))
292    
293    
 ;;;###autoload  
294  (defun compose-chars-after (pos &optional limit object)  (defun compose-chars-after (pos &optional limit object)
295    "Compose characters in current buffer after position POS.    "Compose characters in current buffer after position POS.
296    
# Line 339  This function is the default value of `c Line 331  This function is the default value of `c
331                (setq func nil tail (cdr tail)))))))                (setq func nil tail (cdr tail)))))))
332        result))        result))
333    
 ;;;###autoload  
334  (defun compose-last-chars (args)  (defun compose-last-chars (args)
335    "Compose last characters.    "Compose last characters.
336  The argument is a parameterized event of the form  The argument is a parameterized event of the form
# Line 360  after a sequence character events." Line 351  after a sequence character events."
351              (compose-region (- (point) chars) (point) (nth 2 args))              (compose-region (- (point) chars) (point) (nth 2 args))
352            (compose-chars-after (- (point) chars) (point))))))            (compose-chars-after (- (point) chars) (point))))))
353    
354  ;;;###autoload(global-set-key [compose-last-chars] 'compose-last-chars)  (global-set-key [compose-last-chars] 'compose-last-chars)
355    
356    
357    ;;; Automatic character composition.
358    
359    (defvar composition-function-table
360      (make-char-table nil)
361      "Char table of functions for automatic character composition.
362    For each character that has to be composed automatically with
363    preceding and/or following characters, this char table contains
364    a function to call to compose that character.
365    
366    Each function is called with two arguments, POS and STRING.
367    
368    If STRING is nil, POS is a position in the current buffer, and the
369    function has to compose a character at POS with surrounding characters
370    in the current buffer.
371    
372    Otherwise, STRING is a string, and POS is an index to the string.  In
373    this case, the function has to compose a character at POS with
374    surrounding characters in the string.
375    
376    See also the command `toggle-auto-composition'.")
377    
378    ;; Copied from font-lock.el.
379    (eval-when-compile
380      ;;
381      ;; We don't do this at the top-level as we only use non-autoloaded macros.
382      (require 'cl)
383      ;;
384      ;; Borrowed from lazy-lock.el.
385      ;; We use this to preserve or protect things when modifying text properties.
386      (defmacro save-buffer-state (varlist &rest body)
387        "Bind variables according to VARLIST and eval BODY restoring buffer state."
388        (let ((modified (make-symbol "modified")))
389          `(let* ,(append varlist
390                          `((,modified (buffer-modified-p))
391                            (buffer-undo-list t)
392                            (inhibit-read-only t)
393                            (inhibit-point-motion-hooks t)
394                            (inhibit-modification-hooks t)
395                            deactivate-mark
396                            buffer-file-name
397                            buffer-file-truename))
398             (progn
399               ,@body)
400             (unless ,modified
401               (restore-buffer-modified-p nil)))))
402      (put 'save-buffer-state 'lisp-indent-function 1)
403      (def-edebug-spec save-buffer-state let))
404    
405    
406    (defvar auto-composition-chunk-size 500
407      "*Automatic composition chunks of this many characters, or smaller.")
408    
409    (defun auto-compose-chars (pos string)
410      "Compose characters after the buffer position POS.
411    If STRING is non-nil, it is a string, and POS is an index to the string.
412    In that case, compose characters in the string.
413    
414    This function is the default value of `auto-composition-function' (which see)."
415      (save-buffer-state nil
416        (save-excursion
417          (save-restriction
418            (save-match-data
419              (let* ((start pos)
420                     (end (if string (length string) (point-max)))
421                     (limit (next-single-property-change pos 'auto-composed string
422                                                         end))
423                     (lines 0)
424                     ch func newpos)
425                (if (> (- limit start) auto-composition-chunk-size)
426                    (setq limit (+ start auto-composition-chunk-size)))
427                (while (and (< pos end)
428                            (setq ch (if string (aref string pos)
429                                       (char-after pos)))
430                            (or (< pos limit)
431                                (/= ch ?\n)))
432                  (setq func (aref composition-function-table ch))
433                  (if (fboundp func)
434                      (setq newpos (funcall func pos string)
435                            pos (if (and (integerp newpos) (> newpos pos))
436                                    newpos
437                                  (1+ pos)))
438                    (setq pos (1+ pos))))
439                (if (< pos limit)
440                    (setq pos (1+ pos)))
441                (put-text-property start pos 'auto-composed t string)))))))
442    
443    (setq auto-composition-function 'auto-compose-chars)
444    
445    (defun toggle-auto-composition (&optional arg)
446      "Change whether automatic character composition is enabled in this buffer.
447    With arg, enable it iff arg is positive."
448      (interactive "P")
449      (let ((enable (if (null arg) (not auto-composition-function)
450                      (> (prefix-numeric-value arg) 0))))
451        (if enable
452            (kill-local-variable 'auto-composition-function)
453          (make-local-variable 'auto-composition-function)
454          (setq auto-composition-function nil)
455          (save-buffer-state nil
456            (save-restriction
457              (widen)
458              (decompose-region (point-min) (point-max)))))
459    
460        (save-buffer-state nil
461          (save-restriction
462            (widen)
463            (put-text-property (point-min) (point-max) 'auto-composed nil)))))
464    
465    
466  ;;; The following codes are only for backward compatibility with Emacs  ;;; The following codes are only for backward compatibility with Emacs
467  ;;; 20.4 and the earlier.  ;;; 20.4 and the earlier.
468    
 ;;;###autoload  
469  (defun decompose-composite-char (char &optional type with-composition-rule)  (defun decompose-composite-char (char &optional type with-composition-rule)
470    "Convert CHAR to string.    "Convert CHAR to string.
471  This is only for backward compatibility with Emacs 20.4 and the earlier.  This is only for backward compatibility with Emacs 20.4 and the earlier.

Legend:
Removed from v.1.8.6.1  
changed lines
  Added in v.1.8.6.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26