[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[AUCTeX-devel] Re: Insertion of leading new line with C-c C-s
From: |
Christian Schlauer |
Subject: |
[AUCTeX-devel] Re: Insertion of leading new line with C-c C-s |
Date: |
Sun, 03 Apr 2005 12:50:02 +0200 |
User-agent: |
Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (windows-nt) |
[This is a follow-up to a thread from last december, see
<URL:http://article.gmane.org/gmane.emacs.auc-tex/5093>]
Ralf Angeli <address@hidden> writes:
> * Christian Schlauer (2004-12-02) writes:
>
>> When you press `C-c C-s' to insert a section, the first thing that
>> happens is that AUCTeX inserts a new line at point in the buffer [1].
>> I don't like it for two reasons:
>>
>> 1. I sometimes accidentally press `C-c C-s', and then `C-g' is not
>> sufficient to abort, one also has to do `C-_'.
>
> I find this annoying as well.
>
>> 2. The new line is always inserted [1], even if there is already a
>> blank line before point. I don't want two blank lines in front of a
>> \section, so I always have to remove it.
> [...]
>> I would prefer to remove the two lines, but bundling the modification
>> of the buffer in `LaTeX-section-section' and thus delaying the
>> insertion of the new line would be better than the current state, too.
>> But in the second case, I would prefer a smarter mechanism that
>> doesn't add a new line if there is already a new line before point.
>
> I like this last suggestion. One could check if the return value of
> `(save-excursion (skip-chars-backward "\n\f"))' is less than -1. (Not
> sure if "\f" is needed, but IIRC there were problems with XEmacs if it
> wasn't included.)
Hi,
I attach a patch that does the right thing: it inserts a new line only
if the previous line is not empty or does not start with `[possible
whitespace]\begin'. The latter is to avoid things like
\begin{some-environment}
\section{blah}
where a blank line between the beginning of the environment and the
section is not wanted.
I couldn't use `skip-chars-backward' as suggested by Ralf because that
didn't work when the section is already indented, for example when the
section is within a `multicols' environment. Try to insert sections in
the following document, and you will see that the code `does the right
thing':
\documentclass{article}
\usepackage{multicol}
\begin{document}
\section{foo 1}
\label{sec:foo-1}
\begin{multicols}{2}
\end{multicols}
\end{document}
(There is one case where the code does not do the right thing: when
point is placed behind \begin{some-environment}-!-. But point will
never be there when people use `C-c C-e' and `C-c C-s', so I think
this case can be ignored.)
Here is a ChangeLog entry:
--8<---------------cut here---------------start------------->8---
2005-04-03 Christian Schlauer <address@hidden>
* latex.el (LaTeX-section): Fix typo in doc string. Remove code
that almost always inserts a new line.
(LaTeX-section-section): Fix doc string. Add code that
conditionally inserts a new line (which also bundles the
modification of the buffer in this function).
(LaTeX-section-hook): Fix typo in doc string.
--8<---------------cut here---------------end--------------->8---
A short explanation of the code/the regexp used is given in the
comment in front of it in `LaTeX-section-section'.
About the fixed typos and doc fixes: `determinate' is an adjective,
and in `LaTeX-section-section', `assumes' should be `assume' (plural),
and I took the chance and rephrased the doc string a little as well.
Regards,
--
Christian Schlauer
- [AUCTeX-devel] Re: Insertion of leading new line with C-c C-s,
Christian Schlauer <=