User Tools

Site Tools


playground:plan9_tutorial_sam

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
playground:plan9_tutorial_sam [2021/04/19 21:31] dspplayground:plan9_tutorial_sam [2021/04/20 04:59] (current) – adding external command section dsp
Line 93: Line 93:
 , x/{$/ -/^[ ]*/ t .+0 , x/{$/ -/^[ ]*/ t .+0
 </code> </code>
 +
 +=== 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.
 +<code>
 +if  (foo <bar(bz)) {
 +   do(bxm,as);
 +wrong;
 +   }
 +</code>
 +To pass all this code through cb we can just select it and then
 +issue the command |cb . that would replace the dot by
 +<code>
 +if  (foo <bar(bz)) {
 + do(bxm,as);
 + wrong;
 +}
 +</code>
 +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't changes our current text
 +
 +We could also imagine a command where it replaces every
 +occurrence of //{DATE}// with the current system date in the whole document
 +<code>
 +, x/{DATE}/ <date
 +</code>
 +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 ===
playground/plan9_tutorial_sam.1618867862.txt.gz · Last modified: 2021/04/19 21:31 by dsp