GNU bug report logs - #26032
Indenting in tabulars without &

Previous Next

Package: auctex;

Reported by: Arash Esbati <arash <at> gnu.org>

Date: Wed, 8 Mar 2017 19:45:02 UTC

Severity: normal

Done: Arash Esbati <arash <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 26032 in the body.
You can then email your comments to 26032 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-auctex <at> gnu.org:
bug#26032; Package auctex. (Wed, 08 Mar 2017 19:45:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Arash Esbati <arash <at> gnu.org>:
New bug report received and forwarded. Copy sent to bug-auctex <at> gnu.org. (Wed, 08 Mar 2017 19:45:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Arash Esbati <arash <at> gnu.org>
To: auctex-bugs <bug-auctex <at> gnu.org>
Subject: Indenting in tabulars without &
Date: Wed, 08 Mar 2017 20:43:15 +0100
Hi all,

please consider the following 2 examples and how the column separator is
filled, both do not work as expected:

--8<---------------cut here---------------start------------->8---
\documentclass{article}

\begin{document}

\begin{tabular}{ll}
  \multicolumn{2}{c}{These lines will} `M-RET here'
\end{tabular}
results in:
\begin{tabular}{ll}
  \multicolumn{2}{c}{These lines will} `M-RET here' \\
&
\end{tabular}

And
\begin{tabular}{ll}
  \multicolumn{2}{c}{These lines will}  \\
  & `C-c C-q C-e here'
\end{tabular}
results in:
\begin{tabular}{ll}
  \multicolumn{2}{c}{These lines will}  \\
& `C-c C-q C-e here'
\end{tabular}
\end{document}
--8<---------------cut here---------------end--------------->8---

The issue is in `LaTeX-hanging-ampersand-position' where
(- (current-column) 1) returns a negative value if no "[^\\]&" is found:

--8<---------------cut here---------------start------------->8---
(defun LaTeX-hanging-ampersand-position ()
  "Return indent column for a hanging ampersand (i.e. ^\\s-*&)."
  (destructuring-bind (beg-pos . beg-col)
      (LaTeX-env-beginning-pos-col)
    (let* ((cur-pos (point)))
      (save-excursion
        (if (re-search-backward "\\\\\\\\" beg-pos t)
            (let ((cur-idx (TeX-how-many "[^\\]&" (point) cur-pos)))
              (goto-char beg-pos)
              (re-search-forward "[^\\]&" cur-pos t (+ 1 cur-idx))
              (- (current-column) 1))
          (+ 2 beg-col))))))
--8<---------------cut here---------------end--------------->8---

My suggest to guard (- (current-column) 1) with a (wholenump ...) and
return (+ 2 beg-col) as fallback if the test is not true:

--8<---------------cut here---------------start------------->8---
(defun LaTeX-hanging-ampersand-position ()
  "Return indent column for a hanging ampersand (i.e. ^\\s-*&)."
  (destructuring-bind (beg-pos . beg-col)
      (LaTeX-env-beginning-pos-col)
    (let* ((cur-pos (point)))
      (save-excursion
        (if (re-search-backward "\\\\\\\\" beg-pos t)
            (let ((cur-idx (TeX-how-many "[^\\]&" (point) cur-pos)))
              (goto-char beg-pos)
              (re-search-forward "[^\\]&" cur-pos t (+ 1 cur-idx))
	      (if (wholenump (- (current-column) 1))
		  (- (current-column) 1)
		(+ 2 beg-col)))
          (+ 2 beg-col))))))
--8<---------------cut here---------------end--------------->8---

Any comments welcome.

Best, Arash




Information forwarded to bug-auctex <at> gnu.org:
bug#26032; Package auctex. (Wed, 08 Mar 2017 20:21:01 GMT) Full text and rfc822 format available.

Message #8 received at 26032 <at> debbugs.gnu.org (full text, mbox):

From: Mosè Giordano <mose <at> gnu.org>
To: Arash Esbati <arash <at> gnu.org>
Cc: 26032 <at> debbugs.gnu.org
Subject: Re: bug#26032: Indenting in tabulars without &
Date: Wed, 8 Mar 2017 21:19:52 +0100
Hi Arash,

have you been writing many tables lately? ;-)

2017-03-08 20:43 GMT+01:00 Arash Esbati <arash <at> gnu.org>:
> My suggest to guard (- (current-column) 1) with a (wholenump ...) and
> return (+ 2 beg-col) as fallback if the test is not true:

Yeah, a fallback option in case we get non-sense result is always
useful.  Alas, `wholenump' is not available in XEmacs.  Remember also
the test!

Bye,
Mosè




Information forwarded to bug-auctex <at> gnu.org:
bug#26032; Package auctex. (Wed, 08 Mar 2017 20:59:02 GMT) Full text and rfc822 format available.

Message #11 received at 26032 <at> debbugs.gnu.org (full text, mbox):

From: Arash Esbati <arash <at> gnu.org>
To: Mosè Giordano <mose <at> gnu.org>
Cc: 26032 <at> debbugs.gnu.org
Subject: Re: bug#26032: Indenting in tabulars without &
Date: Wed, 08 Mar 2017 21:57:42 +0100
Hi Mosè,

Mosè Giordano <mose <at> gnu.org> writes:

>> 2017-03-08 20:43 GMT+01:00 Arash Esbati <arash <at> gnu.org>:
>>
> have you been writing many tables lately? ;-)

Tough luck, really! I did exactly one table, with side effects ;-)

>> My suggest to guard (- (current-column) 1) with a (wholenump ...) and
>> return (+ 2 beg-col) as fallback if the test is not true:
>
> Yeah, a fallback option in case we get non-sense result is always
> useful.  Alas, `wholenump' is not available in XEmacs.

Thanks for the heads-up, I will replace it with

    (if (< (- (current-column) 1) 0)
        (+ 2 beg-col)
      (- (current-column) 1))

> Remember also the test!

Yes, will do.

Best, Arash




Information forwarded to bug-auctex <at> gnu.org:
bug#26032; Package auctex. (Thu, 09 Mar 2017 05:51:01 GMT) Full text and rfc822 format available.

Message #14 received at 26032 <at> debbugs.gnu.org (full text, mbox):

From: Ikumi Keita <ikumi <at> ikumi.que.jp>
To: Mosè Giordano <mose <at> gnu.org>
Cc: Arash Esbati <arash <at> gnu.org>, 26032 <at> debbugs.gnu.org
Subject: Re: bug#26032: Indenting in tabulars without &
Date: Thu, 09 Mar 2017 14:50:00 +0900
Hi all,

> Alas, `wholenump' is not available in XEmacs.

In XEmacs, `natnump' is available.  It is available in GNU Emacs, too,
and already used in latex.el and tex-buf.el.

Bye,
Ikumi Keita




Reply sent to Arash Esbati <arash <at> gnu.org>:
You have taken responsibility. (Thu, 09 Mar 2017 14:50:02 GMT) Full text and rfc822 format available.

Notification sent to Arash Esbati <arash <at> gnu.org>:
bug acknowledged by developer. (Thu, 09 Mar 2017 14:50:02 GMT) Full text and rfc822 format available.

Message #19 received at 26032-done <at> debbugs.gnu.org (full text, mbox):

From: Arash Esbati <arash <at> gnu.org>
To: Ikumi Keita <ikumi <at> ikumi.que.jp>
Cc: 26032-done <at> debbugs.gnu.org, Mosè Giordano <mose <at> gnu.org>
Subject: Re: bug#26032: Indenting in tabulars without &
Date: Thu, 09 Mar 2017 15:49:24 +0100
Ikumi Keita <ikumi <at> ikumi.que.jp> writes:

>> Alas, `wholenump' is not available in XEmacs.
>
> In XEmacs, `natnump' is available.  It is available in GNU Emacs, too,
> and already used in latex.el and tex-buf.el.

Hi Keita,

great, thanks a lot.  I've just pushed a change with `natnump' to git.
(I forgot to mention the bug number in changelog entry, but that's a
different story).

Best, Arash




Information forwarded to bug-auctex <at> gnu.org:
bug#26032; Package auctex. (Thu, 09 Mar 2017 18:16:01 GMT) Full text and rfc822 format available.

Message #22 received at 26032-done <at> debbugs.gnu.org (full text, mbox):

From: Ikumi Keita <ikumi <at> ikumi.que.jp>
To: Arash Esbati <arash <at> gnu.org>
Cc: 26032-done <at> debbugs.gnu.org, Mosè Giordano <mose <at> gnu.org>
Subject: Re: bug#26032: Indenting in tabulars without &
Date: Fri, 10 Mar 2017 03:15:03 +0900
Hi Arash,

> I've just pushed a change with `natnump' to git.

I'm afraid that the fix has to be reconsidered.  The current code does
not work as expected when the whole tabular environment itself is
indented like the following examples.

\begin{table}
  \begin{tabular}{ll}
    \multicolumn{2}{c}{These lines will} `M-RET here'
  \end{tabular}
\end{table}

\begin{table}
  \begin{tabular}{ll}
    \multicolumn{2}{c}{These lines will}  \\
    & `C-c C-q C-e here'
  \end{tabular}
\end{table}

So it is not sufficient to examine whether `(- (current-column) 1)' is
negative or not.  I suppose that comparing the `(current-column)' and
`beg-col' would be necessary.  (Or just using `(max (- (current-column)
1) (+ 2 beg-col))' might be sufficient.  I haven't considered the
situation in detail yet.)

Regards,
Ikumi Keita




Information forwarded to bug-auctex <at> gnu.org:
bug#26032; Package auctex. (Thu, 09 Mar 2017 19:31:02 GMT) Full text and rfc822 format available.

Message #25 received at 26032 <at> debbugs.gnu.org (full text, mbox):

From: Arash Esbati <arash <at> gnu.org>
To: Ikumi Keita <ikumi <at> ikumi.que.jp>
Cc: 26032 <at> debbugs.gnu.org, Mosè Giordano <mose <at> gnu.org>
Subject: Re: bug#26032: Indenting in tabulars without &
Date: Thu, 09 Mar 2017 20:28:47 +0100
Ikumi Keita <ikumi <at> ikumi.que.jp> writes:

Hi Keita,

> I'm afraid that the fix has to be reconsidered.

And I was afraid that this would happen; it seemed just too easy ;-)

> The current code does not work as expected when the whole tabular
> environment itself is indented like the following examples.
>
> \begin{table}
>   \begin{tabular}{ll}
>     \multicolumn{2}{c}{These lines will} `M-RET here'
>   \end{tabular}
> \end{table}
>
> \begin{table}
>   \begin{tabular}{ll}
>     \multicolumn{2}{c}{These lines will}  \\
>     & `C-c C-q C-e here'
>   \end{tabular}
> \end{table}
>
> So it is not sufficient to examine whether `(- (current-column) 1)' is
> negative or not.  I suppose that comparing the `(current-column)' and
> `beg-col' would be necessary.  (Or just using `(max (- (current-column)
> 1) (+ 2 beg-col))' might be sufficient.  I haven't considered the
> situation in detail yet.)

Thank you very much for double checking.  I think I won't revert my last
change; it fixes at least part of the problem.  I will also think about
it again (but your suggestion above looks quite appealing to me).

Best, Arash




Did not alter fixed versions and reopened. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Thu, 09 Mar 2017 19:40:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-auctex <at> gnu.org:
bug#26032; Package auctex. (Fri, 10 Mar 2017 10:52:01 GMT) Full text and rfc822 format available.

Message #30 received at 26032 <at> debbugs.gnu.org (full text, mbox):

From: Arash Esbati <arash <at> gnu.org>
To: Ikumi Keita <ikumi <at> ikumi.que.jp>
Cc: 26032 <at> debbugs.gnu.org, Mosè Giordano <mose <at> gnu.org>
Subject: Re: bug#26032: Indenting in tabulars without &
Date: Fri, 10 Mar 2017 11:50:39 +0100
Arash Esbati <arash <at> gnu.org> writes:

> Ikumi Keita <ikumi <at> ikumi.que.jp> writes:
>
>> I'm afraid that the fix has to be reconsidered.
>
> And I was afraid that this would happen; it seemed just too easy ;-)
>
>> The current code does not work as expected when the whole tabular
>> environment itself is indented like the following examples.
>>
>> \begin{table}
>>   \begin{tabular}{ll}
>>     \multicolumn{2}{c}{These lines will} `M-RET here'
>>   \end{tabular}
>> \end{table}
>>
>> \begin{table}
>>   \begin{tabular}{ll}
>>     \multicolumn{2}{c}{These lines will}  \\
>>     & `C-c C-q C-e here'
>>   \end{tabular}
>> \end{table}
>>
>> So it is not sufficient to examine whether `(- (current-column) 1)' is
>> negative or not.  I suppose that comparing the `(current-column)' and
>> `beg-col' would be necessary.  (Or just using `(max (- (current-column)
>> 1) (+ 2 beg-col))' might be sufficient.  I haven't considered the
>> situation in detail yet.)
>
> Thank you very much for double checking.  I think I won't revert my last
> change; it fixes at least part of the problem.  I will also think about
> it again (but your suggestion above looks quite appealing to me).

Hi Keita,

I did some testing, your suggestion with

    (if (natnump (- (current-column) 1))
        (max (+ 2 beg-col)
             (- (current-column) 1))
      (+ 2 beg-col))

seems to do the job.  Do you have any other idea?

Best, Arash




Information forwarded to bug-auctex <at> gnu.org:
bug#26032; Package auctex. (Fri, 10 Mar 2017 11:26:02 GMT) Full text and rfc822 format available.

Message #33 received at 26032 <at> debbugs.gnu.org (full text, mbox):

From: Ikumi Keita <ikumi <at> ikumi.que.jp>
To: Arash Esbati <arash <at> gnu.org>
Cc: 26032 <at> debbugs.gnu.org, Mosè Giordano <mose <at> gnu.org>
Subject: Re: bug#26032: Indenting in tabulars without &
Date: Fri, 10 Mar 2017 20:24:55 +0900
Hi Arash,

Arash Esbati <arash <at> gnu.org> writes:
> I did some testing, your suggestion with

>     (if (natnump (- (current-column) 1))
>         (max (+ 2 beg-col)
>              (- (current-column) 1))
>       (+ 2 beg-col))

> seems to do the job.  Do you have any other idea?

I think that the sign test can be omitted altogether if we use `max'.
That is, just

	     (max (+ 2 beg-col)
		  (- (current-column) 1)))

is enough.  This code does the expected job on my machine.

Regards,
Ikumi Keita




Reply sent to Arash Esbati <arash <at> gnu.org>:
You have taken responsibility. (Fri, 10 Mar 2017 12:36:02 GMT) Full text and rfc822 format available.

Notification sent to Arash Esbati <arash <at> gnu.org>:
bug acknowledged by developer. (Fri, 10 Mar 2017 12:36:02 GMT) Full text and rfc822 format available.

Message #38 received at 26032-done <at> debbugs.gnu.org (full text, mbox):

From: Arash Esbati <arash <at> gnu.org>
To: Ikumi Keita <ikumi <at> ikumi.que.jp>
Cc: 26032-done <at> debbugs.gnu.org, Mosè Giordano <mose <at> gnu.org>
Subject: Re: bug#26032: Indenting in tabulars without &
Date: Fri, 10 Mar 2017 13:34:34 +0100
Ikumi Keita <ikumi <at> ikumi.que.jp> writes:

> I think that the sign test can be omitted altogether if we use `max'.
> That is, just
>
> 	     (max (+ 2 beg-col)
> 		  (- (current-column) 1)))
>
> is enough.  This code does the expected job on my machine.

Hi Keita,

yes, of course.  Thank you very much.  I've push a new change set to
git.  Next try to close this bug.

Best, Arash




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 08 Apr 2017 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 8 years and 71 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.