summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2020-12-08 13:07:17 -0500
committerKrzysztof Gogolewski <krzysztof.gogolewski@tweag.io>2021-01-29 10:16:11 +0100
commit9768f80b0e7df8f60474b0193ddca74d7688f3db (patch)
treef34002ae99779ba56617c3f4f76163afb1fbd472
parent5140841ca1acaeaeef893233ae3d08ce4573b01b (diff)
downloadhaskell-wip/T19030.tar.gz
ghci: Take editor from VISUAL environment variablewip/T19030
Following the example of `git`, as noted in #19030. Fixes #19030.
-rw-r--r--docs/users_guide/9.2.1-notes.rst8
-rw-r--r--docs/users_guide/ghci.rst14
-rw-r--r--ghc/GHCi/UI.hs11
3 files changed, 25 insertions, 8 deletions
diff --git a/docs/users_guide/9.2.1-notes.rst b/docs/users_guide/9.2.1-notes.rst
index a38e334cd6..1e73770c5d 100644
--- a/docs/users_guide/9.2.1-notes.rst
+++ b/docs/users_guide/9.2.1-notes.rst
@@ -79,6 +79,14 @@ Compiler
that the compiler automatically insert cost-centres on all call-sites of
the named function.
+GHCi
+~~~~
+
+- GHCi's :ghci-cmd:`:edit` command now looks for an editor in
+ the :envvar:`VISUAL` environment variable before
+ :envvar:`EDITOR`, following UNIX convention.
+ (:ghc-ticket:`19030`)
+
Runtime system
~~~~~~~~~~~~~~
diff --git a/docs/users_guide/ghci.rst b/docs/users_guide/ghci.rst
index 93b72979b8..78c74c5dc3 100644
--- a/docs/users_guide/ghci.rst
+++ b/docs/users_guide/ghci.rst
@@ -2443,9 +2443,17 @@ commonly used commands.
Opens an editor to edit the file ⟨file⟩, or the most recently loaded
module if ⟨file⟩ is omitted. If there were errors during the last
loading, the cursor will be positioned at the line of the first
- error. The editor to invoke is taken from the :envvar:`EDITOR` environment
- variable, or a default editor on your system if :envvar:`EDITOR` is not
- set. You can change the editor using :ghci-cmd:`:set editor`.
+ error. The editor to invoke is taken from the :envvar:`VISUAL` or
+ :envvar:`EDITOR` environment variables, or a default editor on your system
+ if neither is not set. You can change the editor using :ghci-cmd:`:set
+ editor`.
+
+.. envvar:: VISUAL
+
+ :hidden:
+
+ .. This declaration simply avoids undefined reference warnings as Sphinx
+ doesn't know about VISUAL
.. ghci-cmd:: :enable; * | ⟨num⟩ ...
diff --git a/ghc/GHCi/UI.hs b/ghc/GHCi/UI.hs
index b2909c2441..77801019ee 100644
--- a/ghc/GHCi/UI.hs
+++ b/ghc/GHCi/UI.hs
@@ -427,13 +427,14 @@ defFullHelpText =
findEditor :: IO String
findEditor = do
- getEnv "EDITOR"
- `catchIO` \_ -> do
+ getEnv "VISUAL" <|> getEnv "EDITOR" <|> defaultEditor
+ where
+ defaultEditor = do
#if defined(mingw32_HOST_OS)
- win <- System.Win32.getWindowsDirectory
- return (win </> "notepad.exe")
+ win <- System.Win32.getWindowsDirectory
+ return (win </> "notepad.exe")
#else
- return ""
+ return ""
#endif
default_progname, default_stop :: String