* Format code snippets of the wolfram language to improve readability.
@ 2022-04-26 8:42 Hongyi Zhao
2022-04-26 8:53 ` Robert Pluim
0 siblings, 1 reply; 12+ messages in thread
From: Hongyi Zhao @ 2022-04-26 8:42 UTC (permalink / raw)
To: help-gnu-emacs
I've the following code snippets of the wolfram language:
```
Hold[ReplaceRepeated[List[A, B, IA, A, B, IA, A, B, IA, A, B, IA, A,
B, IA], RuleDelayed[Condition[List[Pattern[x, BlankNullSequence[]],
Pattern[y, Blank[]], Pattern[z, Blank[]], Pattern[t,
BlankNullSequence[]]], Simplify[Equal[Dot[y, z], IdentityMatrix[3]]]],
List[x, t]]]]
```
I want to format it in Emacs to improve readability. Any hints for
achieving this purpose?
Regards
--
Assoc. Prof. Hongsheng Zhao <hongyi.zhao@gmail.com>
Theory and Simulation of Materials
Hebei Vocational University of Technology and Engineering
No. 473, Quannan West Street, Xindu District, Xingtai, Hebei province
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Format code snippets of the wolfram language to improve readability.
2022-04-26 8:42 Format code snippets of the wolfram language to improve readability Hongyi Zhao
@ 2022-04-26 8:53 ` Robert Pluim
2022-04-26 9:34 ` Hongyi Zhao
2022-04-26 9:40 ` Hongyi Zhao
0 siblings, 2 replies; 12+ messages in thread
From: Robert Pluim @ 2022-04-26 8:53 UTC (permalink / raw)
To: Hongyi Zhao; +Cc: help-gnu-emacs
>>>>> 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?
Robert
--
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Format code snippets of the wolfram language to improve readability.
2022-04-26 8:53 ` Robert Pluim
@ 2022-04-26 9:34 ` Hongyi Zhao
2022-04-26 9:40 ` Hongyi Zhao
1 sibling, 0 replies; 12+ messages in thread
From: Hongyi Zhao @ 2022-04-26 9:34 UTC (permalink / raw)
To: Robert Pluim; +Cc: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 923 bytes --]
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?
I installed this package and activated the mode provided by it, but
still can't see any options to do the job discussed here, as shown in
the attached file.
HZ
[-- Attachment #2: image.png --]
[-- Type: image/png, Size: 155614 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Format code snippets of the wolfram language to improve readability.
2022-04-26 8:53 ` Robert Pluim
2022-04-26 9:34 ` Hongyi Zhao
@ 2022-04-26 9:40 ` Hongyi Zhao
2022-04-26 13:13 ` Thibaut Verron
1 sibling, 1 reply; 12+ messages in thread
From: Hongyi Zhao @ 2022-04-26 9:40 UTC (permalink / raw)
To: Robert Pluim; +Cc: help-gnu-emacs
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
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Format code snippets of the wolfram language to improve readability.
2022-04-26 9:40 ` Hongyi Zhao
@ 2022-04-26 13:13 ` Thibaut Verron
2022-04-26 14:00 ` Hongyi Zhao
0 siblings, 1 reply; 12+ messages in thread
From: Thibaut Verron @ 2022-04-26 13:13 UTC (permalink / raw)
To: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 1377 bytes --]
Hi,
Once the mode is activated, introducing newlines at key places should
make the formula readable. You can also use sexp-navigation commands to
quickly navigate the parentheses and find those key points.
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
>
[-- Attachment #2: Screenshot_20220426_151253.png --]
[-- Type: image/png, Size: 22229 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Format code snippets of the wolfram language to improve readability.
2022-04-26 13:13 ` Thibaut Verron
@ 2022-04-26 14:00 ` Hongyi Zhao
2022-04-26 14:31 ` Thibaut Verron
0 siblings, 1 reply; 12+ messages in thread
From: Hongyi Zhao @ 2022-04-26 14:00 UTC (permalink / raw)
To: Thibaut Verron; +Cc: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 1671 bytes --]
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.
> 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
> >
[-- Attachment #2: image.png --]
[-- Type: image/png, Size: 108812 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Format code snippets of the wolfram language to improve readability.
2022-04-26 14:00 ` Hongyi Zhao
@ 2022-04-26 14:31 ` Thibaut Verron
2022-04-27 0:32 ` Hongyi Zhao
0 siblings, 1 reply; 12+ messages in thread
From: Thibaut Verron @ 2022-04-26 14:31 UTC (permalink / raw)
To: Hongyi Zhao; +Cc: help-gnu-emacs
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
>>>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Format code snippets of the wolfram language to improve readability.
2022-04-26 14:31 ` Thibaut Verron
@ 2022-04-27 0:32 ` Hongyi Zhao
2022-04-27 1:14 ` Emanuel Berg via Users list for the GNU Emacs text editor
2022-04-27 7:59 ` Thibaut Verron
0 siblings, 2 replies; 12+ messages in thread
From: Hongyi Zhao @ 2022-04-27 0:32 UTC (permalink / raw)
To: Thibaut Verron; +Cc: help-gnu-emacs
On Tue, Apr 26, 2022 at 10:31 PM Thibaut Verron
<thibaut.verron@gmail.com> wrote:
>
> 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. :)
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.
Regards,
HZ
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Format code snippets of the wolfram language to improve readability.
2022-04-27 0:32 ` Hongyi Zhao
@ 2022-04-27 1:14 ` Emanuel Berg via Users list for the GNU Emacs text editor
2022-04-27 7:59 ` Thibaut Verron
1 sibling, 0 replies; 12+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2022-04-27 1:14 UTC (permalink / raw)
To: help-gnu-emacs
Hongyi Zhao wrote:
>> 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.
Yeah, English, please. I mean Elisp.
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Format code snippets of the wolfram language to improve readability.
2022-04-27 0:32 ` Hongyi Zhao
2022-04-27 1:14 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2022-04-27 7:59 ` Thibaut Verron
2022-04-27 8:33 ` Hongyi Zhao
1 sibling, 1 reply; 12+ messages in thread
From: Thibaut Verron @ 2022-04-27 7:59 UTC (permalink / raw)
To: Hongyi Zhao; +Cc: help-gnu-emacs
On 27/04/2022 02:32, Hongyi Zhao wrote:
> On Tue, Apr 26, 2022 at 10:31 PM Thibaut Verron
> <thibaut.verron@gmail.com> wrote:
>> 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. :)
> 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
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Format code snippets of the wolfram language to improve readability.
2022-04-27 7:59 ` Thibaut Verron
@ 2022-04-27 8:33 ` Hongyi Zhao
2022-04-27 9:00 ` thibaut.verron
0 siblings, 1 reply; 12+ messages in thread
From: Hongyi Zhao @ 2022-04-27 8:33 UTC (permalink / raw)
To: Thibaut Verron; +Cc: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 3140 bytes --]
On Wed, Apr 27, 2022 at 3:59 PM Thibaut Verron <thibaut.verron@gmail.com> wrote:
>
>
> On 27/04/2022 02:32, Hongyi Zhao wrote:
> > On Tue, Apr 26, 2022 at 10:31 PM Thibaut Verron
> > <thibaut.verron@gmail.com> wrote:
> >> 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. :)
> > 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.
Regards,
HZ
[-- Attachment #2: image.png --]
[-- Type: image/png, Size: 51386 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: Format code snippets of the wolfram language to improve readability.
2022-04-27 8:33 ` Hongyi Zhao
@ 2022-04-27 9:00 ` thibaut.verron
0 siblings, 0 replies; 12+ messages in thread
From: thibaut.verron @ 2022-04-27 9:00 UTC (permalink / raw)
To: Hongyi Zhao, help-gnu-emacs
On 27/04/2022 10:33, Hongyi Zhao <hongyi.zhao@gmail.com> wrote:
> On Wed, Apr 27, 2022 at 3:59 PM Thibaut Verron <thibaut.verron@gmail.com> wrote:
> >
> >
> > On 27/04/2022 02:32, Hongyi Zhao wrote:
> >> On Tue, Apr 26, 2022 at 10:31 PM Thibaut Verron
> >> <thibaut.verron@gmail.com> wrote:
> >>> 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. :)
> >> 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
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2022-04-27 9:00 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-04-26 8:42 Format code snippets of the wolfram language to improve readability Hongyi Zhao
2022-04-26 8:53 ` Robert Pluim
2022-04-26 9:34 ` Hongyi Zhao
2022-04-26 9:40 ` Hongyi Zhao
2022-04-26 13:13 ` Thibaut Verron
2022-04-26 14:00 ` Hongyi Zhao
2022-04-26 14:31 ` Thibaut Verron
2022-04-27 0:32 ` Hongyi Zhao
2022-04-27 1:14 ` Emanuel Berg via Users list for the GNU Emacs text editor
2022-04-27 7:59 ` Thibaut Verron
2022-04-27 8:33 ` Hongyi Zhao
2022-04-27 9:00 ` thibaut.verron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).