[ Changed Cc: addresses and Subject: ]

Hi Arash,

There were still difficulties with my last proposal, so I took another
approach.

>>>>> Arash Esbati <[email protected]> writes:
>> Following up myself, I think I have an idea which excludes the boundries
>> while looking for `font-latex-verbatim-face':
----------------------------------------------------------------------
(defun LaTeX-verbatim-p (&optional pos)
[...]
        (when LaTeX-shortvrb-chars
          (let* ((strings (mapcar #'string LaTeX-shortvrb-chars))
                 (regexp (concat "[^\\]"
                                 (mapconcat #'regexp-quote strings "\\|")))
                 (p (point))
                 (match (save-excursion
                          (re-search-forward regexp (line-end-position) t))))
----------------------------------------------------------------------
This regexp search doesn't match when the point is just before the
shortvrb delimiter even if the regexp is built as I suggested before.

----------------------------------------------------------------------
                 (save-excursion
                   (cl-oddp (how-many regexp (line-beginning-position) p)))
                 (save-excursion
                   (cl-evenp (how-many regexp (line-beginning-position) 
match)))))))))
----------------------------------------------------------------------
These `how-many's don't count as expected when there are adjacent
shortvrb quotes like |abc||xyz| .

So I ended up with a thought that this sort of matter should be handled
by emacs built-in syntax facilities. I expect the attached patch
addresses all issues discussed so far.

I changed the syntax for shortvrb delimiters from "|" (generic string
delimiters) to "\"" (string quotes) so that it can handle intermixed
expressions like this:
\documentclass{article}
\usepackage{shortvrb}
\MakeShortVerb{\|}
\MakeShortVerb{\"}
\begin{document}
Donec |posuere"augue| in quam.  "Mauris|ac"
%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% LaTeX-shortvrb-chars: (?| ?\")
%%% End:

Even with this approach, backslash just before the closing shortvrb
delimiter like |xyz\| can't be handled correctly, but I think we can
live with that.

Regards,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine

diff --git a/latex.el b/latex.el
index ac4b0c54..5f408cb5 100644
--- a/latex.el
+++ b/latex.el
@@ -3713,8 +3713,9 @@ non-parenthetical delimiters, like \\verb+foo+, are recognized."
   "Return non-nil if position POS is in a verbatim-like construct."
   (when pos (goto-char pos))
   (save-match-data
-    (or (when (fboundp 'font-latex-faces-present-p)
-          (font-latex-faces-present-p 'font-latex-verbatim-face))
+    (or (progn
+          (syntax-propertize (point))
+          (nth 3 (syntax-ppss)))
         (member (LaTeX-current-verbatim-macro)
                 (LaTeX-verbatim-macros-with-delims))
         (member (TeX-current-macro) (LaTeX-verbatim-macros-with-braces))
diff --git a/style/shortvrb.el b/style/shortvrb.el
index a8b4cd17..e7a0320b 100644
--- a/style/shortvrb.el
+++ b/style/shortvrb.el
@@ -69,12 +69,19 @@
                   (cons str str)))
               LaTeX-shortvrb-chars)))
 
+   ;; Syntax
+   (when LaTeX-shortvrb-chars
+     (let ((st (make-syntax-table (syntax-table))))
+       (dolist (c LaTeX-shortvrb-chars)
+         (modify-syntax-entry c "\"" st))
+       (set-syntax-table st)))
+
    ;; Fontification
    (when (and LaTeX-shortvrb-chars
               (featurep 'font-latex)
               (eq TeX-install-font-lock 'font-latex-setup))
      (font-latex-add-to-syntax-alist
-      (mapcar (lambda (char) (cons char "|"))
+      (mapcar (lambda (char) (cons char "\""))
               LaTeX-shortvrb-chars))
 
      (font-latex-add-keywords '(("MakeShortVerb"   "*{")

Reply via email to