[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))
- [elpa] master updated (2604824 -> 32f3512), Noam Postavsky, 2019/12/22
- [elpa] master 4af3354 02/42: Make less garbage in overlay heavy buffers, Noam Postavsky, 2019/12/22
- [elpa] master e67592c 03/42: Don't use overlays to find active snippets, Noam Postavsky, 2019/12/22
- [elpa] master 79b90c9 04/42: Remove compatibility code for Emacs 22 and earlier, Noam Postavsky, 2019/12/22
- [elpa] master d3bb879 05/42: Remove last-buffer-undo-list compat definition, Noam Postavsky, 2019/12/22
- [elpa] master 4f78d03 01/42: Close #937: Officially support automatically moving to next field, Noam Postavsky, 2019/12/22
- [elpa] master 1e71360 06/42: Per #947: fix typo in README.md, Noam Postavsky, 2019/12/22
- [elpa] master 7a178a2 07/42: Remove spurious change of before-change-functions, Noam Postavsky, 2019/12/22
- [elpa] master 8328c38 08/42: Fix another failure of cc-mode indentation,
Noam Postavsky <=
- [elpa] master eeb05f0 10/42: Handle field adjust of pending active fields, Noam Postavsky, 2019/12/22
- [elpa] master 8452227 13/42: Consider fundamental-mode as ultimate ancestor, Noam Postavsky, 2019/12/22
- [elpa] master fb253ac 15/42: New public function yas-maybe-expand-abbrev-key-filter, Noam Postavsky, 2019/12/22
- [elpa] master bceb65b 16/42: Make backspace/DEL clear field (#957), Noam Postavsky, 2019/12/22
- [elpa] master 3c0be40 11/42: Update FAQ, Noam Postavsky, 2019/12/22
- [elpa] master 8b25d62 20/42: * doc/snippet-development.org: Fix typos., Noam Postavsky, 2019/12/22
- [elpa] master 7612bc1 24/42: Don't check this-command in yas-not-string-or-comment-condition, Noam Postavsky, 2019/12/22
- [elpa] master dabc719 21/42: Don't turn on yas-minor-mode in temp buffers, Noam Postavsky, 2019/12/22
- [elpa] master fc33b2f 28/42: Make overlay-modification protection optional, Noam Postavsky, 2019/12/22
- [elpa] master 048d030 22/42: Fix line-relative snapshotting for org src blocks, Noam Postavsky, 2019/12/22