-
-
Notifications
You must be signed in to change notification settings - Fork 227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Binding keys to REPL functions, passing the namespace and cursor line (Notespace integration) #863
Comments
Interesting! A PR is welcome. |
Related discussion: |
Maye a simple approach could be that the snippets for configuring the custom commands can have some "special character sequences" which get replaced by Calva before calling the snippet:
For the case of notespace we would only need 2: -> a kind of editing context https://github.com/scicloj/notespace/blob/a3758b631420d093ff2d342dd5ee3b98feba3905/emacs-config.el#L14
Not sure, if something else makes sense Somewho information on the current "state" of calva, which a Clojure function itself cannot get from nowhere else. |
|
It works in principle with a trivial change to Calva: @@ -375,11 +375,13 @@ async function evaluateCustomCommandSnippetCommand(): Promise<void> {
saveAs: "runCustomREPLCommand"
});
if (pick && snippetsDict[pick] && snippetsDict[pick].snippet) {
- const command = snippetsDict[pick].snippet;
+ var command = snippetsDict[pick].snippet;
const editor = vscode.window.activeTextEditor;
+ var currentLine = editor.selection.active.line
const editorNS = editor && editor.document && editor.document.languageId === 'clojure' ? namespace.getNamespace(editor.document) : undefined;
const ns = snippetsDict[pick].ns ? snippetsDict[pick].ns : editorNS;
const repl = snippetsDict[pick].repl ? snippetsDict[pick].repl : "clj";
+ command = command.replace("$line",currentLine);
await evaluateInOutputWindow(command, repl ? repl : "clj", ns);
}
} catch (e) { and a custom command setting like thgis: {
"name": "eval-and-realize-note-at-line",
"snippet": "(notespace.api/eval-and-realize-note-at-line $line)",
"repl": "clj"
} |
@daslu This change would be enough for all commands here: A namespace is not really needed. But it would be as well available in variable Your example Emacs configuration saves as well the file. VS code has a built-in autosave feature instead. Both together would bring (nearly) the same notespace experience to Calva. The custom commands can not be bound freely to keystrokes, but are all available as 'Ctrl-Alt-c 1 " 2 / 3 /... |
@behrica that looks wonderful. I will try it soon. |
@behrica this works beautifully. It seems kind of analogous to the Cursive substitutions in REPL commands: @bpringe what do you think? |
Indeed the same idea. |
Awesome, @behrica! Care to provide a PR with those changes? I can pick up the torch from here, but it is more fun if you PR it. 😄 I'm thinking all your suggestions are good. Maybe start with |
I also suspect Calva currently messes up |
I will do an initial change request, as you proposed. Do you have a preference for the "special character" to mark the text substitutions ? It should be something, which is "impossible" to be part of any normal Clojure syntax. So maybe "~" is even less likely to be used for an other purpose in the substitution. I will document this as well somewhere then: https://github.com/BetterThanTomorrow/calva/blob/master/docs/site/custom-commands.md |
Christmas comes early! 🎄 Awesome that you are planning to include docs. Both @bpringe and I will be ready to answer any Calva dev questions. Extra quickly if you're on the Clojurian Slack and the As for special character. This is always tricky with templating, right? As for those two alternatives.
Maybe go for something that is not just ”impossible”. Like What I sometimes do is work Documentation first, so I write the docs and see if they make sense to me and others. Then implement. Maybe that could help here as well. Another thing that has been bothering me regarding the snippets is that they are pretty cumbersome to write inside JSON settings. Would make more sense with an EDN file in the |
@daslu This looks good to me, taking into account what @PEZ said above for the special character. We definitely don't want to have to change it later because of some conflict with Clojure, because that seems like an unavoidable breaking change.
That's a good idea, but I agree, another PR. 😄 |
I propose to stick to the "$line". In any case the subsitution sequence would be "$line", so a single "$" would not be touched. This would mean, it only fails if somebody refers to a Java inner class which is called "line...." Java naming conventions dictate that class names should begin with an upper case letter |
How about people using things like |
Many thanks for Calva!
Background (you can skip reading this part)
In the last few weeks, a few of us started using Notespace for literate programming.
In Emacs+Cider, it is easy to interact with Notespace, as we can comfortably bind keys to Notespace API function calls, and even provide these calls with the important information of what line the cursor is in.
We want to create a more complete Notespace story for Calva as well. This brings us to the following need.
A feature request
(f)
in the REPL, for a pre-configured functionf
.(f nsp line)
in the REPL, for a pre-configured functionf
, wherensp
andline
are external parameters passed by Calva, with the information of the current namespace and the current line where the cursor lies in the edited file.The text was updated successfully, but these errors were encountered: