3 ms·
The best part of sam are the structural regular expressions. I keep a copy installed just for them. Now admittedly I never use it enough to get good at it so ev
by somat 3y ago
The best part of sam are the structural regular expressions. I keep a copy installed just for them. Now admittedly I never use it enough to get good at it so every time it is usually 10 minutes swearing at the manual.
The standard unix regular expression implementations (grep, sed, ed, vi) are very tied to "lines" of text, and most of the time this is exactly what you want. but sometimes it gets in the way. And when you start to have trouble with your regex because it is conflicting with line returns, then it is the sam editor and it's structural regex engines time to shine. They would probably be great elsewhere, but nobody else uses them.
- nerdponx 3y agoIs there a document that describes these? I've seen them mentioned before as one of the superpowers of Sam, but I've never seen a clear explanation of them for someone who isn't already a Sam user. I have no real intention of ever using or trying Sam as my daily text editor for a handful of reasons, but I am interested in new paradigms and tools for working with code.
- projektfu 3y agoYes, this one: http://doc.cat-v.org/plan_9/4th_edition/papers/sam/ http://doc.cat-v.org/plan_9/4th_edition/papers/sam/
- somat 3y agohttp://doc.cat-v.org/plan_9/4th_edition/papers/sam/ http://doc.cat-v.org/plan_9/4th_edition/papers/sam/ look for the section on structural expressions. I am not really an expert but my understanding is that they are called that because you can use them to define the structure of a match. in most regular expression engines the structure is defined as a line of text or the whole document and the expression only matches the contents. This is why they do so well with multi line records you just need to define a structure expression that matches your, well.. structure. I never did learn sam all that well, I mainly used it as a non interactive sed replacement. however I just learned that apparently the vis project uses structural expressions. I might try it. Mainly because at least then my fingers sort of know what to do.
- knodi123 3y ago> when you start to have trouble with your regex because it is conflicting with line returns That definitely happens, but 9 times out of 10, you can add /m to the end of the regex, and now ^ and $ match individual lines, while \A and \Z match the entire string.
- xuejie 3y agoAlso a fan of structural regular expressions in the exact same shoes that every time when I try to use it it's an unpleasant experience. Maybe I'm just not good enough at it. That being said, I've been recently employing comby (https://comby.dev/ https://comby.dev/) in my workflow, which solves similar problem, but understands certain languages to simplify the usage.
- tionis 3y agoHave you tried vis? https://github.com/martanne/vis https://github.com/martanne/vis