From 1525a5ac9ed8abc1cb4bf78dc5bbd9f359fcfca4 Mon Sep 17 00:00:00 2001 From: "modula t. worm" Date: Wed, 3 May 2023 17:06:51 -0500 Subject: [PATCH] Add `sp-navigate-parallel-stop-at-ends` option This option will cause `sp-forward-parallel-sexp` and `sp-backward-parallel-sexp` to raise a `user-error` when hitting the end of the enclosing sexp, rather than looping back to the other end. Fixes Fuco1#1038. --- smartparens.el | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/smartparens.el b/smartparens.el index bf99f5f7..1be141d6 100644 --- a/smartparens.el +++ b/smartparens.el @@ -1325,6 +1325,12 @@ cease to be configurable." :type 'boolean :group 'smartparens) +(defcustom sp-navigate-parallel-stop-at-ends nil + "If non-nil, parallel sexp movements stop when hitting the end of +the containing sexp rather than looping back to the other end." + :type 'boolean + :group 'smartparens) + (defcustom sp-sexp-prefix nil "Alist of `major-mode' specific prefix specification. @@ -5997,8 +6003,12 @@ that is the first child of the enclosing sexp as defined by (progn (goto-char (sp-get next :end)) next) - (goto-char (sp-get next :beg-in)) - (sp-forward-sexp))))))) + (if sp-navigate-parallel-stop-at-ends + (if (= (point) (sp-get next :end-in)) + (user-error "End of containing sexp") + (goto-char (sp-get next :end-in))) + (goto-char (sp-get next :beg-in)) + (sp-forward-sexp)))))))) re))) (defun sp-backward-parallel-sexp (&optional arg) @@ -6030,8 +6040,12 @@ is the last child of the enclosing sexp as defined by (progn (goto-char (sp-get prev :beg)) prev) - (goto-char (sp-get prev :end-in)) - (sp-backward-sexp))))))) + (if sp-navigate-parallel-stop-at-ends + (if (= (point) (sp-get prev :beg-in)) + (user-error "End of containing sexp") + (goto-char (sp-get prev :beg-in))) + (goto-char (sp-get prev :end-in)) + (sp-backward-sexp)))))))) re))) (defun sp--raw-argument-p (arg)