expandable-snip: snip has no snipclass
Nobody has claimed this yet.
- Dominant language
- Racket
- Stars
- 68
- Forks
- 82
- PR merge metrics
- No merged PRs in 30d
Description
I want to create an expandable-snip in the REPL. I don't care about the ability to copy-and-paste it.
The following code results in an error: write-snips-to-file: snip has no snipclass.
#lang racket/gui
(require mrlib/expandable-snip)
(define term-snip%
(class expandable-snip%
(define summary-t (new text%))
(define inner-t (new text%))
(send summary-t insert "foo")
(send inner-t insert "bar")
(super-instantiate ()
(closed-editor summary-t)
(open-editor inner-t))))
(new term-snip%)
@alex-hhh told me to try overriding the copy method. I found that it's not enough. Instead, I need to follow the instructions at https://docs.racket-lang.org/gui/editor-overview.html#%28part._snip-example%29
To define a class of snips that can be saved or cut-and-pasted
- Create an instance of snip-class%, implementing the read method. Export the snip-class% instance as snip-class from a module, and use a classname of the form "(lib ...)" as described in Snip Classes.
- For each instance of the snip class, set the snip’s class object with set-snipclass.
- Override the copy method.
- Override the write method.
The minimal code that "works", though it doesn't quite follow every step in the above instructions, is:
#lang racket/gui
(require mrlib/expandable-snip)
(define snip-class (new snip-class%))
(define term-snip%
(class expandable-snip%
(define summary-t (new text%))
(define inner-t (new text%))
(send summary-t insert "foo")
(send inner-t insert "bar")
(super-instantiate ()
(closed-editor summary-t)
(open-editor inner-t))
(define/override (copy) (new term-snip%))
(define/override (write _) (void))
(inherit set-snipclass)
(set-snipclass snip-class)))
(new term-snip%)
But this doesn't make any sense to me. I don't care about its ability to copy-and-paste. Why do I need to deal with snipclass?
Incidentally, this made me realized that snips are copyable, but then when I tried on the syntax browser snip, it errors.
Steps to reproduce:
- Type
#'1at the definition window and run - Copy the snip from the REPL to the definition window
Result:
An error
read-bytes: cannot load snip-class reader, snipclass name has only one library path, but text mode requested: #"(lib \"syntax-browser.ss\" \"mrlib\")"
occurs.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the expandable-snip example and the snip example in the editor overview linked in the issue. Reproduce the write-snips-to-file error in the REPL, then investigate the syntax-browser copy failure using the reported steps. Done means expandable snips can be used without unwanted copy-and-paste support, and the reported copy operation no longer errors.
Written by the indexing model from the issue text.
Assessment
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100