Hacker News new | ask | show | jobs
by kazinator 702 days ago
TXR Lisp:

  $ cat slurp-source.tl
  (defun slurp-source (path key)
    (let* ((lines (file-get-lines path))
           (match (member-if (op contains key) lines))
           (tail (rest match))
           (indent (find-min-key tail : (op match-regex @1 #/\s*/)))
           (dedent (mapcar (op drop indent) tail)))
      `@{dedent "\n"}\n`))
  $ txr -i slurp-source.tl
  1> (put-string (slurp-source "slurp-source.tl" "let*"))
       (match (member-if (op contains key) lines))
       (tail (rest match))
       (indent (find-min-key tail : (op match-regex @1 #/\s*/)))
       (dedent (mapcar (op drop indent) tail)))
  `@{dedent "\n"}\n`))
  t
1 comments

Wow!