From 4b9c9ee2f3083dc4b48ff784d173ab85ac14961f Mon Sep 17 00:00:00 2001 From: "David J. Rosenbaum" Date: Wed, 9 Apr 2025 17:57:32 -0700 Subject: [PATCH 1/4] Fix puni-forward-sexp and puni-backward-sexp in indented comment blocks This is done by skipping blanks before probing in puni--strict-primitive-forward-sexp-in-thing puni--strict-primitive-backward-sexp-in-thing --- puni.el | 2 ++ 1 file changed, 2 insertions(+) diff --git a/puni.el b/puni.el index 442672e..8a38893 100644 --- a/puni.el +++ b/puni.el @@ -854,6 +854,7 @@ and error \"Not in a THING\"." (when to (save-excursion (while (and (puni--forward-same-syntax to) + (puni--forward-blanks) (funcall probe) (setq pos (point)) (< (point) to)))) @@ -883,6 +884,7 @@ and error \"Not in a THING\"." (when to (save-excursion (while (and (puni--backward-same-syntax to) + (puni--backward-blanks) (funcall probe) (setq pos (point)) (> (point) to)))) From daeeff66621d94744a9bbc6b632aca7a3d9f4e69 Mon Sep 17 00:00:00 2001 From: "David J. Rosenbaum" Date: Wed, 9 Apr 2025 18:12:36 -0700 Subject: [PATCH 2/4] Don't test if blanks were skipped --- puni.el | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/puni.el b/puni.el index 8a38893..757caa2 100644 --- a/puni.el +++ b/puni.el @@ -854,8 +854,9 @@ and error \"Not in a THING\"." (when to (save-excursion (while (and (puni--forward-same-syntax to) - (puni--forward-blanks) - (funcall probe) + (progn + (puni--forward-blanks) + (funcall probe)) (setq pos (point)) (< (point) to)))) ;; We've successfully reached TO, while keeping inside the thing. @@ -884,8 +885,9 @@ and error \"Not in a THING\"." (when to (save-excursion (while (and (puni--backward-same-syntax to) - (puni--backward-blanks) - (funcall probe) + (progn + (puni--backward-blanks) + (funcall probe)) (setq pos (point)) (> (point) to)))) (if (eq pos to) From c402d7b62ef8e9dc3fc7244b35d45eadef4ce886 Mon Sep 17 00:00:00 2001 From: "David J. Rosenbaum" Date: Wed, 9 Apr 2025 18:27:18 -0700 Subject: [PATCH 3/4] Bind parse-sexp-ignore-comments to nil to allow movement in comments by default --- puni.el | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/puni.el b/puni.el index 757caa2..3d4ebac 100644 --- a/puni.el +++ b/puni.el @@ -923,13 +923,17 @@ hit the ending quote), return nil. Notice that a point inside the (multichar) quote is not considered as in the comment." - (puni--strict-primitive-forward-sexp-in-thing #'puni--in-comment-p - "comment")) + ;; Binding `parse-sexp-ignore-comments' is necessary because it is + ;; buffer-locally set to t in prog-mode.el. + (let ((parse-sexp-ignore-comments nil)) + (puni--strict-primitive-forward-sexp-in-thing #'puni--in-comment-p + "comment"))) (defun puni-strict-backward-sexp-in-comment () "Backward version of `puni-strict-forward-sexp-in-comment'." - (puni--strict-primitive-backward-sexp-in-thing #'puni--in-comment-p - "comment")) + (let ((parse-sexp-ignore-comments nil)) + (puni--strict-primitive-backward-sexp-in-thing #'puni--in-comment-p + "comment"))) ;;;;; Indent From 082748c1f897f361e451f45681af3f869f772300 Mon Sep 17 00:00:00 2001 From: "David J. Rosenbaum" Date: Wed, 9 Apr 2025 18:36:54 -0700 Subject: [PATCH 4/4] Fix the code for the case when there isn't a comment on the line after the sexp --- puni.el | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/puni.el b/puni.el index 3d4ebac..034f3b3 100644 --- a/puni.el +++ b/puni.el @@ -854,9 +854,7 @@ and error \"Not in a THING\"." (when to (save-excursion (while (and (puni--forward-same-syntax to) - (progn - (puni--forward-blanks) - (funcall probe)) + (funcall probe) (setq pos (point)) (< (point) to)))) ;; We've successfully reached TO, while keeping inside the thing. @@ -885,9 +883,7 @@ and error \"Not in a THING\"." (when to (save-excursion (while (and (puni--backward-same-syntax to) - (progn - (puni--backward-blanks) - (funcall probe)) + (funcall probe) (setq pos (point)) (> (point) to)))) (if (eq pos to) @@ -926,13 +922,19 @@ considered as in the comment." ;; Binding `parse-sexp-ignore-comments' is necessary because it is ;; buffer-locally set to t in prog-mode.el. (let ((parse-sexp-ignore-comments nil)) - (puni--strict-primitive-forward-sexp-in-thing #'puni--in-comment-p + (puni--strict-primitive-forward-sexp-in-thing (lambda () + (save-excursion + (skip-syntax-forward "-") + (puni--in-comment-p))) "comment"))) (defun puni-strict-backward-sexp-in-comment () "Backward version of `puni-strict-forward-sexp-in-comment'." (let ((parse-sexp-ignore-comments nil)) - (puni--strict-primitive-backward-sexp-in-thing #'puni--in-comment-p + (puni--strict-primitive-backward-sexp-in-thing (lambda () + (save-excursion + (skip-syntax-forward "-") + (puni--in-comment-p))) "comment"))) ;;;;; Indent