Dear all,
For what it's worth, I have put up together a while ago an alternative
function for `LaTeX-indent-tabular`. My biggest problem with the old
function was its insistence on indenting hanging ampersands as if they were
not hanging. It makes it impossible to break long lines, since AUCTeX then
wants to indent the new line to the last column of the previous one.
The function is attached, it does not call
`LaTeX-hanging-ampersand-position`.
I cannot guarantee that it always does the right thing, but so far it
matched all my expectations.
Best,
Thibaut
Le dim. 2 août 2020 à 09:28, Jean-Jacques Rétorré <[email protected]> a
écrit :
> sam. 01 août 2020, François Patte <[email protected]>
> disait :
>
> > Le 01/08/2020 à 19:24, Jean-Jacques Rétorré a écrit :
> >> sam. 01 août 2020, François Patte <[email protected]>
> disait :
> >>
> >>> Bonjour,
> >>>
> >>> I am wondering if it is possible to disable automatic indentation in
> >>> table like environments (tabular, longtable, etc.).
> >>>
> >>> In a complex table, the result of automatic indentation is awfull and
> >>> makes the able unreadable in emacs, so it is difficult to find
> errors...
> >>>
> >>> Thank you.
> >>>
> >>> PS. If possible give me some details on how to proceed, I don't know
> >>> anything of lisp language (shame on me!)
> >>
> >> You can customize the variable 'LaTeX-indent-environment-list
> >> and disable the functions you don't want to be active for the
> >> ennvironments you want to customize
> >>
> >> M-x customize-variable ...
> >
> > Thank you for answering. I edited the LaTeX-indent-environment-list and
> > found that only verbatim and verbatim* environments were set to :
> > "current indentation".
> >
> > The others (equation, equation*, picture, tabbing, table, table*) are
> > set to : "ignore".
> >
> > Do I have to add longtable for instance and how to do this?
> >
>
> I don't have this configuration, yet I haven't changed the default
> configuration.
> Value:
> (("verbatim" current-indentation)
> ("verbatim *" current-indentation)
> ("filecontents" current-indentation)
> ("filecontents *" current-indentation)
> ("tabular" LaTeX-indent-tabular)
> ("tabular *" LaTeX-indent-tabular)
> ("align" LaTeX-indent-tabular)
> ("align *" LaTeX-indent-tabular)
> ("array" LaTeX-indent-tabular)
> ("eqnarray" LaTeX-indent-tabular)
> ("eqnarray *" LaTeX-indent-tabular)
> ("displaymath")
> ("equation")
> ("equation*")
> ("picture")
> ("tabbing"))
>
> Indentation in an environment is controlled by a function. I find that
> the LaTeX-indent-tabular function is not very satisfactory in some
> cases. The solution would be to write a function that does what you
> want, but that's Emacs-lisp code. It is one of the easiest computer
> languages to learn and use that I know ...
>
> --
> JJR.
>
>
>
(defun LaTeX-indent-tabular ()
"Return indent column for the current tabular-like line."
(let* ((beg-pos (car (LaTeX-env-beginning-pos-col)))
(beg-col
(save-excursion
(goto-char beg-pos)
(beginning-of-line)
(+ (current-indentation)
(LaTeX-indent-level-count)
(- 2))))) ; Was hard coded elsewhere before me...
(let ((tabular-like-end-regex
(format "\\\\end{%s}"
(regexp-opt
(let (out)
(mapc (lambda (x)
(when (eq (cadr x) 'LaTeX-indent-tabular)
(push (car x) out)))
LaTeX-indent-environment-list)
out)))))
(cond ((looking-at tabular-like-end-regex)
beg-col)
((looking-at "\\\\\\\\")
(+ 4 beg-col))
((looking-at "&")
(+ 4 beg-col)) ;; If I put a newline it's that the line was too long
(t
(+ 2
(if (and (save-excursion
(re-search-backward "\\\\\\\\\\|[^\\]&" beg-pos t))
(= ?& (char-before (match-end 0))))
;; If a new line is inserted it probably means
;; that the line was too long
(+ 2 beg-col)
beg-col)))))))