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: Tue, 26 Apr 2022 16:31:06 +0200 Message-ID: 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: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="9080"; 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 Tue Apr 26 16:32:28 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 1njMEt-0002B2-M6 for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 26 Apr 2022 16:32:27 +0200 Original-Received: from localhost ([::1]:60770 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1njMEs-000457-7h for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 26 Apr 2022 10:32:26 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:41894) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1njMDz-00044Q-Hp for help-gnu-emacs@gnu.org; Tue, 26 Apr 2022 10:31:31 -0400 Original-Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]:41944) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1njMDx-00088v-M4 for help-gnu-emacs@gnu.org; Tue, 26 Apr 2022 10:31:31 -0400 Original-Received: by mail-wr1-x436.google.com with SMTP id s21so11049988wrb.8 for ; Tue, 26 Apr 2022 07:31: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=C7XUcXH/t75UbfAsBJ43akk44+NYpCfC6k8KMcfNoLs=; b=RpgTX/gt2CWwiSwc4lsvjo/bP4oLQAuTOr0qsP38moMT2mbRS4QwwPMJ5dHbGNemEU PgNbv68pQUpfXpEVhW61ZOopL/bhohpOL9ounqQDNGbay9bT6l05dAO2GAY3E7JsTy74 wWMqn3MNn4TGADSKPxIANiGX5jsOeaNEwrGlFFihEZEMr1v1h547SZr5bmt7oZFE5Flf SpdJNQdzei6cKIjJPCo8adTAgOdbTtOBWYtIvyz7EULbrc267+1cnjcJn4btyW4zOZrH PFRhQepSZX0qplzVJPKWwxpy0ihAg4KzlW08bQEYf8sWEXGK9+/U/nGngMCJOP40V9zx +BmA== 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=C7XUcXH/t75UbfAsBJ43akk44+NYpCfC6k8KMcfNoLs=; b=blZWVxSb/QWIaK+KL9kUAKGc3iTcn4sGHqa63ro5t4upOIZ0hYr3Qh7LXfepurSclA QirvN2Ix38sSGoQseoF8Euh4nb+DL5J1/cDvLrFQP3C5gNwUptqmJS63uxbqqrP0cmIa rrbU6jNTObJszTpPiiiS4OIpuJyL2Mrpfxx/+V6W5wZSPm7L8o2KpHs4gyOooHMb/4m2 Ptd8d38rFdq/qosGBOMDT42F+cE6MyZfeTz4xtwwT+8YMDb2ZoK0KMR4Ib+MVfEHQDOy wRLm5SAm/xZYrPy4DDersm7c6Koi+MnwULF2gYEJb+/XhZTs56LfYjNG+0UBjobpemBF tH2Q== X-Gm-Message-State: AOAM530lIaiNe6snTgv4lVkcISLmYcUASzocurx4jOrAizIB7Xd0GW3/ PJ/Er5RqGuhPfU5cew/B9FI= X-Google-Smtp-Source: ABdhPJyJ+8FbX6pkETbT7lZ/s5p0t/PKmH0S54u6CIWGNCaFtLLsYntd1KKq8fTwTYks5cDxagaM6g== X-Received: by 2002:adf:eb89:0:b0:1e4:b8f4:da74 with SMTP id t9-20020adfeb89000000b001e4b8f4da74mr18778817wrn.408.1650983487993; Tue, 26 Apr 2022 07:31:27 -0700 (PDT) Original-Received: from ?IPV6:2001:628:2010:4094:55cc:900a:c66d:f55a? ([2001:628:2010:4094:55cc:900a:c66d:f55a]) by smtp.gmail.com with ESMTPSA id 7-20020a05600c024700b0038ec0c4a2e7sm13916069wmj.11.2022.04.26.07.31.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 26 Apr 2022 07:31:08 -0700 (PDT) Content-Language: en-US In-Reply-To: Received-SPF: pass client-ip=2a00:1450:4864:20::436; envelope-from=thibaut.verron@gmail.com; helo=mail-wr1-x436.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:137037 Archived-At: 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. :) Best wishes, Thibaut > >> I'm not aware of any language mode which offers to automatically >> introduce line breaks in a long one-liner. >> >> Best wishes, >> >> Thibaut >> >> On 26/04/2022 11:40, Hongyi Zhao wrote: >>> On Tue, Apr 26, 2022 at 4:53 PM Robert Pluim wrote: >>>>>>>>> On Tue, 26 Apr 2022 16:42:26 +0800, Hongyi Zhao said: >>>> Hongyi> I've the following code snippets of the wolfram language: >>>> Hongyi> ``` >>>> Hongyi> Hold[ReplaceRepeated[List[A, B, IA, A, B, IA, A, B, IA, A, B, IA, A, >>>> Hongyi> B, IA], RuleDelayed[Condition[List[Pattern[x, BlankNullSequence[]], >>>> Hongyi> Pattern[y, Blank[]], Pattern[z, Blank[]], Pattern[t, >>>> Hongyi> BlankNullSequence[]]], Simplify[Equal[Dot[y, z], IdentityMatrix[3]]]], >>>> Hongyi> List[x, t]]]] >>>> Hongyi> ``` >>>> >>>> Hongyi> I want to format it in Emacs to improve readability. Any hints for >>>> Hongyi> achieving this purpose? >>>> >>>> Install wolfram-mode? >>> BTW, here [1] is a more recent and alternative version of >>> wolfram-mode, but it does not have the functions required for the >>> issues discussed here. >>> >>> [1] https://github.com/xahlee/xah-wolfram-mode >>> >>> HZ >>>