Subject: bug#52852: 13.0.15; TeX-insert-quote fails near the beginning of buffer

From: Andrea Greselin <[email-masked]>
Date: Wed, 29 Dec 2021 15:57:14 +0100

> I think it’s reasonable to insert an opening quote whenever there
> isn’t room for one behind the point. I’ve attached a patch that
> implements this behaviour.

If I had taken into account narrowed buffers it wouldn’t have seemed
so reasonable.

With this new patch, ‘TeX-insert-quote’ only tries to ‘forward-char’
in reverse when there’s enough room to do so. Unlike with the previous
patch, it can insert a closing quote even if there’s no room for an
opening one before point.
diff --git a/auctex-13.0.15/tex.el b/auctex-13.0.15/tex.el
index 3cf8f65..03027d6 100644
--- a/auctex-13.0.15/tex.el
+++ b/auctex-13.0.15/tex.el
@@ -6169,14 +6169,16 @@ With prefix argument FORCE, always inserts \" characters."
                        ?\")
                       ((= (preceding-char) ?\")
                        ?\")
-                      ((save-excursion
-                         (forward-char (- (length open-quote)))
-                         (looking-at (regexp-quote open-quote)))
+                      ((and (<= (length open-quote) (- (point) (point-min)))
+                            (save-excursion
+                              (forward-char (- (length open-quote)))
+                              (looking-at (regexp-quote open-quote))))
                        (delete-char (- (length open-quote)))
                        ?\")
-                      ((save-excursion
-                         (forward-char (- (length close-quote)))
-                         (looking-at (regexp-quote close-quote)))
+                      ((and (<= (length open-quote) (- (point) (point-min)))
+                            (save-excursion
+                              (forward-char (- (length close-quote)))
+                              (looking-at (regexp-quote close-quote))))
                        (delete-char (- (length close-quote)))
                        ?\")
                       ((save-excursion