From ba33463d5e060222e39f1035e258308c1d8e697b Mon Sep 17 00:00:00 2001 From: Artem Yurchenko Date: Sat, 18 May 2024 13:15:06 -0400 Subject: [PATCH 1/3] add LaTeX tests with delete-selection on the tests fail on the current version of auctex, but pass on the most recent one following https://git.savannah.gnu.org/cgit/auctex.git/commit/?id=45ee2f. --- smartparens.el | 12 ++------ test/smartparens-auctex-latex-test.el | 41 ++++++++++++++++++++++++- test/smartparens-tex-mode-latex-test.el | 40 +++++++++++++++++++++++- 3 files changed, 81 insertions(+), 12 deletions(-) diff --git a/smartparens.el b/smartparens.el index f6251907..02c772cd 100644 --- a/smartparens.el +++ b/smartparens.el @@ -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 @@ -2116,14 +2114,8 @@ 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 + TeX-insert-quote quack-insert-opening-paren quack-insert-closing-paren quack-insert-opening-bracket diff --git a/test/smartparens-auctex-latex-test.el b/test/smartparens-auctex-latex-test.el index c77f3777..be29d128 100644 --- a/test/smartparens-auctex-latex-test.el +++ b/test/smartparens-auctex-latex-test.el @@ -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")))) diff --git a/test/smartparens-tex-mode-latex-test.el b/test/smartparens-tex-mode-latex-test.el index 82b9cbe2..36390f17 100644 --- a/test/smartparens-tex-mode-latex-test.el +++ b/test/smartparens-tex-mode-latex-test.el @@ -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")))) From a2310fd43320da2ae9cf5f970876cd55f95b22c8 Mon Sep 17 00:00:00 2001 From: Artem Yurchenko Date: Mon, 20 May 2024 13:36:39 -0400 Subject: [PATCH 2/3] fixup! add LaTeX tests with delete-selection on --- smartparens.el | 56 ++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/smartparens.el b/smartparens.el index 02c772cd..c599673b 100644 --- a/smartparens.el +++ b/smartparens.el @@ -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) @@ -2111,30 +2111,6 @@ 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-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 - ) - "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)) @@ -2142,9 +2118,31 @@ The `sp--post-self-insert-hook-handler' is called in the (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." + (let ((special-self-insert-commands + `( + ,@(when (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 + ))) + (memq this-command special-self-insert-commands))) (defun sp--signum (x) "Return 1 if X is positive, -1 if negative, 0 if zero." From c6308cf3c09cb79de64600b27953e55846c7c187 Mon Sep 17 00:00:00 2001 From: Artem Yurchenko Date: Mon, 20 May 2024 13:45:31 -0400 Subject: [PATCH 3/3] fixup! fixup! add LaTeX tests with delete-selection on --- smartparens.el | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/smartparens.el b/smartparens.el index c599673b..7674b753 100644 --- a/smartparens.el +++ b/smartparens.el @@ -2127,22 +2127,20 @@ 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." - (let ((special-self-insert-commands - `( - ,@(when (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 - ))) - (memq this-command special-self-insert-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."