Skip to content

Instantly share code, notes, and snippets.

@jberthold-da
Last active December 20, 2022 03:18
Show Gist options
  • Save jberthold-da/9602ea4489b00ae40b84d2e4ef66a191 to your computer and use it in GitHub Desktop.
Save jberthold-da/9602ea4489b00ae40b84d2e4ef66a191 to your computer and use it in GitHub Desktop.
Emacs and Sed things I tend to forget

Emacs

sed

grep -r -e 'deriving.*Generic' DA/ASX/ -B1 | \
  sed -e '/--/d' \
      -e '$!N;s@\(DA/ASX/[^.]*\.daml\)-\([^\n]*\)\n\1:\(.*\)$@\1 --- \2 \3@g' \
      -e 's@\(.*\) --- *newtype \(.*\) *= *\2 \(.*\) deriving (\(.*\))$@\1, \2, \3, \4@g'
  1. grep for things that derive Generic (and other stuff), with one line before as context
  2. remove -- from between matches
  3. apply multiline match
    • N to take the next line into the buffer
    • then match the file name (for context with -, then again for match with :) and the line contents,
    • and print the file name \1 and the two lines \2 \3
  4. then do a match on the now single-line occurrence of the deriving
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment