From: Tim Landscheidt <tim@tim-landscheidt.de>
To: help-gnu-emacs@gnu.org
Subject: Re: RFE: Editing string literals like org-mode?
Date: Sun, 28 Mar 2021 12:31:13 +0000 [thread overview]
Message-ID: <87r1jzmpda.fsf@passepartout.tim-landscheidt.de> (raw)
In-Reply-To: YF90t6vAsqg2Af4f@protected.localdomain
Jean Louis <bugs@gnu.support> wrote:
>> >> - an (optional) function foo-quote for each major mode so
>> >> that (insert (foo-quote (read-string "String: ")))
>> >> inserts the input properly quoted in the current buffer,
>> > (insert (prin1-to-string (read-string "String: "))) → "Some \"New\" string"
>> > Is that?
>> That is the existing solution for Emacs Lisp. I'm looking
>> for a universal one.
> Do you mean like a function maybe, that works everywhere?
> (defun my-insert-string-literal (&optional string)
> "Asks for STRING if not supplied and inserts it as literal
> string with quotes."
> (interactive)
> (let ((string (or string (read-string "String: "))))
> (insert (prin1-to-string string))))
Exactly, but your function will for example not work in SQL.
>> >> - an (optional) function foo-read-string-literal-at-point
>> >> that returns the dequoted string literal at point, and
>> > Do you mean that it works on quote strings like: "Some \"New\" string"?
>> For example.
> thing-at-point would need to be defined, I would not know now how
> to define it universally to find out string with quote on both
> sides and that it works over new lines.
> "Some string✗ here \"Mo✗re\" and more."
> "Then again✗ maybe \"one\" here".
> What would be then string with quotes if cursor is at second ✗ on
> first line or first, or in the second line?
The string-edit buffer's contents would be:
| Some string here "More" and more.
or
| Then again maybe "one" here
> Should program count all quotes, and what about others? It is
> hard to find general boundaries.
> It would be easier to find boundaries in a sexp like
> '(Something "String \"more\" here").
Not really; if I enter:
| print "Some string here \"More\" and more.";
into a perl-mode buffer, Emacs "knows" that there is a
string literal starting at the first and ending at the last
quote in that line.
>> >> - a function bound to C-c ' that edits the string literal at
>> >> point just like org-mode does (if the major mode provides
>> >> the necessary foo-quote and
>> >> foo-read-string-literal-at-point functions).
>> > I have tried searching in the manual, so can you help me, is it
>> > in source block? Or in table?
>> For example in source blocks (#+BEGIN_SRC).
>> > If I got it right, it would be useful to be able to edit strings
>> > without observing quotations.
>> That would be the point; assuming a shell-script-mode buffer
>> with the text:
> For that I have tried with:
> #+BEGIN_SRC shell-script
> Something
> #+END_SRC
> And I do not see how it helps with quoting, maybe I
> misunderstood. What I could see is that it is making new buffer
> and edits it maybe with a different mode.
I did not say that org-mode's edit-in-another-buffer feature
is primarily useful for quoting; it is just a similar con-
cept.
But if, for example, you enter "#+END_SRC" in an org-mode
edit buffer, you will see that it not only gets indented,
but also quoted as:
| #+BEGIN_SRC shell-script
| ,#+END_SRC
| #+END_SRC
> Do you mean to temporarily, during editing, change the mode and
> then come back to original mode?
I believe there are a number of "multiple major modes in one
buffer" solutions, but (AFAIK) they are aimed at situations
like editing HTML with embedded (verbatim) PHP or Java-
Script, not editing an SQL statement in a Perl script in a
shell script in an Emacs Lisp function.
Tim
prev parent reply other threads:[~2021-03-28 12:31 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-27 14:05 RFE: Editing string literals like org-mode? Tim Landscheidt
2021-03-27 14:25 ` Jean Louis
2021-03-27 16:32 ` Tim Landscheidt
2021-03-27 17:09 ` Stefan Monnier
2021-03-28 11:42 ` Tim Landscheidt
2021-03-27 18:08 ` Jean Louis
2021-03-28 12:31 ` Tim Landscheidt [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87r1jzmpda.fsf@passepartout.tim-landscheidt.de \
--to=tim@tim-landscheidt.de \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).