comparison lisp/wid-edit.el @ 1735:c521eeaafa0d

[xemacs-hg @ 2003-10-10 10:44:55 by stephent] widget-default-create optimization <8765ixnzix.fsf_-_@tleepslib.sk.tsukuba.ac.jp>
author stephent
date Fri, 10 Oct 2003 10:45:01 +0000
parents 2e0147538471
children 92dd8587c485
comparison
equal deleted inserted replaced
1734:d6d41d23b6ec 1735:c521eeaafa0d
1761 ;; sjt sez: 1761 ;; sjt sez:
1762 ;; There are other things to try: 1762 ;; There are other things to try:
1763 ;; 1. Use skip-chars-forward. 1763 ;; 1. Use skip-chars-forward.
1764 ;; 2. Use a LIMIT (or narrow buffer?) in the search/skip expression. 1764 ;; 2. Use a LIMIT (or narrow buffer?) in the search/skip expression.
1765 ;; 3. Search/skip backward to allow LIMIT to be constant. 1765 ;; 3. Search/skip backward to allow LIMIT to be constant.
1766 ;; 4. Use a char-table to dispatch to code, instead of a cond.
1767 (while (re-search-forward "%\\(.\\)" nil t) 1766 (while (re-search-forward "%\\(.\\)" nil t)
1768 (let ((escape (aref (match-string 1) 0))) 1767 (let ((escape (aref (match-string 1) 0)))
1769 (replace-match "" t t) 1768 (replace-match "" t t)
1770 (cond ((eq escape ?%) 1769 (funcall
1771 (insert ?%)) 1770 (aref
1772 ((eq escape ?\[) 1771 [(lambda () ;?%
1773 (setq button-begin (point-marker)) 1772 (insert ?%))
1774 (set-marker-insertion-type button-begin nil)) 1773 (lambda () ;?\[
1775 ((eq escape ?\]) 1774 (setq button-begin (point-marker))
1776 (setq button-end (point-marker)) 1775 (set-marker-insertion-type button-begin nil))
1777 (set-marker-insertion-type button-end nil)) 1776 (lambda () ;?\]
1778 ((eq escape ?\{) 1777 (setq button-end (point-marker))
1779 (setq sample-begin (point))) 1778 (set-marker-insertion-type button-end nil))
1780 ((eq escape ?\}) 1779 (lambda () ;?\{
1781 (setq sample-end (point))) 1780 (setq sample-begin (point)))
1782 ((eq escape ?n) 1781 (lambda () ;?\}
1783 (when (widget-get widget :indent) 1782 (setq sample-end (point)))
1783 (lambda () ;?n
1784 (when (widget-get widget :indent)
1785 (insert ?\n)
1786 (insert-char ?\ (widget-get widget :indent))))
1787 (lambda () ;?t
1788 (let* ((tag (widget-get widget :tag))
1789 (glyph (widget-get widget :tag-glyph)))
1790 (cond (glyph
1791 (setq button-glyph
1792 (widget-glyph-insert
1793 widget (or tag "Image") glyph)))
1794 (tag
1795 (insert tag))
1796 (t
1797 (princ (widget-get widget :value)
1798 (current-buffer))))))
1799 (lambda () ;?d
1800 (let ((doc (widget-get widget :doc)))
1801 (when doc
1802 (setq doc-begin (point))
1803 (insert doc)
1804 (while (eq (preceding-char) ?\n)
1805 (delete-backward-char 1))
1784 (insert ?\n) 1806 (insert ?\n)
1785 (insert-char ?\ (widget-get widget :indent)))) 1807 (setq doc-end (point)))))
1786 ((eq escape ?t) 1808 (lambda () ;?v
1787 (let* ((tag (widget-get widget :tag)) 1809 (if (and button-begin (not button-end))
1788 (glyph (widget-get widget :tag-glyph))) 1810 (widget-apply widget :value-create)
1789 (cond (glyph 1811 (setq value-pos (point-marker))))
1790 (setq button-glyph 1812 (lambda () ;otherwise
1791 (widget-glyph-insert 1813 (widget-apply widget :format-handler escape))]
1792 widget (or tag "Image") glyph))) 1814 (string-match (format "[%c\010]" escape) ;^H can't be found in buff
1793 (tag 1815 "%[]{}ntdv\010"))))) ;so it can be 'otherwise' cond
1794 (insert tag))
1795 (t
1796 (princ (widget-get widget :value)
1797 (current-buffer))))))
1798 ((eq escape ?d)
1799 (let ((doc (widget-get widget :doc)))
1800 (when doc
1801 (setq doc-begin (point))
1802 (insert doc)
1803 (while (eq (preceding-char) ?\n)
1804 (delete-backward-char 1))
1805 (insert ?\n)
1806 (setq doc-end (point)))))
1807 ((eq escape ?v)
1808 (if (and button-begin (not button-end))
1809 (widget-apply widget :value-create)
1810 (setq value-pos (point-marker))))
1811 (t
1812 (widget-apply widget :format-handler escape)))))
1813 ;; Specify button, sample, and doc, and insert value. 1816 ;; Specify button, sample, and doc, and insert value.
1814 (when (and button-begin button-end) 1817 (when (and button-begin button-end)
1815 (unless button-glyph 1818 (unless button-glyph
1816 (goto-char button-begin) 1819 (goto-char button-begin)
1817 (insert (widget-get-indirect widget :button-prefix)) 1820 (insert (widget-get-indirect widget :button-prefix))