[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
navigation tool for very long nested enumerate/itemize environments
From: |
Uwe Brauer |
Subject: |
navigation tool for very long nested enumerate/itemize environments |
Date: |
Sat, 18 May 2024 10:28:04 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) |
Hi
Recently I have very long and tested (up to 4 levels) enumerate environments.
Like
--8<---------------cut here---------------start------------->8---
\documentclass[12pt]{article}
\begin{document}
\begin{enumerate}
\item Step 1:
\begin{enumerate}
\item Proof: this
\begin{enumerate}
\item Proof that
\item Final step
\begin{enumerate}
\item Proof
\end{enumerate}
\end{enumerate}
\end{enumerate}
\item Step 2:
\end{enumerate}
\end{document}
--8<---------------cut here---------------end--------------->8---
What I am looking for is a tool, which allows me to jump from Step1 to
Step2, or in other words find the next item on the *same* level.
Rationale: if the list is very long that finding the next item on the
same level is cumbersome
Arash wrote some time ago, just for me I think because I don't find it
in the repository, the following two functions
--8<---------------cut here---------------start------------->8---
(defun ub/delete-item ()
(interactive)
(let* ((currenv (LaTeX-current-environment))
(beg-pos (save-excursion
(LaTeX-find-matching-begin)
(point)))
(end-pos (save-excursion
(LaTeX-find-matching-end)
(point)))
(item-regexp "^[ \t]*\\\\\\(bib\\)?item")
(end-regexp (concat "^[ \t]*\\\\end{" currenv "}"))
item-start item-end)
(beginning-of-line)
(if (looking-at item-regexp)
;; We are in the same line as in \item
(progn
(setq item-start (point))
(setq item-end
(progn
(or (re-search-forward item-regexp end-pos t 2)
(re-search-forward end-regexp end-pos t))
(end-of-line 0)
(point))))
;; We are somewhere within \item
(setq item-end
(progn
(or (re-search-forward item-regexp end-pos t)
(re-search-forward end-regexp end-pos t))
(end-of-line 0)
(point)))
(setq item-start (re-search-backward item-regexp beg-pos t)))
(if (and item-start item-end)
(progn
(delete-region item-start item-end)
(when (looking-at "^$")
(kill-line))
(indent-according-to-mode))
(message "No start of item found."))))
(defun ae/mark-item ()
(interactive)
(let ((currenv (LaTeX-current-environment))
(beg-pos (save-excursion
(LaTeX-find-matching-begin)
(point)))
(end-pos (save-excursion
(LaTeX-find-matching-end)
(point)))
item-start item-end)
(beginning-of-line)
(if (looking-at "^[ \t]*\\\\item")
;; We are in the same line as in \item
(progn
(setq item-start (point))
(setq item-end (progn (or (re-search-forward "^[ \t]*\\\\item"
end-pos t 2)
(re-search-forward (concat "^[
\t]*\\\\end{" currenv "}")
end-pos t))
(end-of-line 0)
(point))))
;; We are somewhere in \item
(setq item-end (progn (or (re-search-forward "^[ \t]*\\\\item" end-pos t)
(re-search-forward (concat "^[ \t]*\\\\end{"
currenv "}")
end-pos t))
(end-of-line 0)
(point)))
(setq item-start (re-search-backward "^[ \t]*\\\\item" beg-pos t)))
(push-mark item-end)
(goto-char item-start)
(TeX-activate-region)
(indent-according-to-mode)))
--8<---------------cut here---------------end--------------->8---
However even ae/mark-item marks one item but does not jump to the next
item on the same level.
Anybody knows about such a feature?
Thanks
Regards
Uwe Brauer
--
I strongly condemn Hamas heinous despicable pogroms/atrocities on Israel
I strongly condemn Putin's war of aggression against Ukraine.
I support to deliver weapons to Ukraine's military.
I support the EU and NATO membership of Ukraine.
- navigation tool for very long nested enumerate/itemize environments,
Uwe Brauer <=