Emacs C模式缩进问题与Doxygen风格评论 [英] Emacs C-mode indent problem with Doxygen style comment

查看:87
本文介绍了Emacs C模式缩进问题与Doxygen风格评论的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在c-mode中使用emacs缩进功能发生Doxygen风格的多行注释问题。根据Doxygen手册( http://www.stack.nl/~dimitri/doxygen /docblocks.html )下面的表单被接受。

  / ********** ********************************** ** ** 
* ...文本
***************************************** $ /

我试图在emacs中使用这种格式,但是当我在文字'*最后在第一行末尾的/ **下方,如下所示:

  / **** **************************************** // ** 
*。 ..文字
********************************************* **** /

有关如何解决此问题的任何建议?仍然在学习emacs的所有内容。



谢谢。

解决方案

这是缩进的原因是(默认情况下)多行注释与上一行的注释开始排列在一起。在这种情况下,包含注释的开始位于第47列。



现在,如何解决它。以下是我如何解决如何解决问题,解决方案是结束。



首先,有一个 cc-mode手册,具体是关于自定义缩进。一个有用的键是 C-c C-s ,它告诉你用于缩进的语法。在这种情况下,它是((c 61)) - c 是现在的重要组成部分。



要以交互方式进行自定义,您可以键入 Cc Co (当点位于您想要的缩进行修理)。系统会提示您要自定义哪个语法条目(默认为 c ,在这种情况下b / c是当前语法),那么将会提示您输入什么您要将语法条目更改为(默认为 c-lineup-C-comments )。



现在我们可以看看这个功能,看看我们如何定制它来满足你的需要。 M-x find-function c-lineup-C-comments



这是更难的地方。您可以自定义cc-mode处理注释缩进的方式,但是您希望它做的事情(在这种情况下)是认识到您所在的c-comment紧随其后的是另一个 c-comment和 注释是您要缩进的缩写。



你该怎么做?我可以想到的最简单的方法是建议'c-lineup-C-comments 以识别这种特殊情况,并将其第一个参数的值更改为您想要的。我的有限测试显示,这对您的例子有用:

 (defadvice c-lineup-C-comments(c-lineup-C之前-comments-handle-doxygen activate)
(let((langelm(ad-get-arg 0)))
(save-excursion
(save-match-data
goto-char(1+(c-langelem-pos langelem)))
(if(progn
(行首)
;;只有当langelm为form $)
;;我们在doxygen注释行
(和(eq'c(car langelm))
(查看^ \\(\ \s- * \\)/ \\ * + // \\ * \\ * $)))
;;将目标位置设置为我们想要的
(ad-set-arg 0(cons'c(match-end 1))))))))

这个建议的最终结果应该是传递给 c-lineup-C-comments 的参数应该从(c 。61) (c。17)(或类似的东西),基本上愚弄了这个例行程序,在行的开始处排列了评论,而不是你正在修改的评论。 >

I am having a problem with Doxygen style multi-line comments with emacs indent feature in c-mode. According to Doxygen manual (http://www.stack.nl/~dimitri/doxygen/docblocks.html) the form below is accepted.

 /********************************************//**
 *  ... text
 ***********************************************/

I am trying to use this format in emacs but when I tab in on the line '* ... text' the * ends up below the /** at the end of the first line like so:

 /********************************************//**
                                                *  ... text
 ***********************************************/

Any suggestions on how to fix this? Still learning all the in-and-outs of emacs.

Thanks.

解决方案

The reason it is indenting as such is that (by default) multi-line comments are lined up with the start of the comment on the previous line. In this case, the start of the containing comment is in column 47.

Now, how to fix it. Here's how I figured out how to fix it, the solution is at the end.

First, there's the cc-mode manual, specifically the section on customizing indentation. A useful key is C-c C-s which tells you which syntax is being used for indentation. In this case it is ((c 61)) - the c is the important part for now.

To customize it interactively, you can type C-c C-o (when the point is on the line whose indentation you want to fix). You'll be prompted for which syntax entry you want to customize (defaults to c in this case b/c that's the current syntax), then you'll be prompted for what you want to change the syntax entry to (default is c-lineup-C-comments).

Now we can look at that function to see how we might customize it to meet your needs. M-x find-function c-lineup-C-comments.

That's where it gets more difficult. You can customize the way cc-mode handles comment indentation, but what it looks like you want it to do (in this case) is to recognize that the c-comment you're in is immediately preceded by another c-comment, and that comment is the one you want to align indentation to.

How do you do that? The easiest way I can think of is to advise 'c-lineup-C-comments to recognize this special case and change the value of its first argument to be what you want. My limited testing shows this works for your example:

(defadvice c-lineup-C-comments (before c-lineup-C-comments-handle-doxygen activate)
  (let ((langelm (ad-get-arg 0)))
    (save-excursion
      (save-match-data 
        (goto-char (1+ (c-langelem-pos langelem)))
        (if (progn
              (beginning-of-line)
              ;; only when the langelm is of form (c . something)
              ;; and we're at a doxygen comment line
              (and (eq 'c (car langelm))
                   (looking-at "^\\(\\s-*\\)/\\*+//\\*\\*$")))
            ;; set the goal position to what we want
            (ad-set-arg 0 (cons 'c (match-end 1))))))))

The end result of this advice should be that the argument passed into c-lineup-C-comments should be transformed from (c . 61) to (c . 17) (or something like that), essentially fooling the routine into lining up with the comment at the beginning of the line, and not the comment which you're currently modifying.

这篇关于Emacs C模式缩进问题与Doxygen风格评论的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆