On Nov 17, 2010, at 5:15 PM, Brett Presnell wrote:

> I have auto-fill turned on automatically in text modes like LaTeX.  However, I
> often find myself editing fairly wide tables and I would like to have 
> auto-fill
> automatically turned off when the point is a tabular environment.
> 
> Is there any easy way to accomplish this?

Yes, there is always a way. :-)

> For the record, the default for LaTeX-indent-environment-list includes
> ("tabular") and ("tabular*") and I did try changing these to ("tabular"
> current-indentation) and ("tabular*" current-indentation).  I didn't
> expect this to defeat auto-fill and it doesn't, but I thought I should
> mention that I had tried it anyway.

If you haven't already gotten a better solution, I have tweaked the following 
from my .emacs (without proper testing).  Needless to say, it could be much 
smarter, but you can of course change it to be whatever you need.


(defvar LaTeX-no-auto-fill-environments
  (mapcar 'car LaTeX-indent-environment-list)
  "List of LaTeX environments to suppress auto-fill.")

(defun auto-preview-auto-fill-function ()
    "Run `do-auto-fill' based on current mode.
Will run `do-auto-fill' to provide auto-filling of current line
unless the current LaTeX environment is a member of
`LaTeX-no-auto-fill-environments'.

 For use as `auto-fill-function'."
  (unless (member (LaTeX-current-environment)
                  LaTeX-no-auto-fill-environments)
    (do-auto-fill)))

;; And then in your LaTeX-mode-hook add
(setq auto-fill-function 'auto-preview-auto-fill-function)


> PS: As is pointed out in the auctex manual, align-current is very useful
> when editing tabular environemnts, but it has the negative effect of
> losing the position of the point.  This bothered me enough that I
> finally added the following to my .emacs and I thought that someone else
> might find it handy as well.  I would appreciate any comments on how
> this can or should be improved (I feel a bit queasy about stealing the
> register P for example).
> 
> ;; Align current environment without losing the point.  Mapped to C-cC-a.
> ;; Mainly used for the tabular and tabular* environments.
> (defun LaTeX-align-current-environment ()
>  (interactive)
>  (point-to-register ?P)
>  (LaTeX-mark-environment)
>  (align-current)
>  (jump-to-register ?P))
> (add-hook 'LaTeX-mode-hook
>  (lambda ()
>   (define-key LaTeX-mode-map "\C-c\C-a" 'LaTeX-align-current-environment)))

I believe save-excursion is what you want.  It evaluates the body and then 
returns point to "where it was before":

(defun LaTeX-align-current-environment ()
  (interactive)
  (save-excursion
    (LaTeX-mark-environment)
    (align-current)))

-Ivan Andrus
_______________________________________________
auctex mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/auctex

Reply via email to