在emacs中怎么给code方法添加属性和返回值的注释

,

在xcode中可以自动添加方法的注释: 例如:

/**
 求两数之和

 @param firstNumber 第一个数
 @param secondNumber 第二个数
 @return 两数之和
 */
- (NSInteger)sumNumber:(NSInteger)firstNumber withNumber:(NSInteger)secondNumber;

在emacs中编写swift时,如何自动补齐func方法和参数注释

方式1:通过snippets代码块,但是对func参数个数不确定无法实现参数注释

方法2: 使用有source-lsp相关提供相关方法,不确定是否存在。

初步实现:

(defun addcommentForFun()
  (interactive)
  (if (string-match-p (string (preceding-char)) "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_")
      (backward-sexp)
    nil)
  (kill-sexp)
  (yank)
  (previous-line)
  (move-end-of-line nil)
  (newline)
  (insert "///\n")
  (insert "/// - Parameters:  \n")
  (insert "///   - name1:\n")
  (insert "///   - name2:\n")
  (indent-for-tab-command)
  )

希望大家帮忙。

https://www.emacswiki.org/emacs/CommentingCode

Elisp:从头开始编写注释命令
http://xahlee.info/emacs/emacs/elisp_comment_command.html

Elisp:如何在主模式下编写Comment命令
http://xahlee.info/emacs/emacs/elisp_comment_handling.html

安装一下 doxymacs 包

你可能需要

https://github.com/jcs-elpa/docstr

1 个赞

docstr 默认支持swift的注释模版是C语言样式的。

看了部分代码,没有搞懂如何自定义注释的样式模版?

开了一个issue:How to customize a swift-style to replace the C-style? · Issue #19 · emacs-vs/docstr · GitHub

根本就没有 snippet 那样的模板,都是用 docstr-writers-XXX & docstr-trigger-XXX 函数一行一行 insert 出来的:

找到一个解决方法:通过设置 (setq! docstr-format-var "- Parameter %s:")来实现 支持swift语法注释。

但是遇到了无法在config 加载时,重写该docstr-format-var属性值的问题: