summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/content/commands.js14
-rw-r--r--common/content/completion.js13
-rw-r--r--common/content/editor.js123
3 files changed, 82 insertions, 68 deletions
diff --git a/common/content/commands.js b/common/content/commands.js
index f0f053cc..38d1ee0c 100644
--- a/common/content/commands.js
+++ b/common/content/commands.js
@@ -743,13 +743,13 @@ function Commands() //{{{
// TODO: offer completion.ex?
var completeOptionMap = {
- altstyle: "alternateStyleSheet", bookmark: "bookmark",
- buffer: "buffer", color: "colorScheme", command: "command",
- dialog: "dialog", dir: "directory", environment: "environment",
- event: "autocmdEvent", file: "file", help: "help",
- highlight: "highlightGroup", javascript: "javascript", macro: "macro",
- mapping: "userMapping", menu: "menuItem", option: "option",
- preference: "preference", search: "search",
+ abbreviation: "abbreviation", altstyle: "alternateStyleSheet",
+ bookmark: "bookmark", buffer: "buffer", color: "colorScheme",
+ command: "command", dialog: "dialog", dir: "directory",
+ environment: "environment", event: "autocmdEvent", file: "file",
+ help: "help", highlight: "highlightGroup", javascript: "javascript",
+ macro: "macro", mapping: "userMapping", menu: "menuItem",
+ option: "option", preference: "preference", search: "search",
shellcmd: "shellCommand", sidebar: "sidebar", url: "url",
usercommand: "userCommand"
};
diff --git a/common/content/completion.js b/common/content/completion.js
index 849530dc..7dfa3b59 100644
--- a/common/content/completion.js
+++ b/common/content/completion.js
@@ -517,7 +517,7 @@ CompletionContext.prototype = {
liberator.threadYield(false, interruptable);
return this.incomplete;
}
-}
+};
function Completion() //{{{
{
@@ -1161,6 +1161,15 @@ function Completion() //{{{
////////////////////// COMPLETION TYPES ////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{
+ abbreviation: function abbreviation(context, args, mode)
+ {
+ if (args.completeArg == 0)
+ {
+ let abbreviations = editor.getAbbreviations(mode);
+ context.completions = [[lhs, ""] for ([, [, lhs,]] in Iterator(abbreviations))];
+ }
+ },
+
alternateStyleSheet: function alternateStylesheet(context)
{
context.title = ["Stylesheet", "Location"];
@@ -1683,7 +1692,7 @@ function Completion() //{{{
context.completions = maps;
}
}
- // }}}
+ //}}}
};
const UrlCompleter = new Struct("name", "description", "completer");
diff --git a/common/content/editor.js b/common/content/editor.js
index 79eba5dc..c9416254 100644
--- a/common/content/editor.js
+++ b/common/content/editor.js
@@ -166,6 +166,7 @@ function Editor() //{{{
editor.listAbbreviations(mode, lhs || "");
},
{
+ completer: function (context, args) completion.abbreviation(context, args, mode),
literal: 1,
serial: function () [
{
@@ -183,6 +184,7 @@ function Editor() //{{{
function (args) { editor.removeAbbreviation(mode, args.literalArg); },
{
argCount: "1",
+ completer: function (context, args) completion.abbreviation(context, args, mode),
literal: 0
});
@@ -907,33 +909,6 @@ function Editor() //{{{
// Abbreviations {{{
- // filter is i, c or "!" (insert or command abbreviations or both)
- // ! -> list all, on c or i ! matches too
- listAbbreviations: function (filter, lhs)
- {
- let searchFilter = (filter == "!") ? "!ci" : filter + "!";
- let list = [[mode, lhs, rhs] for ([lhs, [mode, rhs]] in abbrevs()) if (searchFilter.indexOf(mode) >= 0)];
-
- if (lhs)
- list = list.filter(function (abbrev) abbrev[1].indexOf(lhs) == 0);
-
- if (!list.length)
- {
- liberator.echomsg("No abbreviations found");
- }
- else if (list.length == 1)
- {
- let [mode, lhs, rhs] = list[0];
-
- liberator.echo(mode + " " + lhs + " " + rhs, commandline.FORCE_SINGLELINE); // 2 spaces, 3 spaces
- }
- else
- {
- list = template.tabular(["", "LHS", "RHS"], [], list);
- commandline.echo(list, commandline.HL_NORMAL, commandline.FORCE_MULTILINE);
- }
- },
-
// NOTE: I think this comment block is trying to say something but no
// one is listening. In space, no one can hear you scream. --djk
//
@@ -1019,6 +994,68 @@ function Editor() //{{{
abbreviations[lhs][0] = [filter, rhs];
},
+ expandAbbreviation: function (filter) // try to find an candidate and replace accordingly
+ {
+ var textbox = getEditor();
+ if (!textbox)
+ return;
+ var text = textbox.value;
+ var currStart = textbox.selectionStart;
+ var currEnd = textbox.selectionEnd;
+ var foundWord = text.substring(0, currStart).replace(/^(.|\n)*?(\S+)$/m, "$2"); // get last word \b word boundary
+ if (!foundWord)
+ return true;
+
+ for (let lhs in abbreviations)
+ {
+ for (let i = 0; i < abbreviations[lhs].length; i++)
+ {
+ if (lhs == foundWord && (abbreviations[lhs][i][0] == filter || abbreviations[lhs][i][0] == "!"))
+ {
+ // if found, replace accordingly
+ var len = foundWord.length;
+ var abbrText = abbreviations[lhs][i][1];
+ text = text.substring(0, currStart - len) + abbrText + text.substring(currStart);
+ textbox.value = text;
+ textbox.selectionStart = currStart - len + abbrText.length;
+ textbox.selectionEnd = currEnd - len + abbrText.length;
+ break;
+ }
+ }
+ }
+ return true;
+ },
+
+ // filter is i, c or "!" (insert or command abbreviations or both)
+ // ! -> list all, on c or i ! matches too
+ getAbbreviations: function (filter, lhs)
+ {
+ let searchFilter = (filter == "!") ? "!ci" : filter + "!";
+ return list = [[mode, left, right] for ([left, [mode, right]] in abbrevs())
+ if (searchFilter.indexOf(mode) >= 0 && left.indexOf(lhs || "") == 0)];
+ },
+
+ listAbbreviations: function (filter, lhs)
+ {
+ let list = this.getAbbreviations(filter, lhs);
+
+ if (!list.length)
+ {
+ liberator.echomsg("No abbreviations found");
+ }
+ else if (list.length == 1)
+ {
+ let [mode, lhs, rhs] = list[0];
+
+ liberator.echo(mode + " " + lhs + " " + rhs, commandline.FORCE_SINGLELINE); // 2 spaces, 3 spaces
+ }
+ else
+ {
+ list = template.tabular(["", "LHS", "RHS"], [], list);
+ commandline.echo(list, commandline.HL_NORMAL, commandline.FORCE_MULTILINE);
+ }
+ },
+
removeAbbreviation: function (filter, lhs)
{
if (!lhs)
@@ -1082,38 +1119,6 @@ function Editor() //{{{
}
}
}
- },
-
- expandAbbreviation: function (filter) // try to find an candidate and replace accordingly
- {
- var textbox = getEditor();
- if (!textbox)
- return;
- var text = textbox.value;
- var currStart = textbox.selectionStart;
- var currEnd = textbox.selectionEnd;
- var foundWord = text.substring(0, currStart).replace(/^(.|\n)*?(\S+)$/m, "$2"); // get last word \b word boundary
- if (!foundWord)
- return true;
-
- for (let lhs in abbreviations)
- {
- for (let i = 0; i < abbreviations[lhs].length; i++)
- {
- if (lhs == foundWord && (abbreviations[lhs][i][0] == filter || abbreviations[lhs][i][0] == "!"))
- {
- // if found, replace accordingly
- var len = foundWord.length;
- var abbrText = abbreviations[lhs][i][1];
- text = text.substring(0, currStart - len) + abbrText + text.substring(currStart);
- textbox.value = text;
- textbox.selectionStart = currStart - len + abbrText.length;
- textbox.selectionEnd = currEnd - len + abbrText.length;
- break;
- }
- }
- }
- return true;
}
//}}}
};