emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] externals/latex-table-wizard 1f4effedfa 59/70: NOCYCLE argument a


From: ELPA Syncer
Subject: [elpa] externals/latex-table-wizard 1f4effedfa 59/70: NOCYCLE argument added to movement commands
Date: Sat, 13 May 2023 08:59:14 -0400 (EDT)

branch: externals/latex-table-wizard
commit 1f4effedfa3d601a4cbf6989e23c5f337ddd02e7
Author: Enrico Flor <enrico@eflor.net>
Commit: Enrico Flor <enrico@eflor.net>

    NOCYCLE argument added to movement commands
---
 NEWS                  |  5 ++-
 latex-table-wizard.el | 94 +++++++++++++++++++++++++++++++++++++--------------
 2 files changed, 73 insertions(+), 26 deletions(-)

diff --git a/NEWS b/NEWS
index 38141af4d7..1874e595a0 100644
--- a/NEWS
+++ b/NEWS
@@ -13,7 +13,10 @@
 aliased to new command "latex-table-wizard-kill-column-content"
 *** latex-table-wizard-kill-row
 aliased to new command "latex-table-wizard-kill-row-content"
-
+*** latex-table-wizard-right, latex-table-wizard-left, 
latex-table-wizard-down, latex-table-wizard-up
+added a second optional argument NOCYCLE that makes the command return
+nil (instead of moving point), in case the movement in the chosen
+direction hits the boundaries of the table.
 
 * 1.2.0 <2022-12-20 Tue>
 ** New user option: latex-table-wizard-allow-detached-args
diff --git a/latex-table-wizard.el b/latex-table-wizard.el
index 0fef2c4d7e..84fad56f23 100644
--- a/latex-table-wizard.el
+++ b/latex-table-wizard.el
@@ -743,7 +743,38 @@ plists."
               (lambda (x y) (> (plist-get x other-prop)
                                (plist-get y other-prop))))))))
 
-(defun latex-table-wizard--jump (dir &optional absolute count same-line)
+(defsubst latex-table-wizard--shift (dir cell table)
+  "Given a CELL and a list of cells TABLE, return one of TABLE.
+
+The cell returned is the one whose coordinates correspond to
+having CELL shifted in direction DIR (whose value is either
+\\='next\\=', \\='previous\\=', \\='forward\\=' or
+\\='backward\\=').  If no such cell is found in TABLE, return
+nil."
+  (let (target                       ; cons cell column . row
+        output)
+    (cond ((eq dir 'next)
+           (setq target (cons (plist-get cell :column)
+                              (1+ (plist-get cell :row)))))
+          ((eq dir 'previous)
+           (setq target (cons (plist-get cell :column)
+                              (1- (plist-get cell :row)))))
+          ((eq dir 'forward)
+           (setq target (cons (1+ (plist-get cell :column))
+                              (plist-get cell :row))))
+          ((eq dir 'backward)
+           (setq target (cons (1- (plist-get cell :column))
+                              (plist-get cell :row)))))
+    (catch 'found
+      (dolist (c table)
+        (when (and (= (plist-get c :column) (car target))
+                   (= (plist-get c :row) (cdr target)))
+          (setq output c)
+          (throw 'found t))))
+    output))
+
+(defun latex-table-wizard--jump (dir &optional absolute
+                                     count same-line nocycle)
   "Move point to the beginning of a cell in the table.
 
 DIR is either \\='next\\=', \\='previous\\=', \\='forward\\=' or
@@ -757,7 +788,12 @@ or column (depending on the value of DIR) point is 
currently in.
 COUNT is a positive integer that determines how many steps in
 direction DIR to take.
 
-If SAME-LINE is non-nil, never leave current column or row."
+If SAME-LINE is non-nil, never leave current column or row.
+
+If NOCYCLE is non-nil, do not move and return nil in case the
+jump would move point to a different column (if DIR is either
+\\='forward\\=' or \\='backward\\=') or to a different row (if
+DIR is either \\='next\\=', \\='previous\\=')."
   (unless (ignore-errors (save-excursion (LaTeX-find-matching-begin)))
     (user-error "Not in a LaTeX environment"))
   (let* ((message-log-max 0)
@@ -769,14 +805,17 @@ If SAME-LINE is non-nil, never leave current column or 
row."
                    (let ((sorted (latex-table-wizard--sort cells t dir)))
                      (if (memq dir '(previous backward))
                          (car sorted)
-                       (car (last sorted)))))))
+                       (car (last sorted))))))
+         (stop (and nocycle (not (latex-table-wizard--shift dir curr cells)))))
     (latex-table-wizard--remove-overlays cells)
-    (goto-char (plist-get target :start))
-    (latex-table-wizard--hl-cells `(,target))
-    (latex-table-wizard--hl-cells latex-table-wizard--selection)
-    (message "Col X Row (%d,%d)"
-             (plist-get target :column)
-             (plist-get target :row))))
+    (unless stop
+        ;; (goto-char (plist-get curr :start))
+      (goto-char (plist-get target :start))
+      (latex-table-wizard--hl-cells `(,target))
+      (latex-table-wizard--hl-cells latex-table-wizard--selection)
+      (message "Col X Row (%d,%d)"
+               (plist-get target :column)
+               (plist-get target :row)))))
 
 
 
@@ -1017,46 +1056,51 @@ Leave point at the beginning of the cell.
 
 If N is nil, move one cell to the right.
 
-If there is no cell to the right of where point is, move to the
-leftmost cell of the row below where point is."
+If there is no cell to the right of where point is, and NOCYCLE
+is nil, move to the leftmost cell of the row below where point
+is.  If NOCYCLE is non-nil, do not move and return nil in that
+case."
   (interactive "p")
-  (latex-table-wizard--jump 'forward nil n))
+  (latex-table-wizard--jump 'forward nil nil n))
 
-(defun latex-table-wizard-left (&optional n)
+(defun latex-table-wizard-left (&optional n nocycle)
   "Move point N cells to the left.
 
 Leave point at the beginning of the cell.
 
 If N is nil, move one cell to the left.
 
-If there is no cell to the left of where point is, move to the
-rightmost cell of the row above where point is."
+If there is no cell to the left of where point is, and NOCYCLE is
+nil, move to the rightmost cell of the row above where point is.
+If NOCYCLE is non-nil, do not move and return nil in that case."
   (interactive "p")
-  (latex-table-wizard--jump 'backward nil n))
+  (latex-table-wizard--jump 'backward nil n nil nocycle))
 
-(defun latex-table-wizard-down (&optional n)
+(defun latex-table-wizard-down (&optional n nocycle)
   "Move point N cells down.
 
 Leave point at the beginning of the cell.
 
 If N is nil, move one row down.
 
-If there is no row below where point is, move to the top cell of
-the column to the right of where point is."
+If there is no row below where point is, and NOCYCLE is nil, move
+to the top cell of the column to the right of where point is.  If
+NOCYCLE is non-nil, do not move and return nil in that case."
   (interactive "p")
-  (latex-table-wizard--jump 'next nil n))
+  (latex-table-wizard--jump 'next nil n nil nocycle))
 
-(defun latex-table-wizard-up (&optional n)
+(defun latex-table-wizard-up (&optional n nocycle)
   "Move point N cells up.
 
 Leave point at the beginning of the cell.
 
 If N is nil, move one row up.
 
-If there is no row above where point is, move to the bottom cell
-of the column to the left of where point is."
+If there is no row above where point is, and NOCYCLE is nil, move
+to the bottom cell of the column to the left of where point is.
+If NOCYCLE is non-nil, do not move and return nil in that case."
   (interactive "p")
-  (latex-table-wizard--jump 'previous nil n))
+  (latex-table-wizard--jump 'previous nil n nil nocycle))
 
 (defun latex-table-wizard-end-of-row ()
   "Move point to the rightmost cell in current row."
@@ -1642,7 +1686,7 @@ If non-nil TABLE is a list of cells."
               (envs (latex-table-wizard--get-env-ends tab))
               (out t))
          (dolist (c latex-table-wizard--selection)
-           (unless (< (car envs) (plist-get c :start) (cdr envs))
+           (unless (<= (car envs) (plist-get c :start) (cdr envs))
              (setq out nil)))
          out)))
 



reply via email to

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