Skip to content

Commit

Permalink
feature: treat as selecting current line if no region is selected for…
Browse files Browse the repository at this point in the history
… comments.
  • Loading branch information
sakurawald committed Dec 1, 2024
1 parent 136788a commit a98a8b1
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/ext/language-mode.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,18 @@
(uncomment-region)
(comment-region)))

(defun select-current-line-if-no-region-is-selected (start end)
(when (point= start end)
(setf start (line-start start))
(setf end (line-end end))))

(defun commented-region-p ()
(alexandria:when-let ((line-comment (variable-value 'line-comment :buffer)))
(with-point ((start (current-point))
(end (current-point)))
(set-region-point-using-global-mode (current-global-mode) start end)
(select-current-line-if-no-region-is-selected start end)

(loop
(skip-whitespace-forward start)
(when (point>= start end)
Expand All @@ -176,6 +183,8 @@
(with-point ((start (current-point) :right-inserting)
(end (current-point) :left-inserting))
(set-region-point-using-global-mode (current-global-mode) start end)
(select-current-line-if-no-region-is-selected start end)

(skip-whitespace-forward start)
(when (point>= start end)
(insert-string (current-point) line-comment)
Expand Down Expand Up @@ -203,6 +212,8 @@
(with-point ((start (current-point) :right-inserting)
(end (current-point) :right-inserting))
(set-region-point-using-global-mode (current-global-mode) start end)
(select-current-line-if-no-region-is-selected start end)

(let ((p start))
(loop
(parse-partial-sexp p end nil t)
Expand Down

0 comments on commit a98a8b1

Please sign in to comment.