From a6de0055cde9a37366036990e491af648b43cc65 Mon Sep 17 00:00:00 2001 From: Michael Fogleman Date: Thu, 14 Aug 2014 14:00:38 -0400 Subject: [PATCH] Abstract position tests from sp-show--pair-function. --- smartparens.el | 62 +++++++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/smartparens.el b/smartparens.el index 586477ce..9f8938fb 100644 --- a/smartparens.el +++ b/smartparens.el @@ -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)))))))