unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Mauro Aranda <maurooaranda@gmail.com>
To: 15925@debbugs.gnu.org
Cc: Glenn Morris <rgm@gnu.org>, claudio.bley@googlemail.com
Subject: bug#15925: 24.3.50; error when customizing whitespace-display-mappings
Date: Tue, 22 Sep 2020 12:42:01 -0300	[thread overview]
Message-ID: <CABczVwdS5QJkQh1+GBBoDB4WDtSCCOJRF48whp+it0TyJ1x23Q@mail.gmail.com> (raw)
In-Reply-To: <87mwl0vo36.wl%claudio.bley@gmail.com>


[-- Attachment #1.1: Type: text/plain, Size: 2309 bytes --]

Claudio Bley <claudio.bley@googlemail.com> writes:

> At Tue, 19 Nov 2013 03:24:02 -0500,
> Glenn Morris wrote:
>>
>> Claudio Bley wrote:
>>
>> > I think the regexp should be changed to "\\`\(.\|\n\)\\'" to allow a
>> > single newline also.
>>
>> We already tried that once; it caused more problems than it solved:
>> http://debbugs.gnu.org/2689
>
> I see. So lets get this solved.
>
> At first, changing the regexp is just the right thing to do and
> in itself, IMO, does not break anything.

Indeed.

> Alas, it does not solve the problem at hand because
> `widget-specify-field' behaves /badly/ when the field ends with a
> newline.
>
> So, actually, this hunk of your patch trying to work around
> this behaviour broke other things.

[...]

> How about using a special :value-create function for character fields?

I don't think that's needed.

> Furthermore, the presentation of the character values is bad,
> usability-wise, because for nonprintable chars you cannot see what
> value the field actually has.
>
> How about displaying those chars in the buffer in another format?
> E.g. use escape sequences like \n \r et cetera?

Or we could do what Isearch does, and display TAB as ^I, and so on.

> I (rather hackish) way to fix this would be to always insert a ?\n
> as part of the value of a character field:
>
> (defun widget-field-char-create (widget)
>   "Create an editable character field."
>   (let ((value (widget-get widget :value))
> (from (point))
> ;; This is changed to a real overlay in `widget-setup'.  We
> ;; need the end points to behave differently until
> ;; `widget-setup' is called.
> (overlay (cons (make-marker) (make-marker))))
>     (widget-put widget :field-overlay overlay)
>     (insert value)
>     (insert ?\n) ;; EEEK
>     (unless (memq widget widget-field-list)
>       (setq widget-field-new (cons widget widget-field-new)))
>     (move-marker (cdr overlay) (point))
>     (set-marker-insertion-type (cdr overlay) nil)
>     (insert ?\n)
>     (move-marker (car overlay) from)
>     (set-marker-insertion-type (car overlay) t)))
>
> What do you think?

I don't think this is needed.

I attach a patch that should fix this (but that does not change the
way the characters are displayed) and that doesn't introduce the
breakage of Bug#3136 (for which I added a test).

[-- Attachment #1.2: Type: text/html, Size: 2905 bytes --]

[-- Attachment #2: 0001-Allow-the-newline-character-in-the-character-widget-.patch --]
[-- Type: text/x-patch, Size: 3338 bytes --]

From fc2b1a4e65f0c525a5f78e3109cd3d2f697ac600 Mon Sep 17 00:00:00 2001
From: Mauro Aranda <maurooaranda@gmail.com>
Date: Tue, 22 Sep 2020 11:10:15 -0300
Subject: [PATCH] Allow the newline character in the character widget
 (Bug#15925)

* lisp/wid-edit.el (widget-specify-field): Extend check for adding the
boundary overlay.  Plus, a minor comment indentation fix.
(character widget): Tweak the valid-regexp to allow the newline
character.

* test/lisp/wid-edit-tests.el (widget-test-character-widget-value)
(widget-test-editable-field-widget-value): New tests.
---
 lisp/wid-edit.el            | 11 +++++++----
 test/lisp/wid-edit-tests.el | 16 ++++++++++++++++
 2 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/lisp/wid-edit.el b/lisp/wid-edit.el
index 13d850a57f..8ad99f49aa 100644
--- a/lisp/wid-edit.el
+++ b/lisp/wid-edit.el
@@ -303,12 +303,15 @@ widget-specify-field
 	 (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 (and (or (> to (1+ from)) (null (widget-get widget :size)))
+               (= (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
-     ;; do this by making a small secondary overlay to contain just that
-      ;; one character.
+      ;; do this by making a small secondary overlay to contain just that
+      ;; one character.  BUT we only do this if there is more than one
+      ;; character (so we don't do this for the character widget),
+      ;; or if the size of the editable field isn't specified.
       (let ((overlay (make-overlay (1- to) to nil t nil)))
 	(overlay-put overlay 'field 'boundary)
         ;; We need the real field for tabbing.
@@ -3524,7 +3527,7 @@ 'character
   :value 0
   :size 1
   :format "%{%t%}: %v\n"
-  :valid-regexp "\\`.\\'"
+  :valid-regexp "\\`\\(.\\|\n\\)\\'"
   :error "This field should contain a single character"
   :value-get (lambda (w) (widget-field-value-get w t))
   :value-to-internal (lambda (_widget value)
diff --git a/test/lisp/wid-edit-tests.el b/test/lisp/wid-edit-tests.el
index 2ddb656fa9..df49ffc822 100644
--- a/test/lisp/wid-edit-tests.el
+++ b/test/lisp/wid-edit-tests.el
@@ -113,4 +113,20 @@ widget-test-newline-and-indent-same-widget
         (should (eq (current-column)
                     (widget-get grandchild :indent)))))))
 
+(ert-deftest widget-test-character-widget-value ()
+  "Check that we get the character widget's value correctly."
+  (with-temp-buffer
+    (let ((wid (widget-create '(character :value ?\n))))
+      (goto-char (widget-get wid :from))
+      (should (string= (widget-apply wid :value-get) "\n"))
+      (should (char-equal (widget-value wid) ?\n))
+      (should-not (widget-apply wid :validate)))))
+
+(ert-deftest widget-test-editable-field-widget-value ()
+  "Test that we get the editable field widget's value correctly."
+  (with-temp-buffer
+    (let ((wid (widget-create '(editable-field :value ""))))
+      (widget-insert "And some non-widget text.")
+      (should (string= (widget-apply wid :value-get) "")))))
+
 ;;; wid-edit-tests.el ends here
-- 
2.28.0


  parent reply	other threads:[~2020-09-22 15:42 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-19  7:37 bug#15925: 24.3.50; error when customizing whitespace-display-mappings Claudio Bley
2013-11-19  8:24 ` Glenn Morris
2013-11-20 10:35   ` Claudio Bley
2013-11-20 19:28     ` Stefan Monnier
2020-09-22 15:42 ` Mauro Aranda [this message]
2020-09-23 13:46   ` Lars Ingebrigtsen
2020-09-23 15:26     ` Mauro Aranda
2020-09-24 14:38       ` Lars Ingebrigtsen
2020-09-24 15:29         ` Mauro Aranda
2020-09-24 15:36           ` Mauro Aranda
2020-09-25 10:00           ` Lars Ingebrigtsen
2020-09-25 11:06             ` Eli Zaretskii
2020-09-25 11:10             ` Mauro Aranda
2020-09-25 14:32               ` Mauro Aranda
2020-09-26 13:24                 ` Lars Ingebrigtsen
2020-09-26 13:26                 ` Lars Ingebrigtsen
2020-09-26 13:45                   ` Mauro Aranda
2020-09-26 15:10                     ` Lars Ingebrigtsen
     [not found] <<87mwl0vo36.wl%claudio.bley@gmail.com>
     [not found] ` <<CABczVwdS5QJkQh1+GBBoDB4WDtSCCOJRF48whp+it0TyJ1x23Q@mail.gmail.com>
     [not found]   ` <<87a6xgd2rw.fsf@gnus.org>
     [not found]     ` <<CABczVweQk+Jiiix62mS49n1zoHNn-6uifOEB1H4==EKNSV970g@mail.gmail.com>
     [not found]       ` <<871rirb5ot.fsf@gnus.org>
     [not found]         ` <<CABczVweW=gbepHOLzBQZbAxS9yX-Fo3h2_hPDL7FwmhfjAdk6w@mail.gmail.com>
     [not found]           ` <<87ft76rxaw.fsf@gnus.org>
     [not found]             ` <<83v9g2ru8f.fsf@gnu.org>
2020-09-25 16:07               ` Drew Adams

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=CABczVwdS5QJkQh1+GBBoDB4WDtSCCOJRF48whp+it0TyJ1x23Q@mail.gmail.com \
    --to=maurooaranda@gmail.com \
    --cc=15925@debbugs.gnu.org \
    --cc=claudio.bley@googlemail.com \
    --cc=rgm@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 public inbox

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

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).