all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Mauro Aranda <maurooaranda@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 12533@debbugs.gnu.org
Subject: bug#12533: 24.2.50; incorrect behavior & formatting in Customize
Date: Thu, 26 Sep 2019 11:53:55 -0300	[thread overview]
Message-ID: <CABczVwcvDU61WE4KEX1k+Zhm0K=0JMkfinWmP8kF=xEj4Mkp6g@mail.gmail.com> (raw)
In-Reply-To: <CABczVweJqg3FuMrSEtKt6prCqM_Fy9jbZmN0QjO3iUNPAcK71g@mail.gmail.com>


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

I've added three tests to the patch:
1) One that should fail, because of the use of %n at the end.
2) One that should pass, because \n is used instead of %n.
3) Another one that should pass, because %n is used correctly,
at the middle of the format string.

Let me know what you think.

Best regards,
Mauro.

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

[-- Attachment #2: 0001-Don-t-indent-unrelated-widgets-following-widget-of-t.patch --]
[-- Type: text/x-patch, Size: 4852 bytes --]

From 7033339fe25f490d451d8e599677be48622b9fd3 Mon Sep 17 00:00:00 2001
From: Mauro Aranda <maurooaranda@gmail.com>
Date: Wed, 25 Sep 2019 18:12:55 -0300
Subject: [PATCH] Don't indent unrelated widgets following widget of type
 'other

* lisp/wid-edit.el (widget 'other): Use \n instead of the %n escape in the
:format property of this widget.  If %n is used at the end of the
format string, unrelated widgets get indented.  (Bug#12533)

* test/wid-edit-tests.el (widget-test-indentation-after-%n)
(widget-test-indentation-after-newline)
(widget-test-newline-and-indent-same-widget): New tests.
---
 lisp/wid-edit.el            |  2 +-
 test/lisp/wid-edit-tests.el | 77 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 78 insertions(+), 1 deletion(-)

diff --git a/lisp/wid-edit.el b/lisp/wid-edit.el
index 52b7532..916d41a 100644
--- a/lisp/wid-edit.el
+++ b/lisp/wid-edit.el
@@ -3063,7 +3063,7 @@ 'other
 If the user selects this alternative, that specifies DEFAULT
 as the value."
   :tag "Other"
-  :format "%t%n"
+  :format "%t\n"
   :value 'other)
 
 (defvar widget-string-prompt-value-history nil
diff --git a/test/lisp/wid-edit-tests.el b/test/lisp/wid-edit-tests.el
index a4350e71..679a29a 100644
--- a/test/lisp/wid-edit-tests.el
+++ b/test/lisp/wid-edit-tests.el
@@ -36,4 +36,81 @@
     (insert-button "overlay button")
     (should-not (widget-at (1- (point))))))
 
+;; The following three tests compare the effect of using either %n or \n at the
+;; end of a format string, as well as using %n at the end or in the middle of
+;; the format string.  (Bug#12533)
+
+(ert-deftest widget-test-indentation-after-%n ()
+  "Fail when %n is used at the end of a format string."
+  :expected-result :failed
+  (with-temp-buffer
+    (let (wid indented)
+      (widget-insert "Testing indentation.\n")
+      ;; If we use %n at the end of the format string of the widget `other', we
+      ;; screw up indentation of the following widgets.
+      (setq wid (widget-create
+                 '(repeat :indent 4
+                   (cons
+                    string (choice (other :tag "Other" :format "%t%n" c))))))
+      (goto-char (widget-get wid :value-pos))
+      ;; Since we indent the `repeat' widget, we skip the space characters
+      ;; inserted.
+      (skip-chars-forward " ")
+      (setq indented (current-column)) ; Save the column to which we indented.
+      (should (eq indented (or (widget-get wid :indent) 0)))
+      ;; Insert an entry.  This simulates a click or RET at the INS button.
+      (widget-apply (widget-at) :action)
+      (goto-char (widget-get wid :value-pos))
+      (skip-chars-forward " ")
+      ;; This fails, because the button is not at the right column.
+      (should (eq (current-column) indented)))))
+
+(ert-deftest widget-test-indentation-after-newline ()
+  "Pass when the newline is used at the end of a format string."
+  (with-temp-buffer
+    (let (wid indented)
+      (widget-insert "Testing indentation.\n")
+      (setq wid (widget-create
+                 '(repeat :indent 4
+                   (cons
+                    string
+                    (choice (other :tag "Other" :format "%t\n" c))))))
+      (goto-char (widget-get wid :value-pos))
+      (skip-chars-forward " ")
+      (setq indented (current-column))
+      (should (eq (current-column) (or (widget-get wid :indent) 0)))
+      (widget-apply (widget-at) :action)
+      (goto-char (widget-get wid :value-pos))
+      (skip-chars-forward " ")
+      ;; Because we used \n in the format string, this pass.
+      (should (eq (current-column) indented)))))
+
+(ert-deftest widget-test-newline-and-indent-same-widget ()
+  "It's OK to use the %n escape sequence in the middle of the format string."
+  (with-temp-buffer
+    (let (wid indented)
+      (widget-insert "Testing indentation.\n")
+      (setq wid (widget-create
+                 '(repeat :indent 4
+                          :format "%{%t%}:%n%v%i\n"
+                          (cons
+                           string
+                           (choice (other :tag "Other" :format "%t\n" c))))))
+      (goto-char (widget-get wid :value-pos))
+      (skip-chars-forward " ")
+      (setq indented (current-column))
+      (should (eq indented (or (widget-get wid :indent) 0)))
+      (widget-apply (widget-at) :action)
+      (goto-char (widget-get wid :value-pos))
+      (skip-chars-forward " ")
+      (should (eq (current-column) indented))
+
+      ;; Also, the children are indented correctly.
+      (let ((grandchild
+             ;; This gets the `string' widget.
+             (car (widget-get (car (widget-get wid :children)) :children))))
+        (goto-char (widget-get grandchild :from))
+        (should (eq (current-column)
+                    (widget-get grandchild :indent)))))))
+
 ;;; wid-edit-tests.el ends here
-- 
2.7.4


  reply	other threads:[~2019-09-26 14:53 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-28 16:28 bug#12533: 24.2.50; incorrect behavior & formatting in Customize Drew Adams
2019-09-25 21:26 ` Mauro Aranda
2019-09-25 21:27   ` Mauro Aranda
2019-09-26  7:22     ` Eli Zaretskii
2019-09-26 11:17       ` Mauro Aranda
2019-09-26 14:53         ` Mauro Aranda [this message]
2019-09-26 15:16           ` Lars Ingebrigtsen
2019-09-27 12:32             ` Mauro Aranda

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='CABczVwcvDU61WE4KEX1k+Zhm0K=0JMkfinWmP8kF=xEj4Mkp6g@mail.gmail.com' \
    --to=maurooaranda@gmail.com \
    --cc=12533@debbugs.gnu.org \
    --cc=eliz@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.