Skip to content

Commit b20e65f

Browse files
M-frankiedjosteink
authored andcommitted
communicate default style safely (#118)
Communicate default style safely
1 parent 628a4e2 commit b20e65f

File tree

2 files changed

+40
-14
lines changed

2 files changed

+40
-14
lines changed

csharp-mode-tests.el

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,31 @@
397397
;; look for 'string' - should always be a type
398398
(should (assess-face-at= buf 'csharp-mode (lambda (buf) (m-buffer-match buf "string")) 'font-lock-type-face))))
399399

400+
(ert-deftest activating-mode-doesnt-clobber-global-adaptive-fill-regexp ()
401+
(let ((before adaptive-fill-regexp))
402+
(with-temp-buffer
403+
(csharp-mode))
404+
(should
405+
(equal before adaptive-fill-regexp))))
406+
407+
(ert-deftest activating-mode-style-defaults-to-csharp ()
408+
(let ((c-default-style "defaultc#"))
409+
(with-temp-buffer
410+
(csharp-mode)
411+
(should
412+
(equal "defaultc#" c-indentation-style))))
413+
(let ((c-default-style '((csharp-mode . "defaultc#fromlist")
414+
(java-mode . "defaultjava"))))
415+
(with-temp-buffer
416+
(csharp-mode)
417+
(should
418+
(equal "defaultc#fromlist" c-indentation-style))))
419+
(let (c-default-style)
420+
(with-temp-buffer
421+
(csharp-mode)
422+
(should
423+
(equal "C#" c-indentation-style)))))
424+
400425
;;(ert-run-tests-interactively t)
401426
;; (local-set-key (kbd "<f6>") '(lambda ()
402427
;; (interactive)

csharp-mode.el

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2968,20 +2968,21 @@ Key bindings:
29682968
;; customized values for our language.
29692969
(c-init-language-vars csharp-mode)
29702970

2971-
;; Set style to c# style unless a file local variable or default
2972-
;; style is found, in which case it should be set after
2973-
;; calling `c-common-init' below.
2974-
(unless (or c-file-style
2975-
(stringp c-default-style)
2976-
(assq 'csharp-mode c-default-style))
2977-
(c-set-style "C#" 'do-not-override-customized-values))
2978-
2979-
;; `c-common-init' initializes most of the components of a CC Mode
2980-
;; buffer, including setup of the mode menu, font-lock, etc.
2981-
;; There's also a lower level routine `c-basic-common-init' that
2982-
;; only makes the necessary initialization to get the syntactic
2983-
;; analysis and similar things working.
2984-
(c-common-init 'csharp-mode)
2971+
;; Use our predefined "C#" style unless a file local or default
2972+
;; style is found. This is done by rebinding `c-default-style'
2973+
;; during the `c-common-init' call. 'c-common-init' will initialize
2974+
;; the buffer's style using the value of `c-default-style'.
2975+
(let ((c-default-style (if (or c-file-style
2976+
(stringp c-default-style)
2977+
(assq 'csharp-mode c-default-style))
2978+
c-default-style
2979+
"C#")))
2980+
;; `c-common-init' initializes most of the components of a CC Mode
2981+
;; buffer, including setup of the mode menu, font-lock, etc.
2982+
;; There's also a lower level routine `c-basic-common-init' that
2983+
;; only makes the necessary initialization to get the syntactic
2984+
;; analysis and similar things working.
2985+
(c-common-init 'csharp-mode))
29852986

29862987
(define-key csharp-mode-map (kbd "/") 'csharp-maybe-insert-codedoc)
29872988

0 commit comments

Comments
 (0)