[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [AUCTeX-devel] Ok, I am too stupid to make this work.
From: |
Ralf Angeli |
Subject: |
Re: [AUCTeX-devel] Ok, I am too stupid to make this work. |
Date: |
Sun, 03 Jul 2005 11:12:28 +0200 |
User-agent: |
Gnus/5.110004 (No Gnus v0.4) Emacs/22.0.50 (gnu/linux) |
* David Kastrup (2005-07-02) writes:
> Ralf Angeli <address@hidden> writes:
>
>> * David Kastrup (2005-07-02) writes:
>>
>>> a) a macrocode environment has its begin/end lines _always_
>>> outcommented by single comment characters, regardless of where one
>>> calls C-c C-e.
>>
>> Theoretically there could be environments called `macrocode' in
>> "regular" LaTeX as well, right?
>
> None of our business. The only "macrocode" environment defined in the
> whole texmf tree AFAIK is the one in doc.sty, and that requires to be
> ended by
Consequently we should restrict special treatment of macrocode
environments to docTeX mode (and maybe if `doc' and similar styles are
present).
>>> d) after calling C-c C-e on an active region, point and mark should be
>>> left close to where they were before.
>>
>> Do you remember the discussion we had about this before? I gave up
>> on this, see
>> <URL:http://article.gmane.org/gmane.emacs.latex.preview.bugs/688>.
>
> But just exchange-point-and-mark should not touch the mark stack,
> right?
I'd have to look at what functions called after
`LaTeX-insert-environment' do in order to comment on that.
>>> Unfortunately, this patch does not work at all and I am missing the
>>> respective clue to fix it.
>>
>> What aspect of the patch doesn't work?
>
> Pretty much everything. Using C-c C-e macrocode outside of comments
> makes a completely uncommented macrocode environment, indented by two
> spaces in the middle, like
[...]
> It does not get any worse than that.
I didn't like the code in `LaTeX-insert-environment' so I've just
rewritten the function (see below). I think it is easier to
understand and more maintainable like this. But checking this in
would be a destabilizing change, so it should better wait till after
the release. (Also note that I did not change the placement of the
mark compared to the old version.)
(defun LaTeX-insert-environment (environment &optional extra)
"Insert LaTeX ENVIRONMENT with optional argument EXTRA."
(let ((active-mark (and (TeX-active-mark) (not (eq (mark) (point)))))
(macrocode-p (and (eq major-mode 'doctex-mode)
(string-match "\\`macrocode\\*?\\'" environment)))
prefix content-start)
(when (and active-mark (< (mark) (point))) (exchange-point-and-mark))
;; Compute the prefix.
(cond ((and LaTeX-insert-into-comments (TeX-in-commented-line))
(save-excursion
(beginning-of-line)
(looking-at
(concat "^\\([ \t]*" TeX-comment-start-regexp "+\\)+[ \t]*"))
(setq prefix (match-string 0)))))
;; What to do with the line containing point.
(cond ((save-excursion (beginning-of-line)
(looking-at (concat prefix "[ \t]*$")))
(kill-region (match-beginning 0) (match-end 0)))
((TeX-looking-at-backward (concat "^" prefix "[ \t]*")
(line-beginning-position))
(beginning-of-line)
(newline)
(beginning-of-line 0))
((bolp)
(delete-horizontal-space)
(newline)
(beginning-of-line 0))
(t
(delete-horizontal-space)
(newline 2)
(when prefix (insert prefix))
(beginning-of-line 0)))
;; What to do with the line containing mark.
(when active-mark
(save-excursion
(goto-char (mark))
(cond ((save-excursion (beginning-of-line)
(or (looking-at (concat prefix "[ \t]*$"))
(looking-at "[ \t]*$")))
(kill-region (match-beginning 0) (match-end 0)))
((TeX-looking-at-backward (concat "^" prefix "[ \t]*")
(line-beginning-position))
(beginning-of-line)
(newline)
(beginning-of-line 0))
(t
(delete-horizontal-space)
(insert-before-markers "\n")
(newline)
(when prefix (insert prefix))))))
;; Now insert the environment.
(if macrocode-p (insert "%") (when prefix (insert prefix)))
(insert TeX-esc "begin" TeX-grop environment TeX-grcl)
(indent-according-to-mode)
(when extra (insert extra))
(setq content-start (line-beginning-position 2))
(unless active-mark (newline) (when prefix (insert prefix)) (newline))
(when active-mark (goto-char (mark)))
(if macrocode-p (insert "%") (when prefix (insert prefix)))
(insert TeX-esc "end" TeX-grop environment TeX-grcl)
(end-of-line 0)
(if active-mark
(or (assoc environment LaTeX-indent-environment-list)
(LaTeX-fill-region content-start (line-beginning-position 2)))
(indent-according-to-mode))
(save-excursion (beginning-of-line 2) (indent-according-to-mode))))
--
Ralf