branch: elpa/smartparens
commit ce1b3b9ff83e7eef0da3d2e0e08c8b9e43a08d9a
Author: Matus Goljer <[email protected]>
Commit: Matus Goljer <[email protected]>
feat(org): code marker should prevent nested pairs
Fixes #1031
---
smartparens-org.el | 20 +++++++++++++++++---
test/smartparens-org-test.el | 37 +++++++++++++++++++++++++++++++++++++
2 files changed, 54 insertions(+), 3 deletions(-)
diff --git a/smartparens-org.el b/smartparens-org.el
index 8b864b1dcf..0bd51404db 100644
--- a/smartparens-org.el
+++ b/smartparens-org.el
@@ -58,12 +58,26 @@ This predicate is only tested on \"insert\" action."
(when (eq action 'insert)
(sp--looking-back-p (concat "\\[" (regexp-quote id)))))
+(defun sp-org-inside-inline-code (_id action _context)
+ (when (eq action 'insert)
+ (when-let ((expr (sp-get-stringlike-expression)))
+ (sp-get expr (member :op '("~" "="))))))
+
(sp-with-modes 'org-mode
(sp-local-pair "*" "*"
- :unless '(sp-point-after-word-p sp-point-at-bol-p)
+ :unless '(sp-point-after-word-p
+ sp-point-at-bol-p
+ sp-org-inside-inline-code
+ )
:skip-match 'sp--org-skip-asterisk)
- (sp-local-pair "_" "_" :unless '(sp-point-after-word-p))
- (sp-local-pair "/" "/" :unless '(sp-point-after-word-p
sp-org-point-after-left-square-bracket-p) :post-handlers '(("[d1]" "SPC")))
+ (sp-local-pair "_" "_" :unless '(sp-point-after-word-p
+ sp-org-inside-inline-code
+ ))
+ (sp-local-pair "/" "/" :unless '(sp-point-after-word-p
+ sp-org-point-after-left-square-bracket-p
+ sp-org-inside-inline-code
+ )
+ :post-handlers '(("[d1]" "SPC")))
(sp-local-pair "~" "~" :unless '(sp-point-after-word-p) :post-handlers
'(("[d1]" "SPC")))
(sp-local-pair "=" "=" :unless '(sp-point-after-word-p) :post-handlers
'(("[d1]" "SPC")))
(sp-local-pair "«" "»"))
diff --git a/test/smartparens-org-test.el b/test/smartparens-org-test.el
index 0f6cbfe29c..1be6d5a2e7 100644
--- a/test/smartparens-org-test.el
+++ b/test/smartparens-org-test.el
@@ -165,3 +165,40 @@
'asd|
#+end_src
")))
+
+;; 1031
+(ert-deftest sp-test-org-no-text-pairs-inside-code--slash ()
+ (sp-test-with-temp-buffer "hello ~code|~"
+ (org-mode)
+ (execute-kbd-macro "/")
+ (sp-buffer-equals "hello ~code/|~")))
+
+(ert-deftest sp-test-org-no-text-pairs-inside-code--star ()
+ (sp-test-with-temp-buffer "hello ~code|~"
+ (org-mode)
+ (execute-kbd-macro "/")
+ (sp-buffer-equals "hello ~code/|~")))
+
+(ert-deftest sp-test-org-no-text-pairs-inside-code--underscore ()
+ (sp-test-with-temp-buffer "hello ~code|~"
+ (org-mode)
+ (execute-kbd-macro "/")
+ (sp-buffer-equals "hello ~code/|~")))
+
+(ert-deftest sp-test-org-no-text-pairs-inside-code-equal--slash ()
+ (sp-test-with-temp-buffer "hello =code|="
+ (org-mode)
+ (execute-kbd-macro "/")
+ (sp-buffer-equals "hello =code/|=")))
+
+(ert-deftest sp-test-org-no-text-pairs-inside-code-equal--star ()
+ (sp-test-with-temp-buffer "hello =code|="
+ (org-mode)
+ (execute-kbd-macro "/")
+ (sp-buffer-equals "hello =code/|=")))
+
+(ert-deftest sp-test-org-no-text-pairs-inside-code-equal--underscore ()
+ (sp-test-with-temp-buffer "hello =code|="
+ (org-mode)
+ (execute-kbd-macro "/")
+ (sp-buffer-equals "hello =code/|=")))