emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master 45524b9: Don't indent unrelated widgets following w


From: Lars Ingebrigtsen
Subject: [Emacs-diffs] master 45524b9: Don't indent unrelated widgets following widget of type 'other
Date: Thu, 26 Sep 2019 11:16:37 -0400 (EDT)

branch: master
commit 45524b9702b4a6face2cf453eb02ddf10a496b45
Author: Mauro Aranda <address@hidden>
Commit: Lars Ingebrigtsen <address@hidden>

    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 @@ as in (other DEFAULT) or (other :tag \"NAME\" DEFAULT).
 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



reply via email to

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