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

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

[elpa] master 8328c38 08/42: Fix another failure of cc-mode indentation


From: Noam Postavsky
Subject: [elpa] master 8328c38 08/42: Fix another failure of cc-mode indentation
Date: Sun, 22 Dec 2019 17:37:57 -0500 (EST)

branch: master
commit 8328c38d77f3d6a8aafc67975437ee4fc6c09e1e
Author: Noam Postavsky <address@hidden>
Commit: Noam Postavsky <address@hidden>

    Fix another failure of cc-mode indentation
    
    Suggested by OGAWA Hirofumi in
    https://github.com/joaotavora/yasnippet/issues/953.
    * yasnippet.el (yas--snippet-create): Call before and after change
    functions around yas--snippet-parse-create.
    * yasnippet-tests.el (indent-cc-mode-2): New test.
---
 yasnippet-tests.el | 16 ++++++++++++++++
 yasnippet.el       |  9 +++++++--
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/yasnippet-tests.el b/yasnippet-tests.el
index fb4bc0f..f96bf4c 100644
--- a/yasnippet-tests.el
+++ b/yasnippet-tests.el
@@ -556,6 +556,22 @@ int foo()
   }
 }" (buffer-string)))))
 
+(ert-deftest indent-cc-mode-2 ()
+  "Handling of cc-mode's preprocessor indentation."
+  (with-temp-buffer
+    (c-mode)
+    (yas-minor-mode +1)
+    (yas-expand-snippet "\
+#ifndef `\"FOO\"`
+#define FOO
+#endif
+")
+    (should (string= "\
+#ifndef FOO
+#define FOO
+#endif
+" (buffer-substring-no-properties (point-min) (point-max))))))
+
 (ert-deftest indent-snippet-mode ()
   "Handling of snippet-mode indentation."
   ;; This is an interesting case because newlines match [[:space:]] in
diff --git a/yasnippet.el b/yasnippet.el
index 86f4b61..5fa72c3 100644
--- a/yasnippet.el
+++ b/yasnippet.el
@@ -4035,13 +4035,18 @@ Returns the newly created snippet."
         ;; content.
         (let ((buffer-undo-list t))
           ;; Some versions of cc-mode fail when inserting snippet
-          ;; content in a narrowed buffer.
+          ;; content in a narrowed buffer, so make sure to insert
+          ;; before narrowing.  Furthermore, call before and after
+          ;; change functions, otherwise cc-mode's cache can get
+          ;; messed up.
           (goto-char begin)
+          (run-hook-with-args 'before-change-functions begin begin)
           (insert content)
           (setq end (+ end (length content)))
           (narrow-to-region begin end)
           (goto-char (point-min))
-          (yas--snippet-parse-create snippet))
+          (yas--snippet-parse-create snippet)
+          (run-hook-with-args 'after-change-functions (point-min) (point-max) 
0))
         (when (listp buffer-undo-list)
           (push (cons (point-min) (point-max))
                 buffer-undo-list))



reply via email to

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