Skip to content

Commit

Permalink
More conservative whitespace handling in symex bounds
Browse files Browse the repository at this point in the history
Include at most one trailing whitespace character in symex bounds. Fix
whitespace regex. Don't eliminate intervening trailing whitespace on
deletion. Some whitespace-related utilities.
  • Loading branch information
countvajhula committed Jun 15, 2024
1 parent 0d69fde commit 273f42e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
13 changes: 9 additions & 4 deletions symex-primitives-lisp.el
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
(defvar symex--re-blank-line "^[[:space:]]*$"
"A blank line, either empty or containing only whitespace.")

(defvar symex--re-whitespace "[[:space:]|\n]*"
(defvar symex--re-whitespace "[[:space:]|\n]+"
"Whitespace that may extend over many lines.")

(defvar symex--re-symex-line "^[[:space:]]*[^;[:space:]\n]"
Expand Down Expand Up @@ -211,6 +211,10 @@
(cond ((looking-at "\\s(") (forward-list 1) (backward-char 1))
((looking-at "\\s)") (forward-char 1) (backward-list 1))))

(defun symex-whitespace-p ()
"Check if we're looking at whitespace."
(looking-at-p symex--re-whitespace))

(defun symex-comment-line-p ()
"Check if we're currently at the start of a comment line."
(save-excursion
Expand Down Expand Up @@ -424,8 +428,9 @@ including trailing whitespace at the end of the last symex."
(let ((endpoint (symex-lisp--get-end-point-helper count)))
(if include-whitespace
(progn (goto-char endpoint)
(if (symex--go-to-next-non-whitespace-char)
(1- (point))
(if (and (not (eobp))
(symex-whitespace-p))
(1+ endpoint)
endpoint))
endpoint))))

Expand Down Expand Up @@ -678,7 +683,7 @@ line."
(error nil))
(symex--join-to-match symex--re-right))))))))
((symex-right-p) (fixup-whitespace)) ; abc <>)
(t (symex--join-to-non-whitespace))))
(t nil)))

;;; Utilities

Expand Down
10 changes: 10 additions & 0 deletions symex-utils.el
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ the following recipe instead."
(defvar symex--re-non-whitespace "[^[:space:]\n]"
"A non-whitespace character.")

(defvar symex--re-non-whitespace-or-newline "[^[:space:]]"
"A non-whitespace character.")

(defun symex--go-to-next-non-whitespace-char ()
"Move point to the next non-whitespace character.
Expand Down Expand Up @@ -101,6 +104,13 @@ This eliminates whitespace between the original position and the found
match."
(symex--join-to-match symex--re-non-whitespace))

(defun symex--join-to-non-whitespace-or-newline ()
"Join current position to the next non-whitespace character.
This eliminates whitespace between the original position and the found
match."
(symex--join-to-match symex--re-non-whitespace-or-newline))

;; `with-undo-collapse` macro, to treat a sequence of operations
;; as a single entry in the undo list.
;; From: https://emacs.stackexchange.com/questions/7558/collapsing-undo-history/7560#7560
Expand Down

0 comments on commit 273f42e

Please sign in to comment.