From f9925688329fb02b46e524cd31ac733f37549eeb Mon Sep 17 00:00:00 2001 From: pkova Date: Sat, 31 Jul 2021 23:37:23 +0300 Subject: Add customizable prefix key in js repl --- docs/repl.js | 33 +++++++++++++++++++++------------ docs/style.css | 4 ++-- docs/try.html | 6 ++++-- 3 files changed, 27 insertions(+), 16 deletions(-) (limited to 'docs') diff --git a/docs/repl.js b/docs/repl.js index 5ec386a5..1aaeb218 100644 --- a/docs/repl.js +++ b/docs/repl.js @@ -78,7 +78,13 @@ sysvals.plot = (x,w) => { return '\0'; } -let keymode=0; // 1 for backslash +doc.prfx.onchange = ev => { + prefix = ev.target.value; + buildKb(); +} + +let keymode=0; // 1 for prefix +let prefix=doc.prfx.value; doc.code.onkeydown = ev => { let k = ev.which; if (16<=k && k<=20) { @@ -87,12 +93,12 @@ doc.code.onkeydown = ev => { repl(); return false; } if (keymode) { keymode = 0; - doc.kb.classList.remove('backslash'); + doc.kb.classList.remove('prefix'); let c = keys[ev.key]; if (c) return typeChar(ev.target, c, ev); - } else if (ev.key=='\\') { + } else if (ev.key==prefix) { keymode = 1; - doc.kb.classList.add('backslash'); + doc.kb.classList.add('prefix'); ev.preventDefault(); } } @@ -111,14 +117,17 @@ let kk=Array.from('`123456890-=~!@#$%^&*()_+qwertuiop[]QWERTIOP{}asdfghjkl;ASFGH let kv=Array.from('˜˘¨⁼⌜´˝∞¯•÷׬⎉⚇⍟◶⊘⎊⍎⍕⟨⟩√⋆⌽𝕨∊↑∧⊔⊏⊐π←→↙𝕎⍷𝕣⍋⊑⊒⍳⊣⊢⍉𝕤↕𝕗𝕘⊸∘○⟜⋄↖𝕊𝔽𝔾«⌾»·˙⥊𝕩↓∨⌊≡∾≍≠𝕏⍒⌈≢≤≥⇐‿↩'); let keys={}, revkeys={}, primhelp={}; kk.map((k,i)=>{keys[k]=kv[i];revkeys[kv[i]]=k;}); -doc.kb.innerHTML = keydesc.map(d=>{ - let s = syncls[d[0]]; - let c = Array.from(d)[1]; - let t = d.slice(1+c.length).replace(';','\n'); - let k = revkeys[c]; if (k) t += '\n\\ '+(k==='"'?'"':k); - primhelp[c] = t; - return ''+c+'' -}).concat(['map']).join("​"); // zero-width space +let buildKb = () => { + doc.kb.innerHTML = keydesc.map(d=>{ + let s = syncls[d[0]]; + let c = Array.from(d)[1]; + let t = d.slice(1+c.length).replace(';','\n'); + let k = revkeys[c]; if (k) t += '\n'+prefix+(k==='"'?'"':k); + primhelp[c] = t; + return ''+c+'' + }).concat(['map']).join("​"); // zero-width space +} +buildKb(); doc.kb.onmousedown = ev => { let t = ev.target; if (t.nodeName === 'SPAN') { diff --git a/docs/style.css b/docs/style.css index 847e7448..cfc3e346 100644 --- a/docs/style.css +++ b/docs/style.css @@ -181,7 +181,7 @@ a:link { color: #0b39dc; text-decoration-color: #0b39dc91; } a:visited { color: #3d155f; } .kb span:hover{ background-color: #bce; } -.kb.backslash { background-color: #cee; } +.kb.prefix { background-color: #cee; } @media (prefers-color-scheme: dark) { body, input, select { color: #d6d7d9; background-color: #141515; } @@ -194,7 +194,7 @@ a:visited { color: #3d155f; } table td, th{ border-color: #636967; } table th { border-color: #88918c; background-color: #292a2b; } .kb span:hover { background-color: #237; } - .kb.backslash { background-color: #1e2430; } + .kb.prefix { background-color: #1e2430; } .Value { color: #b2b9bb; } .Function { color: #3aa548; } diff --git a/docs/try.html b/docs/try.html index d5871c0d..0faa3131 100644 --- a/docs/try.html +++ b/docs/try.html @@ -9,10 +9,11 @@ li { margin:0.7em 0; } textarea { padding:0.2em; } .perm, .count { font-size:0.7em; margin:-0.2em 0.8em 0 0; } - .run, .doexplain, .perm { float:right; margin-left:0.4em; } + .run, .doexplain, .perm, .prfx { float:right; margin-left:0.4em; } .doexplain.selected { background:#777; } .count { float:left; opacity:0.6; } .rslt { border:none; background:none; min-height:8em; } + .prfx { width: 1.1em; } @@ -21,6 +22,7 @@
+
permalink @@ -30,7 +32,7 @@

Notes:

-- cgit v1.2.3 From 3577aec3617540ac58d3ab41e8fa163f75e859b7 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Fri, 30 Jul 2021 22:41:17 -0400 Subject: Move editors README to markdown --- docs/editors/index.html | 33 +++++++++++++++++++++++++++++++++ docs/index.html | 2 +- docs/keymap.html | 2 +- 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 docs/editors/index.html (limited to 'docs') diff --git a/docs/editors/index.html b/docs/editors/index.html new file mode 100644 index 00000000..3240ac0a --- /dev/null +++ b/docs/editors/index.html @@ -0,0 +1,33 @@ + + + + BQN: Editor support + + +

Editor support

+ +

Editor plugins and other tools for allowing BQN input are in this folder. Input is always performed with a backslash \ prefix by default, using the layout shown here. To type an actual backslash, hit the backslash key twice.

+

This bookmarklet enables BQN input in any webpage in your browser.

+

This userscript highlights BQN code on GitHub.

+

For Android, this fork adds APL and BQN to Hacker's Keyboard.

+

The file inputrc can be copied or appended to ~/.inputrc to enable backslash input in bash, BQN with rlwrap, and other software that uses GNU Readline.

+

If you'd like to contribute files for another editor I'd gladly accept them!

+

XKB

+

The file bqn is for configuring XKB on Linux. To use, copy it to /usr/share/X11/xkb/symbols/, then run

+
$ setxkbmap -layout us,bqn -option grp:switch
+
+

replacing us with your ordinary keyboard layout. switch indicates the right alt key and can be replaced with lswitch for left alt or other codes. The setting will go away on shutdown so you will probably want to configure it to run every time you start up. The way to do this depends on your desktop environment. For further discussion, see Wikipedia or the APL Wiki.

+

Another XKB option, if you have a compose key enabled, is to place XCompose (possibly with adjustments) in ~/.XCompose.

+

Vim

+

Copy or symlink all files into the corresponding directories in ~/.vim. Add the following two lines to ~/.vim/filetype.vim:

+
  au! BufRead,BufNewFile *.bqn setf bqn
+  au! BufRead,BufNewFile * if getline(1) =~ '^#!.*bqn$' | setf bqn | endif
+
+

Include syntax on in your .vimrc for syntax highlighting and filetype plugin on for keyboard input.

+

Emacs

+

Add the following two lines to init.el (usually ~/.emacs.d/init.el), replacing the path appropriately.

+
(add-to-list 'load-path "/path/to/BQN/editors/emacs")
+(require 'gnu-apl-mode)
+
+

Kakoune

+

Copy or symlink kak/autoload/filetype/bqn.kak into autoload/filetype in your Kakoune config directory (probably .config/kak/).

diff --git a/docs/index.html b/docs/index.html index 7a23a015..b90a5921 100644 --- a/docs/index.html +++ b/docs/index.html @@ -50,7 +50,7 @@

More snippets are programmed into the live demo at the top of the page: hit the arrow at the right of the code window to see them. For longer samples, you can gaze into the abyss that is the self-hosted compiler, or the shallower but wider abyss of the runtime, or take a look at the friendlier markdown processor used to format and highlight documentation files. This repository also has some translations from "A History of APL in 50 Functions".

How do I work with the character set?

-

Right at the beginning, you can use the bar above the online REPL to enter BQN code: hover over a character to see a short description, and click to insert it into the editor. But you'll soon want to skip the clicking and use keyboard input. I type the special characters using a backslash escape, so that, for example, typing \ then z writes (the backslash character itself is not used by BQN). The online REPL supports this method out of the box, and configuration files to enable it in various other places are included with the editor plugins. There's also a bookmarklet you can use to enable BQN input in any webpage in your browser.

+

Right at the beginning, you can use the bar above the online REPL to enter BQN code: hover over a character to see a short description, and click to insert it into the editor. But you'll soon want to skip the clicking and use keyboard input. I type the special characters using a backslash escape, so that, for example, typing \ then z writes (the backslash character itself is not used by BQN). The online REPL supports this method out of the box, and the editor plugins include or link to ways to enable it for editors, browsers, shells, and so on.

The font comparison page shows several fonts that support BQN (including the one used on this site, BQN386). Most other monospace fonts are missing some BQN characters, such as double-struck letters 𝕨, 𝕩 and so on, which will cause these characters to be rendered with a fallback font and possibly have the wrong width or look inconsistent.

Why would I use it?

There are plenty of clean, modern languages out there, and a good number of array languages. I don't think any other language fits both descriptions quite so well as BQN, and I find the combination lets me write powerful and reliable programs quickly. What you find in the language will depend on your background.

diff --git a/docs/keymap.html b/docs/keymap.html index 1e4881db..0597bb52 100644 --- a/docs/keymap.html +++ b/docs/keymap.html @@ -30,4 +30,4 @@ └───────────┴────┴────┴────┴────┴────┴────┴────┴────┴────┴────┴────────────┘ Space: -

See also the editor plugins (and other input methods) and primitive documentation.

+

See also the editor plugins (and other input methods) and primitive documentation.

-- cgit v1.2.3 From 99424bb076edce155fe9f877625484c6fad0f2b1 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Fri, 30 Jul 2021 22:46:03 -0400 Subject: Link to VS Code plugins --- docs/editors/index.html | 2 ++ 1 file changed, 2 insertions(+) (limited to 'docs') diff --git a/docs/editors/index.html b/docs/editors/index.html index 3240ac0a..5b17f09d 100644 --- a/docs/editors/index.html +++ b/docs/editors/index.html @@ -29,5 +29,7 @@
(add-to-list 'load-path "/path/to/BQN/editors/emacs")
 (require 'gnu-apl-mode)
 
+

VS Code

+

See this repository.

Kakoune

Copy or symlink kak/autoload/filetype/bqn.kak into autoload/filetype in your Kakoune config directory (probably .config/kak/).

-- cgit v1.2.3 From bbcb9e49d454c2d4d203df7675626c10c25e539d Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Sat, 31 Jul 2021 18:16:22 -0400 Subject: Move prefix customization to bottom right of keybar --- docs/repl.js | 36 +++++++++++++++++++++--------------- docs/style.css | 13 ++++++++----- docs/try.html | 6 ++---- 3 files changed, 31 insertions(+), 24 deletions(-) (limited to 'docs') diff --git a/docs/repl.js b/docs/repl.js index 1aaeb218..25eef499 100644 --- a/docs/repl.js +++ b/docs/repl.js @@ -78,13 +78,8 @@ sysvals.plot = (x,w) => { return '\0'; } -doc.prfx.onchange = ev => { - prefix = ev.target.value; - buildKb(); -} - let keymode=0; // 1 for prefix -let prefix=doc.prfx.value; +let prefix='\\'; doc.code.onkeydown = ev => { let k = ev.which; if (16<=k && k<=20) { @@ -117,17 +112,20 @@ let kk=Array.from('`123456890-=~!@#$%^&*()_+qwertuiop[]QWERTIOP{}asdfghjkl;ASFGH let kv=Array.from('˜˘¨⁼⌜´˝∞¯•÷׬⎉⚇⍟◶⊘⎊⍎⍕⟨⟩√⋆⌽𝕨∊↑∧⊔⊏⊐π←→↙𝕎⍷𝕣⍋⊑⊒⍳⊣⊢⍉𝕤↕𝕗𝕘⊸∘○⟜⋄↖𝕊𝔽𝔾«⌾»·˙⥊𝕩↓∨⌊≡∾≍≠𝕏⍒⌈≢≤≥⇐‿↩'); let keys={}, revkeys={}, primhelp={}; kk.map((k,i)=>{keys[k]=kv[i];revkeys[kv[i]]=k;}); -let buildKb = () => { - doc.kb.innerHTML = keydesc.map(d=>{ - let s = syncls[d[0]]; +doc.kb.innerHTML = keydesc + .map(d=>''+Array.from(d)[1]+'') + .concat(['map']) + .join("​"); // zero-width space +let setPrefix = () => { + doc.kb.querySelectorAll("span").forEach((x,i) => { + let d = keydesc[i]; let c = Array.from(d)[1]; let t = d.slice(1+c.length).replace(';','\n'); let k = revkeys[c]; if (k) t += '\n'+prefix+(k==='"'?'"':k); - primhelp[c] = t; - return ''+c+'' - }).concat(['map']).join("​"); // zero-width space + x.title = primhelp[c] = t; + }); } -buildKb(); +setPrefix(); doc.kb.onmousedown = ev => { let t = ev.target; if (t.nodeName === 'SPAN') { @@ -135,17 +133,25 @@ doc.kb.onmousedown = ev => { } } +doc.kb.innerHTML += '
'; +doc.kbext = doc.kb.querySelector('.kbext'); + if (doc.demo) { let fonts=[["BQN386"],["DejaVu","Mod"],["Fairfax","HD"],["3270","font"],["Iosevka","Term"],["Julia","Mono"]]; let fclass = f => f==="3270"?"f"+f:f let fontsel = ''; +doc.kbext.querySelector(".prfx").onchange = ev => { + prefix = ev.target.value; setPrefix(); +} + if (doc.perm) doc.perm.onmouseover = doc.perm.onfocus = () => { let b=(new TextEncoder()).encode(doc.code.value); doc.perm.href='#code='+btoa(String.fromCharCode(...b)); diff --git a/docs/style.css b/docs/style.css index cfc3e346..3388aed7 100644 --- a/docs/style.css +++ b/docs/style.css @@ -112,7 +112,7 @@ textarea { width: 100%; outline: none; resize: vertical; margin: 0; } padding: 0.3em 0; position: relative; } -.kb span { +.kb span, .kb div { cursor: default; padding: 1px; } @@ -120,11 +120,14 @@ textarea { width: 100%; outline: none; resize: vertical; margin: 0; } margin-left: 0.8em; font-size: 0.8em; vertical-align: 0.08em; opacity: 0.8; } -.kb select { +.kbext { position: absolute; bottom: 0.4em; right: 0.1em; - color: currentColor; opacity: 0.5; font-size: 0.7em; - border: none; +} +.kbext select { opacity: 0.5; border: none; } +.prfx { + width: 1.2em; text-align: center; border: 1px solid #bdcac4; + margin-left: 0.6em; } .rel { position: relative; } .demo { @@ -187,7 +190,7 @@ a:visited { color: #3d155f; } body, input, select { color: #d6d7d9; background-color: #141515; } input { border-color: #0c0d0e; } textarea, pre, code, .primitives tr td:first-child { color: #969698; background-color: #0c0d0e; } - textarea, pre, code, .kb { border-color: #040509; } + textarea, pre, code, .kb, .prfx { border-color: #040509; } .code, .codeCover { fill: #0c0d0e; stroke: #040509; } .codeCover { stroke: #0c0d0e; } code { border-color: #0c0d0e; background-color: #0f1011; } diff --git a/docs/try.html b/docs/try.html index 0faa3131..97919d20 100644 --- a/docs/try.html +++ b/docs/try.html @@ -9,11 +9,10 @@ li { margin:0.7em 0; } textarea { padding:0.2em; } .perm, .count { font-size:0.7em; margin:-0.2em 0.8em 0 0; } - .run, .doexplain, .perm, .prfx { float:right; margin-left:0.4em; } + .run, .doexplain, .perm { float:right; margin-left:0.4em; } .doexplain.selected { background:#777; } .count { float:left; opacity:0.6; } .rslt { border:none; background:none; min-height:8em; } - .prfx { width: 1.1em; } @@ -22,7 +21,6 @@
-
permalink @@ -32,7 +30,7 @@

Notes:

    -
  • You can type special characters with a backslash (customizable) prefix, as shown by hovering over the character bar above. Documentation links for primitives are here.
  • +
  • You can type special characters with a backslash prefix (customize at the right), as shown by hovering over the character bar above. Documentation links for primitives are here.
  • Any modifier with enter will execute, not just shift. The code window is vertically resizeable.
  • Support for function headers and multiple bodies is missing.
-- cgit v1.2.3