From 84f801e6d6576d872e95c8f84626497058f3e1f6 Mon Sep 17 00:00:00 2001 From: Dmitry Zuikov Date: Sun, 15 Sep 2024 11:20:03 +0300 Subject: [PATCH] added source function to add per-user configs --- .fixme-new/.gitignore | 1 + .fixme-new/config | 4 +--- fixme-new/lib/Fixme/Run.hs | 27 +++++++++++++++++++++++++-- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/.fixme-new/.gitignore b/.fixme-new/.gitignore index a247e95f..84782c39 100644 --- a/.fixme-new/.gitignore +++ b/.fixme-new/.gitignore @@ -1 +1,2 @@ state.db +config.local diff --git a/.fixme-new/config b/.fixme-new/config index 7e94c4a5..736a5462 100644 --- a/.fixme-new/config +++ b/.fixme-new/config @@ -65,9 +65,7 @@ fixme-comments ";" "--" (define (backlog s) (modify s workflow :backlog)) ;; refchan settings -(refchan 3WtddmcE8zzgBAPR7Bu7mKMaVMTN423NNXSPUJp3Hx42) -(reader DTKxNwYCux7zHFLSvmEm5P3Ex21iQrrVdzJpR3giLh1D) -(author 3fKeGjaDGBKtNqeNBPsThh8vSj4TPiqaaK7uHbB8MQUV) +source ./config.local diff --git a/fixme-new/lib/Fixme/Run.hs b/fixme-new/lib/Fixme/Run.hs index 09a7b457..b8a54d8d 100644 --- a/fixme-new/lib/Fixme/Run.hs +++ b/fixme-new/lib/Fixme/Run.hs @@ -434,9 +434,32 @@ runTop forms = do _ -> void $ lift $ refchanExport () - entry $ bindMatch "fixme:refchan:import" $ nil_ $ const $ lift do - void $ refchanImport + entry $ bindMatch "source" $ nil_ $ \case + [StringLike path] -> do + ppath <- if List.isPrefixOf "." path then do + dir <- localConfigDir + let rest = tail $ splitDirectories path + pure $ joinPath (dir:rest) + else do + canonicalizePath path + + debug $ red "SOURCE FILE" <+> pretty ppath + + dd <- readTVarIO tvd + + -- FIXME: raise-warning? + content <- liftIO $ try @_ @IOException (readFile ppath) + <&> fromRight mempty + <&> parseTop + >>= either (error.show) pure + + lift $ run dd content + + _ -> throwIO $ BadFormException @C nil + + entry $ bindMatch "update" $ nil_ $ const $ lift do + refchanUpdate entry $ bindMatch "update" $ nil_ $ const $ lift do refchanUpdate