让你的Emacs像vi一样高亮 “#if 0 ... #endif"


   1. 编辑你的.emacs配置文件
      vi ~/.emacs 或 emacs ~/.emacs
   2. 将以下函数粘贴到你的.emacs文件内
    
;;Highlight #if 0 to #endif
     (defun my-c-mode-font-lock-if0 (limit)
       (save-restriction
         (widen)
         (save-excursion
           (goto-char (point-min))
           (let ((depth 0) str start start-depth)
             (while (re-search-forward "^\\s-*#\\s-*\\(if\\|else\\|endif\\)" limit 'move)
               (setq str (match-string 1))
               (if (string= str "if")
                   (progn
                     (setq depth (1+ depth))
                     (when (and (null start) (looking-at "\\s-+0"))
                       (setq start (match-end 0)
                             start-depth depth)))
                 (when (and start (= depth start-depth))
                   (c-put-font-lock-face start (match-beginning 0) 'font-lock-comment-face)
                   (setq start nil))
                 (when (string= str "endif")
                   (setq depth (1- depth)))))
             (when (and start (> depth 0))
               (c-put-font-lock-face start (point) 'font-lock-comment-face)))))
       nil)

     (defun my-c-mode-common-hook ()
       (font-lock-add-keywords
        nil
        '((my-c-mode-font-lock-if0 (0 font-lock-comment-face prepend))) 'add-to-end))

     (add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
     ;;Highlight end


   3. 重新启动Emacs看看^_^
      

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值