Comments (7)
Should be fixed on the latest hscopes
version, thanks for the report!
from hsnips.
and context does not work in the new version π. I don't know how to make it work.
from hsnips.
Hi there, I'll suppose you're using LaTeX, if you're using markdown, please let me know.
If that is the case, the example given in the README
should work for you, let me change it a little so you can see how to do it more generally:
Here we define two automatic snippets, inv
and tt
, that only work inside math mode
global
function math(context) {
return context.scopes.some(s => s.startsWith("meta.math"));
}
endglobal
context math(context)
snippet inv "inverse" Ai
^{-1}
endsnippet
context math(context)
snippet tt "text" Ai
\text{$1}
endsnippet
Now let me explain how it works:
- First of all, the
global
keyword starts a code block where you can define variables and functions that will be available for any javascript code in the currenthsnips
file. - After that, we have the
context
keyword: it should be followed by a javascript expression, and every time you type a character, that javascript expression is executed, and the following snippet will only be "active" in case the executed expression evaluated totrue
. - Inside the
context
expression, we have access to a variable calledcontext
, which contains information regarding the current scope, as can be seen in theREADME
.
In this case, suppose we just typed tt
inside a math block in LaTeX, what happens is that the context
expression above the tt
snippet will be called with the following context
parameter
{
scopes: [
"support.class.math.block.environment.latex",
"meta.math.block.latex",
"text.tex.latex",
]
}
which in turn will call the math
function defined above with this same parameter, and as you can see, the math
function returns true in case any of the scopes starts with "meta.math"
, which in this case it does, so the tt
snippet will be available, and as it is an automatic snippet it will run.
More generally, you can see the context.scopes
that will be available in a given context
expression by running the vscode
command Developer: Inspect Editor Tokens and Scopes
in the textmate scopes
field.
Implementing context like this is more general, as we are not only restricted to math blocks inside LaTeX documents, we could create a context
expression that would evaluate to true inside comments in javascript files for example.
If you have any further doubts about how to use contexts please let me know, I'll be closing this issue now. π
from hsnips.
Thanks for that!
However I'm very sorry because I'm using markdownInspecting Editor Tokens and Scopes
I can confirm that the scope of the math blocks is meta.embedded.block.katex
:
textmate scopes :
meta.embedded.block.katex
markup.inserted.math.inline.markdown
meta.paragraph.markdown
markup.list.numbered.markdown
text.html.markdown
provided by extension "markdown all in one". I only changed meta.math
into meta.embedded
like that:
function math(context) {
return context.scopes.some(s => s.startsWith("meta.embedded"));
}
, but nothing had happened
Anyway the explanation is great, thanks!
from hsnips.
Personally, I'd use s => s.includes("katex")
in your case, as that is the name of the markdown LaTeX renderer. Please try it and let me know how it goes.
from hsnips.
I see the issue now, it seems to be an issue in the hscopes
library, I'll take a look into it and get back to you!
from hsnips.
thanks! I will try it later
from hsnips.
Related Issues (20)
- Feature Request HOT 1
- a built-in variable representing first operand
- Unable to get C++ snippets file to load in WSL HOT 1
- Unicode property escape matching with RegExp flag 'u'?
- Feature Request: Allow multiple files per language to facilitate sharing of hsnips files separated by functionality HOT 2
- Hsnips broken with recent VSCode update HOT 3
- Rather weird behavior when working with spaces HOT 2
- Tabstop information is lost when using nested snippets HOT 1
- .
- How do I synchronize `.hsnips` files on different devices HOT 3
- Escaped backslash not showing before right curly brace HOT 1
- Support for WSL2 sublinux system for Windows
- Negative and Positive Lookaheads
- "Error creating hsnips directory in WSL2 when using 'open snippets file' command in extension"
- Regular Expression with underscore
- Can Not Match regular expression like: `(\S*)\.log$` "Desc" without A
- "Open snippet file for current language" command?
- ζζΆζ ζ³θ§¦ε HOT 2
- Hypersnip not always start with vscode on MacOS HOT 1
- Hide snippet suggestion
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hsnips.