help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Customize: Space char in `character' specification


From: Reiner Steib
Subject: Re: Customize: Space char in `character' specification
Date: Mon, 22 May 2006 14:39:58 +0200
User-agent: Gnus/5.110006 (No Gnus v0.6) Emacs/22.0.50 (gnu/linux)

[ 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/




reply via email to

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