Skip to content

Commit

Permalink
feat(org): code marker should prevent nested pairs
Browse files Browse the repository at this point in the history
Fixes #1031
  • Loading branch information
Fuco1 committed Mar 17, 2024
1 parent 6901461 commit ce1b3b9
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
20 changes: 17 additions & 3 deletions smartparens-org.el
Original file line number Diff line number Diff line change
Expand Up @@ -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 "«" "»"))
Expand Down
37 changes: 37 additions & 0 deletions test/smartparens-org-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -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/|=")))

0 comments on commit ce1b3b9

Please sign in to comment.