playground:plan9_tutorial_sam
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
playground:plan9_tutorial_sam [2021/04/19 21:30] – adding a toy example for regex dsp | playground:plan9_tutorial_sam [2021/04/20 04:59] (current) – adding external command section dsp | ||
---|---|---|---|
Line 66: | Line 66: | ||
=== Examples for sam regex === | === Examples for sam regex === | ||
The benefit of sam is that it allows for regex tasks to be chained and also debugged | 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 | + | easily from within the editor. We will consider a toy example to indent |
code of the form | code of the form | ||
< | < | ||
Line 93: | Line 93: | ||
, x/{$/ -/^[ ]*/ t .+0 | , x/{$/ -/^[ ]*/ t .+0 | ||
</ | </ | ||
+ | |||
+ | === Interacting with external commands === | ||
+ | Of course creating a indentation program with just regexp would be duplication of work. | ||
+ | For most languages pretty printers exist like gofmt and cb (C beautifier) let' try | ||
+ | to run cb on some ugly-fied C. | ||
+ | < | ||
+ | if (foo < | ||
+ | do(bxm,as); | ||
+ | wrong; | ||
+ | } | ||
+ | </ | ||
+ | To pass all this code through cb we can just select it and then | ||
+ | issue the command |cb . that would replace the dot by | ||
+ | < | ||
+ | if (foo < | ||
+ | do(bxm, | ||
+ | wrong; | ||
+ | } | ||
+ | </ | ||
+ | similarly we can read input from a command | ||
+ | using < and write to a command using > if we want to count all the | ||
+ | characters in a selection for example we can highlight it and issue >wc | ||
+ | , observe that this doesn' | ||
+ | |||
+ | We could also imagine a command where it replaces every | ||
+ | occurrence of //{DATE}// with the current system date in the whole document | ||
+ | < | ||
+ | , x/{DATE}/ <date | ||
+ | </ | ||
+ | would find any occurrence of the string //{DATE}// and then replace that | ||
+ | dot with the output of the date command. | ||
=== Self guided discoveries === | === Self guided discoveries === | ||
Line 102: | Line 133: | ||
* 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 | + | * Improve the toy indent |
* making lines align when no opening brace is detected in the end of line | * 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 | * remove 4 leading spaces if the line has a closing brace |
playground/plan9_tutorial_sam.txt · Last modified: 2021/04/20 04:59 by dsp