- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我解决了此处描述的所有问题(以及一个额外的问题),并发布了 the modified
csharp-mode.el (v0.7.1) 在 emacswiki
csharp-mode I use 几乎真的很好。
它适用于大多数情况,但有一些问题:
#if/#endif 标签打破缩进,但仅限于方法范围内。
应用于结构中字段的属性,中断缩进。 (有时,看例子)
在实现接口(interface)的类中,缩进被破坏了。从那时起。
如果文字字符串中的最后一个字符是斜杠,则文字字符串(以 @ 为前缀)不能正确字体化,实际上会从源文件中的那个点开始破坏字体化。
我认为还有其他一些问题。
我不是模式作家。
有人改进了那个模式吗?
有人愿意自愿解决这些问题吗?
示例代码
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");
}
}
}
最佳答案
这条建议似乎解决了缩进问题 #1 的前半部分。我希望它不会在其他地方引起问题。它只是查找导致错误缩进的条件(语法 statement-cont
和 #if
或 #endif
(好吧,只是 #
)) 开头) 并返回从该点之前 推导出的语法。我觉得不错,但我不是这里的评委。
(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))))))))))))
右大括号的缩进仍然不正确。我认为维护缩进代码的人会知道如何进行更改。这超出了我的理解范围。 cc 引擎管理了 104 种不同的缩进“案例”...
(与问题2和3的缩进相同,它们都被认为是'statement-cont语法的一部分)。要查看 cc 引擎认为当前点下的语法是什么,请执行:C-c C-s。
关于问题 4,文字字符串,上面的代码似乎正确地缩进了文字字符串,但字体化仍然是错误的。
关于c# - 我该如何修复 csharp-mode.el?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1799191/
我正在开发基于桌面 (Windows 7) 的应用程序,并使用 Qt Creator v 5.6.0 开发程序。我有一个非常奇怪的问题,即 我的程序在 DEBUG 模式下崩溃,但在 RELEASE 模
我爱org-tables ,我用它们来记录各种事情。我现在正在为 Nix 记录一些单行代码(在阅读了 Domen Kožar 的 excellent guide 后,在 this year's Eur
org-mode 是否有一个键绑定(bind)可以在编号/项目符号列表项之间移动,就像您可以对标题一样? 喜欢的功能: org-forward-heading-same-level 大纲下一个可见标题
我知道这有点小,但它一直困扰着我。我正在为一个项目使用 Org-mode,我倾向于经常导出为 PDF 或 HTML,这使我的目录中散落着 PDF、Tex 和 HTML 文件。有没有办法将 Org 模式
有什么方法可以让 org-mode 继续编号列表而不是重新启动? 这是情况。你列了一个类似的列表: Sometimes you can restart the display by doing som
如何在组织模式文件中生成所有标签的枚举列表(例如 :tag:)?假设我有一个以下形式的列表: * Head1 :foo:bar: ** Subhead1 :foo: * Head2
我正在使用 org-mode(Emacs:24.3.1,org-mode: 7.9.3f 8.0.6)作为不同代码片段的数据库语言(目前主要是 elisp 和 python)。这在使用 org-mod
相关问题:org-mode: fontify code blocks natively 截至 2012 年 11 月 1 日,我已经获得了最新的 org-mode 和 emacs 版本(组织存储在 o
有谁知道在使用 ido 模式时区分 dired 模式缓冲区名称与迷你缓冲区中其他类型缓冲区的好方法吗?例如...在 dired 模式缓冲区名称末尾显示正斜杠? 最佳答案 您可以简单地更改dired-m
在这个示例脚本中 import argparse parser = argparse.ArgumentParser() parser.add_argument('--modes', help="tes
我第一次学习“操作系统”。在我的书中,我发现了关于“用户模式”和“内核模式”的这句话: "Switch from user to kernel mode" instruction is execute
我刚刚下载了 Processing 2.0 并尝试从“模式管理器”安装 Android 模式。但是在安装时出现错误提示:“无法将模式“Android 模式”移动到速写本”。我怎样才能摆脱这个错误? 最
在 android L 中,我尝试将相机闪光灯模式设置为 TORCH,它工作正常,但我无法将其更改回闪光灯模式 AUTO 或闪光灯模式 打开。我只能返回闪存模式 OFF。我尝试了像 camera360
有 2 台机器,A 和 B。有 2 个分支,p16 和 c2。 A 有一个 ext3 文件系统,但在 B 上,存档位于带有 vfat 的 truecrypt 驱动器上,mount 显示 rw,uid=
我有 linum-mode在我的 Emacs 配置中全局启用。全局启用意味着它也适用于不受欢迎的速度条。 我为这个问题找到的唯一建议是在存档的 Emacs 帮助邮件列表中,它建议以下 speedbar
Google Cloud Firestore 将很快取代旧的 Google Cloud Datastore。然后可以选择在“ native 模式”或“数据存储模式”下使用 Cloud Firestor
org-mode的版本我的版本 Emacs 附带的(24.5.2) 是 8.2.10 .我已安装版本 8.3.1从 ELPA 并将其添加到我的 init 文件中: (add-to-list 'load
The org-mode manual指出 org-mode 将“”“...在 shell 链接”“”中执行命令,但它不显示此类链接的语法。 我希望能有一个简单完整的示例来说明这种 shell 链接是
我正在尝试在 emacs 24 中使用 dart 模式和 d 模式。如果我单独使用任何一种模式,一切都很好。如果我分别对每种类型的文件使用这两种模式,我在尝试缩进 D 代码时会出错。 以下是在初始化时
我的应用程序中有 CupertinoDatePicker 以使用以下代码选择日期和时间: formatColumn( widget: Consumer( builder: (_, mcProvide
我是一名优秀的程序员,十分优秀!