bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#33007: 27.0.50; Proposal for function to edit and return string


From: Juri Linkov
Subject: bug#33007: 27.0.50; Proposal for function to edit and return string
Date: Sun, 08 May 2022 21:22:47 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu)

>> 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:

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))))
 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]