GNU bug report logs - #33007
27.0.50; Proposal for function to edit and return string

Previous Next

Package: emacs;

Reported by: Jean Louis <bugs <at> gnu.support>

Date: Wed, 10 Oct 2018 20:51:02 UTC

Severity: wishlist

Found in version 27.0.50

Fixed in version 29.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Juri Linkov <juri <at> linkov.net>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: Michael Heerdegen <michael_heerdegen <at> web.de>, 33007 <at> debbugs.gnu.org, Jean Louis <bugs <at> gnu.support>
Subject: bug#33007: 27.0.50; Proposal for function to edit and return string
Date: Sun, 08 May 2022 21:22:47 +0300
[Message part 1 (text/plain, inline)]
>> Maybe a separate bug report is needed?  Because it seems that
>> the order of processing these parameters should be rather like this:
>>
>> 1. first set window-height with fit-window-to-buffer;
>> 2. then check if the constraint of window-min-height is fulfilled,
>>    and shrink too high window.
>>
>> Then 'string-edit' will insert the initial string, and
>> 'fit-window-to-buffer' will fit the window.  If the window height
>> is less than 10 lines, it will enlarge to 10 lines.  But in case of
>> too many lines, the window height should not be more than
>> half of the original window.
>
> Yup; sounds like a separate bug report is warranted.

As was found in bug#55169, this is already possible to do with a lambda:

[read-string-from-buffer.patch (text/x-diff, inline)]
diff --git a/lisp/textmodes/string-edit.el b/lisp/textmodes/string-edit.el
index ab0b3b3bd7..d3f614ca94 100644
--- a/lisp/textmodes/string-edit.el
+++ b/lisp/textmodes/string-edit.el
@@ -47,7 +47,10 @@ string-edit
 PROMPT will be inserted at the start of the buffer, but won't be
 included in the resulting string.  If PROMPT is nil, no help text
 will be inserted."
-  (pop-to-buffer-same-window (generate-new-buffer "*edit string*"))
+  (pop-to-buffer (generate-new-buffer "*edit string*")
+                 '(display-buffer-below-selected
+                   (window-height . (lambda (window)
+                                      (fit-window-to-buffer window nil 10)))))
   (when prompt
     (let ((inhibit-read-only t))
       (insert prompt)
@@ -113,14 +116,14 @@ string-edit-done
     (goto-char (prop-match-beginning match)))
   (let ((string (buffer-substring (point) (point-max)))
         (callback string-edit--success-callback))
-    (kill-buffer (current-buffer))
+    (quit-window 'kill)
     (funcall callback string)))
 
 (defun string-edit-abort ()
   "Abort editing the current string."
   (interactive)
   (let ((callback string-edit--abort-callback))
-    (kill-buffer (current-buffer))
+    (quit-window 'kill)
     (when callback
       (funcall callback))))
 

This bug report was last modified 3 years and 15 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.