Mercurial > emacs
comparison lisp/wid-edit.el @ 18374:201d766770fd
(widget-default-value-set): Preserve point here.
(widget-choice-action, widget-toggle-action): Not here.
(widget-choice-action, widget-toggle-action):
Display a message about [State].
(widget-field-action): Improve message.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sat, 21 Jun 1997 23:37:57 +0000 |
parents | 5b5261ce8db9 |
children | 8326843eefd9 |
comparison
equal
deleted
inserted
replaced
18373:45ef45c34aa4 | 18374:201d766770fd |
---|---|
1464 (set-marker to nil)) | 1464 (set-marker to nil)) |
1465 (widget-clear-undo)) | 1465 (widget-clear-undo)) |
1466 | 1466 |
1467 (defun widget-default-value-set (widget value) | 1467 (defun widget-default-value-set (widget value) |
1468 ;; Recreate widget with new value. | 1468 ;; Recreate widget with new value. |
1469 (save-excursion | 1469 (let* ((old-pos (point)) |
1470 (goto-char (widget-get widget :from)) | 1470 (from (copy-marker (widget-get widget :from))) |
1471 (widget-apply widget :delete) | 1471 (to (copy-marker (widget-get widget :to))) |
1472 (widget-put widget :value value) | 1472 (offset (if (and (<= from old-pos) (<= old-pos to)) |
1473 (widget-apply widget :create))) | 1473 (if (>= old-pos (1- to)) |
1474 (- old-pos to 1) | |
1475 (- old-pos from))))) | |
1476 ;;??? Bug: this ought to insert the new value before deleting the old one, | |
1477 ;; so that markers on either side of the value automatically | |
1478 ;; stay on the same side. -- rms. | |
1479 (save-excursion | |
1480 (goto-char (widget-get widget :from)) | |
1481 (widget-apply widget :delete) | |
1482 (widget-put widget :value value) | |
1483 (widget-apply widget :create)) | |
1484 (if offset | |
1485 (if (< offset 0) | |
1486 (goto-char (+ (widget-get widget :to) offset 1)) | |
1487 (goto-char (min (+ from offset) (1- (widget-get widget :to)))))))) | |
1474 | 1488 |
1475 (defun widget-default-value-inline (widget) | 1489 (defun widget-default-value-inline (widget) |
1476 ;; Wrap value in a list unless it is inline. | 1490 ;; Wrap value in a list unless it is inline. |
1477 (if (widget-get widget :inline) | 1491 (if (widget-get widget :inline) |
1478 (widget-value widget) | 1492 (widget-value widget) |
1703 (widget-apply widget :value-to-external answer)))) | 1717 (widget-apply widget :value-to-external answer)))) |
1704 | 1718 |
1705 (defun widget-field-action (widget &optional event) | 1719 (defun widget-field-action (widget &optional event) |
1706 ;; Move to next field. | 1720 ;; Move to next field. |
1707 (widget-forward 1) | 1721 (widget-forward 1) |
1708 (message "To set this variable or face, invoke [State] and choose Set")) | 1722 (message "To set the value, invoke [State] and choose the Set operation")) |
1709 | 1723 |
1710 (defun widget-field-validate (widget) | 1724 (defun widget-field-validate (widget) |
1711 ;; Valid if the content matches `:valid-regexp'. | 1725 ;; Valid if the content matches `:valid-regexp'. |
1712 (save-excursion | 1726 (save-excursion |
1713 (let ((value (widget-apply widget :value-get)) | 1727 (let ((value (widget-apply widget :value-get)) |
1893 (setq choices | 1907 (setq choices |
1894 (cons (cons (widget-apply current :menu-tag-get) | 1908 (cons (cons (widget-apply current :menu-tag-get) |
1895 current) | 1909 current) |
1896 choices))) | 1910 choices))) |
1897 (widget-choose tag (reverse choices) event)))) | 1911 (widget-choose tag (reverse choices) event)))) |
1898 ;; Try to preserve point even if it is within the widget. | 1912 (when current |
1899 (let* ((old-pos (point)) | 1913 (widget-value-set widget |
1900 (from (copy-marker (widget-get widget :from))) | 1914 (widget-apply current :value-to-external |
1901 (to (copy-marker (widget-get widget :to))) | 1915 (widget-get current :value))) |
1902 (offset (if (and (<= from old-pos) (<= old-pos to)) | 1916 (widget-setup) |
1903 (- old-pos from)))) | 1917 (widget-apply widget :notify widget event))) |
1904 (when current | 1918 (message "To set the value, invoke [State] and choose the Set operation")) |
1905 (widget-value-set widget | |
1906 (widget-apply current :value-to-external | |
1907 (widget-get current :value))) | |
1908 (widget-setup) | |
1909 (widget-apply widget :notify widget event)) | |
1910 (if offset | |
1911 (goto-char (min (+ from offset) to)))))) | |
1912 | 1919 |
1913 (defun widget-choice-validate (widget) | 1920 (defun widget-choice-validate (widget) |
1914 ;; Valid if we have made a valid choice. | 1921 ;; Valid if we have made a valid choice. |
1915 (let ((void (widget-get widget :void)) | 1922 (let ((void (widget-get widget :void)) |
1916 (choice (widget-get widget :choice)) | 1923 (choice (widget-get widget :choice)) |
1960 (widget-get widget :off) | 1967 (widget-get widget :off) |
1961 (widget-get widget :off-glyph)))) | 1968 (widget-get widget :off-glyph)))) |
1962 | 1969 |
1963 (defun widget-toggle-action (widget &optional event) | 1970 (defun widget-toggle-action (widget &optional event) |
1964 ;; Toggle value. | 1971 ;; Toggle value. |
1965 ;; Try to preserve point even if it is within the widget. | 1972 (widget-value-set widget (not (widget-value widget))) |
1966 (let* ((old-pos (point)) | 1973 (widget-apply widget :notify widget event) |
1967 (from (copy-marker (widget-get widget :from))) | 1974 (message "To set the value, invoke [State] and choose the Set operation")) |
1968 (to (copy-marker (widget-get widget :to))) | |
1969 (offset (if (and (<= from old-pos) (<= old-pos to)) | |
1970 (- old-pos from)))) | |
1971 (widget-value-set widget (not (widget-value widget))) | |
1972 (widget-apply widget :notify widget event) | |
1973 (if offset | |
1974 (goto-char (min (+ from offset) to))))) | |
1975 | 1975 |
1976 ;;; The `checkbox' Widget. | 1976 ;;; The `checkbox' Widget. |
1977 | 1977 |
1978 (define-widget 'checkbox 'toggle | 1978 (define-widget 'checkbox 'toggle |
1979 "A checkbox toggle." | 1979 "A checkbox toggle." |