Codemirror-grammar how to make keyword checks case-insensitive - codemirror

Codemirror is an excellent JS library for syntax coloring & highlighter etc. I have created a very simple 'macro' language for my project and want to use codemirror for it. However, writing a new mode / lexicon parser for codemirror is not a simple task. Good news though, the excellent codemirror-grammar makes it a relatively simple task to achieve this without being a regexp ninja - it uses a JSON formatted definition file which is very approachable with an easy learning curve. Frustratingly, the docs are not fabulous.
My question is, how can I tell codemirror-grammar that the keywords list should be case-insensitive, for example:
MacroVersion should be matched by 'macroversion'.
Currently 'MacroVersion' is not being highlighted. Image below.
What have I tried so far: I looked at the source code for codemirror-grammar and though not fully understanding it I thought there seemed to be a token as in the highlight below for case sensitivity.
I have also looked at other sample codemirror-grammar language examples but have not found a cut-paste solution there.
Research / other SO questions for codemirror:
CodeMirror autocomplete: Case In Sensitive Search : Not a duplicated as is specific to python mode.js and requires source code change in mode file, whereas codemirror-grammar does not have the mode js file.

apply caseInsensitive = true
for example:
"keyword": {
"autocomplete": true,
"caseInsensitive": true, // <-- make case-insensitive
"tokens": [
"if", "then", "else",
..
]
}
found here:
https://github.com/foo123/codemirror-grammar/issues/12#issuecomment-427387653

Related

Extension to keep annotations on arbitrary keywords

I’ve looked through the VSCode extension store and other random searches but have been unable to find what I’m looking for. Before I dive into learning to write my own extension…
I am looking for a VSCode extension that will let me add keywords and custom annotations for those keywords in my code. In my head, specific words will be highlighted/underlined, and a small pop up will display notes that I have previously set for that keyword.
The primary use case is to remind me on specific use case or implications of particular keywords. For instance, if I use the default HTTP client in Golang, I’d like to be reminded that there is no default timeout.
The definition would look something like:
“definitions”: [
{
“text”: “http.Get”,
“comment”: “the default go http client does not have a timeout.”
}
]
Upon adding this line to my code
*resp, err := http.Get("http://example.com/")
would highlight/underline http.Get and when I mouseover, I will get a custom reminder that “the default http client does not have a timeout.”

How do you change C++ class autocomplete in VS Code so that the public keyword appears first?

When autocompleting a class in C++ on VS code, it will print private first and public second. I would like to change the defaults to the opposite but I cannot find where to access these settings. Is there a key you can set in the c_cpp_properties.json file maybe?
Alright, so I thought that CLang-format had a setting like the one you asked for. I looked through the link above's documentation (which I know fairly well) for a rule that organizes the access modifiers, but there doesn't seem to be one. I also poked around VS Code, and to no ones supprise, VS Code didn't have anything worth mentioning either.
There is Good Option that Might Work for You Though.
This solution is called VS Code Snippets. The snippets are what you are using when you click the suggestion that auto completes. The template that creates the class is defined in the Snippet cpp.json document, or if you downloaded a snippets extension for C++ they might live their. Either way, you can just write your own "C++ Class Snippet",and use that. The snippet will be auto completed in what ever manner you define it. Here is one I wrote, to demonstrate what you can do:
FYI: You are already using snippets each time you use an auto-completion, your just using snippets that someone else wrote.
IMO, VSCode has the best support, by far, for writing auto completions.
"C++ Class Snippet (public first) #JCSB": {
"prefix": "class",
"body":[
"class ${0:Name} {",
"\npublic:",
"\n ${1:publicMember}", // PUBLIC MEMBERS
"\n ${2:publicMember}",
"\n ${3:publicMember}",
"\nprivate:",
"\n ${4:privateMember}", // PRIVATE MEMBERS
"\n ${5:privateMember}",
"\n ${6:privateMember}",
"\nprotected:",
"\n ${7:protectedMember}", // PROTECTED MEMBERS
"\n};"
],
"description": "(#JCSB) C++ class w/ public access modifier placed first."
}
The class has 4 Place holders ($0, $1, $2 & $3).
$0: "choose class name"
$1: "Set your public members"
$2: "Set your private members"
$3: "Author your methods."
You can move from one placeholder to the next using the Tab key.
HELPFULL LINKS:
Official Snippets Documentation
You should read about Emmets as well at the link below:
Read about configuring the "V.S. Code Intellisense Extension". This page will tell you how to configure it, which is an advanced topic with information that is capable of changing the way you look at V.S. Code & how you use its tools & features.
One Last Tip:
Add the following configurations to your settings.json file to make sure your snippets take priority over suggestions and built-in snippets in the suggestions-widget. Quick suggestions is a suggested word, or syntax that intellisense puts at the top. Those who write there own snippets often find it useful to prioritize their snippets over the quick suggestions.
// #file "settings.json"
{
"editor.snippetSuggestions": "inline",
"editor.suggest.showSnippets": true,
"editor.suggest.snippetsPreventQuickSuggestions": true,
}

How underscored directories are filtered in Jekyll/Webrick?

Update: Check my answer below.
I just realized that in Jekyll Webrick server, directories starting with underscores(_includes, _layouts etc.) can't be accessed and are not listed when jekyll serve --show-dir-listing option is turned on. I wonder how Jekyll does that, as Webricks shows underscored directories on default. I did a quick search in the source code, I checked lib/jekyll/commands/serve.rb and similar files, but could not find the exact reason. It might be something related to fancy_listing?
Example:
It is there!:
Update: I found the relevant code in jekyll/reader.rb, which has a filter function and it is defined in jekyll/entry_filter.rb! :) Here is the code:
First a regex is defined:
SPECIAL_LEADING_CHAR_REGEX = %r!\A#{Regexp.union([".", "_", "#", "~"])}!o.freeze
Then special?function is defined:
def special?(entry)
SPECIAL_LEADING_CHAR_REGEX.match?(entry) ||
SPECIAL_LEADING_CHAR_REGEX.match?(File.basename(entry))
end
And special?function is used in the filter function to detect and filter those files matching the regex.
And the Readerclass is using this filtering function in various places.
To be honest, I still did not get how jekyll bring those things together but I think I'll try to figure them out myself.

Including reference links in markdown as bullet point list on GitHub

Currently I'm using this markdown text inside the README.md file of a project on GitHub:
See the docs of [testthat][3] on how to write unit tests.
Links
-----
- http://www.rstudio.com/products/rpackages/devtools/
- https://github.com/hadley/testthat
- http://r-pkgs.had.co.nz/tests.html
---
[1]: http://www.rstudio.com/products/rpackages/devtools/
[2]: https://github.com/hadley/testthat
[3]: http://r-pkgs.had.co.nz/tests.html
I don't like this duplication, but I don't see what choice I have. If I remove the explicit bullet point lists, then GitHub won't display the reference links. If I remove the reference links, then GitHub shows the bullet point list (of course), but the embedded links like "testthat" above don't work.
Is there a better way than duplicating? What am I missing?
Inspired by #mb21, I suppose this would be the right way to do it:
See the docs of [testthat][2] on how to write unit tests.
Links
-----
- [RStudio Devtools][1]
- [testthat][2]
- [More unit test examples][3]
[1]: https://stackoverflow.com/users/214446/mb21
[2]: https://github.com/hadley/testthat
[3]: http://r-pkgs.had.co.nz/tests.html
That is, it's not a good practice to include links verbatim and without a meaningful title. I should keep the link URLs only in the reference links section at the bottom, and in the bullet point list use meaningful titles.
When you view this on GitHub, the URLs shouldn't really matter, and if you really want to know you can move the mouse over. When you view this in plain text, now the links have meaningful titles, which is useful additional information about the URLs.
I'd write that as follows:
See the docs of [testthat][1] on how to write unit tests.
Links
-----
- [RStudio Devtools](http://www.rstudio.com/products/rpackages/devtools/)
- [Testthat](https://github.com/hadley/testthat)
- [Tests][1]
[1]: http://r-pkgs.had.co.nz/tests.html
Did that answer your question? If not, you'll have to clarify it.
An answer from 8 years in the future!
The answer to your question will depend on what your Markdown parser supports. Nowadays, most parsers support CommonMark (plus some flavouring). However, don't take this for granted and double check it. If CommonMark is not supported, try using the "vanilla" Markdown syntax as described below. Just be aware that the "vanilla" Markdown specification is flawed and may result in broken links (by design, almost).
Using CommonMark
If you can guarantee that your Markdown parser supports CommonMark, then you can do it in a simple way:
Writing unit tests is explained in the [Unit Testing] website
[Unit Testing]: https://unittesting.somedomain.com
In the Links section of the CommonMark specification (currently at version 0.30) you see that a "link" is composed of a link text, link destination and a title and each one has its own syntax and quirks. For example, if the link destination contains spaces, you need to wrap it in <angled brackets>, or if your link text is some kind of code, you're allowed to write
[`AwesomeClass`](<../docs/awesome class.md>]
Note:
In this section I am using the CommonMark syntax, so you can click the
"Edit" button to see the syntax that I used for a "real" example.
Using vanilla Markdown
The vanilla Markdown specification simply requires an extra set of angled brackets with nothing in between, as described in the links section.
Writing unit tests is explained in the [Unit Testing][] website
[Unit Testing]: https://unittesting.somedomain.com
Note
And in this section I've only used vanilla Markdown syntax. Stack Overflow's Markdown parser supports both CommonMark and vanilla Markdown. This is not by accident, since CommonMark intends to be compatible with the original specification (wherever possible!). Stack Overflow do state that they use the CommonMark spec in their Markdown help page.
Tl;dr
See the docs of [`testthat`] on how to write unit tests.
Links
-----
- [RT Studio dev tools]
- [`testthat`]
- [R Packages]
---
[RT Studio dev tools]: http://www.rstudio.com/products/rpackages/devtools/
[`testthat`]: https://github.com/hadley/testthat
[R Packages]: http://r-pkgs.had.co.nz/tests.html

Photoshop plugin Pipl resources and disabling save

I have a photoshop plugin for a file format Ive written in c++ that loads and opens the images, however I do not have code to save the image in the same format
Using SimpleFormat sample plugin as a base I have the following code:
FormatFlags { fmtSavesImageResources,
fmtCanRead,
fmtCanWrite,
fmtCanWriteIfRead,
fmtCanWriteTransparency,
fmtCanCreateThumbnail },
However removing fmtCanWrite or IfRead etc produces parser errors in the Pipl tool, I've checked the syntax and it should be correct but I cannot figure out how to do this =s
This is really counter-intuitive but if you check out pg 77 of Plug-in Resource Guide.pdf from the SDK the flags aren't really flags, they are actually keywords. Based on the grammar they give, to not include the write flag you actually need to replace it with a do-not-write flag.
For example, this compiles fine for me:
FormatFlags { fmtDoesNotSavesImageResources,
fmtCanRead,
fmtCannotWrite,
fmtCanWriteIfRead,
fmtCanWriteTransparency,
fmtCanCreateThumbnail }