auctex-diffs
[Top][All Lists]
Advanced

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

feature/capf a119b921 1/2: Drop using `catch/throw'


From: Arash Esbati
Subject: feature/capf a119b921 1/2: Drop using `catch/throw'
Date: Fri, 14 Oct 2022 06:27:29 -0400 (EDT)

branch: feature/capf
commit a119b92153df2b8b206303cbc8a7958f80e46799
Author: Arash Esbati <arash@gnu.org>
Commit: Arash Esbati <arash@gnu.org>

    Drop using `catch/throw'
    
    * latex-capf.el (LaTeX-what-macro): Drop using `catch/throw', use
    `unless' instead.  This is feasible since the `condition-case'
    form for getting out the first parenthesis is also removed.
    (LaTeX-completion-calculate-candidates): Rename to
    `LaTeX-arguments-completion-at-point'.  Also remove `catch/throw'
    and use `unless'.
---
 latex-capf.el | 137 ++++++++++++++++------------------------------------------
 1 file changed, 38 insertions(+), 99 deletions(-)

diff --git a/latex-capf.el b/latex-capf.el
index 2b65bbd4..9c8af3b8 100644
--- a/latex-capf.el
+++ b/latex-capf.el
@@ -33,10 +33,8 @@ type is one of the symbols `mandatory' or `optional'.
 If the optional BOUND is an integer, bound backwards directed
 searches to this point.  If it is nil, limit to the previous 15
 lines."
-  (catch 'exit
-    ;; Exit if we're not inside a list or inside a nested list:
-    (when (/= (car (syntax-ppss)) 1)
-      (throw 'exit nil))
+  ;; Exit if we're not inside a list or inside a nested list:
+  (unless (/= (car (syntax-ppss)) 1)
     (let ((bound (or bound (line-beginning-position -15)))
           (env-or-mac 'mac)
           cmd cnt cnt-opt type)
@@ -44,41 +42,38 @@ lines."
         (save-restriction
           (narrow-to-region (max (point-min) bound) (point-max))
           ;; Move back out of the current parenthesis
-          (while (condition-case nil
-                     (let ((forward-sexp-function nil))
-                       (up-list -1) t)
-                   (error nil))
-            ;; Set the initial value of argument counter
-            (setq cnt 1)
-            ;; Note that we count also the right opt. or man. arg:
-            (setq cnt-opt (if (= (following-char) ?\{) 0 1))
-            ;; Record if we're inside a mand. or opt. argument
-            (setq type (if (= (following-char) ?\{) 'mandatory 'optional))
-            ;; move back over any touching sexps
-            (while (and (TeX-move-to-previous-arg bound)
-                        (condition-case nil
-                            (let ((forward-sexp-function nil))
-                              (backward-sexp) t)
-                          (error nil)))
-              (if (eq (following-char) ?\[) (cl-incf cnt-opt))
-              (cl-incf cnt))
-            (when (and (or (= (following-char) ?\[)
-                           (= (following-char) ?\{))
-                       (re-search-backward "\\\\[*a-zA-Z]+\\=" nil t))
-              (setq cmd (TeX-match-buffer 0))
-              (when (looking-at "\\\\begin{\\([^}]+\\)}")
-                (setq cmd (TeX-match-buffer 1))
-                (setq env-or-mac 'env)
-                (cl-decf cnt))
-              (if (and cmd (not (string= cmd "")))
-                  (throw 'exit
-                         (list (if (eq env-or-mac 'mac)
-                                   ;; Strip leading backslash from
-                                   ;; the macro
-                                   (substring cmd 1)
-                                 cmd)
-                               env-or-mac cnt type))
-                (throw 'exit nil)))))))))
+          (let ((forward-sexp-function nil))
+            (up-list -1))
+          ;; Set the initial value of argument counter
+          (setq cnt 1)
+          ;; Note that we count also the right opt. or man. arg:
+          (setq cnt-opt (if (= (following-char) ?\{) 0 1))
+          ;; Record if we're inside a mand. or opt. argument
+          (setq type (if (= (following-char) ?\{) 'mandatory 'optional))
+          ;; Move back over any touching sexps
+          (while (and (TeX-move-to-previous-arg bound)
+                      (condition-case nil
+                          (let ((forward-sexp-function nil))
+                            (backward-sexp) t)
+                        (error nil)))
+            (if (eq (following-char) ?\[) (cl-incf cnt-opt))
+            (cl-incf cnt))
+          (when (and (or (= (following-char) ?\[)
+                         (= (following-char) ?\{))
+                     (re-search-backward "\\\\[*a-zA-Z]+\\=" nil t))
+            (setq cmd (TeX-match-buffer 0))
+            (when (looking-at "\\\\begin{\\([^}]+\\)}")
+              (setq cmd (TeX-match-buffer 1))
+              (setq env-or-mac 'env)
+              (cl-decf cnt))
+            (if (and cmd (not (string= cmd "")))
+                (list (if (eq env-or-mac 'mac)
+                          ;; Strip leading backslash from
+                          ;; the macro
+                          (substring cmd 1)
+                        cmd)
+                      env-or-mac cnt type)
+              nil)))))))
 
 (defun LaTeX-completion-candidates-key-val (key-vals)
   ;; First find out if we're looking for a key or a value: If we're
@@ -170,14 +165,12 @@ lines."
                     (t tail))))
             )  )))
 
-(defun LaTeX-completion-calculate-candidates ()
-  (catch 'exit
-    ;; Exit if not inside a list or a nested list or in a comment:
-    (when (or (/= (car (syntax-ppss)) 1)
+(defun LaTeX-arguments-completion-at-point ()
+  ;; Exit if not inside a list or a nested list or in a comment:
+  (unless (or (/= (car (syntax-ppss)) 1)
               (TeX-in-comment))
-      (throw 'exit nil))
     (let ((entry (LaTeX-what-macro))
-          mac env arg head)
+          mac env arg)
       (cond ((eq (nth 1 entry) 'mac)
              ;; Feed 'arg' to `LaTeX-completion-parse-arg' only when
              ;; we find one:
@@ -196,60 +189,6 @@ lines."
             ;; Any other constructs?
             (t nil)))))
 
-
-
-
-;; (defun LaTeX-calculate-candidates ()
-;;   (catch 'exit
-;;     ;; Exit if not inside a list or a nested list or in a comment:
-;;     (when (or (/= (car (syntax-ppss)) 1)
-;;               (TeX-in-comment))
-;;       (throw 'exit nil))
-;;     (let ((entry (LaTeX-what-macro))
-;;           mac env arg head) ;; tail
-;;       (cond ((eq (nth 1 entry) 'mac)
-;;              (setq mac (assoc (car entry) (TeX-symbol-list)))
-;;              (setq arg (nth (nth 2 entry) mac))
-;;              (cond ((or (vectorp arg)
-;;                         (listp arg))
-;;                     (when (vectorp arg)
-;;                       (setq arg (append arg nil)))
-;;                     (setq head (car arg))
-;;                     (cond ((functionp head)
-;;                            (cond ((eq head #'TeX-arg-key-val)
-;;                                   (LaTeX-completion-candidates-key-val 
(eval (cadr arg) t)))
-;;                                  ;; ((eq head #'TeX-arg-completing-read) 
...)
-;;                                  ;; ((eq head #'TeX-arg-crm) ...)
-;;                                  (t nil)))
-;;                           (t nil)))
-;;                    ((and (symbolp arg)
-;;                          (functionp arg)
-;;                          (fboundp arg))
-;;                     (LaTeX-completion-candidates-single arg))
-;;                    (t nil)))
-;;             ((eq (nth 1 entry) 'env)
-;;              (setq env (assoc (car entry) (LaTeX-environment-list)))
-;;              ;; Shift the number of arg if `LaTeX-env-args' is present:
-;;              (setq arg (if (eq (cadr env) 'LaTeX-env-args)
-;;                            (nth (1+ (nth 2 entry)) env)
-;;                          (nth (nth 2 entry) env)))
-;;              (cond ((or (vectorp arg)
-;;                         (listp arg))
-;;                     (when (vectorp arg)
-;;                       (setq arg (append arg nil)))
-;;                     (setq head (car arg))
-;;                     (cond ((functionp head)
-;;                            (cond ((eq head #'TeX-arg-key-val)
-;;                                   (LaTeX-completion-candidates-key-val 
(eval (cadr arg) t)))
-;;                                  ;; ((eq head #'TeX-arg-completing-read) 
...)
-;;                                  ;; ((eq head #'TeX-arg-crm) ...)
-;;                                  (t nil)))
-;;                           (t nil)))) )
-;;             ;; Any other constructs?
-;;             (t nil)))))
-
-
-
 ;; (defun LaTeX-completion-candidates-single (func)
 
 ;;   (let ((end (point))



reply via email to

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