From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Thibaut Verron Newsgroups: gmane.emacs.help Subject: Re: Format code snippets of the wolfram language to improve readability. Date: Wed, 27 Apr 2022 09:59:26 +0200 Message-ID: <09b8f470-944c-1f96-ae38-5bf55aba4285@gmail.com> References: <87ilqw6x9i.fsf@gmail.com> <377659b8-dc92-b916-f406-831e1bb24ffb@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="23678"; 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 Cc: help-gnu-emacs To: Hongyi Zhao Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Wed Apr 27 10:06:06 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 1njcgX-0005w4-4r for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 27 Apr 2022 10:06:05 +0200 Original-Received: from localhost ([::1]:52634 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1njcgV-0004x8-4E for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 27 Apr 2022 04:06:03 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:51182) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1njcaB-0003dT-Pp for help-gnu-emacs@gnu.org; Wed, 27 Apr 2022 03:59:32 -0400 Original-Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]:50906) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1njcaA-0001Dm-1v for help-gnu-emacs@gnu.org; Wed, 27 Apr 2022 03:59:31 -0400 Original-Received: by mail-wm1-x336.google.com with SMTP id 129so681012wmz.0 for ; Wed, 27 Apr 2022 00:59:29 -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:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=2hL27h7lMnqV+S9O1OUpF3+5wn2knvnLNTkz3y/LMFk=; b=gLDY3oCvWOrya6B1QASL7qCNOZRLPcboDz3fJ5Zzr1ZHmPNo530DSrncg3/9mBBk4y v8Et7CBL3oMpKruBhRvgTKCYP/GPUHN295HGmTxOIywtkdRExK0b+vDB7IMkhWf/h4LF Rl/U+R36KiBa6hVqXN9irAoOSo5+dO0GJ0XCmRxnpnlrXWsNexJ4PVITDSUI9lC+QA4z 0uN09LueoZg+4Xjm0yn/YJ0oUx2Faz6FAmLKIaO0i8ucSUWYwOMO9+Dz9GXStJTfC+8R zbURLV2ysv6+ImfNrijqjPeRPOGXB0gj6F/MDcMXBjnJw0OnhkK4/QKuKx6fhXTUBaY3 Tssw== 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:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=2hL27h7lMnqV+S9O1OUpF3+5wn2knvnLNTkz3y/LMFk=; b=LHSTUptrkd6yCmYeA3upph0IhIDiHIAGIU3Jr4aSeBgVm6YUa6M2jFHBFGev5eg/Ay vXF/PUd0DzpHUsPh+YArzEwxK5uibNpu/foZtqHPOCdz9nQv32UpON485n5r0dZzyYot /q+zj73oJryDHGE/lR9s8ah5RSOIrTaYOOz6WULYZIjsdh/xgFeD6QUBYO4WGSdYyIYU IRKc2UCNYsFpUG/hFhWfSboAbiRgoq0dc6wCy42ruMPbaqNG5ET/wZgmsf7+qAc9qoK/ JV3KlfZUWn/CFoQr5D7N0eUceIZMHAoPOAEGl9TxupUTh8etuoSXnx7UKajg/hexRk8L beJg== X-Gm-Message-State: AOAM532+bIfCX3QQ3SPJvQi1Ley5X71awuC+TP6wndc/cu0XDA6uQF31 y/wcPy+xYGfvFZcOVlqVCz/Ify7O66o= X-Google-Smtp-Source: ABdhPJxrPw86eWfSfKHunJNiYhozLc7TUILh9RN4QEM/Fu3rFFEV07iwLEOv7IZ3SvV55bERsHtojA== X-Received: by 2002:a05:600c:5006:b0:392:3077:789c with SMTP id n6-20020a05600c500600b003923077789cmr34025047wmr.50.1651046368063; Wed, 27 Apr 2022 00:59:28 -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 k14-20020adfb34e000000b0020ad257aa37sm11034643wrd.102.2022.04.27.00.59.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 27 Apr 2022 00:59:27 -0700 (PDT) Content-Language: en-US In-Reply-To: Received-SPF: pass client-ip=2a00:1450:4864:20::336; envelope-from=thibaut.verron@gmail.com; helo=mail-wm1-x336.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:137044 Archived-At: 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. Best wishes, Thibaut > > Regards, > HZ