diff -r 2471b0509cd5 src/latex.el --- a/src/latex.el Fri Jan 30 20:17:30 2009 +0100 +++ b/src/latex.el Fri Feb 06 23:02:08 2009 +0100 @@ -522,7 +522,7 @@ (interactive "*P") (let ((environment (completing-read (concat "Environment type: (default " - (if (TeX-near-bobp) + (if (TeX-near-bobp t) "document" LaTeX-default-environment) ") ") @@ -531,7 +531,7 @@ 'LaTeX-environment-history))) ;; Get default (cond ((and (zerop (length environment)) - (TeX-near-bobp)) + (TeX-near-bobp t)) (setq environment "document")) ((zerop (length environment)) (setq environment LaTeX-default-environment)) diff -r 2471b0509cd5 src/tex.el --- a/src/tex.el Fri Jan 30 20:17:30 2009 +0100 +++ b/src/tex.el Fri Feb 06 23:02:08 2009 +0100 @@ -3524,10 +3524,22 @@ (buffer-file-name) (TeX-master-directory))) -(defun TeX-near-bobp () - "Return t iff there's nothing but whitespace between (bob) and (point)." - (save-excursion - (skip-chars-backward " \t\n") +(defun TeX-in-whitespace-line () + "Return nun-nil if point is in a line consisting only of whitespace." + (forward-line 0) + (skip-chars-forward " \t") + (eolp)) + +(defun TeX-near-bobp (&optional ignore-comments) + "Return t iff there's nothing but whitespace between (bob) and (point). +For a non-nil IGNORE-COMMENTS lines consisting only of a comment will be +treated in the same way." + (save-excursion + (while (and (or (TeX-in-whitespace-line) + (and ignore-comments (TeX-in-commented-line))) + (not (bobp))) + (forward-line -1)) + (forward-line 0) (bobp))) (defun TeX-deactivate-mark ()