GNU bug report logs - #73302
TeX-find-closing-brace and verbatim macros

Previous Next

Package: auctex;

Reported by: Paul Nelson <ultrono <at> gmail.com>

Date: Mon, 16 Sep 2024 16:13:02 UTC

Severity: normal

Done: Arash Esbati <arash <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Paul Nelson <ultrono <at> gmail.com>
To: Ikumi Keita <ikumi <at> ikumi.que.jp>
Cc: Arash Esbati <arash <at> gnu.org>, 73302 <at> debbugs.gnu.org
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 <at> ikumi.que.jp> wrote:
>
> >>>>> Arash Esbati <arash <at> 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




This bug report was last modified 231 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.