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 of TODO marks, and navigating between them. However, I think it makes more sense to recognize the "TODO" strings only in comments, rather than polluting the whole file. Is it possible?
相关问题
- Symbol's function definition is void: declare-
- How can I set the SVN password with Emacs 23.1 bui
- Emacs shell: save commit message
- Using XPath to access comments a flat hierachy
- emacs bind key to the insertion of another
相关文章
- ess-rdired: I get this error “no ESS process is as
- Emacs/xterm color annoyance on Linux
- Highlight all occurrences of selected word in Aval
- Does learning one Lisp help in learning the other?
- Pipe less to Emacs
- Capturing the output of “diff” with org-babel
- emacs terminal mode: how to copy and paste efficie
- How to permanently enable the hs-minor-mode in ema
Maybe this will help: there's a fn
c-in-literal
in cc-mode, and a similarcsharp-in-literal
in csharp mode. The return value isc
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.Check out the library fic-mode.el, it has been verified in C++ and Emacs-Lisp.
It was written specifically to answer this question.
The installation is like any standard package:
Though Wei Hu did ask for an easy way to add it to multiple modes, so here goes:
It's possible but quite a bit trickier. Fixme mode uses
font-lock
to do its highlighting, so it works on an as-you-type basis to highlight the keywords. Font-lock hooks in at a very low level, basically running after every change is made to the buffer's contents. It is highly optimized, though, which allows it to appear instantaneous on modern computers.The TODO indicator in the left fringe is static. Execute the function and all current TODO's are highlighted; change the buffer (adding or removing TODO's) does not change the fringe indicator; that's only changed when the function runs again.
Your approach would have to get into syntax tables, determining first when you're in a comment and then looking for the keywords. The tricky part comes in doing this interactively (i.e. as you type). You should be able to hook into the
font-lock
constructs to do this, but the function you provide to search for the comment syntax table and then for the keywords better be very efficient, as it will be run each and every time a buffer changes (though it will only run on the changed region, I think). You would want to stuff all of this infont-lock-syntactic-keywords
rather thanfont-lock-keywords
because the syntactic-keyword pass happens before the syntactic pass (which happens before the keyword pass), and you need to set TODO inside comments before comments themselves are set.Sorry it's not a full working-code answer.....