Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#2050 closed feature request (fixed)

GHCi should keep a persistent history file

Reported by: ajd Owned by:
Priority: normal Milestone: 6.10 branch
Component: GHCi Version: 6.8.2
Keywords: Cc: id@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

It would be nice if GHCi kept a persistent history of commands like bash does. This would be especially useful in testing: if one is trying to get a certain command to work, and the command is at all complicated, it is annoying to have to copy and paste or retype the command every time you want to see if the function works.

Attachments (3)

ghci-history-1.patch (1.2 KB) - added by ajd 6 years ago.
Patch to GHCi to implement history file
readline-history-1.patch (1.2 KB) - added by ajd 6 years ago.
Additional readline bindings to read_history and write_history
ghci-history-2.patch (114.3 KB) - added by judah 6 years ago.

Download all attachments as: .zip

Change History (13)

comment:1 Changed 6 years ago by Isaac Dupree

  • Cc id@… added

comment:2 Changed 6 years ago by judah

I have also often wished for this. The header <readline/history.h> provides the functions read_history and write_history which are also present in editline. This task will be easy to implement if we add those to the readline and editline packages. (Although, a pure Haskell implementation would probably also be pretty easy to write.)

comment:3 Changed 6 years ago by ajd

  • Owner set to ajd

I think System.Posix.Readline already has a binding to those functions via the addHistory function. I just finished writing a simple implementation; I'll post a patch when it builds and tests.

comment:4 Changed 6 years ago by ajd

  • Owner ajd deleted

Judah, you were right, it was much easier to write the bindings for read_history and write_history. I wrote the bindings (basically a copy and paste from the add_history binding). I also wrote a simple patch to InteractiveUI.hs to implement the actually history tracking that seems to work correctly, I don't know if we need to check that the file exists or anything.

Changed 6 years ago by ajd

Patch to GHCi to implement history file

Changed 6 years ago by ajd

Additional readline bindings to read_history and write_history

comment:5 Changed 6 years ago by igloo

  • Difficulty set to Unknown
  • Milestone set to 6.10 branch

Changed 6 years ago by judah

comment:6 Changed 6 years ago by judah

I've added a new version of ajd's patch, which works with the types of read/writeHistory that were settled on in #2053. Two other things:

  • The history file is saved as ~/.ghci_history (but not if the home directory can't be retrieved)
  • The history is limited to 100 entries (to prevent the history file from growing too big)

Does this look OK? Note that the history size can be changed by calling stifleHistory in the .ghci file.

comment:7 Changed 6 years ago by ajd

Looks good to me.

comment:8 Changed 6 years ago by simonmar

  • Resolution set to fixed
  • Status changed from new to closed

Fixed:

Wed Mar 12 14:57:24 PDT 2008  Simon Marlow <simonmar@microsoft.com>
  * #2050: save the GHCi history in ~/.ghc/ghci_history
  Modified version of Judah's patch

I decided to put the history file in ~/.ghc/ghci_history, as we're starting to use ~/.ghc consistently for GHC-related configuration files now.

Also I limited the history to 100 items only when saving the file, during a GHCi run there is no limit (as before).

comment:9 Changed 6 years ago by simonmar

  • Architecture changed from Unknown to Unknown/Multiple

comment:10 Changed 6 years ago by simonmar

  • Operating System changed from Unknown to Unknown/Multiple
Note: See TracTickets for help on using tickets.