comparison lisp/wid-edit.el @ 102713:550a8bb34a0e

(widget-specify-field): Don't add a second overlay for a field with just a newline character. (widget-field-value-get): Don't reduce fields with just a space character to null. (character): Accept newline. (Bug#2689)
author Glenn Morris <rgm@gnu.org>
date Tue, 24 Mar 2009 02:30:15 +0000
parents a9dc0e7c3f2b
children 61c93763581b
comparison
equal deleted inserted replaced
102712:ab1b1cb08a25 102713:550a8bb34a0e
340 (follow-link (widget-get widget :follow-link)) 340 (follow-link (widget-get widget :follow-link))
341 (rear-sticky 341 (rear-sticky
342 (or (not widget-field-add-space) (widget-get widget :size)))) 342 (or (not widget-field-add-space) (widget-get widget :size))))
343 (if (functionp help-echo) 343 (if (functionp help-echo)
344 (setq help-echo 'widget-mouse-help)) 344 (setq help-echo 'widget-mouse-help))
345 (when (= (char-before to) ?\n) 345 (when (and (> to (1+ from))
346 (= (char-before to) ?\n))
346 ;; When the last character in the field is a newline, we want to 347 ;; When the last character in the field is a newline, we want to
347 ;; give it a `field' char-property of `boundary', which helps the 348 ;; give it a `field' char-property of `boundary', which helps the
348 ;; C-n/C-p act more naturally when entering/leaving the field. We 349 ;; C-n/C-p act more naturally when entering/leaving the field. We
349 ;; do this by making a small secondary overlay to contain just that 350 ;; do this by making a small secondary overlay to contain just that
350 ;; one character. 351 ;; one character.
352 ;; We DON'T do this if the field just consists of a newline, eg
353 ;; when specifying a character, since it breaks things (below
354 ;; does 1- to, which results in to = from). Bug#2689.
351 (let ((overlay (make-overlay (1- to) to nil t nil))) 355 (let ((overlay (make-overlay (1- to) to nil t nil)))
352 (overlay-put overlay 'field 'boundary) 356 (overlay-put overlay 'field 'boundary)
353 ;; We need the real field for tabbing. 357 ;; We need the real field for tabbing.
354 (overlay-put overlay 'real-field widget) 358 (overlay-put overlay 'real-field widget)
355 ;; Use `local-map' here, not `keymap', so that normal editing 359 ;; Use `local-map' here, not `keymap', so that normal editing
1943 (if (and from to) 1947 (if (and from to)
1944 (progn 1948 (progn
1945 (set-buffer buffer) 1949 (set-buffer buffer)
1946 (while (and size 1950 (while (and size
1947 (not (zerop size)) 1951 (not (zerop size))
1948 (> to from) 1952 ;; Bug#2689. Don't allow this loop to reduce a
1953 ;; character field to zero size if it contains a space.
1954 (> to (1+ from))
1949 (eq (char-after (1- to)) ?\s)) 1955 (eq (char-after (1- to)) ?\s))
1950 (setq to (1- to))) 1956 (setq to (1- to)))
1951 (let ((result (buffer-substring-no-properties from to))) 1957 (let ((result (buffer-substring-no-properties from to)))
1952 (when secret 1958 (when secret
1953 (let ((index 0)) 1959 (let ((index 0))
3448 "A character." 3454 "A character."
3449 :tag "Character" 3455 :tag "Character"
3450 :value 0 3456 :value 0
3451 :size 1 3457 :size 1
3452 :format "%{%t%}: %v\n" 3458 :format "%{%t%}: %v\n"
3453 :valid-regexp "\\`.\\'" 3459 ;; `.' does not match newline, but newline is a valid character.
3460 :valid-regexp "\\`\\(.\\|\n\\)\\'"
3454 :error "This field should contain a single character" 3461 :error "This field should contain a single character"
3455 :value-to-internal (lambda (widget value) 3462 :value-to-internal (lambda (widget value)
3456 (if (stringp value) 3463 (if (stringp value)
3457 value 3464 value
3458 (char-to-string value))) 3465 (char-to-string value)))