* bug#9970: 24.0.90; Commandify set-frame-{height,width}
[not found] ` <m1im5ulz0e.fsf@yahoo.es>
@ 2021-03-15 17:16 ` Juri Linkov
2021-03-16 0:30 ` Lars Ingebrigtsen
1 sibling, 0 replies; 6+ messages in thread
From: Juri Linkov @ 2021-03-15 17:16 UTC (permalink / raw)
To: Daniel Martín; +Cc: Lars Ingebrigtsen, Harald Hanche-Olsen, 9970
reopen 9970
thanks
>>> Would it make sense to ask for the frame width and height using the
>>> minibuffer if no prefix argument is provided? Right now, if you try the
>>> command, the frame resizes to a somewhat arbitrary size, which may
>>> confuse some users.
>>
>> I guess that'd be a natural addition -- we have many commands that
>> either take a numerical prefix, or query the user if there isn't any
>> prefix.
>
> I've attached a patch that implements the idea. It offers the current
> width or height by default, so you can estimate better the new size
> you'd want. Thanks.
frame.el is preloaded as well, so frame.el would be a more
suitable place for this function.
> From 1d48a90b584207290d8785ac4b294b43cc5851b3 Mon Sep 17 00:00:00 2001
> From: =?UTF-8?q?Daniel=20Mart=C3=ADn?= <mardani29@yahoo.es>
> Date: Sun, 14 Mar 2021 12:33:00 +0100
> Subject: [PATCH] Add minibuffer input support to commands that set the frame
> size
>
> * lisp/subr.el (set-frame-property--interactive): Internal function to
> produce the interactive form of `set-frame-width' and
> `set-frame-height'. Offer the current size as default. (Bug#9970)
> * src/frame.c (Fset_frame_height): Modify to call
> `set-frame-property--interactive'.
> (Fset_frame_width): Modify to call `set-frame-property--interactive'.
> * doc/lispref/frames.texi (Frame Size): Update the manuals.
> * etc/NEWS: Advertise the change.
> ---
> doc/lispref/frames.texi | 12 ++++++------
> etc/NEWS | 4 ++++
> lisp/subr.el | 8 ++++++++
> src/frame.c | 4 ++--
> 4 files changed, 20 insertions(+), 8 deletions(-)
>
> diff --git a/doc/lispref/frames.texi b/doc/lispref/frames.texi
> index f4316b753d..cd2ff8f3b3 100644
> --- a/doc/lispref/frames.texi
> +++ b/doc/lispref/frames.texi
> @@ -1120,9 +1120,9 @@ Frame Size
> refuse to truly honor the request if it does not increase/decrease the
> frame height to a multiple of its character height.
>
> -When used interactively, this command will set the height of the
> -currently selected frame to the number of lines specified by the
> -numeric prefix.
> +When used interactively, this command will ask the user for the number
> +of lines to set the height of the currently selected frame. You can
> +also provide this value with a numeric prefix.
> @end defun
>
> @defun set-frame-width frame width &optional pretend pixelwise
> @@ -1136,9 +1136,9 @@ Frame Size
> refuse to fully honor the request if it does not increase/decrease the
> frame width to a multiple of its character width.
>
> -When used interactively, this command will set the width of the
> -currently selected frame to the number of columns specified by the
> -numeric prefix.
> +When used interactively, this command will ask the user for the number
> +of columns to set the width of the currently selected frame. You can
> +also provide this value with a numeric prefix.
> @end defun
>
> None of these three functions will make a frame smaller than needed to
> diff --git a/etc/NEWS b/etc/NEWS
> index fa8784db59..08935dcce4 100644
> --- a/etc/NEWS
> +++ b/etc/NEWS
> @@ -253,6 +253,10 @@ commands. The new keystrokes are 'C-x x g' ('revert-buffer'),
> ('clone-buffer'), 'C-x x i' ('insert-buffer') and 'C-x x t'
> ('toggle-truncate-lines').
>
> +---
> +** Commands 'set-frame-width' and 'set-frame-height' can now get their
> +input using the minibuffer.
> +
> \f
> * Editing Changes in Emacs 28.1
>
> diff --git a/lisp/subr.el b/lisp/subr.el
> index ef0e5e6f78..692346c8ba 100644
> --- a/lisp/subr.el
> +++ b/lisp/subr.el
> @@ -2965,6 +2965,14 @@ goto-char--read-natnum-interactive
> (default (and (natnump number) number)))
> (list (read-number prompt (list default (point)))))))
>
> +(defun set-frame-property--interactive (prompt number)
> + "Get a value for `set-frame-width' or `set-frame-height', prompting with PROMPT.
> +Offer NUMBER as default value, if it is a natural number."
> + (if (and current-prefix-arg (not (consp current-prefix-arg)))
> + (list (selected-frame) (prefix-numeric-value current-prefix-arg))
> + (let ((default (and (natnump number) number)))
> + (list (selected-frame) (read-number prompt (list default (point)))))))
> +
> \f
> (defvar read-char-history nil
> "The default history for the `read-char-from-minibuffer' function.")
> diff --git a/src/frame.c b/src/frame.c
> index a62347c1fb..cfdf3b6193 100644
> --- a/src/frame.c
> +++ b/src/frame.c
> @@ -3595,7 +3595,7 @@ check_frame_pixels (Lisp_Object size, Lisp_Object pixelwise, int item_size)
> }
>
> DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 4,
> - "(list (selected-frame) (prefix-numeric-value current-prefix-arg))",
> + "(set-frame-property--interactive \"Frame height: \" (frame-height))",
> doc: /* Set text height of frame FRAME to HEIGHT lines.
> Optional third arg PRETEND non-nil means that redisplay should use
> HEIGHT lines but that the idea of the actual height of the frame should
> @@ -3620,7 +3620,7 @@ DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 4,
> }
>
> DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 4,
> - "(list (selected-frame) (prefix-numeric-value current-prefix-arg))",
> + "(set-frame-property--interactive \"Frame width: \" (frame-width))",
> doc: /* Set text width of frame FRAME to WIDTH columns.
> Optional third arg PRETEND non-nil means that redisplay should use WIDTH
> columns but that the idea of the actual width of the frame should not
> --
> 2.28.0
^ permalink raw reply [flat|nested] 6+ messages in thread