úÎB¦AY     Open the user's $EDITORCopyright 2015 Peter Harpending Apache-2.0'Peter Harpending <peter@harpending.org> experimentalPOSIXNoneINUV$This is the function you should use. takes a 7, to produce the contents of the original file, and a d to consume them, and returns the result of the consumer, along with the exit code from the editor.0If you don't know how to use conduits, see the  'http://www.stackage.org/package/conduit documentation for the conduit package.¥If you really don't want to use conduits, you can use the strict I/O functions at the bottom of the module. Be warned that those functions are not very performant.Make a template  'mkTemplate ext = _ftempl <> "." <> ext mkTemplate "blah"tmp.blahFile-type template for HTML !htmlTemplate = mkTemplate "html" File-type template for JSON !jsonTemplate = mkTemplate "json" File-type template for Markdown #markdownTemplate = mkTemplate "md" %Older file-type template for Markdown )markdownTemplate = mkTemplate "markdown" !File-type template for plain text !plainTemplate = mkTemplate "txt" File-type template for XML xmlTemplate = mkTemplate "xml" Same as  File-type template for YAML !yamlTemplate = mkTemplate "yaml" =Open an editor. You probably don't want to use this function. ùrunSpecific editorName templ initialContents = withSystemTempFile templ $ filePath hdl -> do hSetBinaryMode hdl True hSetBuffering hdl NoBuffering B.hPut hdl initialContents callProcess editorName [filePath] B.hGetContents hdl  This uses  from  System.Posix to attempt to get the user's $EDITOR variable. userEditor = getEnv _editor Wrapper around  ) that includes a fallback option if the $EDITOR variable doesn't exist. ‹ userEditorDefault def = userEditor >>= case Just e -> pure e Nothing -> pure def .The default editor if no other editor is found _default_editor = "nano" =The variable we should search when finding the user's editor.  _editor = EDITOR The standard filename template _ftempl = "tmp" 7If you don't want to use ByteString, use this function.):t runUserEditorDWIM plainTemplate mempty ByteString5:t wrapStr <$> runUserEditorDWIM plainTemplate memptyStringúThis is most likely the function you want to use. It takes a file type template as an argument, along with what you want displayed when the user opens the editor. It then runs the editor, and returns the version of the text that the user modified. »runUserEditorDWIM templ initialContents = userEditorDefault _default_editor >>= theEditor -> runSpecificEditor theEditor templ initialContents  Examples::set -XOverloadedStrings)runUserEditorDWIM jsonTemplate "{\n\n}\n"This will open up the user's $EDITOR5 configured to edit JSON, and with the initial text: { } ¥There are a bunch of templates. See the "File-type extensions" section. It's also trivially easy to make your own templates. Say you want one for, I dunno, Python: !pythonTemplate = mkTemplate "py" The argument to > should be the file extension you want. In that case, I used "py"&, because Python's file extension is .py.YThis is the same as above, it just takes a file as an argument instead of the ByteString LrunUserEditorDWIMFile templ fp = B.readFile fp >>= runUserEditorDWIM templ kThis is likely the simplest function here. It opens up the user's editor, and fetches a ByteString from it †runUserEditor = userEditorDefault _default_editor >>= theEditor -> runSpecificEditor theEditor plainTemplate mempty .This is probably the second-simplest function. Name of the editor.Template for the file name.Initial contents of the file.Resulting ByteString. Default value if $EDITOR is not found.Template for the file nameInitial contentsResulting ByteStringTemplate for the file name File containing initial contentsResulting ByteStringTemplate for the file nameResulting ByteString        edito_DXis4FIQcGz154uLBDvjWv Text.EditorTemplatebracketConduit mkTemplate htmlTemplate jsonTemplatemarkdownTemplateoldMarkdownTemplate plainTemplate xmlTemplate txtTemplate yamlTemplaterunSpecificEditor userEditoruserEditorDefault_default_editor_editor_ftemplwrapStrrunUserEditorDWIMrunUserEditorDWIMFile runUserEditorrunUserEditorWithTemplatecondu_2M7RWDK37jxF9BsWcrYqQtData.Conduit.Internal.ConduitProducerConsumerunix_G4Yo1pNtYrk8nCq1cx8P9dSystem.Posix.EnvgetEnv