Shougo / neosnippet.vim

neo-snippet plugin
Other
1.12k stars 108 forks source link

Issue with long latex snippets and Vim(let):E745: Using a List as a Number #400

Closed 00krishna closed 6 years ago

00krishna commented 6 years ago

I created a stackoverflow question about this, but figured I should also open an issue in case this rises to that level. Sorry if I am covering established ground.

I am using Spacevim and created a Latex snippet for a document template. The template is rather long, but I include it below. I have not been able to identify the actual cause of the error, though when I try and expand the snippet I get a message:

 `[dein] Error occurred while executing hook: neosnippet.vim
 [dein] Vim(let):E745: Using a List as a Number
 Error detected while processing function <SNR>346 snippets_expand ...
 Line 11
 E15: invalid expression: 
 E15: invalid expression`

Normally I would not include a long snippet, and would instead share a minimal example. However, I can't really tell what combination of characters is actually causing the problem, since I am rather new to vim and such. Hence I figured I had better include the full snippet.

snippet lnotes
alias   lnotes
    \documentclass{book}
    \addtolength{\topmargin}{-.5in}
    \addtolength{\headsep}{.5in}
    \oddsidemargin=.5in
    \evensidemargin=.5in
    \textwidth=5.5in
    \usepackage{
    amsmath,% AMS basic math stuff
    amsthm,% AMS theorem defining stuff
    amsfonts,% defines the blackboard bold fonts for \Z, \R, etc
    longtable,% used to create the tcproof environment below
    verbatim,% allows for verbatim output, and also covering up stuff in comments
    xspace,% adds an extra space an the end of some commands
    multicol,% allows multicolumn output
    tikz,% creates the tikzpicture drawing environment
    charter,% changes the default font to charter
    framed,% used to color in the TIscreen environment below
    bm,
    mathrsfs}
    \usepackage{pifont}
    \usepackage[colorlinks,unicode]{hyperref}
    \newcommand{\R}{\mathbb{R}}
    \newcommand{\Q}{\mathbb{Q}}
    \newcommand{\Z}{\mathbb{Z}}
    \newcommand{\N}{\mathbb{N}}
    \newcommand{\Tau}{\bm{\mathcal{T}}}
    \newcommand{\Taup}{\bm{\mathcal{T}^{\prime}}}
    \newcommand{\Bp}{\mathscr{B}^{\prime}}
    \newcommand{\B}{\mathscr{B}}
    \newcommand{\CCp}{\mathscr{C}^{\prime}}
    \newcommand{\CC}{\mathscr{C}}
    \newcommand{\Ltop}{\R_{\mathscr{L}}}
    \newcommand{\Ktop}{\R_{\mathscr{K}}}
    \DeclareMathOperator{\lcm}{lcm}
    \newcommand{\cl}[1]{[#1]}
    \newcommand{\st}{\mid}
    \newcommand{\eq}{\stackrel{?}{=}}
    \newcommand{\divq}{\stackrel{?}{|}}
    \newcommand{\forwards}{\mbox{``$\Longrightarrow$''}\xspace}
    \newcommand{\backwards}{\mbox{``$\Longleftarrow$''}\xspace}
    \newcommand{\define}[1]{\textbf{#1}}
    \newcommand{\threeven}{pretty\xspace}
    \newcommand{\throd}{normal\xspace}
    \newcommand{\throve}{ugly\xspace}
    \DeclareMathSymbol{\nmid}{\mathrel}{AMSb}{"2D}
    \newcommand{\notdiv}{\nmid}
    \renewcommand{\tilde}{\widetilde}
    \renewcommand{\thefootnote}{\fnsymbol{footnote}}
    \def\endclass#1{\par\noindent\hrulefill\fbox{\tiny This is where we
        ended on #1}\hrulefill\vskip 5pt plus 1pt\par }
    \pagestyle{headings}
    \makeatletter
    \edef\today{%
      \the\year/\two@digits{\the\month}/\two@digits{\the\day}}
    \renewcommand{\@evenhead}{\emph{Ordinary Differential Equations - Arnold}
       (v. \today)
        \hfill Krishna Bhogaonker \hfill \thepage}
    \renewcommand{\@oddhead}{(version \today) \hfill \thepage}
    \makeatother
    \DeclareMathSymbol{\varnothing}{\mathord}{AMSb}{"3F}
    \renewcommand{\emptyset}{\varnothing}
    \colorlet{shadecolor}{gray!35}
    \newenvironment{TIscreen}
    {\begin{center}\tt
    \renewcommand{\in}[1]{##1\\}
    \newcommand{\out}[1]{\mbox{}\hfill##1\\}
    \begin{minipage}{2in}\begin{snugshade}}
    {\end{snugshade}\end{minipage}\end{center}}
    \newenvironment{tcproof}[1]
    {\smallskip\par\begin{longtable}{@{}p{.45\textwidth}p{.45\textwidth}@{}}
    \multicolumn{2}{@{}l}{\emph{#1}}\\[\smallskipamount]
    Assertion & Justification \endfirsthead
    Assertion & Justification \endhead
    \hline }
    {\end{longtable}\qed\smallskip\par}
    \newtheorem{lemma}{Lemma}[section]
    \newtheorem{theorem}[lemma]{Theorem}
    \newtheorem{cor}[lemma]{Corollary}
    \newtheorem*{scholium}{Scholium}
    \theoremstyle{definition}
    \newtheorem{definition}[lemma]{Definition}
    \newtheorem{example}[lemma]{Example}
    \newenvironment{comments}{}{}
    \makeatletter
      \define@key{hide}{scholium}[true]{\renewenvironment{scholium}{\comment}{\endcomment}}
      \define@key{hide}{proof}[true]{\renewenvironment{proof}{\comment}{\endcomment}}
      \define@key{hide}{lemma}[true]{\renewenvironment{lemma}{\comment}{\endcomment}}
      \define@key{hide}{comments}[true]{\renewenvironment{comments}{\comment}{\endcomment}}
      \define@key{hide}{cor}[true]{\renewenvironment{cor}{\comment}{\endcomment}}
      \define@key{hide}{definition}[true]{\renewenvironment{definition}{\comment}{\endcomment}}
      \define@key{hide}{example}[true]{\renewenvironment{example}{\comment}{\endcomment}}
      \define@key{hide}{theorem}[true]{\renewenvironment{theorem}{\comment}{\endcomment}}
    \newcommand{\HideEnvirons}[1]{\setkeys{hide}{#1}}
      \define@key{show}{scholium}[true]{\define@key{hide}{scholium}{}}
      \define@key{show}{proof}[true]{\define@key{hide}{proof}{}}
      \define@key{show}{lemma}[true]{\define@key{hide}{lemma}{}}
      \define@key{show}{comments}[true]{\define@key{hide}{comments}{}}
      \define@key{show}{cor}[true]{\define@key{hide}{cor}{}}
      \define@key{show}{definition}[true]{\define@key{hide}{definition}{}}
      \define@key{show}{example}[true]{\define@key{hide}{example}{}}
      \define@key{show}{theorem}[true]{\define@key{hide}{theorem}{}}
    \newcommand{\ShowEnvirons}[1]
    {\setkeys{show}{#1}\HideEnvirons{%
        comments,
        cor,
        definition,
        example,
        proof,
        theorem,
        lemma,
        scholium
      }}
    \makeatother
    \begin{document}
    \tableofcontents
    \newpage
    \chapter{Basic Concepts}
    ${0}
    \end{document}

I can't seem to understand what is causing this issue. I am not using an escaped character in the snippet, name, etc.

Shougo commented 6 years ago

Please update neosnippet. And you must substitute the backquotes.

    \newcommand{\forwards}{\mbox{````$\Longrightarrow$''}\xspace}
    \newcommand{\backwards}{\mbox{````$\Longleftarrow$''}\xspace}
00krishna commented 6 years ago

Okay great. This is working now. Thank you so much for your very quick response.

So just to clarify, the problem was just with using 4 backquotes instead of 2? If it is not too much trouble, could you explain? I just want to make sure I avoid this combination in the future. I read through the neosnippet documentation, and saw the material about escaping particular characters in some cases. But I did not see anything about the backquotes.

Shougo commented 6 years ago

So just to clarify, the problem was just with using 4 backquotes instead of 2? If it is not too much trouble, could you explain?

Because, neosnippet supports eval feature.

Vim has a built-in expression evaluation. You can also use this feature inside
of snippets if you use back ticks like in the example below. Here the "%:t"
gets expanded to the name of the current active file and the current time gets
inserted by expanding the output of the strftime command.

>
    snippet     header
       File: ${1:`expand('%:t')`}
       ${2:Created at: `strftime("%B %d, %Y")`}
<