8000 GitHub - dangom/canvacs: drawing canvas for emacs · GitHub
[go: up one dir, main page]

Skip to content
dangomPublic

About

drawing canvas for emacs

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

9 Commits

Folders and files

Repository files navigation

Canvacs

An infinite canvas of cards inside Emacs, on macOS.

Open a .canvas file and you get a whiteboard: cards you can move, resize, colour and connect with arrows, pan and zoom with the trackpad. The file is plain JSON Canvas, the same format Obsidian uses.

The idea is that the canvas is still just an Emacs buffer. The buffer's text is the JSON, and every change you make on the canvas is an edit to that text. So saving, reverting, auto-save, backups and undo all work the way they always do. The drawing is a WebKit view laid over the window. The keyboard stays in Emacs.

This is early software. It works, but expect rough edges.

Requirements

  • macOS
  • A graphical Emacs 29 or newer, built with dynamic module support
  • Xcode Command Line Tools (to build the small native module)

Install

Clone the repo, add it to your load-path, and:

(require 'canvacs)

.canvas files now open as canvases. The native module is compiled automatically the first time you open one (or run make yourself).

What you can do

  • Edit cards in place. Double-click a card (or press RET) and a real Emacs buffer opens right on top of it, so all your usual editing keys work. C-c C-c to finish, C-c C-k to cancel.

  • Write in Org (or Markdown). Cards render Org: emphasis, links, headings, TODO/DONE, checkboxes, code blocks. Clicking a link opens it like org-open-at-point. If you share canvases with other apps, switch to Markdown, which is what JSON Canvas expects:

    (setq canvacs-markup 'markdown)   ; or 'plain
  • Yank anything onto the canvas. C-y turns the last kill into a new card; M-y cycles through older ones. M-w / C-w copy and cut cards, and they paste back as cards, edges included.

  • Pictures. Paste an image or drag files in from Finder. Images are saved next to the canvas in NAME.assets/. When an image file changes on disk (say, a plot your script just regenerated) the canvas updates within a second, and every old version is kept so you never lose a figure. Press s to link a picture to the script that made it, v to see past versions.

  • Crop pictures. Press C on a picture: the whole image appears faded with a frame over it. Drag the frame's handles (or the frame itself), then RET or C to keep the crop, C-g to cancel. C-u C uncrops. The image file is never touched: the crop is saved in the card, so it survives the figure being regenerated. (Other JSON Canvas apps will show the whole image.)

  • Several windows. Show the same canvas in two windows and look at different parts of it at once.

  • Capture from anywhere. M-x canvacs-capture in any buffer adds a card linking back to that file and line (with the selected text, if any).

  • Link from Org. [[canvacs:~/notes/plan.canvas]] opens a canvas; [[canvacs:~/notes/plan.canvas::ID]] jumps to a card. org-store-link on a canvas makes these for you.

  • Generate graphs from scripts or agents. Give it nodes and edges with no positions and it lays them out for you:

    {"nodes": [{"id": "lstm", "rank": 1997, "text": "LSTM"},
               {"id": "s2s",  "rank": 2014, "text": "Seq2Seq"}],
     "edges": [{"fromNode": "lstm", "toNode": "s2s"}]}
    emacsclient --eval '(with-current-buffer "map.canvas" (canvacs-graph-add "graph.json"))'
    # or without a running Emacs:
    emacs --batch -L . -l canvacs-graph --eval '(canvacs-graph-file "graph.json" "map.canvas")'

    The optional rank (a year, for example) keeps columns in order. Edges route themselves around cards and re-route as you move things.

Colours follow your Emacs theme. See M-x customize-group RET canvacs for fonts, colours and the rest.

Mouse

Action Does
Two-finger scroll / pinch Pan / zoom
Click, shift-click Select a card, add to selection
Drag on empty space Box-select
Drag a card Move the selection (groups carry their contents)
Drag a handle Resize
Double-click Edit a card, edge label or group name; on empty space, new card
Drag from a dot beside a card Connect to another card, or drop on empty space for a new connected card
Click a dot New connected card on that side
Click an edge Select it (to colour, label or delete)

A small toolbar floats next to the selection for colour, front/back and delete.

Keys

Key Does
RET, e Edit selected card/edge, or start a new card
a New card in the middle of the view
M-RET New card to the right, connected (C-u: below)
l Connect the selected cards, in selection order
d, DEL Delete selection
c Colour selection
i Info: created/modified times, connections, file
o, C-c C-o Open the card's file, URL or link
s / v Picture's source script / past versions
C Crop the selected picture (C-u C: uncrop)
] / [ Bring to front / send to back
M-<arrows> Nudge selection
TAB, S-TAB Next / previous card
n p f b Select card below / above / right / left
C-x h, C-g Select all / none
C-/ u, C-? U Undo / redo
C-n C-p C-f C-b, arrows Pan
SPC, S-SPC Page down / up
+ - 0 1 Zoom in / out / fit all / 100%
C-x C-s Save

Known limitations

  • macOS only.
  • Inside the card editor, C-c C-c finishes editing, so Org's own C-c C-c isn't available there.
  • Checkboxes can't be ticked by clicking yet.

How it's built

  • canvacs-model.el – the document: parses and edits the JSON, reports changes. No display needed.
  • canvacs-graph.el – automatic layout for graphs without positions.
  • canvacs.el – the major mode; keeps the view in sync with the buffer.
  • web/ – the renderer (HTML/JS). route.js draws the edges.
  • src/canvacs-module.m – a small Objective-C module that puts a WebKit view over an Emacs window.

Development: make test runs the tests, make compile byte-compiles with warnings as errors, and test/live.el starts a scratch Emacs with test/sample.canvas to play with.

License

GPL-3.0-or-later.

About

drawing canvas for emacs

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

0