Emacs: highlighting TODO *only* in comments

后端 未结 3 1216
半阙折子戏
半阙折子戏 2020-12-08 16:12

This question is related to another one, Emacs :TODO indicator at left side. I recently came across a minor mode I like a lot called FixmeMode. It supports auto highlighting

3条回答
  •  不知归路
    2020-12-08 17:13

    Maybe this will help: there's a fn c-in-literal in cc-mode, and a similar csharp-in-literal in csharp mode. The return value is c if in a C-style comment, c++ if in a C++ style comment. You could add that to the code at Emacs :TODO indicator at left side to get what you want.

    (defun annotate-todo ()
       "put fringe marker on TODO: lines in the curent buffer"
      (interactive)
      (let (lit)
      (save-excursion
        (goto-char (point-min))
        (while (re-search-forward "TODO:" nil t)
          (progn
            (setq lit (c-in-literal)) ;; or csharp-in-literal
            (if (or (eq lit 'c) (eq lit 'c++))
                (let ((overlay (make-overlay (- (point) 5) (point))))
                  (overlay-put overlay 'before-string
                               (propertize "A"
                                           'display
                                           '(left-fringe   ;; right
                                             horizontal-bar
                                             better-fringes-important-bitmap))))))))))
    

提交回复
热议问题