Fix overaggressive backspace
delete-backward-char would kill adjacent delimited regions: 1. | (...) 2. (|...)
This commit is contained in:
parent
fa19eaf8e0
commit
0f404a513a
1 changed files with 16 additions and 13 deletions
|
@ -10,18 +10,20 @@ whitespace is balanced on either side of the cursor.
|
||||||
If INLINE is nil, returns t if the opening and closing braces are on adjacent
|
If INLINE is nil, returns t if the opening and closing braces are on adjacent
|
||||||
lines, above and below, with only whitespace in between."
|
lines, above and below, with only whitespace in between."
|
||||||
(when-let* ((pair (or pair (sp-get-thing))))
|
(when-let* ((pair (or pair (sp-get-thing))))
|
||||||
(let ((op (plist-get pair :op))
|
(let ((beg (plist-get pair :beg))
|
||||||
(cl (plist-get pair :cl)))
|
(end (plist-get pair :end))
|
||||||
(and op cl
|
(pt (point)))
|
||||||
(not (string-empty-p op))
|
(when (and (> pt beg) (< pt end))
|
||||||
(not (string-empty-p cl))
|
(when-let* ((cl (plist-get pair :cl))
|
||||||
(let ((beg (+ (length op) (plist-get pair :beg)))
|
(op (plist-get pair :op)))
|
||||||
(end (- (plist-get pair :end) (length cl)))
|
(and (not (string-empty-p op))
|
||||||
(pt (point)))
|
(not (string-empty-p cl))
|
||||||
(let ((content (buffer-substring-no-properties beg end)))
|
(let ((nbeg (+ (length op) beg))
|
||||||
(and (string-match-p (format "[ %s]*" (if inline "" "\n")) content)
|
(nend (- end (length cl))))
|
||||||
(or (not balanced)
|
(let ((content (buffer-substring-no-properties nbeg nend)))
|
||||||
(= (- pt beg) (- end pt))))))))))
|
(and (string-match-p (format "[ %s]*" (if inline "" "\n")) content)
|
||||||
|
(or (not balanced)
|
||||||
|
(= (- pt nbeg) (- nend pt))))))))))))
|
||||||
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
|
@ -181,13 +183,14 @@ possible, or just one char if that's not possible."
|
||||||
(insert-char ?\s (- ocol (current-column)) nil))))
|
(insert-char ?\s (- ocol (current-column)) nil))))
|
||||||
;;
|
;;
|
||||||
((and (= n 1) (not (minibufferp)))
|
((and (= n 1) (not (minibufferp)))
|
||||||
|
;; TODO Refactor; abstract with doom-surrounded-p more
|
||||||
(let* ((pair (sp-get-thing))
|
(let* ((pair (sp-get-thing))
|
||||||
(op (plist-get pair :op))
|
(op (plist-get pair :op))
|
||||||
(cl (plist-get pair :cl))
|
(cl (plist-get pair :cl))
|
||||||
(beg (plist-get pair :beg))
|
(beg (plist-get pair :beg))
|
||||||
(end (plist-get pair :end)))
|
(end (plist-get pair :end)))
|
||||||
(cond ((and end beg (= end (+ beg (length op) (length cl))))
|
(cond ((and end beg (= end (+ beg (length op) (length cl))))
|
||||||
(sp-backward-delete-char 0))
|
(sp-backward-delete-char 1))
|
||||||
((doom-surrounded-p pair :inline :balanced)
|
((doom-surrounded-p pair :inline :balanced)
|
||||||
(delete-char -1 killflag)
|
(delete-char -1 killflag)
|
||||||
(delete-char 1)
|
(delete-char 1)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue