Skip to content

Commit

Permalink
Merge pull request #1708 from sakurawald/paredit-wrap
Browse files Browse the repository at this point in the history
feature: the paredit-wrap-around now support to select sexp at point without the need to move point to the beginning of sexp
  • Loading branch information
cxxxr authored Dec 17, 2024
2 parents 3f325ba + 4d97316 commit 3e64ef5
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions extensions/paredit-mode/paredit-mode.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ link : http://www.daregada.sakuraweb.com/paredit_tutorial_ja.html


(defun %paredit-wrap (begin-char end-char)
;; FIXME: the buffer-mark-p always be nil for marks that set by vi-mode. (The mark state in vi-mode and emacs-mode is not synced.)
(if (buffer-mark-p (current-buffer))
(with-point ((begin (region-beginning (current-buffer)))
(end (region-end (current-buffer))))
Expand All @@ -579,14 +580,30 @@ link : http://www.daregada.sakuraweb.com/paredit_tutorial_ja.html
(insert-character (current-point) end-char)
(insert-character (current-point) #\Space)
(move-point (current-point) (character-offset begin 1))))))
(with-point ((origin (current-point)))
(unless (in-string-or-comment-p origin)
(forward-sexp)
(insert-character origin begin-char)
(unless (non-space-following-context-p origin)
(insert-character origin #\Space))
(insert-character (current-point) end-char)
(move-point (current-point) (character-offset origin 1))))))
(with-point ((start (current-point))
(end (current-point)))
(unless (in-string-or-comment-p start)
;; Forward sexp to select the end, unless current-point it not at end-char.
(unless (equal (character-at (current-point))
end-char)
(forward-sexp))
(setf end (copy-point (current-point) :temporary))

;; Backward sexp to select the start.
(backward-sexp)
(setf start (copy-point (current-point) :temporary))

;; Insert the one `open-char` before `start`.
(insert-character start #\Space)
(insert-character start begin-char)

;; Because we have inserted the one `space` and one `open-char`, the `end` should + 2.
(character-offset end 2)
(insert-character end end-char)

;; Move current-point to the `inserted space char`.
(character-offset start 1)
(move-point (current-point) start)))))

(define-command paredit-wrap-round () ()
(%paredit-wrap #\( #\)))
Expand All @@ -595,7 +612,7 @@ link : http://www.daregada.sakuraweb.com/paredit_tutorial_ja.html
(%paredit-wrap #\" #\"))

(define-command paredit-vertical-line-wrap () ()
(lem-paredit-mode::%paredit-wrap #\| #\|))
(%paredit-wrap #\| #\|))

(define-keys *paredit-mode-keymap*
('forward-sexp 'paredit-forward)
Expand Down

0 comments on commit 3e64ef5

Please sign in to comment.