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