From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: thibaut.verron@gmail.com Newsgroups: gmane.emacs.help Subject: Re: Format code snippets of the wolfram language to improve readability. Date: Wed, 27 Apr 2022 11:00:40 +0200 Message-ID: <81c515e4-9e98-a724-52ed-699322f3e1b4@gmail.com> References: <87ilqw6x9i.fsf@gmail.com> <377659b8-dc92-b916-f406-831e1bb24ffb@gmail.com> <09b8f470-944c-1f96-ae38-5bf55aba4285@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="33584"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 To: Hongyi Zhao , help-gnu-emacs Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Wed Apr 27 11:03:56 2022 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 1njdaV-0008Tu-3x for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 27 Apr 2022 11:03:55 +0200 Original-Received: from localhost ([::1]:42780 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1njdaT-0005us-RF for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 27 Apr 2022 05:03:53 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:38778) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1njdXR-0005tM-Lp for help-gnu-emacs@gnu.org; Wed, 27 Apr 2022 05:00:46 -0400 Original-Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]:42814) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1njdXP-000200-Ok for help-gnu-emacs@gnu.org; Wed, 27 Apr 2022 05:00:45 -0400 Original-Received: by mail-wm1-x333.google.com with SMTP id n126-20020a1c2784000000b0038e8af3e788so784190wmn.1 for ; Wed, 27 Apr 2022 02:00:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:from:to:subject:references :in-reply-to:content-transfer-encoding; bh=aXrCHG9APDol8YG4+3zQuSWVmZwP1alPP6JeFY79Y9E=; b=juQXm7SmUQaWV2SGV6AIPsvbRXXkYGcvkDuhwb4vEpxL2T1g659FwzdnJD2jCkzmee LnJZRWcan4XV6l4lnHVfThvbcyTWr5D3AN8sFOIBH1lFxHc7Vw/JRmzBAIpySsvigFg3 GMm3hlyB+SLzNHlZaoQhPaoU4mYcjPHMNumWmsrFRXmx9kdq0iI4Ku+bDyCYsI4La++B 5ctcUCXk61FRZPlhsGi7ic5Z0o6QlrNqff+C3Olh37VraeujUGwLSrM2XtMXusWI7VcS lcW5CG/G03TH83ToYRJYbHqQadgW3QNneOqsZ/1VwE7xfCVzEy+B0+/C2feVVpS5jUhc PRHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:from:to :subject:references:in-reply-to:content-transfer-encoding; bh=aXrCHG9APDol8YG4+3zQuSWVmZwP1alPP6JeFY79Y9E=; b=XmSdz+rWS0slOMxjWrS0SU0RVVA9/PmoUwjJgJ8W47vJZRSg6FHcQoBx0xB0JhtrH+ wDWsK8QZoKErwgGvSsvzF59W60ViIKGV/kDCF5uHK7sX7xxDcbby9yLVb8ikCEhZazB6 7qF7nwc+NB4W4XMTdWz7mt+ubwivGbDXe/S5/GEofOLuR0Rh4dnHyV4dO/Z566ex7zRF 8KbBU5kRoYcGV6fdkCyTAOpIj3V3lU83+fpadlLl+K2WLbawEYn8QYiBPqAfTacTdUJv VjsWtFoALOx+CzfDdGusvq+SeSGOYn0wA8zEIRvpC0gfA/PJ1y8DSS2PscbVW6KMU3+e 749g== X-Gm-Message-State: AOAM5322skCNSCekpq0FP07oIPi+ShwrXDIGnRnstghyIb9mm47TGwMD k5Ing13/oQ/tmX0hKF2HQZo= X-Google-Smtp-Source: ABdhPJzNh5yufKIBWbRcdYr5yT4Pr6KorvvxB+d5FzWtkfh4LvtWGzl+7zEninzLLabWbq9be+kM9Q== X-Received: by 2002:a7b:cb83:0:b0:37e:bc50:3c6b with SMTP id m3-20020a7bcb83000000b0037ebc503c6bmr34962552wmi.67.1651050042165; Wed, 27 Apr 2022 02:00:42 -0700 (PDT) Original-Received: from ?IPV6:2001:628:2010:4094:977a:7eb:fc8:7a03? ([2001:628:2010:4094:977a:7eb:fc8:7a03]) by smtp.gmail.com with ESMTPSA id z3-20020a1cf403000000b0037d1f4a2201sm1122171wma.21.2022.04.27.02.00.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 27 Apr 2022 02:00:41 -0700 (PDT) In-Reply-To: Received-SPF: pass client-ip=2a00:1450:4864:20::333; envelope-from=thibaut.verron@gmail.com; helo=mail-wm1-x333.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, NICE_REPLY_A=-0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 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:137047 Archived-At: On 27/04/2022 10:33, Hongyi Zhao wrote: > On Wed, Apr 27, 2022 at 3:59 PM Thibaut Verron wrote: > > > > > > On 27/04/2022 02:32, Hongyi Zhao wrote: > >> On Tue, Apr 26, 2022 at 10:31 PM Thibaut Verron > >> wrote: > >>> On 26/04/2022 16:00, Hongyi Zhao wrote: > >>>> On Tue, Apr 26, 2022 at 9:17 PM Thibaut Verron wrote: > >>>>> Hi, > >>>>> > >>>>> Once the mode is activated, introducing newlines at key places should > >>>>> make the formula readable. > >>>> Yes. It works. But this method needs to hit many times on to > >>>> achieve the goal. > >>>>> You can also use sexp-navigation commands to > >>>>> quickly navigate the parentheses and find those key points. > >>>> I don't have this command, as shown in the attachment. > >>> It's not one command, but a set of commands for navigating paired > >>> expressions: for example forward-sexp C-M-f (jumping over a symbol or a > >>> paired expression), backward-sexp C-M-b, and down-list C-M-d (jumping > >>> inside the next paired expression). Those commands are designed for lisp > >>> languages, but they work remarkably well for most programming languages > >>> (and are even occasionally useful with natural languages). > >>> > >>> For example for your expression, you can get the formatted version I > >>> sent with: (indented to follow the depth in the expression) > >>> > >>> C-M-d > >>> C-M-d > >>> C-j > >>> C-M-f C-M-f C-f C-j > >>> C-M-d > >>> C-j > >>> C-M-d > >>> C-M-d > >>> C-M-f C-M-f C-f C-j > >>> C-M-f C-M-f C-f C-j > >>> C-M-f C-M-f C-f C-j > >>> C-M-f > >>> C-f > >>> C-f C-j > >>> C-M-f C-M-f > >>> C-f > >>> C-f C-j > >>> > >>> I know that it looks somewhat complicated and long, but it's easier done > >>> interactively than read. :) > >> It would be much more useful to generalize the working logic like the > >> one above and use a function implementation to handle the work here. > > > > As usual with this type of questions, the difficulty is in formalizing > > the requirement. > > > > For instance, if the goal is to break the line after each syntactic > > unit, that's reasonably easy to automatize. But then the first list will > > be 15 lines, so I don't think that's what you want. > > > > But as it stands, there is no "working logic", it's an interactive > > process. And the best the editor can do is make this process easy, by > > letting us navigate through the possible points for inserting line > > breaks, and leaving the choice to us. > > > > This is exactly what the sequence of key presses I suggested does: each > > M-C-f, M-C-d and C-f just means "jump to the next candidate break > > point", with sometimes C-M-f used for jumping over multiple points (such > > as the first list). And you just add a C-j (or RET) whenever you reach a > > point where you would like to break the expression. > > > > If you have a precise way to describe the result you want, I'm sure > > writing a function to do it won't be too difficult. > > I think the criterion is readability and perhaps the results shown in > the attachment are desirable. That's exactly what I mean. :) "Readability" is a human concept, something that we recognize when we see it. But how would you explain to a computer (or someone writing the function you want) what "readability" is? In your example, how would you formalize the fact that the 1st and 3rd lists shouldn't be broken, but the second should? Again, it has little to do with wolfram (which is good for the list), I don't know of any mode offering a function for inserting smart line breaks in one-liners. Best wishes, Thibaut