aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMauro Aranda2020-09-23 15:45:29 +0200
committerLars Ingebrigtsen2020-09-23 15:45:36 +0200
commitb252e09ae4fc816ecee1971e8f0b7f207fb4a507 (patch)
tree93ad7a177ad92d1fc0c579c96a7a153e7880d357
parent6037051f49ab5f96b406461490dba56faa2a5f35 (diff)
downloademacs-b252e09ae4fc816ecee1971e8f0b7f207fb4a507.tar.gz
emacs-b252e09ae4fc816ecee1971e8f0b7f207fb4a507.zip
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 (bug#15925).
-rw-r--r--lisp/wid-edit.el11
-rw-r--r--test/lisp/wid-edit-tests.el16
2 files changed, 23 insertions, 4 deletions
diff --git a/lisp/wid-edit.el b/lisp/wid-edit.el
index 13d850a57f5..8ad99f49aa1 100644
--- a/lisp/wid-edit.el
+++ b/lisp/wid-edit.el
@@ -303,12 +303,15 @@ the :notify function can't know the new value.")
303 (or (not widget-field-add-space) (widget-get widget :size)))) 303 (or (not widget-field-add-space) (widget-get widget :size))))
304 (if (functionp help-echo) 304 (if (functionp help-echo)
305 (setq help-echo 'widget-mouse-help)) 305 (setq help-echo 'widget-mouse-help))
306 (when (= (char-before to) ?\n) 306 (when (and (or (> to (1+ from)) (null (widget-get widget :size)))
307 (= (char-before to) ?\n))
307 ;; When the last character in the field is a newline, we want to 308 ;; When the last character in the field is a newline, we want to
308 ;; give it a `field' char-property of `boundary', which helps the 309 ;; give it a `field' char-property of `boundary', which helps the
309 ;; C-n/C-p act more naturally when entering/leaving the field. We 310 ;; C-n/C-p act more naturally when entering/leaving the field. We
310 ;; do this by making a small secondary overlay to contain just that 311 ;; do this by making a small secondary overlay to contain just that
311 ;; one character. 312 ;; one character. BUT we only do this if there is more than one
313 ;; character (so we don't do this for the character widget),
314 ;; or if the size of the editable field isn't specified.
312 (let ((overlay (make-overlay (1- to) to nil t nil))) 315 (let ((overlay (make-overlay (1- to) to nil t nil)))
313 (overlay-put overlay 'field 'boundary) 316 (overlay-put overlay 'field 'boundary)
314 ;; We need the real field for tabbing. 317 ;; We need the real field for tabbing.
@@ -3524,7 +3527,7 @@ To use this type, you must define :match or :match-alternatives."
3524 :value 0 3527 :value 0
3525 :size 1 3528 :size 1
3526 :format "%{%t%}: %v\n" 3529 :format "%{%t%}: %v\n"
3527 :valid-regexp "\\`.\\'" 3530 :valid-regexp "\\`\\(.\\|\n\\)\\'"
3528 :error "This field should contain a single character" 3531 :error "This field should contain a single character"
3529 :value-get (lambda (w) (widget-field-value-get w t)) 3532 :value-get (lambda (w) (widget-field-value-get w t))
3530 :value-to-internal (lambda (_widget value) 3533 :value-to-internal (lambda (_widget value)
diff --git a/test/lisp/wid-edit-tests.el b/test/lisp/wid-edit-tests.el
index 2ddb656fa9e..df49ffc8224 100644
--- a/test/lisp/wid-edit-tests.el
+++ b/test/lisp/wid-edit-tests.el
@@ -113,4 +113,20 @@
113 (should (eq (current-column) 113 (should (eq (current-column)
114 (widget-get grandchild :indent))))))) 114 (widget-get grandchild :indent)))))))
115 115
116(ert-deftest widget-test-character-widget-value ()
117 "Check that we get the character widget's value correctly."
118 (with-temp-buffer
119 (let ((wid (widget-create '(character :value ?\n))))
120 (goto-char (widget-get wid :from))
121 (should (string= (widget-apply wid :value-get) "\n"))
122 (should (char-equal (widget-value wid) ?\n))
123 (should-not (widget-apply wid :validate)))))
124
125(ert-deftest widget-test-editable-field-widget-value ()
126 "Test that we get the editable field widget's value correctly."
127 (with-temp-buffer
128 (let ((wid (widget-create '(editable-field :value ""))))
129 (widget-insert "And some non-widget text.")
130 (should (string= (widget-apply wid :value-get) "")))))
131
116;;; wid-edit-tests.el ends here 132;;; wid-edit-tests.el ends here