how can I write extension for existing major mode, e.g. dart-mode to highlight block of codes. For example:

// $done>
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'dart:ui';
// $done<

import 'package:android_id/android_id.dart';
import 'package:banagher/gen/i18n/strings.g.dart';
import 'package:banagher/gen/models/meta.pbgrpc.dart';

I code that is located between tags // $done> and //$done< to have green background color.

  • emacs.stackexchange.com/tags/elisp/info
    – Drew
    Jan 7, 2023 at 17:31
  • Just add font-lock rules that do what you want. Search this site for tag font-lock using [font-lock] in the Search bar. This question may even be a duplicate.
    – Drew
    Jan 7, 2023 at 18:11

1 Answer 1


I've done this with the following code:

(font-lock-add-keywords 'dart-mode
                        '(("\\<done\\$\n\\(\\(\\(.*?\n\\)*?.*?\\)\\)\\/\\/ end\\$" 1 font-lock-done-region-face prepend)))

It doesn't work perfectly but it's enough for my need.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.