Skip to content

Configuration

prjctimg edited this page Aug 5, 2026 · 1 revision

Configuration

Everything is configured through require("p5").setup({...}). Values shown are the defaults.

require("p5").setup({
  -- Server configuration
  server = {
    port = 8000,
    auto_start = false,           -- start server when entering a sketchspace
    auto_open_browser = true,     -- open http://localhost:port after start
    live_reload = {
      enabled = true,
      port = 12002,
      debounce_ms = 300,          -- wait after last change before reloading
      watch_extensions = { ".js", ".css", ".html", ".json" },
      exclude_dirs = { ".git", "node_modules", "dist", "build" },
    },
  },

  -- Library management
  libraries = {
    cdn_sources = { "jsdelivr", "cdnjs", "unpkg" }, -- tried in order
    auto_update = false,
  },

  -- Sketch template (nil => prompt for mode on :P5 create)
  sketch = {
    mode = nil,                   -- "global" | "instance"
  },

  -- p5.js runtime defaults
  p5 = {
    version = nil,                -- default pin for new projects
    check_update = true,          -- prompt when a newer p5.js exists
  },

  -- GitHub sketchbook
  sketchbook = {
    user = "",                    -- "your-github-username"
  },

  -- Chrome DevTools Protocol panel
  cdp = {
    enabled = false,              -- enable the :P5 cdp panel
    remote_debugging_port = 9222,
    keymaps = true,               -- HUD keymaps; set false to disable
    close_browser_on_close = true, -- kill CDP Chrome + remove temp profile
    browser_flags = {
      "--enable-gpu-rasterization",
      "--disable-frame-rate-limit",
      "--disable-gpu-driver-bug-workarounds",
      "--enable-precise-memory-info",
      "--disable-software-rasterizer",
    },
  },

  -- HUD window layout
  view = {
    position = "below",           -- "below" | "above" | "left" | "right"
    height = 10,                  -- rows
  },

  -- LSP hover documentation
  hover = {
    enabled = false,
    delay_ms = 6000,              -- hover time needed to trigger
  },

  -- Autocommands
  autocmds = {
    server_on_enter = false,
    cdp_on_server_start = false,
    save_on_focus_lost = false,
    refresh_on_save = false,
    close_cdp_on_stop = true,
    reset_on_dir_change = false,
  },
})

Per-Project Options

The server also reads options from the sketchspace's p5.json (e.g. version, mode, libs, includes), and extra CLI flags can be passed on the command line:

python3 server.py --port 8000 --live-reload-port 12002 --cdp-port 9222

--cdp-port selects the Chrome DevTools remote-debugging port used by the CDP panel.

Enable the CDP Panel

CDP is off by default. Enable it to get the full debugging panel:

require("p5").setup({
  cdp = { enabled = true },
})

Chrome is then launched automatically (with the isolated temp profile) when you run :P5 cdp, or you can attach to a Chrome instance already running with --remote-debugging-port.

Autocmd Behavior

  • server_on_enter — starts the dev server when you BufEnter a sketchspace
  • cdp_on_server_start — opens the CDP panel whenever the server starts
  • refresh_on_save — triggers a live reload on BufWritePost without waiting for the file watcher
  • close_cdp_on_stop — tears down the CDP panel (and isolated Chrome) when the server stops

Clone this wiki locally