简体   繁体   English

如何修复未成功匹配的emacs中的字体锁定正则表达式

[英]How to fix a font-lock regex in emacs that is not successfully matching

I'm trying to make a regex in emacs to font-lock tasks, projects and notes in taskpaper files. 我正在尝试在emacs中创建一个正则表达式来控制任务文件中的字体锁定任务,项目和注释。

Taskpaper is a simple text based format for task management, with the following format: Taskpaper是一种基于文本的简单任务管理格式,格式如下:

Project 1:
    - Task 1
    - Task 2
    Note about Task2    
Project 2:
    - Task 3
    Note about Task 3
A general note about something

I'm using a taskpaper mode I found here as a basis ( https://github.com/jedthehumanoid/taskpaper.el/blob/master/taskpaper.el ). 我正在使用我在这里找到的任务纸模式( https://github.com/jedthehumanoid/taskpaper.el/blob/master/taskpaper.el )。 However, this mode is based on space indentation, and it seems that at the moment, the taskpaper format uses tabs to indent. 但是,此模式基于空格缩进,目前看来,任务纸格式使用制表符缩进。

(setq font-lock-defaults 
'(("^.*@done.*$" . font-lock-comment-face)
  ("^.*:$" . font-lock-function-name-face)
  ("^[\t]*[^-\t].*[^:]$" font-lock-comment-face)
  ("@.*" . font-lock-variable-name-face)))

At the moment, the third regex (which should font-lock notes in the comment face) is not working, and I can't see why. 目前,第三个正则表达式(应该在注释面中字体锁定注释)不起作用,我不明白为什么。 Notes are all lines with any indentation that do not begin with a - and do not end with a : Notes是所有带有任何缩进但不以a开头的行-并且不以:

The strange thing is, in the regex builder, the regex ^[\\t]*[^-\\t].*[^:]$ successfully matches the notes lines. 奇怪的是,在正则表达式构建器中,正则表达式^[\\t]*[^-\\t].*[^:]$成功匹配注释行。

I've tried double escaping the \\t characters (as \\\\t) as suggested in some other questions, but this appears to make no difference. 我已经尝试过双重转义\\ t字符(如\\\\ t),如其他一些问题所示,但这似乎没有区别。

What makes the third rule different from the others is that the others use a dotted pair, ie (xxx . yyy) whereas the third use list notation, ie (xxx yyy) . 使第三条规则与其他规则不同的是,其他规则使用虚线对,即(xxx . yyy)而第三条使用列表符号,即(xxx yyy)

The list notation can also be used, but then you must supply the subexpression to be highlighted, as in (regexp 0 font-lock-comment-face) . 也可以使用列表表示法,但是必须提供要突出显示的子表达式,如(regexp 0 font-lock-comment-face)

Where a \\t is in 3rd expression, put an empty space aside, ie [ \\t] for [\\t] etc. Thus empty spaces an TAB are matched alike. 如果一个\\ t在第三个表达式中,则将一个空的空格放在一边,即[\\ t]为[\\ t]等等。因此空的空格与TAB相匹配。 HTH HTH

Part of the problem probably has to do with the use of the * character. 部分问题可能与使用*字符有关。 Since it matches 0 or more times, you're not actually requiring that the line begin with a tab. 由于它匹配0次或更多次,因此实际上并不要求该行以制表符开头。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM