我正在運行Emacs 23.3.1(Ubuntu,Oneiric軟件包),emacs似乎並不瞭解任何新的C++ 11關鍵字,constexpr,thread_local等。它也不理解''>> '現在允許使用模板參數或新的'enum class'語法。有沒有更新或替代模塊?或者做不到這一點,一些設置使emacs在此期間更友好?C++ 11模式或emacs的設置?
回答
我檢查了幹線版本,cc-mode
尚未更新,AFAIK沒有其他選擇。如果你真的想要它,但不想讓你的手變髒,你應該付錢給你實施它...
做一個kickstarter項目:p – 2013-11-15 03:30:41
那麼,我使用24.1。一些C++ 98關鍵字缺失,以及所有新的C++ 11關鍵字。它甚至不能爲數字常量賦值。看起來好像C++ - 模式還沒有更新十年。
我現在正在使用以下代碼很久,並且最近添加了C++ 11關鍵字。嘗試將其放入您的.emacs;它應該填補一些漏洞。
(require 'font-lock)
(defun --copy-face (new-face face)
"Define NEW-FACE from existing FACE."
(copy-face face new-face)
(eval `(defvar ,new-face nil))
(set new-face new-face))
(--copy-face 'font-lock-label-face ; labels, case, public, private, proteced, namespace-tags
'font-lock-keyword-face)
(--copy-face 'font-lock-doc-markup-face ; comment markups such as Javadoc-tags
'font-lock-doc-face)
(--copy-face 'font-lock-doc-string-face ; comment markups
'font-lock-comment-face)
(global-font-lock-mode t)
(setq font-lock-maximum-decoration t)
(add-hook 'c++-mode-hook
'(lambda()
(font-lock-add-keywords
nil '(;; complete some fundamental keywords
("\\<\\(void\\|unsigned\\|signed\\|char\\|short\\|bool\\|int\\|long\\|float\\|double\\)\\>" . font-lock-keyword-face)
;; add the new C++11 keywords
("\\<\\(alignof\\|alignas\\|constexpr\\|decltype\\|noexcept\\|nullptr\\|static_assert\\|thread_local\\|override\\|final\\)\\>" . font-lock-keyword-face)
("\\<\\(char[0-9]+_t\\)\\>" . font-lock-keyword-face)
;; PREPROCESSOR_CONSTANT
("\\<[A-Z]+[A-Z_]+\\>" . font-lock-constant-face)
;; hexadecimal numbers
("\\<0[xX][0-9A-Fa-f]+\\>" . font-lock-constant-face)
;; integer/float/scientific numbers
("\\<[\\-+]*[0-9]*\\.?[0-9]+\\([ulUL]+\\|[eE][\\-+]?[0-9]+\\)?\\>" . font-lock-constant-face)
;; user-types (customize!)
("\\<[A-Za-z_]+[A-Za-z_0-9]*_\\(t\\|type\\|ptr\\)\\>" . font-lock-type-face)
("\\<\\(xstring\\|xchar\\)\\>" . font-lock-type-face)
))
) t)
希望這會有所幫助。
這太棒了!這次真是萬分感謝。我將從現在開始使用它。你有沒有想過爲此項目回饋? – 2012-12-21 16:35:39
也許...但是,誰維護cc模式?第一作者是RMS(1985),最後一個Alan Mackenzie(2003)。我會發郵件給gnu.org;讓我們看看他們說什麼。 – 2013-05-22 08:10:27
@AndreasSpindler:最後一次編輯絕對不是在2003年 - 最新的源代碼簽名是在2周前由Alan Mackenzie撰寫,請參閱[更新日誌](http://cc-mode.hg.sourceforge.net/hgweb/ CC-模式/ cc的模/數)。 – 2013-05-22 19:41:38
根據Mike Weller的要求,此處爲C++ 11字符串文字(包括用戶定義文字)的更新版本。
(add-hook
'c++-mode-hook
'(lambda()
;; We could place some regexes into `c-mode-common-hook', but note that their evaluation order
;; matters.
(font-lock-add-keywords
nil '(;; complete some fundamental keywords
("\\<\\(void\\|unsigned\\|signed\\|char\\|short\\|bool\\|int\\|long\\|float\\|double\\)\\>" . font-lock-keyword-face)
;; namespace names and tags - these are rendered as constants by cc-mode
("\\<\\(\\w+::\\)" . font-lock-function-name-face)
;; new C++11 keywords
("\\<\\(alignof\\|alignas\\|constexpr\\|decltype\\|noexcept\\|nullptr\\|static_assert\\|thread_local\\|override\\|final\\)\\>" . font-lock-keyword-face)
("\\<\\(char16_t\\|char32_t\\)\\>" . font-lock-keyword-face)
;; PREPROCESSOR_CONSTANT, PREPROCESSORCONSTANT
("\\<[A-Z]*_[A-Z_]+\\>" . font-lock-constant-face)
("\\<[A-Z]\\{3,\\}\\>" . font-lock-constant-face)
;; hexadecimal numbers
("\\<0[xX][0-9A-Fa-f]+\\>" . font-lock-constant-face)
;; integer/float/scientific numbers
("\\<[\\-+]*[0-9]*\\.?[0-9]+\\([ulUL]+\\|[eE][\\-+]?[0-9]+\\)?\\>" . font-lock-constant-face)
;; c++11 string literals
;; L"wide string"
;; L"wide string with UNICODE codepoint: \u2018"
;; u8"UTF-8 string", u"UTF-16 string", U"UTF-32 string"
("\\<\\([LuU8]+\\)\".*?\"" 1 font-lock-keyword-face)
;; R"(user-defined literal)"
;; R"(a "quot'd" string)"
;; R"delimiter(The String Data")delimiter"
;; R"delimiter((a-z))delimiter" is equivalent to "(a-z)"
("\\(\\<[uU8]*R\"[^\\s-\\\\()]\\{0,16\\}(\\)" 1 font-lock-keyword-face t) ; start delimiter
( "\\<[uU8]*R\"[^\\s-\\\\()]\\{0,16\\}(\\(.*?\\))[^\\s-\\\\()]\\{0,16\\}\"" 1 font-lock-string-face t) ; actual string
( "\\<[uU8]*R\"[^\\s-\\\\()]\\{0,16\\}(.*?\\()[^\\s-\\\\()]\\{0,16\\}\"\\)" 1 font-lock-keyword-face t) ; end delimiter
;; user-defined types (rather project-specific)
("\\<[A-Za-z_]+[A-Za-z_0-9]*_\\(type\\|ptr\\)\\>" . font-lock-type-face)
("\\<\\(xstring\\|xchar\\)\\>" . font-lock-type-face)
))
) t)
在上述實施用戶定義的字符串文字的,定界符代碼被分別標爲font-lock-keyword-face
;另一種選擇是font-lock-constant-face
。這個實現並不像它可能的那樣高效;但它工作並不會減慢Emacs的速度。請注意,用戶定義的字符串文字的正則表達式並未從某處「被盜」;所以我希望他們工作。歡迎任何評論。
如果您希望將整個文字字符串分成font-lock-string-face
(包括分隔符),請將三個正則表達式替換爲一個。像這樣:
.
.
("\\<\\([uU8]*R\"[^\\s-\\\\()]\\{0,16\\}(.*?)[^\\s-\\\\()]\\{0,16\\}\"\\)\\>" 1 font-lock-string-face t)
玩得開心。
我喜歡它。但是,它不會正確突出顯示多行字符串文字。 ![見此](http://i39.tinypic.com/2z6v5o6.jpg)。 – 2013-06-18 14:39:19
好吧,這是因爲'.'與換行符不匹配。用'[[:ascii:] [:nonascii:]]替換所有的'。*'*' – 2013-06-18 15:19:16
*'但我不明白爲什麼它會用紅色突出顯示一些字符串引號。 [見此](http://i41.tinypic.com/16ld3iw.jpg)。 – 2013-06-18 15:35:12
用這個替換Andreas的浮點正則表達式可以提高浮點數的高亮度。
integer/float/scientific literals
("\\<[-+]?[0-9]*\\.?[0-9]+\\([uUlL]+\\|[eE][-+]?[0-9]+\\)?[fFlL]?\\>" . font-lock-constant-face)
希望能幫助別人。
看看包裝:"Modern C++" font-lock for Emacs。它也可在Melpa上獲得。
語法突出顯示支持「Modern C++」 - 直到C++ 17和 Technical Specification。這個包旨在提供一個簡單的 突出顯示的C++語言而不依賴。
除了C++模式主要模式 以外,還推薦使用它來額外突出顯示(用戶定義的類型,函數等)和縮進。
我是這個小模式的維護者。任何反饋意見。
對我來說,隨着現代的C字型鎖的兩個最緊迫的痛點++代碼已經
- 事實
auto
被突出顯示作爲關鍵字(而不是一種類型的),因此下面的標識符將通常不是最重要的變量聲明,並且當呈現一些代碼時(例如,嘗試rtags'src/ClangIndexer.cpp
),突出顯示簡單地變得瘋狂,然後例如未能突出顯示諸如函數定義的頂級構造。
經過一番實驗,我得出了一個適合我的解決方案,可以解決這兩個問題。
第一種是通過修改lisp/progmodes/cc-langs.el
(複製到一個人的load-path
然後修改也適用),以除去"auto"
從
(c-lang-defconst c-modifier-kwds
"Keywords that can prefix normal declarations of identifiers
和添加它c++-font-lock-extra-types
(例如,經由自定義)來實現的。
對於第二個,清空c++-font-lock-extra-types
(保留"auto"
除外)有幫助。
- 1. Erlang emacs模式 - 設置outdir
- 2. 在emacs中設置模式
- 3. 設置PSGML模式上的Emacs 24
- 4. 需要設置emacs縮進模式
- 5. 將.h設置爲C++ - emacs中的模式組
- 6. 設置自動模式ALIST在Emacs
- 7. Emacs設置哪個函數模式
- 8. 如何爲C#模式配置Emacs speedbar?
- 9. Emacs的C++模式壓痕
- 10. 設置TAB作爲快捷方式在Emacs Haskell的模式
- 11. 在emacs組織模式之外爲.emacs文件設置
- 12. emacs regexp用「11」取代11
- 13. 爲特定的Emacs模式設置自定義鍵綁定
- 14. Emacs,cedet和C++/C++ 11支持
- 15. 如何在Emacs中使用eval-after-load進行c/C++模式設置?
- 16. 設置從的.emacs
- 17. 無法設置Eclipse Juno C++ std = C++ 11
- 18. 如何將.php模式設置從.emacs移動到.dir-locals.el?
- 19. 如何讓emacs支持C++ 11中公司模式的鏗鏘後端?
- 20. emacs - 僅在主要模式下設置快捷鍵?
- 21. CMake的:C++ 11沒有設置與CXX_STANDARD
- 22. 如何在批處理模式下在emacs中設置變量
- 23. 準備Emacs的設置對於C
- 24. 顯式設置Emacs窗口的大小
- 25. 定製的Emacs縮進C模式
- 26. Emacs:在更改日誌模式下設置填充列
- 27. Emacs:設置java模式本地的密鑰。
- 28. 如何在Emacs中重新設置CUA模式的密鑰集?
- 29. 設置加價的粗體,斜體,...在Emacs組織模式
- 30. Emacs的ediff模式
請注意''thread_local'還不被G ++支持:http://gcc.gnu.org/projects/cxx0x.html gcc擴展'__thread'類似,但不調用構造函數或析構函數IIRC。 – bdonlan 2011-12-18 03:37:09
我對vim有同樣的問題,它有一些我調整過的語法文件。我認爲必須是相同的emacs :) – Geoffroy 2011-12-20 02:13:26