From 03808552ff43795bb1891900369a972bcf81f90a Mon Sep 17 00:00:00 2001 From: ShrykeWindgrace Date: Mon, 27 Nov 2023 17:51:14 +0100 Subject: [PATCH] feat: add notepad as default editor for windows --- hledger-ui/Hledger/UI/Editor.hs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/hledger-ui/Hledger/UI/Editor.hs b/hledger-ui/Hledger/UI/Editor.hs index 188ea7e82..b4bf40c42 100644 --- a/hledger-ui/Hledger/UI/Editor.hs +++ b/hledger-ui/Hledger/UI/Editor.hs @@ -16,6 +16,7 @@ import Safe import System.Environment import System.Exit import System.FilePath +import System.Info (os) import System.Process import Hledger @@ -123,13 +124,17 @@ editFileAtPositionCommand mpos f = do return $ unwords $ cmd:args -- | Get the user's preferred edit command. This is the value of the --- $HLEDGER_UI_EDITOR environment variable, or of $EDITOR, or a --- default ("emacsclient -a '' -nw", which starts/connects to an emacs --- daemon in terminal mode). +-- $HLEDGER_UI_EDITOR environment variable, or of $EDITOR, or an OS-specific default. +-- +-- For non-windows machines that would be "emacsclient -a '' -nw", +-- which starts/connects to an emacs daemon in terminal mode. +-- +-- For windows the default is a plain "notepad.exe" getEditCommand :: IO String getEditCommand = do hledger_ui_editor_env <- lookupEnv "HLEDGER_UI_EDITOR" editor_env <- lookupEnv "EDITOR" - let Just cmd = hledger_ui_editor_env <|> editor_env <|> Just "emacsclient -a '' -nw" + let defaultEditor = Just $ if os == "mingw32" then "notepad.exe" else "emacsclient -a '' -nw" + let Just cmd = hledger_ui_editor_env <|> editor_env <|> defaultEditor return cmd