emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/smartparens 0bbd854d76 1/2: fix(yas): when expanding a sni


From: ELPA Syncer
Subject: [nongnu] elpa/smartparens 0bbd854d76 1/2: fix(yas): when expanding a snippet with hippie, do not add extra parens
Date: Sat, 30 Mar 2024 16:00:35 -0400 (EDT)

branch: elpa/smartparens
commit 0bbd854d766d64c9eeaa4a034de10fb14d5f1d48
Author: Matus Goljer <matus.goljer@gmail.com>
Commit: Matus Goljer <matus.goljer@gmail.com>

    fix(yas): when expanding a snippet with hippie, do not add extra parens
    
    Fixes #911
---
 smartparens.el                  |  7 ++++--
 test/smartparens-advice-test.el | 51 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+), 2 deletions(-)

diff --git a/smartparens.el b/smartparens.el
index cd72006162..d45616b877 100644
--- a/smartparens.el
+++ b/smartparens.el
@@ -9756,12 +9756,15 @@ has been created."
 (defadvice company--insert-candidate (after sp-company--insert-candidate 
activate)
   "If `smartparens-mode' is active, we check if the completed string
 has a pair definition.  If so, we insert the closing pair."
-  (when (and ad-return-value smartparens-mode)
+  (when (and ad-return-value
+             smartparens-mode
+             (not (sp-get-enclosing-sexp)))
     (sp-insert-pair))
   ad-return-value)
 
 (defadvice hippie-expand (after sp-auto-complete-advice activate)
-  (when smartparens-mode
+  (when (and smartparens-mode
+             (not (sp-get-enclosing-sexp)))
     (sp-insert-pair)))
 
 (defvar sp--mc/cursor-specific-vars
diff --git a/test/smartparens-advice-test.el b/test/smartparens-advice-test.el
new file mode 100644
index 0000000000..779badd53d
--- /dev/null
+++ b/test/smartparens-advice-test.el
@@ -0,0 +1,51 @@
+;;; Tests for advices and compat with external packages
+
+(require 'yasnippet)
+(require 'hippie-exp)
+
+;; These macros are copied from yasnippet-tests.el
+(progn
+  (defmacro yas-with-snippet-dirs (dirs &rest body)
+    (declare (indent defun) (debug t))
+    `(yas-call-with-snippet-dirs
+      ,dirs #'(lambda () ,@body)))
+
+  (defun yas-make-file-or-dirs (ass)
+    (let ((file-or-dir-name (car ass))
+          (content (cdr ass)))
+      (cond ((listp content)
+             (make-directory file-or-dir-name 'parents)
+             (let ((default-directory (concat default-directory "/" 
file-or-dir-name)))
+               (mapc #'yas-make-file-or-dirs content)))
+            ((stringp content)
+             (with-temp-buffer
+               (insert content)
+               (write-region nil nil file-or-dir-name nil 'nomessage)))
+            (t
+             (message "[yas] oops don't know this content")))))
+
+  (defun yas-call-with-snippet-dirs (dirs fn)
+    (let* ((default-directory (make-temp-file "yasnippet-fixture" t))
+           (yas-snippet-dirs (mapcar (lambda (d) (expand-file-name (car d))) 
dirs)))
+      (with-temp-message ""
+        (unwind-protect
+            (progn
+              (mapc #'yas-make-file-or-dirs dirs)
+              (funcall fn))
+          (when (>= emacs-major-version 24)
+            (delete-directory default-directory 'recursive)))))))
+
+(ert-deftest sp-test-advice--hippie-no-pairing-if-sexp-already-exists ()
+  "Test that after hippie expand expands a yasnippet template it
+won't add an extra closing paren if the snippet already provides
+it."
+  (yas-with-snippet-dirs
+    '((".emacs.d/snippets"
+       ("emacs-lisp-mode" ("defun" . "(defun hello ($0))"))))
+    (let ((hippie-expand-try-functions-list
+           '(yas-hippie-try-expand)))
+      (sp-test-with-temp-elisp-buffer "defun|"
+        (yas-reload-all)
+        (yas-minor-mode 1)
+        (call-interactively 'hippie-expand)
+        (sp-buffer-equals "(defun hello (|))")))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]