ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

Define Parser

by ukyouz ST4

A Sublime Text Plugin helps you getting values of #define in C source code.

Details

Installs

  • Total 81
  • Win 55
  • Mac 16
  • Linux 10
Oct 11 Oct 10 Oct 9 Oct 8 Oct 7 Oct 6 Oct 5 Oct 4 Oct 3 Oct 2 Oct 1 Sep 30 Sep 29 Sep 28 Sep 27 Sep 26 Sep 25 Sep 24 Sep 23 Sep 22 Sep 21 Sep 20 Sep 19 Sep 18 Sep 17 Sep 16 Sep 15 Sep 14 Sep 13 Sep 12 Sep 11 Sep 10 Sep 9 Sep 8 Sep 7 Sep 6 Sep 5 Sep 4 Sep 3 Sep 2 Sep 1 Aug 31 Aug 30 Aug 29 Aug 28
Windows 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0
Mac 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0
Linux 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0

Readme

Source
raw.​githubusercontent.​com

SublimeText-DefineParser

Hero Screenshot

This is a python parser for calculating C #define values, extended from ukyouz/C-define-Parser.

Support functions:

  • Show cursor define value/ all define values
  • Parse define values from the folder marked as root
  • Mark inactive code under the specified configuration

Usages

Open a C project folder with Sublime Text, this plugin will start building the define data.

With default settings, parser will lookup the closest parent folder that contains the following root markers.

{
    "define_parser_root_markers": [".root", ".git", ".gitlab"],
}

After define data is built, you can enjoy the following features.

Get the Define Value

By default, you have to manually execute Define Parser: Calculate #define Value to get the macro value under cursor. I highly recommend you adding the following configuration in the plugin Mouse Binding file, that you open from Menu -> Preferences -> Package Settings -> Define Parser -> Mouse Bindings.

[
    {
        "button": "button1",
        "count": 1,
        "press_command": "drag_select",
        "modifiers": ["alt"],
        "command": "calculate_define_value"
    },
]

Then you can left clicking with Alt being pressed to show the calculated value of the define under current cursor position.

Preview: Alt-Click Button1

Or, drag a selection with Alt being pressed.

Preview: Alt-Drag Button1

Highlight Inactive Code Region

Inactive code region will be highlighted in gray by default.

Preview: Highlight Inactive Code

If you don’t want this behavior at startup, change the follow setting:

{
    "highlight_inactive_enable": true,
}

You can also run the Define Parser: Toggle Highlight for Inactive Code command to toggle the highlight state for the current window, or use the default keymap Ctrl-\.

The inactive code highlighting by default only shown for files with following extensions:

{
    //"highlight_inactive_extensions": [".h", ".c", ".cpp"], // deprecated!
    "highlight_inactive_header_exts": [".h"],
    "highlight_inactive_source_exts": [".c", ".cpp"],
}

Notice that these settings are case-sensitive. The local definitions in source files will be well considered for parsing to calculate an accurate and correct result.

If mismatch happened or the define data is corrupted, try run the Define Parser: Rebuild #define Data command to rebuild parsing data.

Compiler Configurations

For C compiler, some extra defines are specified in the compile command without being written in the source codes. To setup such extra defines, you can simply create a compiler flag file by running Define Parser: Select Define Configuration command. Follow the instructions, this plugin help you creating a config file in your root folder. After config file is created, you can choose the configuration you want for more precise parsing result.

The file name will be used as the config name, and for the define parser usage, this plugin only take -D options.

After the config selection, it takes a while to rebuild the define data; then the new configuration takes affect and the inactive region changes accordingly.

For example, we specify the -DENV=ENV_TEST in our config file:

Preview: Highlight Inactive Code with Config


Limitations/ Known Issues

  • Currently only support one folder open in one Sublime Text Window.
  • The DEFINITION appears before #define DEFINITION will also be seen as a defined value, context order is not well-handled.
  • Build define data may be slow (few seconds) for large project, required further optimizations for parsing speed.