Skip to content

Commit f0b5efa

Browse files
committed
Use code with same arrangement as before rework
1 parent 4eeccbd commit f0b5efa

File tree

1 file changed

+126
-124
lines changed

1 file changed

+126
-124
lines changed

Diff for: csharp-mode.el

+126-124
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525

2626
;;; Code:
27+
28+
2729
(when (version< emacs-version "25.1")
2830
(require 'cl))
2931
(require 'cc-mode)
@@ -38,7 +40,6 @@
3840
"Major mode for editing C# code."
3941
:group 'prog-mode)
4042

41-
4243
(defcustom csharp-mode-enable-tree-sitter nil
4344
"Use tree sitter for font locking and indentation."
4445
:type 'boolean)
@@ -346,8 +347,10 @@
346347

347348
(defcustom csharp-codedoc-tag-face 'c-doc-markup-face-name
348349
"Face to be used on the codedoc docstring tags.
350+
349351
Should be one of the font lock faces, such as
350352
`font-lock-variable-name-face' and friends.
353+
351354
Needs to be set before `csharp-mode' is loaded, because of
352355
compilation and evaluation time conflicts."
353356
:type 'symbol
@@ -378,6 +381,118 @@ compilation and evaluation time conflicts."
378381
(defun csharp-font-lock-keywords ()
379382
(c-compose-keywords-list csharp-font-lock-keywords))
380383

384+
;;; Compilation support
385+
;; When invoked by MSBuild, csc’s errors look like this:
386+
;; subfolder\file.cs(6,18): error CS1006: Name of constructor must
387+
;; match name of class [c:\Users\user\project.csproj]
388+
389+
(defun csharp--compilation-error-file-resolve ()
390+
"Resolve an msbuild error to a (filename . dirname) cons cell."
391+
;; http://stackoverflow.com/a/18049590/429091
392+
(cons (match-string 1) (file-name-directory (match-string 4))))
393+
394+
(defconst csharp-compilation-re-msbuild-error
395+
(concat
396+
"^[[:blank:]]*\\(?:[[:digit:]]+>\\)?"
397+
"\\([^(\r\n)]+\\)(\\([0-9]+\\)\\(?:,\\([0-9]+\\)\\)?): "
398+
"error [[:alnum:]]+: [^\r\n]+\\[\\([^]\r\n]+\\)\\]$")
399+
"Regexp to match compilation error from msbuild.")
400+
401+
(defconst csharp-compilation-re-msbuild-warning
402+
(concat
403+
"^[[:blank:]]*\\(?:[[:digit:]]+>\\)?"
404+
"\\([^(\r\n)]+\\)(\\([0-9]+\\)\\(?:,\\([0-9]+\\)\\)?): "
405+
"warning [[:alnum:]]+: [^\r\n]+\\[\\([^]\r\n]+\\)\\]$")
406+
"Regexp to match compilation warning from msbuild.")
407+
408+
;; Notes on xbuild and devenv commonalities
409+
;;
410+
;; These regexes were tailored for xbuild, but apart from the concurrent
411+
;; build-marker ("1>") they share exactly the same match-markers.
412+
;;
413+
;; If we don't exclude the match-markers explicitly, these regexes
414+
;; will also be used to match for devenv as well, including the build-marker
415+
;; in the file-name, causing the lookup to fail.
416+
;;
417+
;; So if we don't want devenv to fail, we actually need to handle it in our
418+
;; xbuild-regexes, but then we automatically get devenv-support for free.
419+
420+
(defconst csharp-compilation-re-xbuild-error
421+
(concat
422+
"^[[:blank:]]*\\(?:[[:digit:]]+>\\)?"
423+
"\\([^(\r\n)]+\\)(\\([0-9]+\\)\\(?:,\\([0-9]+\\)\\)?"
424+
;; handle weird devenv output format with 4 numbers, not 2 by having optional
425+
;; extra capture-groups.
426+
"\\(?:,\\([0-9]+\\)\\)*): "
427+
"error [[:alnum:]]+: .+$")
428+
"Regexp to match compilation error from xbuild.")
429+
430+
(defconst csharp-compilation-re-xbuild-warning
431+
(concat
432+
"^[[:blank:]]*\\(?:[[:digit:]]+>\\)?"
433+
"\\([^(\r\n)]+\\)(\\([0-9]+\\)\\(?:,\\([0-9]+\\)\\)?"
434+
;; handle weird devenv output format with 4 numbers, not 2 by having optional
435+
;; extra capture-groups.
436+
"\\(?:,\\([0-9]+\\)\\)?*): "
437+
"warning [[:alnum:]]+: .+$")
438+
"Regexp to match compilation warning from xbuild.")
439+
440+
(defconst csharp-compilation-re-dotnet-error
441+
"\\([^\r\n]+\\) : error [A-Z]+[0-9]+:")
442+
443+
(defconst csharp-compilation-re-dotnet-warning
444+
"\\([^\r\n]+\\) : warning [A-Z]+[0-9]+:")
445+
446+
(defconst csharp-compilation-re-dotnet-testfail
447+
(concat
448+
"^[[:blank:]]+X \\(?:.+\n\\)"
449+
"[[:blank:]]+Error Message:\n"
450+
"[[:blank:]]+\\(?:.+\n\\)"
451+
"\\(?:^Expected: \\(?:.+\n\\)\\)?"
452+
"\\(?:^Actual: \\(?:.+\n\\)\\)?"
453+
"[[:blank:]]+Stack Trace:\n"
454+
"[[:blank:]]+at [^\n]+ in \\([^\n]+\\):line \\([0-9]+\\)"))
455+
456+
457+
(eval-after-load 'compile
458+
(lambda ()
459+
(dolist
460+
(regexp
461+
`((dotnet-testfail
462+
,csharp-compilation-re-dotnet-testfail
463+
1 2)
464+
(xbuild-error
465+
,csharp-compilation-re-xbuild-error
466+
1 2 3 2)
467+
(xbuild-warning
468+
,csharp-compilation-re-xbuild-warning
469+
1 2 3 1)
470+
(msbuild-error
471+
,csharp-compilation-re-msbuild-error
472+
csharp--compilation-error-file-resolve
473+
2
474+
3
475+
2
476+
nil
477+
(1 compilation-error-face)
478+
(4 compilation-error-face))
479+
(msbuild-warning
480+
,csharp-compilation-re-msbuild-warning
481+
csharp--compilation-error-file-resolve
482+
2
483+
3
484+
1
485+
nil
486+
(1 compilation-warning-face)
487+
(4 compilation-warning-face))
488+
(dotnet-error
489+
,csharp-compilation-re-dotnet-error
490+
1)
491+
(dotnet-warning
492+
,csharp-compilation-re-dotnet-warning
493+
1 nil nil 1)))
494+
(add-to-list 'compilation-error-regexp-alist-alist regexp)
495+
(add-to-list 'compilation-error-regexp-alist (car regexp)))))
381496

382497
;;; Doc comments
383498

@@ -531,137 +646,24 @@ compilation and evaluation time conflicts."
531646
;;; End of fix for strings on version 27.1
532647

533648

649+
(eval-and-compile
650+
(unless csharp-mode-enable-tree-sitter
651+
(defvar csharp-mode-syntax-table
652+
(funcall (c-lang-const c-make-mode-syntax-table csharp))
653+
"Syntax table used in csharp-mode buffers.")
534654

535-
(defvar csharp-mode-syntax-table
536-
(funcall (c-lang-const c-make-mode-syntax-table csharp))
537-
"Syntax table used in csharp-mode buffers.")
538-
539-
(defvar csharp-mode-map
540-
(let ((map (c-make-inherited-keymap)))
541-
map)
542-
"Keymap used in csharp-mode buffers.")
655+
(defvar csharp-mode-map
656+
(let ((map (c-make-inherited-keymap)))
657+
map)
658+
"Keymap used in csharp-mode buffers.")))
543659

544660
(easy-menu-define csharp-mode-menu csharp-mode-map "C# Mode Commands"
545661
(cons "C#" (c-lang-const c-mode-menu csharp)))
546662

547-
548-
;;; Compilation support
549-
;; When invoked by MSBuild, csc’s errors look like this:
550-
;; subfolder\file.cs(6,18): error CS1006: Name of constructor must
551-
;; match name of class [c:\Users\user\project.csproj]
552-
553-
(defun csharp--compilation-error-file-resolve ()
554-
"Resolve an msbuild error to a (filename . dirname) cons cell."
555-
;; http://stackoverflow.com/a/18049590/429091
556-
(cons (match-string 1) (file-name-directory (match-string 4))))
557-
558-
(defconst csharp-compilation-re-msbuild-error
559-
(concat
560-
"^[[:blank:]]*\\(?:[[:digit:]]+>\\)?"
561-
"\\([^(\r\n)]+\\)(\\([0-9]+\\)\\(?:,\\([0-9]+\\)\\)?): "
562-
"error [[:alnum:]]+: [^\r\n]+\\[\\([^]\r\n]+\\)\\]$")
563-
"Regexp to match compilation error from msbuild.")
564-
565-
(defconst csharp-compilation-re-msbuild-warning
566-
(concat
567-
"^[[:blank:]]*\\(?:[[:digit:]]+>\\)?"
568-
"\\([^(\r\n)]+\\)(\\([0-9]+\\)\\(?:,\\([0-9]+\\)\\)?): "
569-
"warning [[:alnum:]]+: [^\r\n]+\\[\\([^]\r\n]+\\)\\]$")
570-
"Regexp to match compilation warning from msbuild.")
571-
572-
;; Notes on xbuild and devenv commonalities
573-
;;
574-
;; These regexes were tailored for xbuild, but apart from the concurrent
575-
;; build-marker ("1>") they share exactly the same match-markers.
576-
;;
577-
;; If we don't exclude the match-markers explicitly, these regexes
578-
;; will also be used to match for devenv as well, including the build-marker
579-
;; in the file-name, causing the lookup to fail.
580-
;;
581-
;; So if we don't want devenv to fail, we actually need to handle it in our
582-
;; xbuild-regexes, but then we automatically get devenv-support for free.
583-
584-
(defconst csharp-compilation-re-xbuild-error
585-
(concat
586-
"^[[:blank:]]*\\(?:[[:digit:]]+>\\)?"
587-
"\\([^(\r\n)]+\\)(\\([0-9]+\\)\\(?:,\\([0-9]+\\)\\)?"
588-
;; handle weird devenv output format with 4 numbers, not 2 by having optional
589-
;; extra capture-groups.
590-
"\\(?:,\\([0-9]+\\)\\)*): "
591-
"error [[:alnum:]]+: .+$")
592-
"Regexp to match compilation error from xbuild.")
593-
594-
(defconst csharp-compilation-re-xbuild-warning
595-
(concat
596-
"^[[:blank:]]*\\(?:[[:digit:]]+>\\)?"
597-
"\\([^(\r\n)]+\\)(\\([0-9]+\\)\\(?:,\\([0-9]+\\)\\)?"
598-
;; handle weird devenv output format with 4 numbers, not 2 by having optional
599-
;; extra capture-groups.
600-
"\\(?:,\\([0-9]+\\)\\)?*): "
601-
"warning [[:alnum:]]+: .+$")
602-
"Regexp to match compilation warning from xbuild.")
603-
604-
(defconst csharp-compilation-re-dotnet-error
605-
"\\([^\r\n]+\\) : error [A-Z]+[0-9]+:")
606-
607-
(defconst csharp-compilation-re-dotnet-warning
608-
"\\([^\r\n]+\\) : warning [A-Z]+[0-9]+:")
609-
610-
(defconst csharp-compilation-re-dotnet-testfail
611-
(concat
612-
"^[[:blank:]]+X \\(?:.+\n\\)"
613-
"[[:blank:]]+Error Message:\n"
614-
"[[:blank:]]+\\(?:.+\n\\)"
615-
"\\(?:^Expected: \\(?:.+\n\\)\\)?"
616-
"\\(?:^Actual: \\(?:.+\n\\)\\)?"
617-
"[[:blank:]]+Stack Trace:\n"
618-
"[[:blank:]]+at [^\n]+ in \\([^\n]+\\):line \\([0-9]+\\)"))
619-
620-
621-
(eval-after-load 'compile
622-
(lambda ()
623-
(dolist
624-
(regexp
625-
`((dotnet-testfail
626-
,csharp-compilation-re-dotnet-testfail
627-
1 2)
628-
(xbuild-error
629-
,csharp-compilation-re-xbuild-error
630-
1 2 3 2)
631-
(xbuild-warning
632-
,csharp-compilation-re-xbuild-warning
633-
1 2 3 1)
634-
(msbuild-error
635-
,csharp-compilation-re-msbuild-error
636-
csharp--compilation-error-file-resolve
637-
2
638-
3
639-
2
640-
nil
641-
(1 compilation-error-face)
642-
(4 compilation-error-face))
643-
(msbuild-warning
644-
,csharp-compilation-re-msbuild-warning
645-
csharp--compilation-error-file-resolve
646-
2
647-
3
648-
1
649-
nil
650-
(1 compilation-warning-face)
651-
(4 compilation-warning-face))
652-
(dotnet-error
653-
,csharp-compilation-re-dotnet-error
654-
1)
655-
(dotnet-warning
656-
,csharp-compilation-re-dotnet-warning
657-
1 nil nil 1)))
658-
(add-to-list 'compilation-error-regexp-alist-alist regexp)
659-
(add-to-list 'compilation-error-regexp-alist (car regexp)))))
660-
661-
662663
;;;###autoload
663664
(add-to-list 'auto-mode-alist '("\\.cs\\'" . csharp-mode))
664665

666+
;; Custom variables
665667
;;;###autoload
666668
(defcustom csharp-mode-hook nil
667669
"*Hook called by `csharp-mode'."

0 commit comments

Comments
 (0)