help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Format code snippets of the wolfram language to improve readability.


From: Thibaut Verron
Subject: Re: Format code snippets of the wolfram language to improve readability.
Date: Tue, 26 Apr 2022 16:31:06 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0

On 26/04/2022 16:00, Hongyi Zhao wrote:
On Tue, Apr 26, 2022 at 9:17 PM Thibaut Verron <thibaut.verron@gmail.com> 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 <RET> 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 <rpluim@gmail.com> wrote:
On Tue, 26 Apr 2022 16:42:26 +0800, Hongyi Zhao <hongyi.zhao@gmail.com> 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]