aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMauro Aranda2019-09-25 14:51:18 +0200
committerLars Ingebrigtsen2019-09-25 14:51:18 +0200
commit84567150e757ee3991a4b4f96a27080f92cb6d48 (patch)
tree92812c26d159ac15ea9e5c08381e9d4691717597
parent524a8eb7307b3efc1124c35014b46ecb2f99818f (diff)
downloademacs-84567150e757ee3991a4b4f96a27080f92cb6d48.tar.gz
emacs-84567150e757ee3991a4b4f96a27080f92cb6d48.zip
Fix indentation of widgets (Bug#7851)
* lisp/wid-edit.el (widget--should-indent-p): New function, to decide whether to indent or not. (widget-checklist-value-add-item, widget-radio-add-item) (widget-editable-list-format-handler) (widget-editable-list-entry-create) (widget-group-value-create): Use it (bug#7851).
-rw-r--r--lisp/wid-edit.el31
1 files changed, 25 insertions, 6 deletions
diff --git a/lisp/wid-edit.el b/lisp/wid-edit.el
index 2978dc80375..52b75325673 100644
--- a/lisp/wid-edit.el
+++ b/lisp/wid-edit.el
@@ -412,6 +412,17 @@ the :notify function can't know the new value.")
412 (overlay-put overlay 'evaporate t) 412 (overlay-put overlay 'evaporate t)
413 (widget-put widget :doc-overlay overlay))) 413 (widget-put widget :doc-overlay overlay)))
414 414
415(defun widget--should-indent-p (&optional check-after)
416 "Non-nil if we should indent at the current position.
417With CHECK-AFTER non-nil, considers also the content after point, if needed."
418 (save-restriction
419 (widen)
420 (and (eq (preceding-char) ?\n)
421 (or (not check-after)
422 ;; If there is a space character, then we probably already
423 ;; indented it.
424 (not (eq (following-char) ?\s))))))
425
415(defmacro widget-specify-insert (&rest form) 426(defmacro widget-specify-insert (&rest form)
416 "Execute FORM without inheriting any text properties." 427 "Execute FORM without inheriting any text properties."
417 (declare (debug body)) 428 (declare (debug body))
@@ -2254,7 +2265,7 @@ when he invoked the menu."
2254(defun widget-checklist-add-item (widget type chosen) 2265(defun widget-checklist-add-item (widget type chosen)
2255 "Create checklist item in WIDGET of type TYPE. 2266 "Create checklist item in WIDGET of type TYPE.
2256If the item is checked, CHOSEN is a cons whose cdr is the value." 2267If the item is checked, CHOSEN is a cons whose cdr is the value."
2257 (and (eq (preceding-char) ?\n) 2268 (and (widget--should-indent-p)
2258 (widget-get widget :indent) 2269 (widget-get widget :indent)
2259 (insert-char ?\s (widget-get widget :indent))) 2270 (insert-char ?\s (widget-get widget :indent)))
2260 (widget-specify-insert 2271 (widget-specify-insert
@@ -2435,7 +2446,7 @@ Return an alist of (TYPE MATCH)."
2435(defun widget-radio-add-item (widget type) 2446(defun widget-radio-add-item (widget type)
2436 "Add to radio widget WIDGET a new radio button item of type TYPE." 2447 "Add to radio widget WIDGET a new radio button item of type TYPE."
2437 ;; (setq type (widget-convert type)) 2448 ;; (setq type (widget-convert type))
2438 (and (eq (preceding-char) ?\n) 2449 (and (widget--should-indent-p)
2439 (widget-get widget :indent) 2450 (widget-get widget :indent)
2440 (insert-char ?\s (widget-get widget :indent))) 2451 (insert-char ?\s (widget-get widget :indent)))
2441 (widget-specify-insert 2452 (widget-specify-insert
@@ -2614,7 +2625,8 @@ Return an alist of (TYPE MATCH)."
2614 ;; We recognize the insert button. 2625 ;; We recognize the insert button.
2615 ;; (let ((widget-push-button-gui widget-editable-list-gui)) 2626 ;; (let ((widget-push-button-gui widget-editable-list-gui))
2616 (cond ((eq escape ?i) 2627 (cond ((eq escape ?i)
2617 (and (widget-get widget :indent) 2628 (and (widget--should-indent-p)
2629 (widget-get widget :indent)
2618 (insert-char ?\s (widget-get widget :indent))) 2630 (insert-char ?\s (widget-get widget :indent)))
2619 (apply 'widget-create-child-and-convert 2631 (apply 'widget-create-child-and-convert
2620 widget 'insert-button 2632 widget 'insert-button
@@ -2723,8 +2735,9 @@ Return an alist of (TYPE MATCH)."
2723 child delete insert) 2735 child delete insert)
2724 (widget-specify-insert 2736 (widget-specify-insert
2725 (save-excursion 2737 (save-excursion
2726 (and (widget-get widget :indent) 2738 (and (widget--should-indent-p)
2727 (insert-char ?\s (widget-get widget :indent))) 2739 (widget-get widget :indent)
2740 (insert-char ?\s (widget-get widget :indent)))
2728 (insert (widget-get widget :entry-format))) 2741 (insert (widget-get widget :entry-format)))
2729 ;; Parse % escapes in format. 2742 ;; Parse % escapes in format.
2730 (while (re-search-forward "%\\(.\\)" nil t) 2743 (while (re-search-forward "%\\(.\\)" nil t)
@@ -2752,6 +2765,12 @@ Return an alist of (TYPE MATCH)."
2752 (if insert (push insert buttons)) 2765 (if insert (push insert buttons))
2753 (if delete (push delete buttons)) 2766 (if delete (push delete buttons))
2754 (widget-put widget :buttons buttons)) 2767 (widget-put widget :buttons buttons))
2768 ;; After creating the entry, we must check if we should indent the
2769 ;; following entry. This is necessary, for example, to keep the correct
2770 ;; indentation of editable lists inside group widgets.
2771 (and (widget--should-indent-p t)
2772 (widget-get widget :indent)
2773 (insert-char ?\s (widget-get widget :indent)))
2755 (let ((entry-from (point-min-marker)) 2774 (let ((entry-from (point-min-marker))
2756 (entry-to (point-max-marker))) 2775 (entry-to (point-max-marker)))
2757 (set-marker-insertion-type entry-from t) 2776 (set-marker-insertion-type entry-from t)
@@ -2786,7 +2805,7 @@ Return an alist of (TYPE MATCH)."
2786 args (cdr args) 2805 args (cdr args)
2787 answer (widget-match-inline arg value) 2806 answer (widget-match-inline arg value)
2788 value (cdr answer)) 2807 value (cdr answer))
2789 (and (eq (preceding-char) ?\n) 2808 (and (widget--should-indent-p)
2790 (widget-get widget :indent) 2809 (widget-get widget :indent)
2791 (insert-char ?\s (widget-get widget :indent))) 2810 (insert-char ?\s (widget-get widget :indent)))
2792 (push (cond ((null answer) 2811 (push (cond ((null answer)