diff --git a/README.md b/README.md index 5b3a20e31..cc7ca5a05 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Livebook is a web application for writing interactive and collaborative code notebooks for Elixir, built with [Phoenix LiveView](https://github.com/phoenixframework/phoenix_live_view). It features: - * Code notebooks with Markdown support and Elixir cells where code is evaluated on demand. + * Code notebooks with Markdown support and Code cells where Elixir code is evaluated on demand. * Shareable: notebooks are stored in the `.livemd` format, which is a subset of Markdown with support for diagrams via [Mermaid](https://mermaid-js.github.io/mermaid) and for mathematical formulas via [KaTex](https://katex.org/). `.livemd` files can be easily shared and play well with version control. diff --git a/assets/js/cell/index.js b/assets/js/cell/index.js index e9738908a..50d8678b1 100644 --- a/assets/js/cell/index.js +++ b/assets/js/cell/index.js @@ -24,14 +24,14 @@ const Cell = { this.state = { isFocused: false, insertMode: false, - // For text cells (markdown or elixir) + // For text cells (markdown or code) liveEditor: null, markdown: null, evaluationDigest: null, }; // Setup action handlers - if (this.props.type === "elixir") { + if (this.props.type === "code") { const amplifyButton = this.el.querySelector( `[data-element="amplify-outputs-button"]` ); @@ -74,7 +74,7 @@ const Cell = { // Setup the editor instance. const language = { markdown: "markdown", - elixir: "elixir", + code: "elixir", smart: "elixir", }[this.props.type]; const readOnly = this.props.type === "smart"; diff --git a/assets/js/lib/notebook.js b/assets/js/lib/notebook.js index a15c2ca8a..72ab085f1 100644 --- a/assets/js/lib/notebook.js +++ b/assets/js/lib/notebook.js @@ -2,12 +2,12 @@ * Checks if the given cell type is eligible for evaluation. */ export function isEvaluable(cellType) { - return ["elixir", "smart"].includes(cellType); + return ["code", "smart"].includes(cellType); } /** * Checks if the given cell type has editable editor. */ export function isDirectlyEditable(cellType) { - return ["markdown", "elixir"].includes(cellType); + return ["markdown", "code"].includes(cellType); } diff --git a/assets/js/session/index.js b/assets/js/session/index.js index 5cd776760..844bf7ae5 100644 --- a/assets/js/session/index.js +++ b/assets/js/session/index.js @@ -396,9 +396,9 @@ function handleDocumentKeyDown(hook, event) { } else if (keyBuffer.tryMatch(["K"])) { moveFocusedCell(hook, -1); } else if (keyBuffer.tryMatch(["n"])) { - insertCellBelowFocused(hook, "elixir"); + insertCellBelowFocused(hook, "code"); } else if (keyBuffer.tryMatch(["N"])) { - insertCellAboveFocused(hook, "elixir"); + insertCellAboveFocused(hook, "code"); } else if (keyBuffer.tryMatch(["m"])) { insertCellBelowFocused(hook, "markdown"); } else if (keyBuffer.tryMatch(["M"])) { diff --git a/lib/livebook/live_markdown.ex b/lib/livebook/live_markdown.ex index 7a0231bbb..1fa80f471 100644 --- a/lib/livebook/live_markdown.ex +++ b/lib/livebook/live_markdown.ex @@ -16,7 +16,7 @@ defmodule Livebook.LiveMarkdown do # # 2. Every *Heading 2* starts a new section # - # 3. Every Elixir code block maps to an Elixir cell + # 3. Every Elixir code block maps to a Code cell # # 4. Adjacent regular Markdown text maps to a Markdown cell # @@ -31,7 +31,7 @@ defmodule Livebook.LiveMarkdown do # # - `{"force_markdown":true}` - an annotation forcing the next Markdown # block to be treated as part of Markdown cell (relevant for Elixir code - # blocks, which otherwise are interpreted as Elixir cells) + # blocks, which otherwise are interpreted as Code cells) # # - `{"break_markdown":true}` - an annotation splitting the markdown content # into separate Markdown cells @@ -73,7 +73,7 @@ defmodule Livebook.LiveMarkdown do # ``` # # This file defines a notebook named *My Notebook* with two sections. - # The first section includes 3 cells and the second section includes 1 Elixir cell. + # The first section includes 3 cells and the second section includes 1 Code cell. @doc """ The file extension used by Live Markdown files. diff --git a/lib/livebook/live_markdown/export.ex b/lib/livebook/live_markdown/export.ex index 32b9ea9b8..437ab9fbd 100644 --- a/lib/livebook/live_markdown/export.ex +++ b/lib/livebook/live_markdown/export.ex @@ -111,9 +111,9 @@ defmodule Livebook.LiveMarkdown.Export do |> prepend_metadata(metadata) end - defp render_cell(%Cell.Elixir{} = cell, ctx) do + defp render_cell(%Cell.Code{} = cell, ctx) do delimiter = MarkdownHelpers.code_block_delimiter(cell.source) - code = get_elixir_cell_code(cell) + code = get_code_cell_code(cell) outputs = if ctx.include_outputs?, do: render_outputs(cell, ctx), else: [] metadata = cell_metadata(cell) @@ -130,7 +130,7 @@ defmodule Livebook.LiveMarkdown.Export do end defp render_cell(%Cell.Smart{} = cell, ctx) do - %{Cell.Elixir.new() | source: cell.source, outputs: cell.outputs} + %{Cell.Code.new() | source: cell.source, outputs: cell.outputs} |> render_cell(ctx) |> prepend_metadata(%{ "livebook_object" => "smart_cell", @@ -139,11 +139,11 @@ defmodule Livebook.LiveMarkdown.Export do }) end - defp cell_metadata(%Cell.Elixir{} = cell) do + defp cell_metadata(%Cell.Code{} = cell) do put_unless_default( %{}, Map.take(cell, [:disable_formatting, :reevaluate_automatically]), - Map.take(Cell.Elixir.new(), [:disable_formatting, :reevaluate_automatically]) + Map.take(Cell.Code.new(), [:disable_formatting, :reevaluate_automatically]) ) end @@ -199,10 +199,10 @@ defmodule Livebook.LiveMarkdown.Export do defp encode_js_data(data) when is_binary(data), do: {:ok, data} defp encode_js_data(data), do: Jason.encode(data) - defp get_elixir_cell_code(%{source: source, disable_formatting: true}), + defp get_code_cell_code(%{source: source, disable_formatting: true}), do: source - defp get_elixir_cell_code(%{source: source}), do: format_code(source) + defp get_code_cell_code(%{source: source}), do: format_code(source) defp render_metadata(metadata) do metadata_json = Jason.encode!(metadata) diff --git a/lib/livebook/live_markdown/import.ex b/lib/livebook/live_markdown/import.ex index 13bb1d167..f9986b0c8 100644 --- a/lib/livebook/live_markdown/import.ex +++ b/lib/livebook/live_markdown/import.ex @@ -150,7 +150,7 @@ defmodule Livebook.LiveMarkdown.Import do elems ) do {outputs, ast} = take_outputs(ast, []) - group_elements(ast, [{:cell, :elixir, source, outputs} | elems]) + group_elements(ast, [{:cell, :code, source, outputs} | elems]) end defp group_elements([ast_node | ast], [{:cell, :markdown, md_ast} | rest]) do @@ -218,7 +218,7 @@ defmodule Livebook.LiveMarkdown.Import do end defp build_notebook( - [{:cell, :elixir, source, outputs}, {:cell, :smart, data} | elems], + [{:cell, :code, source, outputs}, {:cell, :smart, data} | elems], cells, sections, messages, @@ -239,16 +239,16 @@ defmodule Livebook.LiveMarkdown.Import do end defp build_notebook( - [{:cell, :elixir, source, outputs} | elems], + [{:cell, :code, source, outputs} | elems], cells, sections, messages, output_counter ) do {metadata, elems} = grab_metadata(elems) - attrs = cell_metadata_to_attrs(:elixir, metadata) + attrs = cell_metadata_to_attrs(:code, metadata) {outputs, output_counter} = Notebook.index_outputs(outputs, output_counter) - cell = %{Notebook.Cell.new(:elixir) | source: source, outputs: outputs} |> Map.merge(attrs) + cell = %{Notebook.Cell.new(:code) | source: source, outputs: outputs} |> Map.merge(attrs) build_notebook(elems, [cell | cells], sections, messages, output_counter) end @@ -392,7 +392,7 @@ defmodule Livebook.LiveMarkdown.Import do end) end - defp cell_metadata_to_attrs(:elixir, metadata) do + defp cell_metadata_to_attrs(:code, metadata) do Enum.reduce(metadata, %{}, fn {"disable_formatting", disable_formatting}, attrs -> Map.put(attrs, :disable_formatting, disable_formatting) diff --git a/lib/livebook/notebook/cell.ex b/lib/livebook/notebook/cell.ex index 576bf4b01..621623297 100644 --- a/lib/livebook/notebook/cell.ex +++ b/lib/livebook/notebook/cell.ex @@ -12,9 +12,9 @@ defmodule Livebook.Notebook.Cell do @type id :: Utils.id() - @type t :: Cell.Markdown.t() | Cell.Elixir.t() | Cell.Smart.t() + @type t :: Cell.Markdown.t() | Cell.Code.t() | Cell.Smart.t() - @type type :: :markdown | :elixir | :smart + @type type :: :markdown | :code | :smart @type indexed_output :: {non_neg_integer(), Livebook.Runtime.output()} @@ -25,7 +25,7 @@ defmodule Livebook.Notebook.Cell do def new(type) def new(:markdown), do: Cell.Markdown.new() - def new(:elixir), do: Cell.Elixir.new() + def new(:code), do: Cell.Code.new() def new(:smart), do: Cell.Smart.new() @doc """ @@ -34,7 +34,7 @@ defmodule Livebook.Notebook.Cell do @spec type(t()) :: type() def type(cell) - def type(%Cell.Elixir{}), do: :elixir + def type(%Cell.Code{}), do: :code def type(%Cell.Markdown{}), do: :markdown def type(%Cell.Smart{}), do: :smart @@ -44,7 +44,7 @@ defmodule Livebook.Notebook.Cell do @spec evaluable?(t()) :: boolean() def evaluable?(cell) - def evaluable?(%Cell.Elixir{}), do: true + def evaluable?(%Cell.Code{}), do: true def evaluable?(%Cell.Smart{}), do: true def evaluable?(_cell), do: false diff --git a/lib/livebook/notebook/cell/elixir.ex b/lib/livebook/notebook/cell/code.ex similarity index 94% rename from lib/livebook/notebook/cell/elixir.ex rename to lib/livebook/notebook/cell/code.ex index eb903530e..2efbd352b 100644 --- a/lib/livebook/notebook/cell/elixir.ex +++ b/lib/livebook/notebook/cell/code.ex @@ -1,4 +1,4 @@ -defmodule Livebook.Notebook.Cell.Elixir do +defmodule Livebook.Notebook.Cell.Code do @moduledoc false # A cell with Elixir code. diff --git a/lib/livebook/notebook/explore/elixir_and_livebook.livemd b/lib/livebook/notebook/explore/elixir_and_livebook.livemd index f4b6f2f6f..6b228772c 100644 --- a/lib/livebook/notebook/explore/elixir_and_livebook.livemd +++ b/lib/livebook/notebook/explore/elixir_and_livebook.livemd @@ -146,7 +146,7 @@ Process.exit(self(), :kill) ## Evaluation vs compilation -Livebook automatically shows the execution time of each Elixir +Livebook automatically shows the execution time of each Code cell on the bottom-right of the cell. After evaluation, the total time can be seen by hovering the green dot. diff --git a/lib/livebook/notebook/explore/intro_to_livebook.livemd b/lib/livebook/notebook/explore/intro_to_livebook.livemd index 3bff2f34c..fb3b6034b 100644 --- a/lib/livebook/notebook/explore/intro_to_livebook.livemd +++ b/lib/livebook/notebook/explore/intro_to_livebook.livemd @@ -18,12 +18,12 @@ and run them locally. Each notebook consists of a number of cells, which serve as primary building blocks. There are **Markdown** cells (such as this one) that allow you to describe your work -and **Elixir** cells to run your code! +and **Code** cells to run your Elixir code! To insert a new cell move your cursor between cells and click one of the revealed buttons. 👇 ```elixir -# This is an Elixir cell - as the name suggests that's where the code goes. +# This is a Code cell - as the name suggests that's where the code goes. # To evaluate this cell, you can either press the "Evaluate" button above # or use `Ctrl + Enter` (or Cmd + Enter on a Mac)! @@ -83,7 +83,7 @@ suited for running long computations "in background". Process.sleep(300_000) ``` -Having this cell running, feel free to insert another Elixir cell +Having this cell running, feel free to insert another Code cell in the section below and see it evaluates immediately. ## Saving notebooks diff --git a/lib/livebook/notebook/explore/intro_to_nx.livemd b/lib/livebook/notebook/explore/intro_to_nx.livemd index 0bcb1c9c7..e6f10b746 100644 --- a/lib/livebook/notebook/explore/intro_to_nx.livemd +++ b/lib/livebook/notebook/explore/intro_to_nx.livemd @@ -205,7 +205,7 @@ shape of a tensor using the tensor's API instead of the struct). Primarily, a tensor is a struct, and the functions to access it go through a specific backend. We'll get to the backend details in a moment. For now, use the IEx `h` helper -to get more documentation about tensors. We could also open an Elixir +to get more documentation about tensors. We could also open a Code cell, type Nx.tensor, and hover the cursor over the word `tensor` to see the help about that function. @@ -520,8 +520,8 @@ our code within a `defn` block. To use Nx in a Mix project or a notebook, we need to include the `:nx` dependency and import the `Nx.Defn` module. The -dependency is already included, so import it in an Elixir -cell, like this: +dependency is already included, so import it in a Code cell, +like this: ```elixir import Nx.Defn @@ -572,7 +572,7 @@ Now, it's your turn. Add a `defn` to `TensorMath` that accepts two tensors representing the lengths of sides of a right triangle and uses the pythagorean theorem to return the [length of the hypotenuse](https://www.mathsisfun.com/pythagoras.html). -Add your function directly to the previous Elixir cell. +Add your function directly to the previous Code cell. The last major feature we'll cover is called auto-differentiation, or autograd. diff --git a/lib/livebook/notebook/explore/kino/chat_app.livemd b/lib/livebook/notebook/explore/kino/chat_app.livemd index 5aded66a4..fb6cad7fd 100644 --- a/lib/livebook/notebook/explore/kino/chat_app.livemd +++ b/lib/livebook/notebook/explore/kino/chat_app.livemd @@ -106,7 +106,7 @@ this particular section as a branched section, which means the main execution flow will not be interrupted. But it is something you should keep in mind in the future. You can also stop it by pressing the "Stop" button above the -Elixir cell. +Code cell. diff --git a/lib/livebook/notebook/explore/kino/intro_to_kino.livemd b/lib/livebook/notebook/explore/kino/intro_to_kino.livemd index e46687da7..f4ecd35b6 100644 --- a/lib/livebook/notebook/explore/kino/intro_to_kino.livemd +++ b/lib/livebook/notebook/explore/kino/intro_to_kino.livemd @@ -42,7 +42,7 @@ color dialogs, selects, and more. Feel free to explore them. Given our notebooks already know how to render Markdown, you won't be surprised to find we can also render Markdown -directly from our Elixir cells. This is done by wrapping +directly from our Code cells. This is done by wrapping the Markdown contents in [`Kino.Markdown.new/1`](https://hexdocs.pm/kino/Kino.Markdown.html): ````elixir diff --git a/lib/livebook/notebook/export/elixir.ex b/lib/livebook/notebook/export/elixir.ex index 8e7df8aea..11a0516b3 100644 --- a/lib/livebook/notebook/export/elixir.ex +++ b/lib/livebook/notebook/export/elixir.ex @@ -47,8 +47,8 @@ defmodule Livebook.Notebook.Export.Elixir do |> Enum.map_intersperse("\n", &comment_out/1) end - defp render_cell(%Cell.Elixir{} = cell, section) do - code = get_elixir_cell_code(cell) + defp render_cell(%Cell.Code{} = cell, section) do + code = get_code_cell_code(cell) if section.parent_id do code @@ -61,7 +61,7 @@ defmodule Livebook.Notebook.Export.Elixir do end defp render_cell(%Cell.Smart{} = cell, ctx) do - render_cell(%{Cell.Elixir.new() | source: cell.source}, ctx) + render_cell(%{Cell.Code.new() | source: cell.source}, ctx) end defp render_cell(_cell, _section), do: [] @@ -69,10 +69,10 @@ defmodule Livebook.Notebook.Export.Elixir do defp comment_out(""), do: "" defp comment_out(line), do: ["# ", line] - defp get_elixir_cell_code(%{source: source, disable_formatting: true}), + defp get_code_cell_code(%{source: source, disable_formatting: true}), do: source - defp get_elixir_cell_code(%{source: source}), do: format_code(source) + defp get_code_cell_code(%{source: source}), do: format_code(source) defp format_code(code) do try do diff --git a/lib/livebook/session.ex b/lib/livebook/session.ex index 0ae5e0cae..544d76593 100644 --- a/lib/livebook/session.ex +++ b/lib/livebook/session.ex @@ -550,7 +550,7 @@ defmodule Livebook.Session do end defp default_notebook() do - %{Notebook.new() | sections: [%{Section.new() | cells: [Cell.new(:elixir)]}]} + %{Notebook.new() | sections: [%{Section.new() | cells: [Cell.new(:code)]}]} end defp schedule_autosave(state) do @@ -707,7 +707,7 @@ defmodule Livebook.Session do state |> handle_operation({:delete_cell, client_pid, cell.id}) |> handle_operation( - {:insert_cell, client_pid, section.id, index, :elixir, Utils.random_id(), attrs} + {:insert_cell, client_pid, section.id, index, :code, Utils.random_id(), attrs} ) else _ -> state diff --git a/lib/livebook/session/data.ex b/lib/livebook/session/data.ex index b57e8ec3c..0bbc8ff16 100644 --- a/lib/livebook/session/data.ex +++ b/lib/livebook/session/data.ex @@ -58,13 +58,13 @@ defmodule Livebook.Session.Data do evaluation_queue: list(Cell.id()) } - @type cell_info :: markdown_cell_info() | elixir_cell_info() | smart_cell_info() + @type cell_info :: markdown_cell_info() | code_cell_info() | smart_cell_info() @type markdown_cell_info :: %{ source: cell_source_info() } - @type elixir_cell_info :: %{ + @type code_cell_info :: %{ source: cell_source_info(), eval: cell_eval_info() } @@ -159,7 +159,7 @@ defmodule Livebook.Session.Data do | {:evaluation_started, pid(), Cell.id(), binary()} | {:add_cell_evaluation_output, pid(), Cell.id(), term()} | {:add_cell_evaluation_response, pid(), Cell.id(), term(), metadata :: map()} - | {:bind_input, pid(), elixir_cell_id :: Cell.id(), input_id()} + | {:bind_input, pid(), code_cell_id :: Cell.id(), input_id()} | {:reflect_main_evaluation_failure, pid()} | {:reflect_evaluation_failure, pid(), Section.id()} | {:cancel_cell_evaluation, pid(), Cell.id()} @@ -1466,7 +1466,7 @@ defmodule Livebook.Session.Data do } end - defp new_cell_info(%Cell.Elixir{}, clients_map) do + defp new_cell_info(%Cell.Code{}, clients_map) do %{ source: new_source_info(clients_map), eval: new_eval_info() diff --git a/lib/livebook_web/live/session_live.ex b/lib/livebook_web/live/session_live.ex index c3f99f77b..1bb1e86e8 100644 --- a/lib/livebook_web/live/session_live.ex +++ b/lib/livebook_web/live/session_live.ex @@ -527,8 +527,8 @@ defmodule LivebookWeb.SessionLive do """ end - defp settings_component_for(%Cell.Elixir{}), - do: LivebookWeb.SessionLive.ElixirCellSettingsComponent + defp settings_component_for(%Cell.Code{}), + do: LivebookWeb.SessionLive.CodeCellSettingsComponent defp branching_tooltip_attrs(name, parent_name) do direction = if String.length(name) >= 16, do: "left", else: "right" @@ -1258,7 +1258,7 @@ defmodule LivebookWeb.SessionLive do end defp cell_type_and_attrs_from_params(%{"type" => "markdown"}), do: {:markdown, %{}} - defp cell_type_and_attrs_from_params(%{"type" => "elixir"}), do: {:elixir, %{}} + defp cell_type_and_attrs_from_params(%{"type" => "code"}), do: {:code, %{}} defp cell_type_and_attrs_from_params(%{"type" => "smart", "kind" => kind}) do {:smart, %{kind: kind}} @@ -1420,12 +1420,12 @@ defmodule LivebookWeb.SessionLive do } end - defp cell_to_view(%Cell.Elixir{} = cell, data) do + defp cell_to_view(%Cell.Code{} = cell, data) do info = data.cell_infos[cell.id] %{ id: cell.id, - type: :elixir, + type: :code, source_view: cell_source_view(cell, info), eval: eval_info_to_view(cell, info.eval, data), reevaluate_automatically: cell.reevaluate_automatically diff --git a/lib/livebook_web/live/session_live/bin_component.ex b/lib/livebook_web/live/session_live/bin_component.ex index 747d4adf6..7aed959a3 100644 --- a/lib/livebook_web/live/session_live/bin_component.ex +++ b/lib/livebook_web/live/session_live/bin_component.ex @@ -123,7 +123,7 @@ defmodule LivebookWeb.SessionLive.BinComponent do """ end - defp cell_icon(%{cell_type: :elixir} = assigns) do + defp cell_icon(%{cell_type: :code} = assigns) do ~H"""
@@ -159,7 +159,7 @@ defmodule LivebookWeb.SessionLive.BinComponent do end defp cell_language(%Cell.Markdown{}), do: "markdown" - defp cell_language(%Cell.Elixir{}), do: "elixir" + defp cell_language(%Cell.Code{}), do: "elixir" defp cell_language(%Cell.Smart{}), do: "elixir" defp format_date_relatively(date) do diff --git a/lib/livebook_web/live/session_live/cell_component.ex b/lib/livebook_web/live/session_live/cell_component.ex index 071b424eb..d0d17b854 100644 --- a/lib/livebook_web/live/session_live/cell_component.ex +++ b/lib/livebook_web/live/session_live/cell_component.ex @@ -66,7 +66,7 @@ defmodule LivebookWeb.SessionLive.CellComponent do """ end - defp render_cell(%{cell_view: %{type: :elixir}} = assigns) do + defp render_cell(%{cell_view: %{type: :code}} = assigns) do ~H""" <.cell_actions> <:primary> @@ -268,7 +268,7 @@ defmodule LivebookWeb.SessionLive.CellComponent do defp convert_smart_cell_button(assigns) do ~H""" - + + >+ Code