emacs 中的 Objective-C 缩进

发布于 2024-07-30 06:39:34 字数 624 浏览 3 评论 0原文

我正在使用 Emacs 编辑 Objective-C 代码。 默认的缩进看起来像这样:

    NSTimer *timer =
        [NSTimer timerWithTimeInterval:1.0
                 target:self
                 selector:@selector(callback:)
                 userInfo:nil 
                 repeats:YES];

我希望 Emacs 像 XCode 一样缩进代码,即与冒号对齐:

    NSTimer *timer =
        [NSTimer timerWithTimeInterval:1.0
                                target:self
                              selector:@selector(callback:)
                              userInfo:nil 
                               repeats:YES];

有没有希望实现这一点?

I'm using Emacs to edit my Objective-C code. The default indentation looks like this:

    NSTimer *timer =
        [NSTimer timerWithTimeInterval:1.0
                 target:self
                 selector:@selector(callback:)
                 userInfo:nil 
                 repeats:YES];

I would like Emacs to indent the code like XCode, that is, to align with the colons:

    NSTimer *timer =
        [NSTimer timerWithTimeInterval:1.0
                                target:self
                              selector:@selector(callback:)
                              userInfo:nil 
                               repeats:YES];

Is there any hope to achieve this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

甜中书 2024-08-06 06:39:34

c-offsets-alist 中 objc-method-call-cont 的 c-lineup-ObjC-method-call-colons 是否有问题?

Is there something wrong with c-lineup-ObjC-method-call-colons for objc-method-call-cont in c-offsets-alist?

心奴独伤 2024-08-06 06:39:34

有一个 Objective C 模式可以在此处执行此操作

它看起来像这样

There is a Objective C mode that does this here

Here is what it looks like

娇柔作态 2024-08-06 06:39:34

我已经对此进行了一些尝试并且已经接近了,但它还没有完全发挥作用。 我的解决方案是向 align-rules-list 添加一个条目,这样一个简单的 Mxalign 就可以解决问题。 问题是您必须运行 align 两次才能使其正常工作。

(obj-c-colons
 (regexp . "^\\(\\s-*[^:]+\\):")
 (justify . t)
 (repeat . t)
 (modes obj-c-mode)) ;; <= Replace with actual name of major mode

我实际上不知道 Objective-C 模式的名称是什么,因此您必须将 obj-c-mode 替换为实际调用的模式。 您可以将其添加到 align-rules-list 中:

(add-to-list 'align-rules-list
             '(obj-c-colons
               (regexp . "^\\(\\s-*[^:]+\\):")
               (justify . t)
               (repeat . t)
               (modes obj-c-mode)))

现在,您必须执行 align 两次; 第一次只会按如下方式排列:

 NSTimer *timer =
        [NSTimer timerWithTimeInterval:1.0
                              target:self
                            selector:@selector(callback:)
                            userInfo:nil
                             repeats:YES];

请注意,冒号是离左侧太远的两个字符。 第二个align将纠正这个问题。 别问我为什么。

align 命令有很多作用,所以弄清楚它很困难。 希望有人能想出一种方法来改进这一点。 不管怎样,请查看相关 EmacsWiki 页面,了解有关对齐的更多信息。

I've been hacking on this for a bit and have gotten closer, but it's not fully functional yet. The solution I have is to add an entry to align-rules-list, so that a simple M-x align will do the trick. The problem is that you have to run align twice in order to get it to work.

(obj-c-colons
 (regexp . "^\\(\\s-*[^:]+\\):")
 (justify . t)
 (repeat . t)
 (modes obj-c-mode)) ;; <= Replace with actual name of major mode

I don't actually know what the name of the objective-c mode is, so you will have to replace obj-c-mode with whatever the mode is actually called. You can add this to align-rules-list with:

(add-to-list 'align-rules-list
             '(obj-c-colons
               (regexp . "^\\(\\s-*[^:]+\\):")
               (justify . t)
               (repeat . t)
               (modes obj-c-mode)))

For now, you have to execute align twice; the first time will only line it up as follows:

 NSTimer *timer =
        [NSTimer timerWithTimeInterval:1.0
                              target:self
                            selector:@selector(callback:)
                            userInfo:nil
                             repeats:YES];

Notice that the colons are two characters too far to the left. The second align will correct this. Don't ask me why.

There is a lot that goes on with the align command, so figuring it out is hard. Hopefully someone comes up with a way to improve upon this. Anyway, take a look at the relevant EmacsWiki page for more info on aligning.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文