回答
一個簡單的方法是定義自己的命令來插入這個 評論。添加到您的.emacs文件:
(defun insert-doc-comment() (interactive)
(insert "/**\n * Brief description. Long description. \n * @param \n * @return \n * @exception \n * @see \n * @author \n */"))
新的命令然後綁定自己的喜好的關鍵:
(define-key global-map [(S-f1)] 'insert-doc-comment)
現在按Shift-F1將插入一個註釋塊這樣的:
/**
* Brief description. Long description.
* @param
* @return
* @exception
* @see
* @author
*/
您可以使用emacs構建模板。模板是文件結構的骨架,可以綁定到具有特定擴展名的文件。例如,您可以創建一個適用於您使用.java擴展名創建的任何新文件的java模板,並且可以創建一個C++模板,該模板適用於您使用.cpp擴展名創建的任何文件(另一個用於.h文件如果需要的話)。
這個wiki有更多的例子來幫助你開始使用C++類模板。
您可以定義一個鍵盤宏來完成工作,然後運行它。對於你的情況,輸入開始/*
,然後做C-x (
然後,C-n M-m *
和C-x)
。做C-x e
直到你想註釋掉的最後一行。在最後一行時,以/
結束。
我知道它看起來很醜,而且這樣,但FWIW,它適用於我。當我不得不評論大塊時,我使用這種方法。
M-x customize-group RET comment
看看「Comment Style」變量的「Value Menu」。
(然後你就可以同時使用「的評論,DWIM」或「評論或 - 取消註釋區域」來切換意見進出選定塊)
您還可以,如果你想在當前行使用此註釋輸入/輸出,如果沒有區域活躍:
(defun px-toggle-comments()
"If region is set, [un]comments it. Otherwise [un]comments current line."
(interactive)
(if (eq mark-active nil)
(progn
(beginning-of-line 1)
(set-mark (point))
(forward-line)
(comment-dwim nil))
(comment-dwim nil))
(deactivate-mark))
我通常把它綁定到MD:
(global-set-key (kbd "M-d") 'px-toggle-comments)
使用yasnippet snipept,如果你不使用它,試試吧。
在你的片段將這個/ ** - 模式/
# -*- mode: snippet -*-
# name: dock
# key: /*
# --
/*
* $1
*/
$0
或另一個版本:
# -*- mode: snippet -*-
# name: docblock
# key: /**
# --
/**
* ${1:name} - ${2:short description}
* @${3:argv1}: $4
* @${5:argv2}: $6
*
* ${7:long description}
*/
$0
我得到了兩個兩個我片段/,順便說一句,你應該複製yasnippets-xx/snippets
到像~/.emacs.d/snippets
另一個地方,並把這個在您的.emacs
:
(setq yas-snippet-dirs '("~/.emacs.d/snippets"))
在每次更新yasnippet時,yasnippet-xx/snippets將被作者的片段取代,您可以在~/.emacs.d/snippets
中根據自己的需要add/delete/modify
自己的片段。
- 1. 在Emacs中縮進C塊註釋
- 2. Emacs的中心插入註釋塊
- 3. 函數聲明中的塊註釋?
- 4. 如何在emacs python-mode中取消註釋代碼塊?
- 5. Emacs:每行一行註釋
- 6. Emacs模式多行註釋
- 7. 註釋地塊
- 8. C註釋在Emacs - Linux內核風格
- 9. Emacs中的函數的註釋
- 10. 註釋模塊在dotnetnuke
- 11. Emacs的 - 定義註釋功能
- 12. 評論註釋塊
- 13. 問:註釋模塊
- 14. 關於註釋的說明
- 15. PHP的preg_replace註釋塊
- 16. Emacs設置行間距(行尾)註釋
- 17. Emacs Lisp:多個註釋開始值
- 18. 如何在emacs次要模式下設置註釋開始和註釋結束?
- 19. Doxygen strip關閉markdown代碼塊中的註釋說明
- 20. 多行註釋聲明後
- 21. Spring聲明與註釋
- 22. Hibernate繼承註釋說明
- 23. Mypy「類模塊」註釋
- 24. 從註釋塊逃脫
- 25. TextMate source.java註釋塊摺疊
- 26. C++代碼註釋塊
- 27. 取消註釋XML塊
- 28. 如何將包含註釋的HTML塊註釋掉
- 29. 如何註釋掉已有多行註釋的代碼塊?
- 30. C中的註釋部分和註釋塊C
就像你說的那樣。但按Shift + F1時,它會顯示'; 2P'。你知道爲什麼嗎? – ajmartin
也許你在一個不識別Shift +功能鍵的終端上。按'C-h k'然後按'S-f1'查看Emacs是否將這些鍵識別爲「S-f1」。 – sanityinc
是的,它沒有識別Shift鍵。修改了別的關鍵。謝謝。 – ajmartin