Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "build",
"type": "PowerShell",
"request": "launch",
"script": "${workspaceRoot}/package.ps1",
"cwd": "${workspaceRoot}",
"args": ["-Local"]
},
],
"compounds": [

]
}
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"[javascript]": {

}
}
15 changes: 7 additions & 8 deletions bililiteRange.evim.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';
const { bililiteRange } = require('./bililiteRange.js');

(function(){
const editorKey = Symbol(); // marker


Expand Down Expand Up @@ -41,7 +40,7 @@ bililiteRange.prototype.evim = function (toolbarContainer, statusbar){
}
}
});

// A variation on VIM keys, in visual mode, as evim (every command starts with ctrl-o then goes back to insert mode)
this.listen('keydown', keymap(/ctrl-o (?:ctrl-)?[:;]/, evt => {
Promise.prompt(':', statusbar).
Expand Down Expand Up @@ -74,7 +73,7 @@ bililiteRange.prototype.evim = function (toolbarContainer, statusbar){
i: ['whole', false, undefined],
t: ['to', false, 'endbounds'],
};

const evim1 = RegExp (`ctrl-o ([${Object.keys(vimverbs).join('')}]) ([${Object.keys(vimobjects).join('')}])`);
const handler1 = keymap(evim1, evt => {
const match = evim1.exec(evt.keymapSequence);
Expand Down Expand Up @@ -104,9 +103,9 @@ bililiteRange.prototype.evim = function (toolbarContainer, statusbar){
rng.select().scrollIntoView();
});
this.listen('keydown', handler3);



this.ex('%%source .exrc');
this.initUndo(true); // attach the ctrl-z, ctrl-y handlers
};
Expand Down Expand Up @@ -152,4 +151,4 @@ function parseToolbarCommand(string){
return ret;
}

})();
module.exports = bililiteRange;
66 changes: 32 additions & 34 deletions bililiteRange.ex.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

(function(undefined){
const { bililiteRange } = require('./bililiteRange.js');

/*********************** the actual ex plugin *********************************/
bililiteRange.ex = {}; // namespace for exporting utility functions
Expand Down Expand Up @@ -45,7 +43,7 @@ bililiteRange.prototype.ex = function (commandstring = '', defaultaddress = '.')

data.directory ??= this.window.location.origin;
data.file ??= this.window.location.pathname; // if this is set to the empty string, then don't save anything.

addListener (this, 'visibilitychange', evt => {
if (document.visibilityState == 'hidden') preserve(this);
}, document);
Expand Down Expand Up @@ -83,7 +81,7 @@ bililiteRange.prototype.ex = function (commandstring = '', defaultaddress = '.')
let parsed = parseCommand(command, defaultaddress);
interpretAddresses(this, parsed.addresses, data);
parsed.command.call(this, parsed.parameter, parsed.variant);
}, this);
}, this);
this.dispatch({type: 'excommand', command: commandstring, range: this});
}catch(err){
this.data.stderr(err);
Expand All @@ -100,7 +98,7 @@ function commandCompletion(command){
if (commands[command]) return commands[command];
command = command.toLowerCase();
for (var trialCommand in commands){
if (trialCommand.substr(0,command.length) == command) return commands[trialCommand];
if (trialCommand.substring(0,command.length) == command) return commands[trialCommand];
}
throw new Error(command+" not defined");
})();
Expand All @@ -115,7 +113,7 @@ function splitCommands(commandLine, splitter = '|'){
var delims = /[/"]/; // regular expressions and strings
var escaper = /\\/;
for (var i = 0; i < commandLine.length; ++i){
if (commandLine.substr(i, splitter.length) == splitter){
if (commandLine.substring(i, splitter.length) == splitter){
commands.push (commandLine.slice(0, i));
commandLine = commandLine.slice(i+splitter.length);
i = -1; // restart the loop
Expand Down Expand Up @@ -162,7 +160,7 @@ const addressRE = new RegExp('^\\s*' + // allow whitespace at the beginning
);

// command names. Technically multiple >>> and <<< are legal, but we will treat them as parameters
const idRE = /^\s*([!=&~><]|[a-zA-Z]+)/;
const idRE = /^\s*([!=&~><]|[a-zA-Z]+)/;

function parseCommand(command, defaultaddress){
return {
Expand All @@ -171,7 +169,7 @@ function parseCommand(command, defaultaddress){
variant: parseVariant(),
parameter: parseParameter()
};

function parseAddresses(){
var addresses = [defaultaddress];
// basic addresses
Expand Down Expand Up @@ -351,7 +349,7 @@ function pushRegister(text, register){
}else{
// unnamed register is the delete stack
registers.unshift(text);
}
}
}

function popRegister (register){
Expand Down Expand Up @@ -390,7 +388,7 @@ function addListener (rng, ...handler){
function removeListeners (rng){
rng.element[exkey].forEach( handler => rng.dontlisten(...handler) );
}

/*********************** the actual editing commands *********************************/

// a command is a function (parameter {String}, variant {Boolean})
Expand All @@ -408,7 +406,7 @@ var commands = bililiteRange.ex.commands = {
},

c: 'change',

cd: 'directory',

change: function (parameter, variant){
Expand All @@ -420,7 +418,7 @@ var commands = bililiteRange.ex.commands = {
// the test is variant XOR autoindent. the !'s turn booleany values to boolean, then != means XOR
if (!variant != !this.data.autoindent) this.indent(indentation);
},

chdir: 'directory',

copy: function (parameter, variant){
Expand All @@ -447,9 +445,9 @@ var commands = bililiteRange.ex.commands = {
},

'delete': 'del',

dir: 'directory',

edit: function (parameter, variant){
if (this.data.confirm && this.data.savestatus == 'dirty' && !variant){
throw new Error (this.data.file + ' not saved. Use edit! to force reloading');
Expand Down Expand Up @@ -485,7 +483,7 @@ var commands = bililiteRange.ex.commands = {
const addedlines = this.all().split('\n').length - oldlines;
lines[1] += addedlines;
i += addedlines;
// note that this assumes the added lines are all before or immediately after the current line. If not, we will skip the wrong lines
// note that this assumes the added lines are all before or immediately after the current line. If not, we will skip the wrong lines
}
}
this.bounds(line).bounds('EOL'); // move to the end of the last modified line
Expand Down Expand Up @@ -522,7 +520,7 @@ var commands = bililiteRange.ex.commands = {
k: 'mark',

m: 'move',

map: function (parameter, variant){
const parameters = splitCommands (parameter, ' ');
const lhs = string(parameters.shift());
Expand Down Expand Up @@ -556,7 +554,7 @@ var commands = bililiteRange.ex.commands = {
},

print: function() { this.select() },

preserve () { preserve(this) },

put: function (parameter, variant){
Expand All @@ -565,7 +563,7 @@ var commands = bililiteRange.ex.commands = {
ownline: true
}).bounds('endbounds');
},

quit (parameter, variant){
const data = this.data;
if (!variant && data.savestatus != 'clean' && data.confirm){
Expand All @@ -578,7 +576,7 @@ var commands = bililiteRange.ex.commands = {
data.marks = {};
this.window.dispatchEvent( new CustomEvent('quit', { detail: this.element }) );
},

read: function (parameter, variant){
if (variant) {
this.text(Function (parameter).call(this));
Expand All @@ -594,7 +592,7 @@ var commands = bililiteRange.ex.commands = {
);
}
},

recover () { recover(this) },

redo: function (parameter, variant){
Expand All @@ -603,7 +601,7 @@ var commands = bililiteRange.ex.commands = {
},

s: 'substitute',

sendkeys: function (parameter, variant){
this.sendkeys(parameter);
},
Expand Down Expand Up @@ -634,7 +632,7 @@ var commands = bililiteRange.ex.commands = {
},

shiftwidth: "tabsize",

source: function (parameter, variant){
if (!parameter) throw new Error ('No file named in source');
this.data.reader(parameter, this.data.directory).then( sourcefile => {
Expand All @@ -652,19 +650,19 @@ var commands = bililiteRange.ex.commands = {
if (re.source == '' && re.replacement == '') re = lastSubstitutionRE;
if (re.source == '') re.source = lastRE.source;
this.replace(re, string(re.replacement)).bounds('EOL');
lastSubstitutionRE = Object.assign({}, re); // clone, so
lastSubstitutionRE = Object.assign({}, re); // clone, so
},

sw: 'tabsize',

t: 'copy',

tabstop: 'tabsize',

transcribe: 'copy',

ts: 'tabsize',

unmap: function (parameter, variant){
this.dispatch ({type: 'map', detail: { command: 'unmap', variant, lhs: parameter }});
},
Expand All @@ -682,15 +680,15 @@ var commands = bililiteRange.ex.commands = {
},

v: 'notglobal',

version: function (parameter, variant){
this.data.stdout(this.element[exkey]);
},

wq: 'xit',

ws: 'wrapscan',

xit: function(parameter, variant){
writer(this, parameter).finally( ()=> {
if (variant || this.data.savestatus == 'clean'){
Expand All @@ -714,27 +712,27 @@ var commands = bililiteRange.ex.commands = {
let lines = this.lines();
this.data.stdout ('['+(lines[0] == lines[1] ? lines[0] : lines[0]+', '+lines[1])+']');
},

'&': 'substitute',

'~': function (parameter, variant){
lastSubstitutionRE.source = lastRE.source;
lastSubstitutionRE.flags = '';
commands.substitute.call (this, parameter, variant);
},

'>': function (parameter, variant){
parameter = parseInt(parameter);
if (isNaN(parameter) || parameter < 0) parameter = 1;
this.indent('\t'.repeat(parameter));
},

'<': function (parameter, variant){
parameter = parseInt(parameter);
if (isNaN(parameter) || parameter < 0) parameter = 1;
this.unindent(parameter, this.data.tabsize);
},

'!': function (parameter, variant){
// not a shell escape but a Javascript escape
Function (parameter).call(this);
Expand Down Expand Up @@ -809,4 +807,4 @@ createOption ('wrapscan');
createOption ('directory', '');
createOption ('file', 'document');

})();
module.exports = bililiteRange;
8 changes: 3 additions & 5 deletions bililiteRange.find.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
'use strict';

(function(bililiteRange){
const { bililiteRange } = require('./bililiteRange.js');

bililiteRange.createOption('dotall', {value: false});
bililiteRange.createOption('global', {value: false});
Expand Down Expand Up @@ -33,7 +31,7 @@ bililiteRange.prototype.replace = function (search, replace, flags = ''){
replaceprimitive (search, parseFlags(this, flags), this.all(), replace, this[0], this[1]),
{ inputType: 'insertReplacementText' }
);
}
}

bililiteRange.createOption ('word', {value: /\b/});
bililiteRange.createOption ('bigword', {value: /\s+/});
Expand Down Expand Up @@ -200,4 +198,4 @@ function replaceprimitive (search, flagobject, text, replace, from, to){
return text.replace (re, replace).slice(from, to-text.length || undefined);
}

})(bililiteRange);
module.exports = bililiteRange;
Loading