使用颜色主题在 Emacs 下的 c 模式下设置浮点值的颜色?

发布于 2024-11-03 06:16:17 字数 1181 浏览 0 评论 0原文

我正在使用 EmacsForMacOsX v23.3.1,我想知道如何将浮点值的颜色 celsiusFloat = (5.0/9.0); 更改为与我当前获得的颜色不同的颜色
color-theme-billw 整数主题age = 23;

我怀疑 StackOverflow 给它们上色的方式不同。


EDIT: My initial approach to add a regex for the floating point d*\.d* in cc-mode.el was apparently not the way Emacs work with syntax highlighting (also known as font locking) - further research has led me to the following website: http://www.gnu.org/software/emacs/elisp/html_node/Customizing-Keywords.html

编辑2: 我似乎在 http://www.emacswiki.org/emacs/AddKeywords 找到了答案和
http://www.gnu.org/software/emacs/manual/html_node/emacs/Font-Lock.html#Font-Lock

(add-hook 'c-mode -钩 (拉姆达() (字体锁定添加关键字 nil '(("[0-9]+\\.[0-9]+" 1 字体锁定警告面 t)))))

I'm using EmacsForMacOsX, v23.3.1, and I wonder how I can change the color for floating point values celsiusFloat = (5.0/9.0); to be a different color than those I get from my current
color-theme-billw theme for integers age = 23;.

I doubt that StackOverflow colours them differently.


EDIT:
My initial approach to add a regex for the floating point d*\.d* in cc-mode.el was apparently not the way Emacs work with syntax highlighting (also known as font locking) - further research has led me to the following website: http://www.gnu.org/software/emacs/elisp/html_node/Customizing-Keywords.html

Edit 2:
I seem to have found my answer at http://www.emacswiki.org/emacs/AddKeywords and
http://www.gnu.org/software/emacs/manual/html_node/emacs/Font-Lock.html#Font-Lock

(add-hook 'c-mode-hook
(lambda ()
(font-lock-add-keywords nil
'(("[0-9]+\\.[0-9]+" 1 font-lock-warning-face t)))))

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

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

发布评论

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

评论(1

爱给你人给你 2024-11-10 06:16:17

我在以下位置找到了解决方案: http://hbfs.wordpress。 com/2010/03/02/adding-keywords-in-emacs/

首先:

(make-face 'font-lock-special-macro-face) ;; Create a new face
(set-face-foreground 'font-lock-special-macro-face "pink") ;; Set the colour

然后我们继续将正则表达式添加到关键字列表中,并将每个正则表达式与一个面孔相关联:

(defun add-custom-keyw()
  "adds a few special keywords for c and c++ modes"
  ;
  (font-lock-add-keywords nil
   '(
     ("[0-9]+\\.[0-9]+" . 'font-lock-special-macro-face )

     ; more of those would go here
     )
   )
 )

最后我们将其挂接到我们的模式:

(add-hook 'c-mode-hook 'add-custom-keyw)

I found a solution at: http://hbfs.wordpress.com/2010/03/02/adding-keywords-in-emacs/

First:

(make-face 'font-lock-special-macro-face) ;; Create a new face
(set-face-foreground 'font-lock-special-macro-face "pink") ;; Set the colour

Then we proceed to add regular expressions to the list of keywords and associate each regexp with a face:

(defun add-custom-keyw()
  "adds a few special keywords for c and c++ modes"
  ;
  (font-lock-add-keywords nil
   '(
     ("[0-9]+\\.[0-9]+" . 'font-lock-special-macro-face )

     ; more of those would go here
     )
   )
 )

Last we hook it to our mode:

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