From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Tim Landscheidt Newsgroups: gmane.emacs.help Subject: Re: RFE: Editing string literals like org-mode? Date: Sun, 28 Mar 2021 12:31:13 +0000 Organization: http://www.tim-landscheidt.de/ Message-ID: <87r1jzmpda.fsf@passepartout.tim-landscheidt.de> References: <87ft0gofon.fsf@passepartout.tim-landscheidt.de> <875z1co8v0.fsf@passepartout.tim-landscheidt.de> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="23696"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) To: help-gnu-emacs@gnu.org Cancel-Lock: sha1:XMobdUucX6kfpitBO3kaPJhqkXY= Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sun Mar 28 14:33:17 2021 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lQUbV-00062y-6G for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 28 Mar 2021 14:33:17 +0200 Original-Received: from localhost ([::1]:53698 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lQUbR-0003iL-Vq for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 28 Mar 2021 08:33:15 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:45442) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lQUZg-0003i9-Cy for help-gnu-emacs@gnu.org; Sun, 28 Mar 2021 08:31:24 -0400 Original-Received: from ciao.gmane.io ([116.202.254.214]:37114) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lQUZe-000560-Fv for help-gnu-emacs@gnu.org; Sun, 28 Mar 2021 08:31:24 -0400 Original-Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1lQUZb-00045l-Nt for help-gnu-emacs@gnu.org; Sun, 28 Mar 2021 14:31:19 +0200 X-Injected-Via-Gmane: http://gmane.org/ Received-SPF: pass client-ip=116.202.254.214; envelope-from=geh-help-gnu-emacs@m.gmane-mx.org; helo=ciao.gmane.io X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.249, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:128741 Archived-At: Jean Louis 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