Hi,

when calling "LaTeX-environment" for a LaTeX buffer that contains only
whitespace between point and the buffer's begin, "document" is
suggested as default environment to be inserted. I would like that
behavior extended to LaTeX buffers with nothing but commented lines
and whitespace between point and the begin of the buffer. (This is
useful, for instance, if you use, like I, a standard comment block at
the begin of every LaTeX file.)

To get this I have enhanced "TeX-near-bobp" with an optional argument.
When non-nil, not only whitespace lines will be skipped but commented
lines too. This allows to get behavior sketched above.

Maybe it's a good idea to preserve the old behavior for docTeX. But
this could easily be acomplished by letting the optional argument of
the enhanced "TeX-near-bobp" depend on the buffer's mode.

Dirk
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 ()
_______________________________________________
auctex-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/auctex-devel

Reply via email to