Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何修复csharp-mode.el?_C#_Emacs - Fatal编程技术网

C# 如何修复csharp-mode.el?

C# 如何修复csharp-mode.el?,c#,emacs,C#,Emacs,我修复了这里描述的所有问题(以及一个附加问题),并发布在emacswiki上 这部电影几乎真的很好 它适用于大多数情况,但存在一些问题: #if/#endif标记打断缩进,但仅在方法的范围内 应用于结构中字段的属性,断开缩进。(有时,参见示例) 在实现接口的类中,缩进被破坏。从那以后 文字字符串(前缀为@)的字体设置不正确,事实上,如果文字字符串中的最后一个字符是斜杠,则在源文件中从该点向前中断字体设置 我认为还有其他一些问题 我不是时尚作家 有人对该模式进行了改进吗? 有人愿意自愿修复这

我修复了这里描述的所有问题(以及一个附加问题),并发布在emacswiki上


这部电影几乎真的很好

它适用于大多数情况,但存在一些问题:

  • #if/#endif标记打断缩进,但仅在方法的范围内

  • 应用于结构中字段的属性,断开缩进。(有时,参见示例)

  • 在实现接口的类中,缩进被破坏。从那以后

  • 文字字符串(前缀为@)的字体设置不正确,事实上,如果文字字符串中的最后一个字符是斜杠,则在源文件中从该点向前中断字体设置

  • 我认为还有其他一些问题

我不是时尚作家

有人对该模式进行了改进吗?
有人愿意自愿修复这几件事吗


示例代码

using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Xml.Serialization;

namespace Cheeso.Says.TreyIsTheBest
{
    public class Class1
    {
        private void Method1()
        {
            // Problem 1: the following if / endif pair causes indenting to break.
            // This occurs only within the scope of a method. If the #if/#endif  is
            // outside of a method, then the indenting does not break.

            #if DIAGS

                // this first line of code within the conditional scope
                // is indented 
                String StringNumber1;

            // the second line of code within the conditional scope
            // is un-indented
            public String StringNumber2;

            #endif

                // The endif is where I expect it to be, I guess.
                // It's in-line with the matched #if.  But the comments here
                // are weirdly indented still further. ??  

                }

        // The prior close-curly is indented 2 units more than I would expect.
    }
    // the close-curly for the class is indented correctly. 


    // ==================================================================
    // ------------------------------------------------------------------

    [StructLayout(LayoutKind.Sequential,
                  CharSet = CharSet.Unicode)]
    public struct Class2
    {
        // Problem 2: when there is an attribute applied to a field
        // within a struct, and the attribute include a newline, then
        // the field indents strangely.  See also "Note 1", and "Note 2"
        // below.
        [MarshalAs(UnmanagedType.ByValArray,
                   SizeConst = 128)]
            public int Value1;

        // Note 1: this indents fine.  
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)]
        public int Value2;
    }

    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
    public class Class3
    {
        public short PrintNameLength;

        [MarshalAs(UnmanagedType.ByValArray,
                   SizeConst = 128)]
        // Note 2: this indents just fine
        public int Value1;
    }

    // ==================================================================
    // ------------------------------------------------------------------

    // Linq Syntax is not a problem as I had originally thought
    public class Class4
    {
        #region eee

        #endregion

        private void Method1()
        {
            var files = Directory.GetFiles("Something");

            var selection = from f in files
                where System.IO.Path.GetFileName(f).StartsWith("C")
                select f;

            foreach (var e in selection)
                Console.WriteLine(e);
        }
    }


    // ==================================================================
    // ------------------------------------------------------------------

    public interface IGuess { }

    public class Class5 : IGuess
    {
        // Problem 3: When a #region tag is used inside a class that
        // implements an interface (or derives from a class) the line
        // following the region tag gets indented one extra unit.

        #region utility

            private static System.Random rnd= new System.Random(); 

        private string FigureCategory()
        {
            return "unknown";
        }

        #endregion


            // You can also see artifacts of the same confusion in
            // methods that have multiple attributes.  Again, this only
            // occurs when the containing class implements a particular
            // interface or derives from a parent class.

        [System.Web.Services.WebMethodAttribute()]
            [return: System.Xml.Serialization.XmlElementAttribute("getContainerObjectsReturn")]
            public String Method1()
        {
            return "Hello.";
        }
    }


    // ==================================================================
    // ------------------------------------------------------------------

    public class Pippo
    {
        // Problem 4: when the final char in an "escaped" string literal is a
        // slash, indenting and fontification breaks.

        List<string> directories = new List<string> { 
            @"C:\Temp\sub1\",

                // The emacs parser thinks the string has not ended.
                // This comment is fontified and indented as if it is in
                // the middle of a string literal.

                @"C:\Temp\sub2\",

            // Because we have another \" at the end of a string,
            // emacs now thinks we're "out" of the string literal.
            // This comment is now indented and fontified correctly. 

            @"C:\Home\"

                // A third \", and now emacs thinks we're back inside the string literal.
                // The rest of the code will be treated as if it were inside the string literal.

            };

        protected void Page_Load(object sender, EventArgs e)
        {
            Console.WriteLine("Hello {0}", "world");
        }
    }

}
使用系统;
使用System.IO;
使用System.Linq;
使用System.Collections.Generic;
使用System.Runtime.InteropServices;
使用System.Xml.Serialization;
命名空间Cheeso.Says.TreyIsTheBest
{
公共班级1
{
私有void方法1()
{
//问题1:以下if/endif对导致缩进中断。
//这仅在方法的范围内发生
//在方法之外,则缩进不会中断。
#如果诊断
//这是条件范围内的第一行代码
//缩进
字符串编号1;
//条件范围内的第二行代码
//不缩进
公共字符串StringNumber2;
#恩迪夫
//我想结局就是我所期望的。
//这与匹配的#if一致。但是这里的注释
//都有奇怪的凹痕,更进一步??
}
//之前的紧密卷曲比我预期的缩进多了2个单位。
}
//类的闭合卷曲已正确缩进。
// ==================================================================
// ------------------------------------------------------------------
[StructLayout(LayoutKind.Sequential,
CharSet=CharSet.Unicode)]
公共结构类2
{
//问题2:当有属性应用于字段时
//在结构中,属性包含换行符
//字段奇怪地缩进。另见“注1”和“注2”
//下面。
[Marshallas(UnmanagedType.ByValArray,
SizeConst=128)]
公共价值1;
//注1:此缩进很好。
[Marshallas(UnmanagedType.ByValArray,SizeConst=128)]
公共价值2;
}
[StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode)]
公共班级3
{
公共短打印长度;
[Marshallas(UnmanagedType.ByValArray,
SizeConst=128)]
//注2:此缩进正好
公共价值1;
}
// ==================================================================
// ------------------------------------------------------------------
//Linq语法并不像我最初认为的那样是个问题
公共班级4
{
#区域eee
#端区
私有void方法1()
{
var files=Directory.GetFiles(“某物”);
var selection=来自文件中的f
其中System.IO.Path.GetFileName(f).StartsWith(“C”)
选择f;
foreach(选择中的变量e)
控制台写入线(e);
}
}
// ==================================================================
// ------------------------------------------------------------------
公共接口IGuess{}
公共课类别5:IGuess
{
//问题3:在类中使用#region标记时
//实现一个接口(或从类派生)行
//区域标记后面将缩进一个额外的单位。
#区域效用
私有静态系统.Random rnd=新系统.Random();
私有字符串FigureCategory()
{
返回“未知”;
}
#端区
//您还可以在中看到相同混淆的工件
//具有多个属性的方法。同样,这仅限于
//在包含类实现特定
//接口或派生自父类。
[System.Web.Services.WebMethodAttribute()]
[返回:System.Xml.Serialization.XmlElementAttribute(“GetContainerObject返回”)]
公共字符串Method1()
{
回复“你好”;
}
}
// ==================================================================
// ------------------------------------------------------------------
公共类皮波
{
//问题4:当“转义”字符串文字中的最后一个字符是
//斜线、缩进和字体化中断。
列表目录=新列表{
@“C:\Temp\sub1\”,
//emacs解析器认为字符串尚未结束。
//此注释被格式化和缩进,就像在
//字符串文字的中间部分。
@“C:\Temp\sub2\”,
//因为在一个字符串的末尾有另一个\“,
//emacs现在认为我们已经“用完”了字符串文字。
//此注释现在已正确缩进和格式化。
@“C:\Home\”
//第三个\“,现在emacs认为我们回到了字符串文本中。
//代码的其余部分将被视为在字符串文本中。
};
受保护的
(defvar csharp-mode-syntax-table-no-special-slash
  (let ((res (copy-syntax-table csharp-mode-syntax-table)))
    (modify-syntax-entry ?\\ "w" res)
    res)
  "same as regular csharp-mode-syntax-table, only \\ is not an escape char")

(defadvice c-guess-basic-syntax (after c-guess-basic-syntax-csharp-hack activate)
  "following an #if/#endif, indentation gets screwey, fix it"
  (let ((res ad-return-value))
    (save-excursion
      (save-match-data
        (cond ((and (eq major-mode 'csharp-mode)
                    (eq 'statement-cont (caar res))
                    (progn
                      (goto-char (cadar res))
                      (looking-at "#")))
               ;; when following a #if, try for a redo
               (goto-char (cadar res))
               (setq ad-return-value (c-guess-basic-syntax)))

              ((and (eq major-mode 'csharp-mode)
                    (eq 'string (caar res)))
               ;; inside a string
               ;; check to see if it is a literal
               ;; and if so, redo with modified syntax table
               (let ((p (point))
                     (extent (c-literal-limits)))
                 (when extent
                   (goto-char (- (car extent) 1))
                   (when (looking-at "@\"")
                     ;; yup, a string literal
                     (with-syntax-table csharp-mode-syntax-table-no-special-slash
                       (goto-char p)
                       (setq ad-return-value (c-guess-basic-syntax))))))))))))