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