unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Customize: Space char in `character' specification
@ 2006-05-20 12:40 Reiner Steib
  2006-05-21 10:23 ` martin rudalics
  0 siblings, 1 reply; 6+ messages in thread
From: Reiner Steib @ 2006-05-20 12:40 UTC (permalink / raw)


Hi,

I can't seem to find the right syntax for the following defcustom, or
there's a bug in customize (both, Emacs 21 and 22):

(defcustom rs-test-list-char-string
  '("<body[^>]*>"
    ((?&  . "&amp;")
     (?   . "&nbsp;") ;; This is the problematic entry
     (?\n . "<br>")
     ))
  "List for inserting mail headers into the HTML output."
  :type '(choice
	  (list :tag "Default"
		(regexp :tag "Body regexp" "<body[^>]*>")
		(repeat :value ((?&  . "&amp;")
				(?   . "&nbsp;")
				(?\n . "<br>"))
			(cons (character) (string :tag "Replacement"))))))

After modifying the "Body regexp" and pressing "Set for Current
Session", I get "This field should contain a single character". 

I can reproduce the same problem with the following defcustom:

(defcustom rs-test-char
  ?  ;; whitespace
  "Foo bar"
  :type '(character))

Replace the space character with some other character and change is
back to a space.  "Set for Current Session" again barfs with "This
field should contain a single character".

What am I doing wrong?

Bye, Reiner.
-- 
       ,,,
      (o o)
---ooO-(_)-Ooo---  |  PGP key available  |  http://rsteib.home.pages.de/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Customize: Space char in `character' specification
@ 2006-05-21 10:23 ` martin rudalics
  2006-05-21 20:22   ` Reiner Steib
  2006-05-22  9:42   ` martin rudalics
  0 siblings, 2 replies; 6+ messages in thread
From: martin rudalics @ 2006-05-21 10:23 UTC (permalink / raw)
  Cc: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 32 bytes --]

Try the attached patch.

martin

[-- Attachment #2: wid-edit.patch --]
[-- Type: text/plain, Size: 1196 bytes --]

*** wid-edit.el	Tue Apr 11 16:23:54 2006
--- wid-edit.el	Sun May 21 12:18:38 2006
***************
*** 3380,3385 ****
--- 3380,3386 ----
    :value 0
    :size 1
    :format "%{%t%}: %v\n"
+   :value-get 'widget-character-value-get
    :valid-regexp "\\`.\\'"
    :error "This field should contain a single character"
    :value-to-internal (lambda (widget value)
***************
*** 3393,3398 ****
--- 3394,3395 ----
    :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))
+ 	(old (current-buffer)))
+     (if (and from to)
+ 	(progn
+ 	  (set-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)))))
+ 	    (set-buffer old)
+ 	    result))
+       (widget-get widget :value))))
+ 
  (define-widget 'list 'group
    "A Lisp list."
    :tag "List"

[-- Attachment #3: Type: text/plain, Size: 152 bytes --]

_______________________________________________
help-gnu-emacs mailing list
help-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gnu-emacs

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Customize: Space char in `character' specification
  2006-05-21 10:23 ` martin rudalics
@ 2006-05-21 20:22   ` Reiner Steib
  2006-05-22  9:42   ` martin rudalics
  1 sibling, 0 replies; 6+ messages in thread
From: Reiner Steib @ 2006-05-21 20:22 UTC (permalink / raw)


On Sun, May 21 2006, martin rudalics wrote:

> Try the attached patch.

Thanks.  It fixed the problem for the simple test case `rs-test-char',
but not for the more complicated case `rs-test-list-char-string'.

Bye, Reiner.
-- 
       ,,,
      (o o)
---ooO-(_)-Ooo---  |  PGP key available  |  http://rsteib.home.pages.de/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Customize: Space char in `character' specification
  2006-05-21 10:23 ` martin rudalics
  2006-05-21 20:22   ` Reiner Steib
@ 2006-05-22  9:42   ` martin rudalics
  2006-05-22 12:39     ` Reiner Steib
  1 sibling, 1 reply; 6+ messages in thread
From: martin rudalics @ 2006-05-22  9:42 UTC (permalink / raw)
  Cc: help-gnu-emacs, reinersteib+gmane

 > Thanks.  It fixed the problem for the simple test case `rs-test-char',
 > but not for the more complicated case `rs-test-list-char-string'.

The patch permits to insert a single space character in a `character'
field, something which was not allowed before.  The error you see comes
from the `\n' on the next line.  Replace the "\n" by a "\t" and the
error should disappear.

It's not easy to resolve the "\n" problem since wid-edit creates two
overlays when a newline character is last in an editable field.  I'll
try to look at that eventually.  Is the following inacceptable?

(defcustom rs-test-list-string
   '("<body[^>]*>"
     (("&"   . "&amp;")
      (" "   . "&nbsp;")
      ("\n"  . "<br>")
      ))
   "List for inserting mail headers into the HTML output."
   :type '(choice
           (list :tag "Default"
                 (regexp :tag "Body regexp" "<body[^>]*>")
                 (repeat :value (("&"   . "&amp;")
                                 (" "   . "&nbsp;")
                                 ("\n"  . "<br>"))
                         (cons (string) (string :tag "Replacement"))))))

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Customize: Space char in `character' specification
  2006-05-22  9:42   ` martin rudalics
@ 2006-05-22 12:39     ` Reiner Steib
  2006-05-23  9:38       ` martin rudalics
  0 siblings, 1 reply; 6+ messages in thread
From: Reiner Steib @ 2006-05-22 12:39 UTC (permalink / raw)
  Cc: help-gnu-emacs

[ I'm redirecting this to emacs-devel. ]

On Mon, May 22 2006, martin rudalics wrote on help-gnu-emacs:

>> Thanks.  It fixed the problem for the simple test case `rs-test-char',
>> but not for the more complicated case `rs-test-list-char-string'.

[ For the readers of emacs-devel, I repeat the initial problem: ]

(defcustom rs-test-list-char-string
  '("<body[^>]*>"
    ((?&  . "&amp;")
     (?   . "&nbsp;") ;; This is the problematic entry
     (?\n . "<br>")
     ))
  "List for inserting mail headers into the HTML output."
  :type '(choice
	  (list :tag "Default"
		(regexp :tag "Body regexp" "<body[^>]*>")
		(repeat :value ((?&  . "&amp;")
				(?   . "&nbsp;")
				(?\n . "<br>"))
			(cons (character) (string :tag "Replacement"))))))

After modifying the "Body regexp" and pressing "Set for Current
Session", I get "This field should contain a single character".
(Emacs 21 and 22).

I can reproduce the same problem with the following defcustom:

(defcustom rs-test-char
  ?  ;; whitespace
  "Foo bar"
  :type '(character))

Replace the space character with some other character and change is
back to a space.  "Set for Current Session" again barfs with "This
field should contain a single character".

Martin Rudalics suggested the patch below[1] which partly solved the
problem...

> The patch permits to insert a single space character in a `character'
> field, something which was not allowed before.  The error you see comes
> from the `\n' on the next line.  Replace the "\n" by a "\t" and the
> error should disappear.
>
> It's not easy to resolve the "\n" problem since wid-edit creates two
> overlays when a newline character is last in an editable field.  I'll
> try to look at that eventually.  Is the following inacceptable?
[ Using `string' instead of a `character' ]

I can use `string-to-char' in the code that uses the variable, but it
would be better if `wid-edit.el' could be fixed to accept both, space
and newline characters in editable fields.

Bye, Reiner.

Footnotes: 
[1]  See also <http://article.gmane.org/gmane.emacs.help/35188>:

*** wid-edit.el	Tue Apr 11 16:23:54 2006
--- wid-edit.el	Sun May 21 12:18:38 2006
***************
*** 3380,3385 ****
--- 3380,3386 ----
    :value 0
    :size 1
    :format "%{%t%}: %v\n"
+   :value-get 'widget-character-value-get
    :valid-regexp "\\`.\\'"
    :error "This field should contain a single character"
    :value-to-internal (lambda (widget value)
***************
*** 3393,3398 ****
--- 3394,3395 ----
    :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))
+ 	(old (current-buffer)))
+     (if (and from to)
+ 	(progn
+ 	  (set-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)))))
+ 	    (set-buffer old)
+ 	    result))
+       (widget-get widget :value))))
+ 
  (define-widget 'list 'group
    "A Lisp list."
    :tag "List"

-- 
       ,,,
      (o o)
---ooO-(_)-Ooo---  |  PGP key available  |  http://rsteib.home.pages.de/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Customize: Space char in `character' specification
  2006-05-22 12:39     ` Reiner Steib
@ 2006-05-23  9:38       ` martin rudalics
  0 siblings, 0 replies; 6+ messages in thread
From: martin rudalics @ 2006-05-23  9:38 UTC (permalink / raw)
  Cc: help-gnu-emacs, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1351 bytes --]

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.


[-- Attachment #2: wid-edit.patch --]
[-- Type: text/plain, Size: 2387 bytes --]

*** 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"


[-- Attachment #3: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2006-05-23  9:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-05-20 12:40 Customize: Space char in `character' specification Reiner Steib
2006-05-21 10:23 ` martin rudalics
2006-05-21 20:22   ` Reiner Steib
2006-05-22  9:42   ` martin rudalics
2006-05-22 12:39     ` Reiner Steib
2006-05-23  9:38       ` martin rudalics

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).