Skip to content

Commit

Permalink
update environment variables to not use dash
Browse files Browse the repository at this point in the history
  • Loading branch information
daanx committed Nov 29, 2020
1 parent 4a16558 commit e330ca7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
31 changes: 25 additions & 6 deletions src/Compiler/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -433,9 +433,9 @@ readHtmlBases s
-- | Environment table
environment :: [ (String, String, (String -> [String]), String) ]
environment
= [ -- ("koka-dir", "dir", dirEnv, "The install directory")
("koka-options", "options", flagsEnv, "Add <options> to the command line")
, ("koka-editor", "command", editorEnv, "Use <cmd> as the editor (substitutes %l, %c, and %s)")
= [ -- ("koka_dir", "dir", dirEnv, "The install directory")
("koka_options", "options", flagsEnv, "Add <options> to the command line")
, ("koka_editor", "command", editorEnv, "Use <cmd> as the editor (substitutes %l, %c, and %f)")
]
where
flagsEnv s = [s]
Expand Down Expand Up @@ -466,7 +466,10 @@ processOptions flags0 opts
else if (any isInteractive options) then ModeInteractive files
else if (null files) then ModeInteractive files
else ModeCompiler files
in do pkgs <- discoverPackages (outDir flags)
in do ed <- if (null (editor flags))
then detectEditor
else return (editor flags)
pkgs <- discoverPackages (outDir flags)
(localDir,localLibDir,localShareDir,localBinDir) <- getKokaDirs
ccmd <- if (ccompPath flags == "") then detectCC
else if (ccompPath flags == "mingw") then return "gcc"
Expand All @@ -479,6 +482,7 @@ processOptions flags0 opts
localShareDir = localShareDir,
ccompPath = ccmd,
ccomp = cc,
editor = ed,
includePath = (localShareDir ++ "/lib") : includePath flags }
,mode)
else invokeError errs
Expand All @@ -489,8 +493,8 @@ getKokaDirs
let binDir = dirname bin
rootDir = rootDirFrom binDir
isRootRepo <- doesFileExist (joinPath rootDir "koka.cabal")
libDir0 <- getEnvVar "KOKA_LIB_DIR"
shareDir0 <- getEnvVar "KOKA_SHARE_DIR"
libDir0 <- getEnvVar "koka_lib_dir"
shareDir0 <- getEnvVar "koka_share_dir"
let libDir = if (not (null libDir0)) then libDir0
else if (isRootRepo) then joinPath rootDir "out"
else joinPath rootDir ("lib/koka/v" ++ version)
Expand Down Expand Up @@ -744,6 +748,21 @@ findCC paths (name:rest)



detectEditor :: IO String
detectEditor
= do paths <- getEnvPaths "PATH"
findEditor paths [("code","--goto %f:%l:%c"),("atom","%f:%l:%c")]

findEditor :: [FilePath] -> [(String,String)] -> IO String
findEditor paths []
= do -- putStrLn "warning: cannot find editor"
return ""
findEditor paths ((name,options):rest)
= do mbPath <- searchPaths paths [exeExtension] name
case mbPath of
Nothing -> findEditor paths rest
Just _ -> return (name ++ " " ++ options)

{--------------------------------------------------------------------------
Show options
--------------------------------------------------------------------------}
Expand Down
2 changes: 1 addition & 1 deletion src/Interpreter/Interpret.hs
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ runEditorAt :: State -> FilePath -> Int -> Int -> IO ()
runEditorAt st fpath line col
= let command = replace line col (editor (flags st)) fpath
in if null (editor (flags st))
then raiseIO ("no editor specified. (use the \"koka-editor\" environment variable?)")
then raiseIO ("no editor specified. (use the \"koka_editor\" environment variable?)")
else runSystem command

replace :: Int -> Int -> FilePath -> String -> String
Expand Down
8 changes: 2 additions & 6 deletions util/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ MODE="install" # or uninstall
PREFIX="/usr/local"
QUIET=""
FORCE=""

KOKA_TEMP_DIR="" # empty creates one dynamically
KOKA_DIST_BASE_URL="https://github.com/koka-lang/koka/releases/download"
KOKA_DIST_URL="" # $KOKA_DIST_BASE_URL/$VERSION
KOKA_DIST_SOURCE="" # $KOKA_DIST_URL/koka-$VERSION-<osarch>.tar.gz

# KOKA_DIST_URL="."

# ---------------------------------------------------------
# helper functions
Expand Down Expand Up @@ -370,11 +370,9 @@ install_dist() {
info " (failed to copy atom support files)"
else
info " Please restart Atom for Koka syntax highlighting to take effect."
info " Also add the following to your ~/.bashrc file to use Atom from the Koka interpreter:"
info " > export koka-editor=atom %f:%l:%c"
fi
fi
fi
fi

# install Visual Studio Code editor support
if [ -d ~/.vscode/extensions ] ; then
Expand All @@ -385,8 +383,6 @@ install_dist() {
info " (failed to copy vscode support files)"
else
info " Please restart VS Code for Koka syntax highlighting to take effect."
info " Also add the following to your ~/.bashrc file to use VS code from the Koka interpreter:"
info " > export koka-editor=code --goto %f:%l:%c"
fi
fi
fi
Expand Down

0 comments on commit e330ca7

Please sign in to comment.