Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abstract position tests from sp-show--pair-function. #355

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 34 additions & 28 deletions smartparens.el
Original file line number Diff line number Diff line change
Expand Up @@ -7674,39 +7674,45 @@ support custom pairs."
(sp-show--pair-enc-function ok)))
(execute-kbd-macro cmd))))

(defun sp-test-opening ()
(or (sp--looking-at (if sp-show-pair-from-inside
(and sp-show-pair-from-inside (sp--get-allowed-regexp))
(sp--get-opening-regexp (sp--get-allowed-pair-list))))
(and (memq major-mode sp-navigate-consider-stringlike-sexp)
(looking-at (sp--get-stringlike-regexp)))
(and (memq major-mode sp-navigate-consider-sgml-tags)
(looking-at "<"))))

(defun sp-test-closing ()
(or (sp--looking-back (if sp-show-pair-from-inside
(and sp-show-pair-from-inside (sp--get-allowed-regexp))
(sp--get-closing-regexp (sp--get-allowed-pair-list))))
(and (memq major-mode sp-navigate-consider-stringlike-sexp)
(sp--looking-back (sp--get-stringlike-regexp)))
(and (memq major-mode sp-navigate-consider-sgml-tags)
(sp--looking-back ">"))))

(defun sp-show--pair-function ()
"Display the show pair overlays."
(when show-smartparens-mode
(save-match-data
(let* ((pair-list (sp--get-allowed-pair-list))
(opening (sp--get-opening-regexp pair-list))
(closing (sp--get-closing-regexp pair-list))
(allowed (and sp-show-pair-from-inside (sp--get-allowed-regexp)))
ok match)
(let* (ok match)
(cond
((or (sp--looking-at (if sp-show-pair-from-inside allowed opening))
(and (memq major-mode sp-navigate-consider-stringlike-sexp)
(looking-at (sp--get-stringlike-regexp)))
(and (memq major-mode sp-navigate-consider-sgml-tags)
(looking-at "<")))
(setq match (match-string 0))
;; we can use `sp-get-thing' here because we *are* at some
;; pair opening, and so only the tag or the sexp can trigger.
(setq ok (sp-get-thing))
(if ok
(sp-get ok (sp-show--pair-create-overlays :beg :end :op-l :cl-l))
(sp-show--pair-create-mismatch-overlay (point) (length match))))
((or (sp--looking-back (if sp-show-pair-from-inside allowed closing))
(and (memq major-mode sp-navigate-consider-stringlike-sexp)
(sp--looking-back (sp--get-stringlike-regexp)))
(and (memq major-mode sp-navigate-consider-sgml-tags)
(sp--looking-back ">")))
(setq match (match-string 0))
(setq ok (sp-get-thing t))
(if ok
(sp-get ok (sp-show--pair-create-overlays :beg :end :op-l :cl-l))
(sp-show--pair-create-mismatch-overlay (- (point) (length match))
(length match))))
((sp-test-opening)
(setq match (match-string 0))
;; we can use `sp-get-thing' here because we *are* at some
;; pair opening, and so only the tag or the sexp can trigger.
(setq ok (sp-get-thing))
(if ok
(sp-get ok (sp-show--pair-create-overlays :beg :end :op-l :cl-l))
(sp-show--pair-create-mismatch-overlay (point) (length match))))
((sp-test-closing)
(setq match (match-string 0))
(setq ok (sp-get-thing t))
(if ok
(sp-get ok (sp-show--pair-create-overlays :beg :end :op-l :cl-l))
(sp-show--pair-create-mismatch-overlay (- (point) (length match))
(length match))))
(sp-show-pair-overlays
(sp-show--pair-delete-overlays)))))))

Expand Down