bug-auctex
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#73302: TeX-find-closing-brace and verbatim macros


From: Paul Nelson
Subject: bug#73302: TeX-find-closing-brace and verbatim macros
Date: Thu, 26 Sep 2024 20:39:41 +0200

For whatever it's worth, I updated my package czm-tex-fold to support
the variety of verbatim formats from Arash's earlier email.  This is
less flexible than what we would get by extending the display spec
format, but has the advantage that it's been implemented.

If you want to try it without setting up my package, just evaluate the
following code, with the final line evaluated in your tex buffer.
Then run folding commands (e.g., C-c C-o C-b) as usual.

(defun czm-tex-fold--create-misc-overlay (start end str spec)
  "Create an overlay to fold quotes between START and END with STR and SPEC."
  (let ((priority (TeX-overlay-prioritize start end))
        (ov (make-overlay start end)))
    (overlay-put ov 'category 'TeX-fold)
    (overlay-put ov 'priority priority)
    (overlay-put ov 'evaporate t) ; Remove the overlay when the text
is modified.
    (overlay-put ov 'display str)
    (overlay-put ov 'TeX-fold-display-string-spec spec)))

(defvar czm-tex-fold--verb-regex
  "\\\\\\(Verb\\|verb\\)\\(?:\\[[^]]*\\]\\)?[|{]\\([^|}]*\\)[|}]")

(defun czm-tex-fold-verbs (start end)
  "Fold `\\verb|...|', `\\Verb|...|', and `\\Verb{...}' macros between
START and END."
  (save-excursion
    (goto-char start)
    (while (re-search-forward czm-tex-fold--verb-regex end t)
      (let* ((verb-start (match-beginning 0))
             (verb-end (match-end 0))
             (verb-content (match-string 2))
             (spec (lambda (&rest _args)
                     (when (looking-at czm-tex-fold--verb-regex)
                       (match-string 2)))))
        (czm-tex-fold--create-misc-overlay verb-start verb-end
verb-content spec)))))

(add-hook 'TeX-fold-region-functions #'czm-tex-fold-verbs nil t)

On Thu, Sep 26, 2024 at 7:04 AM Ikumi Keita <ikumi@ikumi.que.jp> wrote:
>
> >>>>> Arash Esbati <arash@gnu.org> writes:
> >> Alternatively, one could view the contents of "|...|" as a "required
> >> argument" and extend the string display spec folding to work with
> >> "|...|" in addition to "{...}", but I don't see the immediate payoff
> >> from doing so.
>
> > What do others think?
>
> It seems a reasonable idea to me, provided that it is limited to
> \verb-like commands. It would be nice if it is easily extended for
> non-LaTeX mode constructs. (I imagine that ConTeXt has some \verb-like
> commands.)
>
> Regards,
> Ikumi Keita
> #StandWithUkraine #StopWarInUkraine
> #Gaza #StopMassiveKilling #CeasefireNOW





reply via email to

[Prev in Thread] Current Thread [Next in Thread]