emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Customize: Space char in `character' specification


From: martin rudalics
Subject: Re: Customize: Space char in `character' specification
Date: Tue, 23 May 2006 11:38:34 +0200
User-agent: Mozilla Thunderbird 1.0 (Windows/20041206)

The attached patch should accept newlines.  It breaks with two
conveniences though:

1. Field boundaries with character fields are gone.  I had to remove
that step since it is done once only (at widget-setup time) and not
repeated in the after-change hook.  If I had left that in, character
widgets would appear visually different with regard to whether their
initial value was a newline or not.  In the first case there would
_always_ have been an empty line after the line containing the field
regardless of whether the modified value is a newline or not.  In the
second case the empty line would appear iff the modified value is a
newline.

2. The size of a character field has changed from 1 to 0.  Hence if you
erase all characters in the field, there won't be any visible clues left
that there's a field here.  I had to change that since otherwise
wid-edit would have automatically inserted a space (in its after-change
hook) after a user erased all characters in the field.  That space could
have been subsequently used by `custom-variable-set' instead of raising
an error.

Note that tabbing doesn't stop at empty widgets.  I don't consider that
too serious since empty character widgets are invalid anyway.

I tried to keep any side-effects of the patch within the character
widget environment.  Nevertheless you should test it extensively.

*** wid-edit.el Tue Apr 11 16:23:54 2006
--- wid-edit.el Tue May 23 10:59:04 2006
***************
*** 343,349 ****
         (or (not widget-field-add-space) (widget-get widget :size))))
      (if (functionp help-echo)
        (setq help-echo 'widget-mouse-help))
!     (when (= (char-before to) ?\n)
        ;; When the last character in the field is a newline, we want to
        ;; give it a `field' char-property of `boundary', which helps the
        ;; C-n/C-p act more naturally when entering/leaving the field.  We
--- 343,350 ----
         (or (not widget-field-add-space) (widget-get widget :size))))
      (if (functionp help-echo)
        (setq help-echo 'widget-mouse-help))
!     (when (and (= (char-before to) ?\n)
!              (not (eq (car widget) 'character)))
        ;; When the last character in the field is a newline, we want to
        ;; give it a `field' char-property of `boundary', which helps the
        ;; C-n/C-p act more naturally when entering/leaving the field.  We
***************
*** 3378,3386 ****
    "A character."
    :tag "Character"
    :value 0
!   :size 1
    :format "%{%t%}: %v\n"
!   :valid-regexp "\\`.\\'"
    :error "This field should contain a single character"
    :value-to-internal (lambda (widget value)
                       (if (stringp value)
--- 3379,3388 ----
    "A character."
    :tag "Character"
    :value 0
!   :size 0
    :format "%{%t%}: %v\n"
!   :value-get 'widget-character-value-get
!   :valid-regexp "\\`\\(?:.\\|\n\\)\\'"
    :error "This field should contain a single character"
    :value-to-internal (lambda (widget value)
                       (if (stringp value)
***************
*** 3393,3398 ****
--- 3395,3396 ----
    :match (lambda (widget value)
           (char-valid-p value)))

+ (defun widget-character-value-get (widget)
+   "Return character value."
+   (let ((from (widget-field-start widget))
+       (to (widget-field-end widget))
+       (buffer (widget-field-buffer widget))
+       (secret (widget-get widget :secret)))
+     (if (and from to)
+       (with-current-buffer buffer
+         (let ((result (buffer-substring-no-properties from to)))
+           (when secret
+             (let ((index 0))
+               (while (< (+ from index) to)
+                 (aset result index
+                       (get-char-property (+ from index) 'secret))
+                 (setq index (1+ index)))))
+           result))
+       (widget-get widget :value))))
+ 
  (define-widget 'list 'group
    "A Lisp list."
    :tag "List"


reply via email to

[Prev in Thread] Current Thread [Next in Thread]