|
|
@@ -1,88 +1,14 @@
|
|
|
define [
|
|
|
- "./package_definitions"
|
|
|
- ], (packageCommandMappings) ->
|
|
|
- noArgumentCommands = [
|
|
|
- 'item', 'hline', 'lipsum', 'centering', 'noindent', 'textwidth', 'draw',
|
|
|
- 'maketitle', 'newpage', 'verb', 'bibliography', 'hfill', 'par',
|
|
|
- 'in', 'sum', 'cdot', 'ldots', 'linewidth', 'left', 'right', 'today',
|
|
|
- 'clearpage', 'newline', 'endinput', 'tableofcontents', 'vfill',
|
|
|
- 'bigskip', 'fill', 'cleardoublepage', 'infty', 'leq', 'geq', 'times',
|
|
|
- 'alpha', 'beta', 'gamma', 'delta', 'epsilon', 'varepsilon', 'zeta',
|
|
|
- 'eta', 'theta', 'vartheta', 'iota', 'kappa', 'lambda', 'mu', 'nu', 'xi',
|
|
|
- 'pi', 'varpi', 'rho', 'varrho', 'sigma', 'varsigma', 'tau', 'upsilon',
|
|
|
- 'phi', 'varphi', 'chi', 'psi', 'omega', 'Gamma', 'Delta', 'Theta',
|
|
|
- 'Lambda', 'Xi', 'Pi', 'Sigma', 'Upsilon', 'Phi', 'Psi', 'Omega'
|
|
|
- ]
|
|
|
- singleArgumentCommands = [
|
|
|
- 'chapter', 'usepackage', 'section', 'label', 'textbf', 'subsection',
|
|
|
- 'vspace', 'cite', 'textit', 'documentclass', 'includegraphics', 'input',
|
|
|
- 'emph','caption', 'ref', 'title', 'author', 'texttt', 'include',
|
|
|
- 'hspace', 'bibitem', 'url', 'large', 'subsubsection', 'textsc', 'date',
|
|
|
- 'footnote', 'small', 'thanks', 'underline', 'graphicspath', 'pageref',
|
|
|
- 'section*', 'subsection*', 'subsubsection*', 'sqrt', 'text',
|
|
|
- 'normalsize', 'footnotesize', 'Large', 'paragraph', 'pagestyle',
|
|
|
- 'thispagestyle', 'bibliographystyle', 'hat'
|
|
|
- ]
|
|
|
- doubleArgumentCommands = [
|
|
|
- 'newcommand', 'frac', 'dfrac', 'renewcommand', 'setlength', 'href',
|
|
|
- 'newtheorem'
|
|
|
- ]
|
|
|
- tripleArgumentCommands = [
|
|
|
- 'addcontentsline', 'newacronym', 'multicolumn'
|
|
|
- ]
|
|
|
- special = ['LaTeX', 'TeX']
|
|
|
-
|
|
|
- rawCommands = [].concat(
|
|
|
- noArgumentCommands,
|
|
|
- singleArgumentCommands,
|
|
|
- doubleArgumentCommands,
|
|
|
- tripleArgumentCommands,
|
|
|
- special
|
|
|
- )
|
|
|
-
|
|
|
- noArgumentCommands = for cmd in noArgumentCommands
|
|
|
- {
|
|
|
- caption: "\\#{cmd}"
|
|
|
- snippet: "\\#{cmd}"
|
|
|
- meta: "cmd"
|
|
|
- }
|
|
|
- singleArgumentCommands = for cmd in singleArgumentCommands
|
|
|
- {
|
|
|
- caption: "\\#{cmd}{}"
|
|
|
- snippet: "\\#{cmd}{$1}"
|
|
|
- meta: "cmd"
|
|
|
- }
|
|
|
- doubleArgumentCommands = for cmd in doubleArgumentCommands
|
|
|
- {
|
|
|
- caption: "\\#{cmd}{}{}"
|
|
|
- snippet: "\\#{cmd}{$1}{$2}"
|
|
|
- meta: "cmd"
|
|
|
- }
|
|
|
- tripleArgumentCommands = for cmd in tripleArgumentCommands
|
|
|
- {
|
|
|
- caption: "\\#{cmd}{}{}{}"
|
|
|
- snippet: "\\#{cmd}{$1}{$2}{$3}"
|
|
|
- meta: "cmd"
|
|
|
- }
|
|
|
- special = for cmd in special
|
|
|
- {
|
|
|
- caption: "\\#{cmd}{}"
|
|
|
- snippet: "\\#{cmd}{}"
|
|
|
- meta: "cmd"
|
|
|
- }
|
|
|
-
|
|
|
- staticCommands = [].concat(
|
|
|
- noArgumentCommands,
|
|
|
- singleArgumentCommands,
|
|
|
- doubleArgumentCommands,
|
|
|
- tripleArgumentCommands,
|
|
|
- special
|
|
|
- )
|
|
|
-
|
|
|
- # packageCommandMappings = {
|
|
|
- # amsmath: ['holyshititworks', 'mathematics']
|
|
|
- # natbib: ['somebibliographystuff']
|
|
|
- # }
|
|
|
+ "./top_hundred_snippets",
|
|
|
+ "./package_definition_snippets"
|
|
|
+], (topHundred, packageCommandMappings) ->
|
|
|
+
|
|
|
+ rawCommands = Object.keys topHundred
|
|
|
+
|
|
|
+ commandSnippets = []
|
|
|
+ for cmd, snippets of topHundred
|
|
|
+ for snippet in snippets
|
|
|
+ commandSnippets.push snippet
|
|
|
|
|
|
class Parser
|
|
|
constructor: (@doc, @prefix) ->
|
|
|
@@ -136,10 +62,10 @@ define [
|
|
|
return realCommands
|
|
|
|
|
|
# Ignore single letter commands since auto complete is moot then.
|
|
|
- commandRegex: /\\([a-zA-Z][a-zA-Z]+)/
|
|
|
+ commandRegex: /\\([a-zA-Z]{2,})/
|
|
|
|
|
|
nextCommand: () ->
|
|
|
- i = @doc.search(@commandRegex)
|
|
|
+ i = @doc.search @commandRegex
|
|
|
if i == -1
|
|
|
return false
|
|
|
else
|
|
|
@@ -179,14 +105,21 @@ define [
|
|
|
packages = @metadataManager.getAllPackages()
|
|
|
packageCommands = []
|
|
|
for pkg in packages
|
|
|
- if packageCommandMappings[pkg]?
|
|
|
- for cmd in packageCommandMappings[pkg]
|
|
|
- packageCommands.push {
|
|
|
- caption: "\\#{cmd}"
|
|
|
- snippet: "\\#{cmd}"
|
|
|
- meta: "#{pkg}-cmd"
|
|
|
- score: 60
|
|
|
- }
|
|
|
+ commands = packageCommandMappings[pkg]
|
|
|
+ if commands?
|
|
|
+ for command, snippets of commands
|
|
|
+ if command not in rawCommands
|
|
|
+ for snippet in snippets
|
|
|
+ packageCommands.push snippet
|
|
|
+ # for pkg in packages
|
|
|
+ # if packageCommandMappings[pkg]?
|
|
|
+ # for cmd in packageCommandMappings[pkg]
|
|
|
+ # packageCommands.push {
|
|
|
+ # caption: "\\#{cmd}"
|
|
|
+ # snippet: "\\#{cmd}"
|
|
|
+ # meta: "#{pkg}-cmd"
|
|
|
+ # score: 60
|
|
|
+ # }
|
|
|
|
|
|
doc = session.getValue()
|
|
|
parser = new Parser(doc, prefix)
|
|
|
@@ -212,7 +145,7 @@ define [
|
|
|
meta: "cmd"
|
|
|
score: score
|
|
|
}
|
|
|
- completions = completions.concat staticCommands, packageCommands
|
|
|
+ completions = completions.concat commandSnippets, packageCommands
|
|
|
|
|
|
callback null, completions
|
|
|
|