playground:plan9_tutorial_sam
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
playground:plan9_tutorial_sam [2021/04/19 18:06] – dsp | playground:plan9_tutorial_sam [2021/04/19 21:30] – adding a toy example for regex dsp | ||
---|---|---|---|
Line 63: | Line 63: | ||
notice that if we rename an entry that doesn' | notice that if we rename an entry that doesn' | ||
issue **w** on the renamed entry it will create a new file on disk. | issue **w** on the renamed entry it will create a new file on disk. | ||
+ | |||
+ | === Examples for sam regex === | ||
+ | The benefit of sam is that it allows for regex tasks to be chained and also debugged | ||
+ | easily from within the editor. We will consider a toy example to ident properly some | ||
+ | code of the form | ||
+ | < | ||
+ | if foo { | ||
+ | bar | ||
+ | } | ||
+ | </ | ||
+ | We would like bar to be indented at 8 spaces in, one more level than //if// is. | ||
+ | We can start with a regex to detect the opening brace | ||
+ | < | ||
+ | should detect, in the whole file (,) these braces. | ||
+ | Now we can match backwards to find the prepending white space in that line we matched | ||
+ | by just chaining the next regex. | ||
+ | < | ||
+ | now that matches the white space before. | ||
+ | We would like to add at least as much white space to the line below and | ||
+ | then some (4 spaces for example). | ||
+ | But for that to work the line below must be free of leading white space. | ||
+ | Therefore we will remove it from any line that is below an opening brace. The search is | ||
+ | < | ||
+ | and to remove the white space between the start of line and the first character we chain it like | ||
+ | < | ||
+ | The final form of our regex chain is | ||
+ | < | ||
+ | , x/{\n[ ]*/ s/^[ ]*/ / | ||
+ | , x/{$/ -/^[ ]*/ t .+0 | ||
+ | </ | ||
=== Self guided discoveries === | === Self guided discoveries === | ||
Line 72: | Line 102: | ||
* can you specify a reverse range like #10,#5 ? | * can you specify a reverse range like #10,#5 ? | ||
* highlight a word. then issue **m+0**. why is this happening? what is **t+0** doing? what if you keep issuing **t+0**? | * highlight a word. then issue **m+0**. why is this happening? what is **t+0** doing? what if you keep issuing **t+0**? | ||
+ | * Improve the toy ident example by | ||
+ | * making lines align when no opening brace is detected in the end of line | ||
+ | * remove 4 leading spaces if the line has a closing brace | ||
+ | |||
+ | === Documentation and more === | ||
+ | *[[http:// | ||
+ | *[[http:// | ||
+ | *[[http:// | ||
+ | *[[http:// | ||
+ | *[[https:// | ||
+ | *[[https:// |
playground/plan9_tutorial_sam.txt · Last modified: 2021/04/20 04:59 by dsp