all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: martin rudalics <rudalics@gmx.at>
Cc: help-gnu-emacs@gnu.org, emacs-devel@gnu.org
Subject: Re: Customize: Space char in `character' specification
Date: Tue, 23 May 2006 11:38:34 +0200	[thread overview]
Message-ID: <4472D81A.9000202@gmx.at> (raw)
In-Reply-To: <v9u07ii675.fsf@marauder.physik.uni-ulm.de>

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

      reply	other threads:[~2006-05-23  9:38 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4472D81A.9000202@gmx.at \
    --to=rudalics@gmx.at \
    --cc=emacs-devel@gnu.org \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.