summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2020-12-08 13:07:17 -0500
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-01-30 14:11:48 -0500
commitf5d62eb2d5a1058f355aaa1fd0a959694d160ec4 (patch)
tree19f568ae8d1ee963bc21b15b9dea502330314264
parentbd0b27267985c6c3482578ccf71a3cab9a1d7b12 (diff)
downloadhaskell-f5d62eb2d5a1058f355aaa1fd0a959694d160ec4.tar.gz
ghci: Take editor from VISUAL environment variable
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