[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [AUCTeX] [PATCH] Add indentation for tabular environment

From: Tassilo Horn
Subject: Re: [AUCTeX] [PATCH] Add indentation for tabular environment
Date: Thu, 10 Oct 2013 11:36:01 +0200
User-agent: Gnus/5.130008 (Ma Gnus v0.8) Emacs/24.3.50 (gnu/linux)

Oleh <address@hidden> writes:

Hi Oleh,

> I wrote some indentation for the tabular environment.
> Let me know if it's alright.
> I attach a patch and a test.

I like that table formatting.  Nice!

As you might know, as official GNU project AUCTeX only incorporates code
from people that have assigned copyright to the FSF.  Are you Oleh
Krehel from Ukraine?  If so, then you have already done that.  If not,
are you willing to sign a CA?  Then I'll send you the request off-list.

> +(defun re-search-backward->column (str)
> +  (save-excursion
> +    (if (re-search-backward str nil t)
> +        (current-column)
> +      0)))

New functions/variable should always be namespace-prefixed.  But I don't
see why you need that function anyhow.  If the re-search-backward
doesn't find a match, then we're not in a table and calling
`LaTeX-indent-tabular' shouldn't have been called in the first place.

> +(defun LaTeX-indent-tabular ()
> +  (let ((beg-col (re-search-backward->column "\\\\begin{tabular}")))

It would be good if it would work with other tabular-like environments,
too.  Say tabular*, tabularx, tabulary, longtable, and the math
tabular-alikes array, align, eqnarray, cases, ...

You should be able to figure out the nearest surrounding tabular-like
environment with `LaTeX-current-environment'.

> +    (if (looking-at "\\\\end{tabular}")
> +        beg-col
> +      (+ 2
> +         (if (looking-at "\\\\\\\\")
> +             beg-col
> +           (let ((any-col (re-search-backward->column
> +                           "\\\\begin{tabular}\\|\\\\\\\\\\|&")))
> +             (if (equal "&" (match-string-no-properties 0))

Better use `string-equal' here.

> +                 any-col
> +               beg-col)))))))
> +
>  (provide 'latex)
>  ;;; latex.el ends here


reply via email to

[Prev in Thread] Current Thread [Next in Thread]