dbmrq / vim-bucky

:leaves: Ventilated prose
8 stars 1 forks source link

Ignore lines in certain environments or between special comment markers #5

Open kiryph opened 6 years ago

kiryph commented 6 years ago

List of environments to be ignored

There are many ways to embed different type of source code into a texfile. A few examples are

They are typically content of a specific environment. Obviously, a list of these specific environments should be customisable since there are too many possibilities to add all of them to vim-bucky itself. I personally would also add math environments where I use alignment tools such as vim-easy-align, tabular.vim or Align by Dr.Chip (e.g. systems of equations). Also tables are a likely candidate that somebody wants to format them with a different tool than by vim-bucky.

The tool neoformat allows to use a different formatter for a visual selection than the default one for the file.

Ignore lines between special marker

A second feature request is to add support for manual markers to ignore lines in the code.

Tools such as astyle and uncrustify support the lines // *INDENT-OFF* and // *INDENT-ON*. clang-format uses // clang-format off/on and yapf (python) # yapf: disable/enable. I would prefer a less tool specific marker such as // *INDENT-OFF* even though indent-off means more than just disabling indentation but all formatting at all.

dbmrq commented 6 years ago

Vim's own ftplugin has a variable for environments that shouldn't be indented:

let g:tex_noindent_env = 'document\|verbatim\|lstlisting'

So I had Bucky just use that same variable. Add the environments you want to ignore to that string separated by \|. E.g.: 'document|verbatim|lstlisting|filecontents'.

As for the special marker, I just added that option with the last commit. Use % bucky: off and % bucky: on around the code you want to ignore. :)

kiryph commented 6 years ago

Great! Thanks for adding the marker % bucky: off/on and taking the variable g:tex_noindent_env into account.

The file $VIMRUNTIME/indent/tex.vim should put its documentation where other indent settings are described in vim help: e.g. for vim files one can find it with :h ft-vim-indent. Similarly I would expect that these variables (g:tex_noindent_env, ...) can be found under :h ft-tex-indent. Unfortunately, it looks like the file $VIMRUNTIME/indent/tex.vim is unmaintained.

Another question: comment after in-sentence equation

I have added to myvimrc:

" ft-tex-indent
" only in-source documentation under `:e $VIMRUNTIME/indent/tex.vim`
let g:tex_noindent_env = 'document\|verbatim\|lstlisting\|subequations'

I have following sentence with an equation in two versions where I have not yet decided which one comes into the final manuscript:

I have formatted it with gq and the equation manually:

xxx xxx xxxxxxxxxxxx xxxxx xxx xxxxxxxxxxxx xxxxxxxx xx xxx xxxxxxxxxxxxx xxxx
  xxx xxxxxxxxxx xxxxx xx xxx xxxxxxx xxxxxxxxxx
  \begin{subequations}
    \mydoubleequation{eq:general_hooke}{eq:general_hooke_inv}
      {\gls{stress_comp}_{ij} &= \gls{stiffness_comp}_{ijkl}
      \gls{strain_comp}_{kl},} {\gls{strain_comp}_{ij} &=
      \gls{compliance_comp}_{ijkl} \gls{stress_comp}_{kl}}
      \label[pluralequation]{eqn:general_hooke}
  \end{subequations}
  % Index-free notation:
% \begin{subequations}
%   \mydoubleequation{eq:general_hooke_direct}{eq:general_hooke_inv_direct}
%   {\gls{stress} &= \gls{stiffness}: \gls{strain},} {\gls{strain} &=
%   \gls{compliance}: \gls{stress}}
%   \label[pluralequation]{eqn:general_hooke_direct}
% \end{subequations}
xxxx xxx xxxxxxxxx xxxxxxxxxxxx xxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxx xxx
  xxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxx xxxxxxx
  xxx xxxxxxxxxxxxxxxx xxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxx xxxxxxxxx
  xxxxxxxxxxxx xxxxxxx xxxxxxxxxxxxxxxxxxxx xxxxxxx xxxxxxx xxxx xxx xx xxx
  xxxxxxx xxxxxxxxx xxx xxx xxx xxxxx xxxxxxxxx xxxx xxx xxxxxxxx xxxxxxx xx x
  xxxxxx xxxxxxxxxxxxxxxxx x xxxxxx xxxxxxxxx xxxxxx xxxxxxxx xx xxxxxxxxxx
  xxxxxx xxxxx xxxxxxxxxxxx xxxxxxxx xxx xxxxxxxxxx xxxxxxxx xxx
  xxxxxxxxxxxxxxxxxxxxxxxxxxx.

% vim: tw=80

However, I would expect that this would be formatted as:

xxx xxx xxxxxxxxxxxx xxxxx xxx xxxxxxxxxxxx xxxxxxxx xx xxx xxxxxxxxxxxxx xxxx
  xxx xxxxxxxxxx xxxxx xx xxx xxxxxxx xxxxxxxxxx
  \begin{subequations}
    \mydoubleequation{eq:general_hooke}{eq:general_hooke_inv}
      {\gls{stress_comp}_{ij} &= \gls{stiffness_comp}_{ijkl}
      \gls{strain_comp}_{kl},} {\gls{strain_comp}_{ij} &=
      \gls{compliance_comp}_{ijkl} \gls{stress_comp}_{kl}}
      \label[pluralequation]{eqn:general_hooke}
  \end{subequations}
  % Index-free notation:
  % \begin{subequations}
  %   \mydoubleequation{eq:general_hooke_direct}{eq:general_hooke_inv_direct}
  %     {\gls{stress} &= \gls{stiffness}: \gls{strain},}
  %     {\gls{strain} &= \gls{compliance}: \gls{stress}}
  %     \label[pluralequation]{eqn:general_hooke_direct}
  % \end{subequations}
  xxxx xxx xxxxxxxxx xxxxxxxxxxxx xxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxx xxx
  xxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxx xxxxxxx
  xxx xxxxxxxxxxxxxxxx xxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxx xxxxxxxxx
  xxxxxxxxxxxx xxxxxxx xxxxxxxxxxxxxxxxxxxx xxxxxxx xxxxxxx xxxx xxx xx xxx
  xxxxxxx xxxxxxxxx xxx xxx xxx xxxxx xxxxxxxxx xxxx xxx xxxxxxxx xxxxxxx xx x
  xxxxxx xxxxxxxxxxxxxxxxx x xxxxxx xxxxxxxxx xxxxxx xxxxxxxx xx xxxxxxxxxx
  xxxxxx xxxxx xxxxxxxxxxxx xxxxxxxx xxx xxxxxxxxxx xxxxxxxx xxx
  xxxxxxxxxxxxxxxxxxxxxxxxxxx.
kiryph commented 6 years ago

Also disabling vim-bucky with your new marker seems weird:

xxx xxx xxxxxxxxxxxx xxxxx xxx xxxxxxxxxxxx xxxxxxxx xx xxx xxxxxxxxxxxxx xxxx
  xxx xxxxxxxxxx xxxxx xx xxx xxxxxxx xxxxxxxxxx
  % bucky: off
  \begin{subequations}
    \mydoubleequation{eq:general_hooke}{eq:general_hooke_inv}
      {\gls{stress_comp}_{ij} &= \gls{stiffness_comp}_{ijkl}
      \gls{strain_comp}_{kl},} {\gls{strain_comp}_{ij} &=
      \gls{compliance_comp}_{ijkl} \gls{stress_comp}_{kl}}
      \label[pluralequation]{eqn:general_hooke}
  \end{subequations}
    % Index-free notation:
  % \begin{subequations}
  %   \mydoubleequation{eq:general_hooke_direct}{eq:general_hooke_inv_direct}
  %     {\gls{stress} &= \gls{stiffness}: \gls{strain},}
  %     {\gls{strain} &= \gls{compliance}: \gls{stress}}
  %     \label[pluralequation]{eqn:general_hooke_direct}
  % \end{subequations}
    xxxx xxx xxxxxxxxx xxxxxxxxxxxx xxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxx xxx
  xxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxx xxxxxxx
  xxx xxxxxxxxxxxxxxxx xxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxx xxxxxxxxx
  xxxxxxxxxxxx xxxxxxx xxxxxxxxxxxxxxxxxxxx xxxxxxx xxxxxxx xxxx xxx xx xxx
  xxxxxxx xxxxxxxxx xxx xxx xxx xxxxx xxxxxxxxx xxxx xxx xxxxxxxx xxxxxxx xx x
  xxxxxx xxxxxxxxxxxxxxxxx x xxxxxx xxxxxxxxx xxxxxx xxxxxxxx xx xxxxxxxxxx
  xxxxxx xxxxx xxxxxxxxxxxx xxxxxxxx xxx xxxxxxxxxx xxxxxxxx xxx
  xxxxxxxxxxxxxxxxxxxxxxxxxxx.
  % bucky: on

% vim: tw=80

Two lines are still indented: the one containing % Index-free notation: and the first one after the comment block.

dbmrq commented 6 years ago

You're right, that does seem weird. I'm very busy these next few days, but I'll look into it as soon as I can.