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

add LaTeX tests with delete-selection on #1208

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
64 changes: 26 additions & 38 deletions smartparens.el
Original file line number Diff line number Diff line change
Expand Up @@ -730,8 +730,8 @@ You can enable pre-set bindings by customizing
;; `self-insert-command', rather, they insert via `insert'.
;; Therefore, we need to call this handler in
;; `post-command-hook' too (inside
;; `sp--post-command-hook-handler'). The list
;; `sp--special-self-insert-commands' specifies which commands
;; `sp--post-command-hook-handler'). The function
;; `sp--special-self-insert-command-p' specifies which commands
;; to handle specially.
(add-hook 'post-self-insert-hook 'sp--post-self-insert-hook-handler nil 'local)
(add-hook 'pre-command-hook 'sp--save-pre-command-state nil 'local)
Expand Down Expand Up @@ -2102,9 +2102,7 @@ BODY, do nothing."
;; Please contribute these if you come across some!
(defvar sp--self-insert-commands
'(self-insert-command
org-self-insert-command
LaTeX-insert-left-brace
latex-insert-left-brace)
org-self-insert-command)
"List of commands that are some sort of `self-insert-command'.

Many modes rebind \"self-inserting\" keys to \"smart\" versions
Expand All @@ -2113,46 +2111,36 @@ insertion to `self-insert-command'. Smartparens needs to be able
to distinguish these to properly handle insertion and reinsertion
of pairs and wraps.")

;; Please contribute these if you come across some!
(defvar sp--special-self-insert-commands
'(
TeX-insert-dollar
TeX-insert-quote
;; At some point the TeX and LaTeX functions were renamed to
;; lower-case names. This broke some code dealing with these
;; modes, so we just add both versions for now.
tex-insert-dollar
tex-insert-quote
latex-insert-quote
quack-insert-opening-paren
quack-insert-closing-paren
quack-insert-opening-bracket
quack-insert-closing-bracket
racket-insert-closing-paren
racket-insert-closing-bracket
racket-insert-closing-brace
)
"List of commands which are handled as if they were `self-insert-command's.

Some modes redefine \"self-inserting\" keys to \"smart\" versions
which do some additional processing but do _not_ delegate the
insertion to `self-insert-command', instead inserting via
`insert'. Smartparens needs to be able to distinguish these to
properly handle insertion and reinsertion of pairs and wraps.

The `sp--post-self-insert-hook-handler' is called in the
`post-command-hook' for these commands.")

(defun sp--self-insert-command-p ()
"Return non-nil if `this-command' is some sort of `self-insert-command'."
(memq this-command sp--self-insert-commands))

(defun sp--special-self-insert-command-p ()
"Return non-nil if `this-command' is \"special\" self insert command.

A special self insert command is one that inserts a character but
does not trigger `post-self-insert-hook'."
(memq this-command sp--special-self-insert-commands))
Some modes redefine \"self-inserting\" keys to \"smart\" versions
which do some additional processing but do _not_ delegate the
insertion to `self-insert-command', instead inserting via
`insert' and not triggering the `post-self-insert-hook'.
Smartparens needs to be able to distinguish these to properly
handle insertion and reinsertion of pairs and wraps.

The `sp--post-self-insert-hook-handler' is called in the
`post-command-hook' for these commands."
(memq this-command
`(
,@(and (boundp 'AUCTeX-version) (version<= AUCTeX-version "14.0.5")
'(TeX-insert-dollar))
tex-insert-quote
TeX-insert-quote
quack-insert-opening-paren
quack-insert-closing-paren
quack-insert-opening-bracket
quack-insert-closing-bracket
racket-insert-closing-paren
racket-insert-closing-bracket
racket-insert-closing-brace
)))

(defun sp--signum (x)
"Return 1 if X is positive, -1 if negative, 0 if zero."
Expand Down
41 changes: 40 additions & 1 deletion test/smartparens-auctex-latex-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,48 @@ thesmeves and would not break unrelated pair)"
(sp-buffer-equals "$foo ``| baz$")))

;; #834
(ert-deftest sp-test-LaTeX-wrap-with-trigger ()
(ert-deftest sp-test-LaTeX-wrap-with-trigger-quote ()
"A region should be wrapped with a pair if trigger key is pressed."
(sp-test-with-temp-buffer "foo Mbar baz| bam"
(LaTeX-mode)
(execute-kbd-macro "\"")
(sp-buffer-equals "foo ``bar baz''| bam")))

;; FIXME
;; (ert-deftest sp-test-LaTeX-wrap-with-trigger-quote-delsel ()
;; "A region should be wrapped with a pair if trigger key is pressed."
;; (sp-test-with-delete-selection-mode
;; (sp-test-with-temp-buffer "foo Mbar baz| bam"
;; (LaTeX-mode)
;; (execute-kbd-macro "\"")
;; (sp-buffer-equals "foo ``bar baz''| bam"))))

(ert-deftest sp-test-LaTeX-wrap-with-trigger-backslash-paren ()
"A region should be wrapped with a pair if trigger key is pressed."
(sp-test-with-temp-buffer "foo |bar bazM bam"
(LaTeX-mode)
(execute-kbd-macro "\\(")
(sp-buffer-equals "foo \\(|bar baz\\) bam")))

(ert-deftest sp-test-LaTeX-wrap-with-trigger-backslash-paren-delsel ()
"A region should be wrapped with a pair if trigger key is pressed."
(sp-test-with-delete-selection-mode
(sp-test-with-temp-buffer "foo |bar bazM bam"
(LaTeX-mode)
(execute-kbd-macro "\\(")
(sp-buffer-equals "foo \\(|bar baz\\) bam"))))

(ert-deftest sp-test-LaTeX-wrap-with-trigger-dollar ()
"A region should be wrapped with a pair if trigger key is pressed."
(sp-test-with-temp-buffer "foo |bar bazM bam"
(LaTeX-mode)
(execute-kbd-macro "$")
(sp-buffer-equals "foo $|bar baz$ bam")))

(ert-deftest sp-test-LaTeX-wrap-with-trigger-dollar-delsel ()
"A region should be wrapped with a pair if trigger key is pressed."
(sp-test-with-delete-selection-mode
(sp-test-with-temp-buffer "foo |bar bazM bam"
(LaTeX-mode)
(execute-kbd-macro "$")
(sp-buffer-equals "foo $|bar baz$ bam"))))
40 changes: 39 additions & 1 deletion test/smartparens-tex-mode-latex-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,47 @@ thesmeves and would not break unrelated pair)"
(sp-buffer-equals "$foo ``| baz$")))

;; #834
(ert-deftest sp-test-latex-wrap-with-trigger ()
(ert-deftest sp-test-latex-wrap-with-trigger-quote ()
"A region should be wrapped with a pair if trigger key is pressed."
(sp-test-with-temp-buffer "foo Mbar baz| bam"
(latex-mode)
(execute-kbd-macro "\"")
(sp-buffer-equals "foo ``bar baz''| bam")))

(ert-deftest sp-test-latex-wrap-with-trigger-quote-delsel ()
"A region should be wrapped with a pair if trigger key is pressed."
(sp-test-with-delete-selection-mode
(sp-test-with-temp-buffer "foo Mbar baz| bam"
(latex-mode)
(execute-kbd-macro "\"")
(sp-buffer-equals "foo ``bar baz''| bam"))))

(ert-deftest sp-test-latex-wrap-with-trigger-backslash-paren ()
"A region should be wrapped with a pair if trigger key is pressed."
(sp-test-with-temp-buffer "foo |bar bazM bam"
(latex-mode)
(execute-kbd-macro "\\(")
(sp-buffer-equals "foo \\(|bar baz\\) bam")))

(ert-deftest sp-test-latex-wrap-with-trigger-backslash-paren-delsel ()
"A region should be wrapped with a pair if trigger key is pressed."
(sp-test-with-delete-selection-mode
(sp-test-with-temp-buffer "foo |bar bazM bam"
(latex-mode)
(execute-kbd-macro "\\(")
(sp-buffer-equals "foo \\(|bar baz\\) bam"))))

(ert-deftest sp-test-latex-wrap-with-trigger-dollar ()
"A region should be wrapped with a pair if trigger key is pressed."
(sp-test-with-temp-buffer "foo |bar bazM bam"
(latex-mode)
(execute-kbd-macro "$")
(sp-buffer-equals "foo $|bar baz$ bam")))

(ert-deftest sp-test-latex-wrap-with-trigger-dollar-delsel ()
"A region should be wrapped with a pair if trigger key is pressed."
(sp-test-with-delete-selection-mode
(sp-test-with-temp-buffer "foo |bar bazM bam"
(latex-mode)
(execute-kbd-macro "$")
(sp-buffer-equals "foo $|bar baz$ bam"))))