X.P.OrgMode: Return "exitCode" mkOrgPrompt

More formally, return whether the user cancelled the prompt or not.
This is useful in case we want to do things only after a "successful"
input.
This commit is contained in:
Tony Zorman 2022-10-03 21:22:03 +02:00
parent b9c8294045
commit cd95bf9c28

View File

@ -202,7 +202,7 @@ orgPrompt
-- a single @*@ -- a single @*@
-> FilePath -- ^ Path to @.org@ file, e.g. @home\/me\/todos.org@ -> FilePath -- ^ Path to @.org@ file, e.g. @home\/me\/todos.org@
-> X () -> X ()
orgPrompt xpc = (mkOrgPrompt xpc =<<) .: mkOrgCfg NoClpSupport orgPrompt xpc = (void . mkOrgPrompt xpc =<<) .: mkOrgCfg NoClpSupport
-- | Like 'orgPrompt', but additionally make use of the primary -- | Like 'orgPrompt', but additionally make use of the primary
-- selection. If it is a URL, then use an org-style link -- selection. If it is a URL, then use an org-style link
@ -212,12 +212,14 @@ orgPrompt xpc = (mkOrgPrompt xpc =<<) .: mkOrgCfg NoClpSupport
-- The prompt will display a little @+ PS@ in the window -- The prompt will display a little @+ PS@ in the window
-- after the type of note. -- after the type of note.
orgPromptPrimary :: XPConfig -> String -> FilePath -> X () orgPromptPrimary :: XPConfig -> String -> FilePath -> X ()
orgPromptPrimary xpc = (mkOrgPrompt xpc =<<) .: mkOrgCfg PrimarySelection orgPromptPrimary xpc = (void . mkOrgPrompt xpc =<<) .: mkOrgCfg PrimarySelection
-- | Create the actual prompt. -- | Create the actual prompt. Returns 'False' when the input was
mkOrgPrompt :: XPConfig -> OrgMode -> X () -- cancelled by the user (by, for example, pressing @Esc@ or @C-g@) and
-- 'True' otherwise.
mkOrgPrompt :: XPConfig -> OrgMode -> X Bool
mkOrgPrompt xpc oc@OrgMode{ todoHeader, orgFile, clpSupport } = mkOrgPrompt xpc oc@OrgMode{ todoHeader, orgFile, clpSupport } =
mkXPrompt oc xpc (const (pure [])) appendNote isJust <$> mkXPromptWithReturn oc xpc (const (pure [])) appendNote
where where
-- | Parse the user input, create an @org-mode@ note out of that and -- | Parse the user input, create an @org-mode@ note out of that and
-- try to append it to the given file. -- try to append it to the given file.