Skip to content

Instantly share code, notes, and snippets.

@bpsm
Created August 16, 2010 19:56
Show Gist options
  • Save bpsm/527621 to your computer and use it in GitHub Desktop.
Save bpsm/527621 to your computer and use it in GitHub Desktop.
(ns libpsm.string
(:require [clojure.string :as str]))
(let [triml-with-pipe (comp #(str/replace-first % "|" "")
str/triml)]
(defn mstr*
"Multiline string with explicit left margin."
[s]
(str/join "\n" (map triml-with-pipe
(str/split-lines s)))))
(defmacro mstr
"Multiline string with explicit left margin, maked by |.
Each line is trimmed of leading whitespace, up to and including
a leading | character."
[s]
(if (string? s)
(mstr* s)
`(mstr* ~s)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment