[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/tex-parens 3c138a5b36 04/62: seem to have begin/end wor
From: |
ELPA Syncer |
Subject: |
[elpa] externals/tex-parens 3c138a5b36 04/62: seem to have begin/end working |
Date: |
Thu, 6 Jun 2024 04:00:54 -0400 (EDT) |
branch: externals/tex-parens
commit 3c138a5b36628887fd79e85474dc2b0dc4e9224f
Author: Paul Nelson <ultrono@gmail.com>
Commit: Paul Nelson <ultrono@gmail.com>
seem to have begin/end working
---
tex-parens.el | 127 ++++++++++++++++++++++++++++++++++++++--------------------
1 file changed, 83 insertions(+), 44 deletions(-)
diff --git a/tex-parens.el b/tex-parens.el
index d00e1f93d7..249cb0ca30 100644
--- a/tex-parens.el
+++ b/tex-parens.el
@@ -24,7 +24,7 @@
;; tailored to my use cases
;; (cf. https://github.com/Fuco1/smartparens/issues/1193).
;;
-;; Work in progress. TODO: support begin/end, sexp commands
+;; Work in progress. TODO: sexp commands
;;; Code:
@@ -52,8 +52,7 @@
("\\left\\lVert" . "\\right\\rVert")
("\\left|" . "\\right|")
("$" . "$")
- ("``" . "''")
- ("\\begin{.*}" . "''")))
+ ("``" . "''")))
(defun tex-parens-open ()
(mapcar #'car tex-parens-pairs))
@@ -64,6 +63,14 @@
(defun tex-parens-delims ()
(append (tex-parens-open) (tex-parens-close)))
+(defun tex-parens-regexp ()
+ (concat (regexp-opt (tex-parens-delims))
+ "\\|\\\\begin{[^}]+}\\|\\\\end{[^}]+}"))
+
+(defun tex-parens-reverse-regexp ()
+ (concat "}[^{]+{nigeb\\\\\\|}[^{]+{dne\\\\\\|"
+ (regexp-opt (mapcar #'reverse (tex-parens-delims)))))
+
(defun tex-parens-bound-default-forward ()
(save-excursion
(min
@@ -79,20 +86,38 @@
(defun tex-parens-basic-forward (&optional bound)
(interactive)
(unless bound (setq bound (tex-parens-bound-default-forward)))
- (when (re-search-forward (regexp-opt (tex-parens-delims))
- bound t)
+ (when (re-search-forward (tex-parens-regexp) bound t)
(match-string 0)))
(defun tex-parens-basic-backward (&optional bound)
(interactive)
(unless bound (setq bound (tex-parens-bound-default-backward)))
- (greedy-search-list-backward (tex-parens-delims) bound))
+ (let* ((text (buffer-substring-no-properties bound (point)))
+ match result)
+ (with-temp-buffer
+ (insert (reverse text))
+ (goto-char (point-min))
+ (setq result (re-search-forward (tex-parens-reverse-regexp) nil t))
+ (when result (setq match (match-string 0))))
+ (when result
+ (backward-char (1- result))
+ (reverse match))))
(defun tex-parens-is-open (delim)
- (cdr (assoc delim tex-parens-pairs)))
+ (or
+ (cdr (assoc delim tex-parens-pairs))
+ (and (stringp delim)
+ (string-match "\\\\begin{\\([^}]+\\)}" delim)
+ (let ((type (match-string 1 delim)))
+ (format "\\end{%s}" type)))))
(defun tex-parens-is-close (delim)
- (cdr (assoc delim (mapcar (lambda (x) (cons (cdr x) (car x)))
tex-parens-pairs))))
+ (or
+ (cdr (assoc delim (mapcar (lambda (x) (cons (cdr x) (car x)))
tex-parens-pairs)))
+ (and (stringp delim)
+ (string-match "\\\\end{\\([^}]+\\)}" delim)
+ (let ((type (match-string 1 delim)))
+ (format "\\begin{%s}" type)))))
(defun tex-parens-face-mathy ()
(let ((face (plist-get (text-properties-at (point))
@@ -115,32 +140,19 @@
(and (not (equal delim "$"))
(tex-parens-is-open delim))) ; Opening delimiter
(push delim stack))
- ((cdr (tex-parens-delim-pair delim)) ; Closing delimiter
- (if (equal (cdr (tex-parens-delim-pair delim)) (car stack))
- (pop stack)
- (backward-char (length delim))
- ;; (push (cdr (tex-parens-delim-pair delim)) stack)
- )))
+ (t
+ (let ((other (tex-parens-is-close delim)))
+ (cl-assert other)
+ (if (equal other (car stack))
+ (pop stack)
+ (backward-char (length delim))
+ ;; (push (cdr (tex-parens-delim-pair delim)) stack)
+ ))))
(setq delim (and stack (tex-parens-basic-forward bound))))))
-(defun greedy-search-list-backward (lst &optional bound noerror count)
- "Search backward for REGEXP, return t if found, nil otherwise."
- (unless bound (setq bound (tex-parens-bound-default-backward)))
- (let* ((text (buffer-substring-no-properties bound (point)))
- match result)
- (with-temp-buffer
- (insert (reverse text))
- (goto-char (point-min))
- (setq result (re-search-forward (regexp-opt (mapcar #'reverse lst)) nil
t))
- (when result
- (setq match (match-string 0))))
- (when result
- (backward-char (1- result))
- (reverse match))))
-
-(defun tex-parens-delim-pair (delim)
- (or (assoc delim tex-parens-pairs)
- (assoc delim (mapcar (lambda (x) (cons (cdr x) (car x)))
tex-parens-pairs))))
+;; (defun tex-parens-delim-pair (delim)
+;; (or (assoc delim tex-parens-pairs)
+;; (assoc delim (mapcar (lambda (x) (cons (cdr x) (car x)))
tex-parens-pairs))))
(defun tex-parens-backward (&optional bound)
"Find previous TeX sexp. Moves point to start of sexp."
@@ -158,10 +170,21 @@
(and (not (equal delim "$"))
(tex-parens-is-close delim)))
(push delim stack))
- ((assoc delim tex-parens-pairs) ; Opening delimiter
- (if (equal (cdr (tex-parens-delim-pair delim)) (car stack))
- (pop stack)
- (forward-char (length delim))))
+ (
+ t
+ (let ((other (tex-parens-is-open delim)))
+ (cl-assert other)
+ (if (equal other (car stack))
+ (pop stack)
+ (forward-char (length delim))
+ ;; (push delim stack)
+ ))
+ ;; (assoc delim tex-parens-pairs)
+ ; Opening delimiter
+ ;; (if (equal (cdr (tex-parens-delim-pair delim)) (car stack))
+ ;; (pop stack)
+ ;; (forward-char (length delim)))
+ )
)
(setq delim (and stack (tex-parens-basic-backward bound))))))
@@ -184,10 +207,18 @@
(and (not (equal delim "$"))
(tex-parens-is-close delim)))
(push delim stack))
- ((assoc delim tex-parens-pairs) ; Opening delimiter
- (if (equal (cdr (tex-parens-delim-pair delim)) (car stack))
- (pop stack)
- (setq success t)))
+ (t
+ (let ((other (tex-parens-is-open delim)))
+ (cl-assert other)
+ (if (equal other (car stack))
+ (pop stack)
+ (setq success t)))
+ ;; (assoc delim tex-parens-pairs)
+ ; Opening delimiter
+ ;; (if (equal (cdr (tex-parens-delim-pair delim)) (car stack))
+ ;; (pop stack)
+ ;; (setq success t))
+ )
)
(setq delim (and (not success) (tex-parens-basic-backward bound))))
(unless success
@@ -209,10 +240,18 @@
(and (not (equal delim "$"))
(tex-parens-is-open delim)))
(push delim stack))
- ((cdr (tex-parens-delim-pair delim)) ; Closing delimiter
- (if (equal (cdr (tex-parens-delim-pair delim)) (car stack))
- (pop stack)
- (setq success t)))
+ (t
+ (let ((other (tex-parens-is-close delim)))
+ (cl-assert other)
+ (if (equal other (car stack))
+ (pop stack)
+ (setq success t)))
+ ;; (cdr (tex-parens-delim-pair delim))
+ ; Closing delimiter
+ ;; (if (equal (cdr (tex-parens-delim-pair delim)) (car stack))
+ ;; (pop stack)
+ ;; (setq success t))
+ )
)
(setq delim (and (not success) (tex-parens-basic-forward bound))))
(unless success
- [elpa] externals/tex-parens 73b7fc98ad 57/62: update readme to indicate how to remap keys, (continued)
- [elpa] externals/tex-parens 73b7fc98ad 57/62: update readme to indicate how to remap keys, ELPA Syncer, 2024/06/06
- [elpa] externals/tex-parens 84b9b5e76e 06/62: added sexp stuff, ELPA Syncer, 2024/06/06
- [elpa] externals/tex-parens ddc4663eaa 11/62: add other math delimiters like $$, ELPA Syncer, 2024/06/06
- [elpa] externals/tex-parens 145e9eafc4 15/62: lots of cleanup, support for $\text{..$..$..}$, etc, ELPA Syncer, 2024/06/06
- [elpa] externals/tex-parens 82eff30aa5 16/62: ignore dollar delimiters that do not demarcate math mode, ELPA Syncer, 2024/06/06
- [elpa] externals/tex-parens 665c91c331 18/62: typo, ELPA Syncer, 2024/06/06
- [elpa] externals/tex-parens 683add8b7c 29/62: fix silly tp-kill-sexp bug, ELPA Syncer, 2024/06/06
- [elpa] externals/tex-parens dab79b2515 33/62: make end-of-defun go beyond the \end{...} line, ELPA Syncer, 2024/06/06
- [elpa] externals/tex-parens 1ef410b16c 36/62: clarify docstring of tp--ignore, ELPA Syncer, 2024/06/06
- [elpa] externals/tex-parens c084e037f1 02/62: Add files via upload, ELPA Syncer, 2024/06/06
- [elpa] externals/tex-parens 3c138a5b36 04/62: seem to have begin/end working,
ELPA Syncer <=
- [elpa] externals/tex-parens 20471db76e 05/62: add begin/end of defun functions, ELPA Syncer, 2024/06/06
- [elpa] externals/tex-parens 02392afeea 07/62: debugging forward-sexp stuff, ELPA Syncer, 2024/06/06
- [elpa] externals/tex-parens 70f1ba5f59 08/62: allow mismatched delimiters, add most lisp.el functions, ELPA Syncer, 2024/06/06
- [elpa] externals/tex-parens 6002c20edc 12/62: make the construction of paren-like pairs systematic, ELPA Syncer, 2024/06/06
- [elpa] externals/tex-parens dd318e66bc 17/62: typo, ELPA Syncer, 2024/06/06
- [elpa] externals/tex-parens 969635a931 24/62: fix dumb bug, ELPA Syncer, 2024/06/06
- [elpa] externals/tex-parens 3f4cdf093d 21/62: typos, ELPA Syncer, 2024/06/06
- [elpa] externals/tex-parens 0b5f6a95b0 26/62: add burp features, ELPA Syncer, 2024/06/06
- [elpa] externals/tex-parens 63584af148 38/62: make commands skip over, e.g., \cite[...]{...} commands, ELPA Syncer, 2024/06/06
- [elpa] externals/tex-parens 45e6872f48 25/62: .gitignore @.html, ELPA Syncer, 2024/06/06