From 51146403e0e7b9d49efe8592ac8380f785ce9cf3 Mon Sep 17 00:00:00 2001 From: defanor Date: Tue, 28 Nov 2017 07:07:58 +0300 Subject: Introduce initial image support Pancake reports saved files to Emacs, Emacs inserts them into appropriate positions if they are images; `pancake-load-images' just sends "save" commands for all the images. `pancake-display-hook' was added as well, so that image loading can be requested automatically, among other things. There is a few things to improve: currently the images don't get sliced, there's no caching or parallelization, and no tracking of explicitly requested images. --- Pancake.hs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'Pancake.hs') diff --git a/Pancake.hs b/Pancake.hs index 74990fa..0c9db1e 100644 --- a/Pancake.hs +++ b/Pancake.hs @@ -179,6 +179,7 @@ goTo t u' = do command :: MonadIO m => Command -> StateT LoopState m () command (Save (RURI uri') p) = do (uri, mraw) <- loadRaw uri' + st <- get case mraw of Nothing -> pure () Just (raw, euri, _) -> liftIO $ do @@ -202,10 +203,15 @@ command (Save (RURI uri') p) = do targetFileName = fromMaybe remoteFileName mTargetName targetPath = targetDir targetFileName e <- try $ BS.writeFile targetPath raw - putErrLn $ unwords $ case e of + case e of Left (err :: SomeException) -> - ["Failed to write", targetPath ++ ":", show err] - Right _ -> ["Saved", remoteURIStr, "as", targetPath] + putErrLn $ unwords ["Failed to write", targetPath ++ ":", show err] + Right () -> do + when (embedded st) $ + putSexpLn [ "saved" + , encodeSexpStr $ uriToString id uri' "" + , encodeSexpStr targetPath] + putErrLn $ unwords ["Saved", remoteURIStr, "as", targetPath] where escapeURI c | isPathSeparator c = '-' -- cgit v1.2.3