Rebol2/View question: How does the layout function in Rebol2 work? - view

Some functions that are used in the 'layout function do apparently not exist, yet 'layout works fine. But when you try to replace the 'layout function by an adapted version containing some debugging statements, the functions and undeclared variables will immediately cause an error.
The functions BIND? and BOUND? don't show results for, for example, the used TRACK function, so there is no extra information by using those.
Special interest in the do-facets and grow-facets functions.

Here are two ways to create anonymous contexts in Rebol 2:
context [
semi-hidden-function: does [print "ok"]
set 'non-hidden-function does [semi-hidden-function]
]
use [semi-hidden-function] [
semi-hidden-function: does [print "ok"]
set 'non-hidden-function does [semi-hidden-function]
]
In the first form you may reach the context of the word semi-hidden-function:
>> probe bound? first body-of :non-hidden-function
make object! [
semi-hidden-function: func [][print "ok"]
]
But in second form you may not:
>> probe bound? first body-of :non-hidden-function
make object! [
]
I see many Rebolers use one of above forms, not only to hide but to keep the main function clean and separate.
Here I also add the functions you like to see, it is a bit long so I compressed & enbased:
You can simply paste below line to the console, copy the below text and execute the line to decompress it:
write clipboard:// decompress debase trim/lines read clipboard://
eJyNVrty6zYQrcmvWKuJPWNFqXkn0Uyq29zbpeKwgMElhRgCOABoRfn67C7Ah5xkksJje3dxcPZ1w
N4fB6UxxQaG2Wlo6+rw62xsD2/W63fwA0wqqCsmDBGeletBpRTM25wQbj708QVuF2MRnE+g4MP0Yg
YfIKa7xR8PdRUn1DFHZ2OEE6ErC/luMAmvdUd3L1y0n+7QdnWVsVsGT8rYMwhWxzwrPkW0TYgpm9k
2QMR05LvO0HAEtG8B1TthVWjSBQM8OMnMh5Sj+wZD6VEGx0xVAsRWSLOh2+BWtsZFDGlJptwiiBxV
KWuhzZCCtqF3m188gnD85O/a5I/WZHvhsDi79u88Tt7Z+0JGsuRA+pEaNeDwj7VeZA7Yz5pKnJtU/
rugKmyo1vCFm4sLpAoI+KHsrBL2FBnwqe7qegz+9mmWHN4oely7PSnqFSS6n9K7qpFKqr31gevC9Z
WRi0DYkK6TNJkgTgsoQ9V19eV4hG+zTUbsQPfOE7HSGicm9ByTSkYzyozxpa7k1gZAW1RBhkoYPFg
yjWZnEUYPMZndPibnsLPQMR+4nZI194ZYLCMq9KkLN5P05dTjoCgJSPcJzydpLect/WTGTwDQqmlC
GotcN3LLPBiXcEQK+Gd3pO104+bN5V68aZ4sPm3Qpf6LW3Lc3HmUtrbkqTeCsELk3i3eOVh2/otXK
ra7vkzB4tYXlRPntr/jXfsem9Vr/Wj0U/H2Kime5duJ+72L6lETKpHYha3Zmyuu+OHhGHdAXHkl1+
UVceAF5SN5M2k2m7zJm61hnOVINbtkeKdpC5Lx7lwmQA7K+sl482ItITB4a/2tqOQrjDOpLjUa+wL
J09NA7zcoWNYrR3Qr3Y3fXk+adbyqVQl/gl9+JokfSDLPAjncjjSeF2iJGs2Zp8V3stRl+cvx/5fg
Evyf1IuM7Yhlrc8HBS8vFIZA78rhm4mRZpyN8xUdKa8Ph9yCFaiinCgFuYkzL8CTjyaZDzyvaVPKA
6IoDmynq4edXVhSVdBGfCUV/oEkx4F/+x11gmdiRZXCF4izvoAiQfNEi6z8eG6g1JwNF9qresf8To
yPZPkN4oKf8lhtZ7qNTP3pj/K7I47f5SmWRys/xrluJsoj7WiosH8Fqsci9zc/04t/UR8IWs3jhci
kegXdHppS/99cQO1HZ/7Efvs8aA7MPb81XdHpr/TBQCSuLNflcXiFIn35JTGO2mJYuIfgr2vmTZZ+
OXhiCQMpjojZ3hWJQ3aJCu5drDzZJRq0d4nsiCsL0N4niii+rI17X/4mYl/WxLr7C5ZY7idACQAA

You can find the definitions in the source files of the sdk
e.g
track: func [blk] [if verbose [print blk]]
in view-vid.r
Here a helper function to get the definition/source of a word/function in an unknown context and e.g. without access to the sdk
find-anon: func [ words fn /local ] [
foreach word words [
if word = fn [set :fn probe get word halt]
if block? word [
find-anon word fn
]
]
]
find-anon second :layout 'grow-facets
help grow-facets

Related

How to embed a syntax object in another in TextMate language definitions, tmLanguage

I am trying to support Clojure's ignore text form, #_, (a sort of comment) in VS Code, which uses tmLanguage for its grammar definitions. Since it is common to disable a block of code using #_, I want the disabled block of code to retain its syntax highlighting and just italicize it, indicating its status.
But my lack of skills using tmLanguage seems to stop me. This is one of the failing attempts (a snippet of the cson):
'comment-constants':
'begin': '#_\\s*(?=\'?#?[^\\s\',"\\(\\)\\[\\]\\{\\}]+)'
'beginCaptures':
'0':
'name': 'punctuation.definition.comment.begin.clojure'
'end': '(?=[\\s\',"\\(\\)\\[\\]\\{\\}])'
'name': 'meta.comment-expression.clojure'
'patterns':
[
{
'include': '#constants'
}
]
With constants defining some Clojure constants objects, like keyword:
'keyword':
'match': '(?<=(\\s|\\(|\\[|\\{)):[\\w\\#\\.\\-\\_\\:\\+\\=\\>\\<\\/\\!\\?\\*]+(?=(\\s|\\)|\\]|\\}|\\,))'
'name': 'constant.keyword.clojure'
What I want to happen is that the constants definitions will be used ”inside” the comment. For keywords I have this (failing) spec:
it "tokenizes keywords", ->
tests =
"meta.expression.clojure": ["(:foo)"]
"meta.map.clojure": ["{:foo}"]
"meta.vector.clojure": ["[:foo]"]
"meta.quoted-expression.clojure": ["'(:foo)", "`(:foo)"]
"meta.comment-expression.clojure": ["#_:foo"]
for metaScope, lines of tests
for line in lines
{tokens} = grammar.tokenizeLine line
expect(tokens[1]).toEqual value: ":foo", scopes: ["source.clojure", metaScope, "constant.keyword.clojure"]
(The last test in that list). It fails with this message:
Expected
{ value : ':foo',
scopes : [ 'source.clojure', 'meta.comment-expression.clojure' ] }
to equal
{ value : ':foo',
scopes : [ 'source.clojure', 'meta.comment-expression.clojure', 'constant.keyword.clojure' ] }.
Meaning I am not getting the constant.keyword.clojure scope in place and thus no keyword-colorization for me. 😢
Anyone knows how to do this?
Your keyword regex starts with a lookbehind that requires that there must be a single whitespace, (, [ or { character before keywords. The _ from #_ doesn't meet that requirement.
(?<=(\\s|\\(|\\[|\\{))
You could simply add _ to the list of allowed characters:
(?<=(\\s|\\(|\\[|\\{|_))
Note that this still wouldn't work as-is for your "#_:foo" test case because of the similar lookahead at the end. You could possibly allow $ there, make the match optional, or change the test case.

Extract the content of OUTLINE ( or AL OUTLINE ) from VS Code

Is there any bash command so that we can extract the content of OUTLINE or AL OUTLINE section of the VS Code and write the same into some text document ?
I made a VSCode extension to accomplish this.
Extension page
GitHub Repo
Install and run ctrl + shift + p -> List Symbols
If you don't get a better answer, you can try the Show Functions extension.
It can produce an output of a (clickable) list of functions and symbols into a separate editor which you can then Ctrl-A to copy and paste.
You don't say what languages you are using, I use the following for .js files:
"funcList": {
"doubleSpacing": true,
"filters": [
{
"extensions": [
".js"
],
"native": "/^[a-z]+\\s+\\w+\\s*\\(.*\\)/mgi",
"display": "/\\S* +(\\w+\\s*\\(.*\\))/1",
"sort": 0
}
]
}
which captures and displays the function name and args like:
loadCountryTaxonomy(country)
toggleSearchResultsPanel()
updatetaxArticleQueries(data)
but you can modify the regex to your requirements. I don't try to list symbols other than functions but apparently you can with this extension.

Adding GUI items from a series in Red Language

I want to add GUI items from a series. I am trying following code but it does not work:
mylist: ["first" "second" "third" "fourth" ]
view[
foreach i mylist [
text i ]]
The error is:
*** Script Error: VID - invalid syntax at: [foreach ll mylist]
*** Where: do
*** Stack: view layout cause-error
Where is the problem and how can it be solved? Thanks for your answers.
Remember that...
view [... what goes in here...]
...is a dialect, it is not regular code. It's a special dialect that has some evaluative qualities, but the normal rules don't always apply.
Don't forget that a dialect is just a block of values like anything else in Red. You can pre-build it as such:
view collect [
foreach i mylist [
keep 'text keep i
]
]
You can stick a PROBE between VIEW and COLLECT there to see what you're generating and COLLECT/KEEP gives you a lot of scope for tuning the values that end up in your view spec.
Your problem is you are mixing dialects. You have a VID dialect inside the View block, but you're also using the DO dialect there as well which is not understood by View.
At least in Rebol you would add a do block as an initialization sequence inside the VID dialect eg.
view [
VID dialect goes here ...
do [ do dialect stuff that could initialize gui elements go here ]
]

Rebol shift-tab side effects

Given this:
view layout [ field [print "1" ] field [print "2"] ]
When I shift+tab from field #2 to field #1, no actions are fired.
How do I get them to fire just like a normal tab?
It is a bug in the key handler for field style in the Rebol/View engine. Here is a quick patch you can include in your code to fix it and make SHIFT+Tab work:
use [body f pos][
;-- patch `ctx-text/back-field` function to fix the bug
body: copy/deep second f: get in ctx-text 'back-field
insert body/2/while [if head? item [item: tail item]]
ctx-text/back-field: func first :f :body
;-- remove test that disables face/action for back-tabs
body: second get in ctx-text 'edit-text
body: find body 'word?
pos: at body/3/7/tab-char/5/6 11
change/part pos pos/4 4
]
This code will walk through View engine functions at run-time (code is data in Rebol) and hot-patch the functions bodies, by injecting or removing code where required.
If you happen to be a Rebol/SDK user, I can give you the instructions for patching the source files directly, so you can encap a fixed View executable.
Enjoy.

What causes a misplaced item error in rebol?

Here is the code pruned down to a minimum to show the error:
Rebol []
view center-face layout [
fld1: field
fld2: field
flds: [fld1 fld2]
]
Here is the shortest example to show the error:
layout [ test: []]
>>Misplaced item: []
Rebol uses a number of different dialects, and the two you are using in this example are the do dialect and the view dialect. Now inside the 'layout function, you can only have the view dialect but you have mixed the two. So, the parser used by the 'layout function complains of the misplaced item. The dialect expects to see after flds: one of the faces such as field, area, label etc but instead finds a block.
Regarding your clarification comment, if you wish to create a block of fields, you can just create the block first and then provide it to the 'layout function like this so that you end up with fields named var1 to var9.
lo: [ across ]
for i 1 9 1 [
repend lo [ 'label form join "var" i to set-word! join "var" i 'field 'return ]
]
view layout lo

Resources