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

From: Jean Louis <[email-masked]>
Date: Thu, 11 Oct 2018 08:33:21 +0200

On Thu, Oct 11, 2018 at 05:36:59AM +0300, Eli Zaretskii wrote:
> > From: Jean Louis <[email-masked]>
> > Date: Wed, 10 Oct 2018 22:49:19 +0200
> > 
> > 
> > I would like to propose function for GNU Emacs so that there is
> > function to edit and return the string.
> > 
> > It would be equivalent to read-from-minibuffer only that we shall have
> > function to edit in the whole buffer, not just in one line in mini
> > buffer.
> 
> We already have read-string, I think it does what you want.

It reads from mini buffer, it does not open
standard buffer where one could change modes and
have editing capabilities, preview, insert from
other files, etc.

I have found solution for me. And I think
something like that shall be included in emacs.

Why?

We have read-from-minibuffer.

Logically there shall be read-from-buffer too.

Isn't it?

I am using this one below now but it would be nice
to have it as fully fledged with options
etc. professional built-in function.

I have website revision system written in LISP
that invokes Emacs to edit PostgreSQL variables,
including LISP variables. Such contain markup,
notes, description, bodies of text that cannot fit
into read-string function and where I need to
preview the file, work with it, until it is
published. Some page are even in Org mode, so I
would need to see how they look like before I let
it be fed into the database again.

At the moment I tried doing the same from within
Emacs, I have spent hours trying to find something
like read-from-buffer as I was convinced it exists
there.

That is why I am proposing standardized function
to read-from-buffer with nice options as built in
function.

And I will appreciate any improvements to the
below function.

Jean

Something like this below shall become read-from-buffer

;;; edited from https://raw.githubusercontent.com/deestan/emacs/master/emacs-goodies-el/miniedit.el
(defun edit-string (value)
  "Edits string and returns it"
  (let ((this-buffer (buffer-name))
	(new-value value)
	(buffy "*edit-string*"))
    (save-excursion
      (switch-to-buffer buffy)
      (set-buffer buffy)
      (text-mode)
      (local-set-key (kbd "C-c C-c") 'exit-recursive-edit)
      (if (stringp value) (insert value))
      (message "When you're done editing press C-c C-c or C-M-c to continue.")
      (unwind-protect
	  (recursive-edit)
	(if (get-buffer-window buffy)
	    (progn
	      (setq new-value (buffer-substring (point-min) (point-max)))
	      (kill-buffer buffy))))
      (switch-to-buffer this-buffer)
      new-value)))