Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ Croissant looks at the first word of your entry and runs any command it matches.

## Caveats

- Pretty printing values can be expensive in CPU and memory: avoid dumping either large of deeply nested tables. You can play with the `dump.depthLimit` and `dump.itemsLimit` value in your `~/.croissantrc` or the `depth` command to avoid exploring to far down in complex tables.
- Pretty printing values can be expensive in CPU and memory: avoid dumping either large of deeply nested tables. You can play with the `dump.depthLimit` and `dump.itemsLimit` value in your `$XDG_CONFIG_HOME/croissantrc` or `~/.croissantrc`, or the `depth` command to avoid exploring to far down in complex tables.
- The debugger will slow your program down. Croissant will try and clear hooks whenever possible but if you know you won't hit anymore breakpoints, do a `clear` before doing `continue`.
- A breakpoint on a function name will not work if the function is not called by its name in your code. Example:

Expand All @@ -133,7 +133,7 @@ call(stopMe)

## Configuration

You can customize some aspect of croissant by writing a `~/.croissantrc` lua file. Here are the default values than you can overwrite:
You can customize some aspect of croissant by writing a `$XDG_CONFIG_HOME/croissantrc` or `~/.croissantrc` lua file. Here are the default values than you can overwrite:

```lua
return {
Expand All @@ -143,8 +143,8 @@ return {
continuationPrompt = ".... ",

-- Maximum amount of remembered lines
-- Croissant manages two history file: one for the repl (~/.croissant_history),
-- one for the debugger (~/.croissant_debugger_history)
-- Croissant manages two history file: one for the repl ($XDG_STATE_HOME/croissant_history),
-- one for the debugger ($XDG_STATE_HOME/croissant_debugger_history)
historyLimit = 1000,

-- How many rows `where` should print around the current line
Expand Down
5 changes: 3 additions & 2 deletions croissant/conf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ local default = {
}
}

-- Read from ~/.croissantrc
-- Read from $XDG_CONFIG_HOME/croissantrc or ~/.croissantrc
local user = {}
local file, _ = io.open(os.getenv "HOME" .. "/.croissantrc", "r")
local xdg_config_home = os.getenv("XDG_CONFIG_HOME") or os.getenv("HOME") .. "/.config"
local file = io.open(xdg_config_home .. "/croissantrc", "r") or io.open(os.getenv "HOME" .. "/.croissantrc", "r")

if file then
local rc = file:read("*all")
Expand Down
23 changes: 19 additions & 4 deletions croissant/do.lua
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,25 @@ local function runFile(script, arguments)
end
end

local function getHistoryFile(debugger, mode)
Copy link
Copy Markdown
Owner

@giann giann Dec 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could cache the response so we don't stat two files each time we add something to the history

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite understand what you mean by that. Could you elaborate?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You only need the information about which file is the right one once. So keep that information somewhere (cache it), and return that instead of checking files each time getHistoryFile is called.

Copy link
Copy Markdown
Author

@Susensio Susensio Dec 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where would you implement the cache? Function wise? Session wise on boot?
Implementing a cache is a delicate task that should be handled with care, with some edge cases.
I don't think checking for a file existence is a task worth caching, honestly.

In addition, is this duality between xdg files and home files a feature that you want to keep in croissant? I mean, is there a reason to keep it long term? I personally would migrate towards xdg completely, and not check for files in $HOME.
Maybe if you want to keep it customizable, a envvar could be read. I personally never use those per app config path envvars, I have $XDG_{FOLDER}_HOME if I ever want to move all my configurations

On the other hand, in my code for getHistoryFile I only stat one file (old $HOME/.croissanthistory is ignored.
Regarding the config file, the old config is only checked up if the xdg one does not exist.

local xdg_state_home = os.getenv("XDG_STATE_HOME") or os.getenv("HOME") .. "/.local/state"

local filename
if debugger == true then
filename = "croissant_debugger_history"
else
filename = "croissant_history"
end

local file = io.open(xdg_state_home .. "/" .. filename, mode)

return file
end

local function loadHistory()
local history = {}

local historyFile = io.open(os.getenv "HOME" .. "/.croissant_history", "r")
local historyFile = getHistoryFile(false, "r")

if historyFile then
for line in historyFile:lines() do
Expand All @@ -284,7 +299,7 @@ end
local function loadDebugHistory()
local history = {}

local historyFile = io.open(os.getenv "HOME" .. "/.croissant_debugger_history", "r")
local historyFile = getHistoryFile(true, "r")

if historyFile then
for line in historyFile:lines() do
Expand All @@ -300,7 +315,7 @@ local function loadDebugHistory()
end

local function appendToHistory(code)
local historyFile = io.open(os.getenv "HOME" .. "/.croissant_history", "a+")
local historyFile = getHistoryFile(false, "a+")

if historyFile then
historyFile:write(code:gsub("\n", "\\n") .. "\n")
Expand All @@ -310,7 +325,7 @@ local function appendToHistory(code)
end

local function appendToDebugHistory(code)
local historyFile = io.open(os.getenv "HOME" .. "/.croissant_debugger_history", "a+")
local historyFile = getHistoryFile(true, "a+")

if historyFile then
historyFile:write(code:gsub("\n", "\\n") .. "\n")
Expand Down