From b0313c7cb28680060da9bc56c05bf041165b91bf Mon Sep 17 00:00:00 2001 From: Mauro Aranda Date: Mon, 16 Sep 2019 18:15:46 -0300 Subject: [PATCH] Fill tag strings in customize buffers (Bug#6755) * lisp/wid-edit.el (widget-fill-tag-string): New variable, to control whether to fill strings specified by the %t format escape. (widget-default-create): Use it. * doc/misc/widget.texi (Basic Types): Document the new variable. * lisp/cus-edit.el (custom--initialize-widget-variables): Set widget-fill-tag-string to t, to fill tag strings. --- doc/misc/widget.texi | 6 +++++- lisp/cus-edit.el | 1 + lisp/wid-edit.el | 14 ++++++++++---- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/doc/misc/widget.texi b/doc/misc/widget.texi index 6d94768..488b44e 100644 --- a/doc/misc/widget.texi +++ b/doc/misc/widget.texi @@ -533,9 +533,13 @@ Basic Types lambda expression, it will be called with the widget's value as an argument, and the result will be used as the documentation text. +@vindex widget-fill-tag-string @item %t Insert the string specified by @code{:tag} here, or the @code{princ} -representation of the value if there is no tag. +representation of the value if there is no tag. The variable +@code{widget-fill-tag-string} controls whether to fill the inserted +string or not. @xref{Filling,,, elisp, the Emacs Lisp Reference Manual}, +for details on filling. @item %% Insert a literal @samp{%}. diff --git a/lisp/cus-edit.el b/lisp/cus-edit.el index 8a8bad9..0c392ff 100644 --- a/lisp/cus-edit.el +++ b/lisp/cus-edit.el @@ -4833,6 +4833,7 @@ custom--initialize-widget-variables (setq-local widget-push-button-suffix "") (setq-local widget-link-prefix "") (setq-local widget-link-suffix "")) + (setq-local widget-fill-tag-string t) (setq show-trailing-whitespace nil)) (define-derived-mode Custom-mode nil "Custom" diff --git a/lisp/wid-edit.el b/lisp/wid-edit.el index 7ed7b81..69e9716 100644 --- a/lisp/wid-edit.el +++ b/lisp/wid-edit.el @@ -1477,6 +1477,9 @@ widget-default-completions (call-interactively (widget-get widget :complete-function))))))))) +(defvar widget-fill-tag-string nil + "If non-nil, fill the string inserted by the %t :format escape.") + (defun widget-default-create (widget) "Create WIDGET at point in the current buffer." (widget-specify-insert @@ -1509,15 +1512,18 @@ widget-default-create (insert-char ?\s (widget-get widget :indent)))) ((eq escape ?t) (let ((image (widget-get widget :tag-glyph)) - (tag (substitute-command-keys - (widget-get widget :tag)))) + (tag (substitute-command-keys (widget-get widget :tag))) + (opoint (point))) (cond (image (widget-image-insert widget (or tag "image") image)) (tag (insert tag)) (t - (princ (widget-get widget :value) - (current-buffer)))))) + (princ (widget-get widget :value) (current-buffer)))) + (when widget-fill-tag-string + (save-restriction + (widen) + (fill-region opoint (point) nil t))))) ((eq escape ?d) (let ((doc (widget-get widget :doc))) (when doc -- 2.7.4