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 91
  • Win 63
  • Mac 18
  • Linux 10
Dec 22 Dec 21 Dec 20 Dec 19 Dec 18 Dec 17 Dec 16 Dec 15 Dec 14 Dec 13 Dec 12 Dec 11 Dec 10 Dec 9 Dec 8 Dec 7 Dec 6 Dec 5 Dec 4 Dec 3 Dec 2 Dec 1 Nov 30 Nov 29 Nov 28 Nov 27 Nov 26 Nov 25 Nov 24 Nov 23 Nov 22 Nov 21 Nov 20 Nov 19 Nov 18 Nov 17 Nov 16 Nov 15 Nov 14 Nov 13 Nov 12 Nov 11 Nov 10 Nov 9 Nov 8
Windows 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1
Mac 0 0 0 0 0 0 1 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 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 0 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.