comparison lisp/wid-edit.el @ 51047:497252d655f0

(pp-to-string, Info-goto-node): Don't autoload. (widget-choose, widget-map-buttons): Use with-current-buffer. (widget-field-add-space): Change to nil (and to defconst). (widget-info-link-action): Use `info'.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Sat, 17 May 2003 20:29:40 +0000
parents 60e3eed1b79e
children 2d011e9999e9
comparison
equal deleted inserted replaced
51046:2c49296df7d3 51047:497252d655f0
1 ;;; wid-edit.el --- Functions for creating and using widgets -*-byte-compile-dynamic: t;-*- 1 ;;; wid-edit.el --- Functions for creating and using widgets -*-byte-compile-dynamic: t;-*-
2 ;; 2 ;;
3 ;; Copyright (C) 1996, 1997, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. 3 ;; Copyright (C) 1996, 1997, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
4 ;; 4 ;;
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk> 5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
6 ;; Maintainer: FSF 6 ;; Maintainer: FSF
7 ;; Keywords: extensions 7 ;; Keywords: extensions
8 8
60 ;;; Compatibility. 60 ;;; Compatibility.
61 61
62 (defun widget-event-point (event) 62 (defun widget-event-point (event)
63 "Character position of the end of event if that exists, or nil." 63 "Character position of the end of event if that exists, or nil."
64 (posn-point (event-end event))) 64 (posn-point (event-end event)))
65
66 (autoload 'pp-to-string "pp")
67 (autoload 'Info-goto-node "info")
68 65
69 (defun widget-button-release-event-p (event) 66 (defun widget-button-release-event-p (event)
70 "Non-nil if EVENT is a mouse-button-release event object." 67 "Non-nil if EVENT is a mouse-button-release event object."
71 (and (eventp event) 68 (and (eventp event)
72 (memq (event-basic-type event) '(mouse-1 mouse-2 mouse-3)) 69 (memq (event-basic-type event) '(mouse-1 mouse-2 mouse-3))
234 (next-digit ?0) 231 (next-digit ?0)
235 map choice some-choice-enabled value) 232 map choice some-choice-enabled value)
236 ;; Define SPC as a prefix char to get to this menu. 233 ;; Define SPC as a prefix char to get to this menu.
237 (define-key overriding-terminal-local-map " " 234 (define-key overriding-terminal-local-map " "
238 (setq map (make-sparse-keymap title))) 235 (setq map (make-sparse-keymap title)))
239 (save-excursion 236 (with-current-buffer (get-buffer-create " widget-choose")
240 (set-buffer (get-buffer-create " widget-choose"))
241 (erase-buffer) 237 (erase-buffer)
242 (insert "Available choices:\n\n") 238 (insert "Available choices:\n\n")
243 (while items 239 (while items
244 (setq choice (car items) items (cdr items)) 240 (setq choice (car items) items (cdr items))
245 (if (consp choice) 241 (if (consp choice)
302 298
303 ;;; Widget text specifications. 299 ;;; Widget text specifications.
304 ;; 300 ;;
305 ;; These functions are for specifying text properties. 301 ;; These functions are for specifying text properties.
306 302
307 (defvar widget-field-add-space t 303 ;; We can set it to nil now that get_local_map uses get_pos_property.
304 (defconst widget-field-add-space nil
308 "Non-nil means add extra space at the end of editable text fields. 305 "Non-nil means add extra space at the end of editable text fields.
309 If you don't add the space, it will become impossible to edit a zero 306 If you don't add the space, it will become impossible to edit a zero
310 size field.") 307 size field.")
311 308
312 (defvar widget-field-use-before-change t 309 (defvar widget-field-use-before-change t
568 respectively." 565 respectively."
569 (let ((cur (point-min)) 566 (let ((cur (point-min))
570 (widget nil) 567 (widget nil)
571 (parent nil) 568 (parent nil)
572 (overlays (if buffer 569 (overlays (if buffer
573 (save-excursion (set-buffer buffer) (overlay-lists)) 570 (with-current-buffer buffer (overlay-lists))
574 (overlay-lists)))) 571 (overlay-lists))))
575 (setq overlays (append (car overlays) (cdr overlays))) 572 (setq overlays (append (car overlays) (cdr overlays)))
576 (while (setq cur (pop overlays)) 573 (while (setq cur (pop overlays))
577 (setq widget (overlay-get cur 'button)) 574 (setq widget (overlay-get cur 'button))
578 (if (and widget (funcall function widget maparg)) 575 (if (and widget (funcall function widget maparg))
1102 (widget-apply field :complete) 1099 (widget-apply field :complete)
1103 (error "Not in an editable field")))) 1100 (error "Not in an editable field"))))
1104 1101
1105 ;;; Setting up the buffer. 1102 ;;; Setting up the buffer.
1106 1103
1107 (defvar widget-field-new nil) 1104 (defvar widget-field-new nil
1108 ;; List of all newly created editable fields in the buffer. 1105 "List of all newly created editable fields in the buffer.")
1109 (make-variable-buffer-local 'widget-field-new) 1106 (make-variable-buffer-local 'widget-field-new)
1110 1107
1111 (defvar widget-field-list nil) 1108 (defvar widget-field-list nil
1112 ;; List of all editable fields in the buffer. 1109 "List of all editable fields in the buffer.")
1113 (make-variable-buffer-local 'widget-field-list) 1110 (make-variable-buffer-local 'widget-field-list)
1114 1111
1115 (defun widget-at (&optional pos) 1112 (defun widget-at (&optional pos)
1116 "The button or field at POS (default, point)." 1113 "The button or field at POS (default, point)."
1117 (or (get-char-property (or pos (point)) 'button) 1114 (or (get-char-property (or pos (point)) 'button)
1673 "A link to an info file." 1670 "A link to an info file."
1674 :action 'widget-info-link-action) 1671 :action 'widget-info-link-action)
1675 1672
1676 (defun widget-info-link-action (widget &optional event) 1673 (defun widget-info-link-action (widget &optional event)
1677 "Open the info node specified by WIDGET." 1674 "Open the info node specified by WIDGET."
1678 (Info-goto-node (widget-value widget))) 1675 (info (widget-value widget)))
1679 1676
1680 ;;; The `url-link' Widget. 1677 ;;; The `url-link' Widget.
1681 1678
1682 (define-widget 'url-link 'link 1679 (define-widget 'url-link 'link
1683 "A link to an www page." 1680 "A link to an www page."