oleg-shilo / sublime-codemap

CodeMap - is a ST3 plugin for showing the code tree representing the code structure of the active view/document
MIT License
41 stars 4 forks source link

CodeMap panel doesn't automatically choose correct syntax highlighting ( resets to default every time file is saved ) #19

Closed Acecool closed 2 months ago

Acecool commented 6 years ago

sublime_text_unregistered__screenshot_20171120154756_328

Every time I save the file I'm editing, the CodeMap panel reverts back to my default syntax highlighting selection even though I manually set it and try forcing it....

Is there any way to force it or make ST3 believe it is a file ( Well, actually - since it opens as Code - Map there must be a way to add an extension to it to simulate it as a file which is currently open - and hopefully it is possible to make it dynamic because I do switch between several languages all the time )...


Here's an example from about a week ago - It is for GLua - Garry's Mod Lua... It'll work for Lua too - but you may want to remove the C Style comments, etc... Also I left my AccessorFunc extensions slop in as multiple examples... https://www.dropbox.com/s/nujjbkfbcy1rrg4/__SublimeText3_Work_and_Addons__.zip?dl=0 --- EDIT: Adding GMod Lua package mods to support f and func function prefixes which are in the current list so the map highlights properly along with snippets and more...

---- Off topic update ( Photo shows what the output looks like although I haven't added nested categories yet so I think adding functions to class earmarks is meh - when nesting is added it'll look similar so you can have it output similar to this and / or only have class definitions show up and / or have functions show up with the class designation in front - etc.. many different ways for it to work )... ----

Also Universal System is nearing completion... Lot of features - Callback class is to be filled for each language and allows AccessorFuncs to be expanded into multiple functions without adding that line to the output. Callbacks to replace function / class arguments ( if you want to add data-type next to arg so _p, _w becomes _p, _w or you can remove _p and _w and leave only , or whatever )... Callback with finalized data being added so you can check for syntax errors ( ie in Python for Function / Class definitions - check to see if line ends with : and if not then add notification in Errors category )... Full support for reorganizing output so if you want TODO / Tasks list on the bottom, or removed, etc... 1 line.. Until I add support for nested categories I have python declarations for functions and classes both added to the class category so they appear nested / indented instead of in separate categories...

It is taking a long time due to limited amount of time I'm able to commit to it - I am a few hours in so far - started with proof of concept, then converted it into objects, then added callbacks and now working on config and converting into a way into separating the classes so the language script will be a very simple Callback object and the generate function. I haven't used python in a long time so quite a bit is looking up certain things I've forgotten...

But, when done it'll be worth it for beautifying the data and for being able to sort the data how you want it - also some error checking is highly helpful for those learning and professional alike ( a quick glance seeing [ ERROR ] tag on one of the functions / classes in python and a link at the top with the type of error....

Callbacks:

sublime_text_unregistered__screenshot_20171120161906_5329

oleg-shilo commented 6 years ago

Thank you, Will need some time to process it. Will get back to you as soon as it's done.

Acecool commented 6 years ago

Thanks for the response... I too am looking into it as etc... permits. If I find a solution I'll definitely submit it for review but I am unlikely able to put the required time into reading up on the sublime api, familiarizing myself with the back-end coding, etc.. in order to find a solution prior to you so I definitely appreciate your looking into this!

Here's what I've looked at so far:

I edited 2 locations in code_map.py to add .' + source to 'Code - Map' string either by using code_map_generator.source ( if not None ) otherwise GetExt from the filename... If not apparent, I appended it to the name.

There is a flaw in this approach - you have to open a new Code - Map group for each extension you edit as it becomes a new name - it also doesn't solve the issue I'm having... Every time I save a file, even if it is Code - Map.py or Code - Map.lua it reverts to GMod Lua instead of using python highlighting in the Code - Map.py group and Lua / GMod Lua in the Code - Map.lua group....

I haven't seen the sublime package api or source yet - is there one? - but there must be a way to rename the group on the fly - if this approach is to work.... However, a better approach would be - if the sublime api allows - is to READ the currently mapped filename, the extension and reading from sublime api the syntax associated with that extension.. and then applying it to the Code - Map group. Then we wouldn't need to mess with renaming on the fly or needing to create a new group each time, etc.... so if there is a way to apply the syntax that'd be the preferred method..

Now, if sublime api doesn't support reading the default or overwritten default syntax highlighting from the currently mapped file - but does support altering it for the group - then an override configuration var should be set in the custom mapper file --- something like force_highlighter or force_highlighting or use_syntax_highlighter etc.... = 'GMod Lua' or 'python' etc... -- or a map / config option to map which highlighter to use for the group when mapping certain files could be a viable solution...

Again: Unless we can rename the group on the fly - the method of naming the 'Code - Map' group-name to 'Code - Map.' + ext isn't viable as it would require the user / dev to manually close the CodeMap group and manually re-open it using alt+m... Additionally, because changing the name to an extension didn't even resolve the issue of the syntax highlighter ( despite my forcing, via the menu, ST3 to set the syntax python or GMod Lua highlighter to ALL files of the same extension ) choosing the wrong highlighter...

On a side note: I remember having an issue a while back where Code - Map group would close when switching to a syntax not recognized ( although in my case I did have the custom mappers present if I recall correctly ) which forced me to manually attempt to open it.. This may have been an issue with the installation / unpacking + user folder or something else... But if there was a way to resolve the issue of the extension properly using the highlighter then opening, if already open, the new file could work before closing the old one - to prevent the user / dev from manually resizing the group when it is completely closed and re-opened - would be an acceptable hack if renaming on the fly doesn't work or the api doesn't have the ability to set the syntax thereby requiring the use of extensions to the group.....

Acecool commented 6 years ago

I felt this required a new response - I found map_syntax seems to work.... When I updated it ( as I thought it only supported tmLanguage ) to map_syntax = 'Packages/Python/Python.sublime-syntax' -- the highlighter seemed to properly set the syntax to Python for the python files I opened and then when I switched to Lua it seemed to properly switch back to GMod Lua....... Because python didn't have a .tmLanguage file available I didn't use that variable ( and I found when making changes to my universal mapper that SublimeText seems to keep things in memory when I found issues with my mapper after restarting ST3 - is it possible the map_syntax is also kept in memory, despite not being explicitly defined as global between extensions if one isn't used? )

This issue-request is looking to be a non-issue...

On a side note, the comment from the custom_mappers I looked at was a bit ambiguous as to the nature of supported files - so I went by what was used which was .tmLanguage - If we swapped the comment from:

-- you can support custom language definitions, with a fallback if not installed

to something along the lines of

-- you can support custom language definitions, with a fallback if not installed - this supports .tmLanguage and sublime-syntax files...

It may help others.... The new md custom_mapper does use sublime-syntax file for the map_syntax assignment though, but when I originally downloaded CodeMap, the md mapper wasn't available so I went with what I saw - it is likely this won't happen to the next person as there are more examples available, however updating the comment wouldn't hurt.

oleg-shilo commented 6 years ago

I found map_syntax seems to work....

Sorry but I couldn't respond yesterday with more than a single statement and just hoped that you wouldn't spend too much time on it until I provide you the explanation. Well... you found the answer.

The syntax highlighting of the CodeMap view is optionally defined by the mapper object. It can be either a stock or a custom syntax definition.

For the universal mapper the syntax comes from the settings file:

image

I added some extra content to the syntax highlighting comments in the included scripts. Hopefully it will help:

# `map_syntax` is a syntax highlighting that will be applied to CodeMap at runtime
# you can set it to the custom or built-in language definitions
if 'MagicPython' in installed:
    map_syntax = 'Packages/MagicPython/grammars/MagicPython.tmLanguage'
else:
    # fallback as MagicPython is not installed
    map_syntax = 'Packages/Python/Python.tmLanguage'

Do you still want me to have a look at your Lua mapper?

Acecool commented 6 years ago

I have a few wrinkles to iron out before it is ready for mass consumption and I haven't added automatic support for language files yet or the separation of the objects from the file meaning each mapper would have a ton of back-end code on top of the Callback class which is for the user / dev to set up the earmarks which are seen in the right or left Code - Map panel..

If you are interested in seeing it, here's an old version: https://www.dropbox.com/s/nujjbkfbcy1rrg4/__SublimeText3_Work_and_Addons__.zip?dl=0

which should work out of the box but there is a lot extra which isn't needed for Lua - it is set up for GLua and my framework in GLua because of the AccessorFunc definitions and Syntax settings. It's still merging from proof of concept to actual product in the current version but I've started working on code for php so multiple languages can be used in a file ( .php uses html, php and javascript in some cases - although the way I code is by having html templates, etc.. to avoid mixing - others may not which is why that support is necessary ) in certain scenarios..

I am also planning on slightly changing the way the code is managed to something similar to my GLua automatic wiki generation system ( which reads the function definitions comments, and the structure for returns, etc.. ) and take it a step further because this can also track function calls for earmarking things such as console commands being added, etc... which can run for more than a single line....

I am still familiarizing myself with python again after a long long break since using it for a project - and how sublime text uses it, keeps things in memory, etc... I may simply alter my classes to be more of a support system / library system as some of them are now by extracting data-storage, etc... with a runtime class being used for data storage / output / etc.. I prefer to do things right, and right now I see I am doing things wrong in some cases so this isn't representative of how the final product will look..For example: The Acecool.table. Function Args call chops off the end of the function due to my adding support for functions being added in for Lua ( I remove the function and rename the arg to FUNC_REF so that the on each arg callback can insert the appropriate function args depending on the situation - for concommand.Add it turns FUNC_REF into function( _p, _cmd, _args, _args_text ) ... end ) but I did open up a bitbucket for this project so I'll update that more frequently if you want to keep track of this..

This issue can be closed as it isn't an issue and you did update the comments to clarify that it is used for highlighting instead of syntax to add data...

The bitbucket address for the universal addon project is ( I haven't updated it to use the new Callback class so the some of the callback functions are still in the primary scope of the file because I am still working on separating the Acecool library / class from it as well as the XCodeMapper class / library which will probably be renamed later... X typically means work in progress in my naming scheme... ): https://bitbucket.org/Acecool/acecooldev_sublimetext3/src

I do recommend downloading from my acecooldev_userscripts repo the tampermonkey / greasemonkey / javascript system for your browser to view bitbucket repos source-code by rewriting all links to use the master link.... unless in history mode... It makes the links much shorter and easier to share... ( https://bitbucket.org/Acecool/acecooldev_userscripts/src/master/bitbucket_org/acecool_bitbucket_replace_src_links_to_master.js?at=master&fileviewer=file-view-default ) - I have to update this repo too as I created a framework for adding features to websites in a much easier way when modifying a lot of sites but it should still work...

With all of that out of the way - what do you think of the category system and the callback system to add more features in addition to making them much more easily accessible and allowing devs to customize the mapper to work with their frameworks without having to do what I did and without having to write a ton of code just to add support for everything they wish to earmark?

oleg-shilo commented 6 years ago

Sorry for the delay with response.

I had a look at your mapper and I have one conceptual question.

...what do you think of the category system and the callback system to add more features in addition to making them much more easily accessible and allowing devs to customize the mapper to work with their frameworks...

I anticipated a language (Lua) specific mapper but your question above makes me think that you see your mapper as a generic mapper for other non-Lua languages as well. Please correct me if I am wrong.

There is no problem at all with a particular mapper being generic by nature so other devs can reuse it. Something like this: code_map.lng1.py code_map.lng2.py code_map.lng3.py master_mapper.py

Where all code_map.*.py scripts import master_mapper.py and use it as they wish. Such a model does not conflict with the CodeMap hosting concept, which require the mappers and the plugin to be completely decoupled.

However it is a problem if a new mapper requires changes in the way the plugin (code_map.py) interacts with mappers.

Thus can you please elaborate on your vision of the integration path for your plugin.

Now a practical question.

In my environment Lua-mapper fails to initialize due to the lua.sublime-syntax problem:

image

However if I remove the syntax file the mapper works OK but without syntax highlighting. Can you please have a look at this.

Acecool commented 6 years ago

Download from the bitbucket link - it is the latest version: https://bitbucket.org/Acecool/acecooldev_sublimetext3/src

Right now I have mappers set up for GMod Lua ( and for my AcecoolDev_Framework - again, the reason for XCodeMapper is to be able to easily customize it to your specific needs without having to do a lot - with my mapper I can earmark things with 1 line or add more lines if more specific things come up ), Python ( with a basic syntax error check if : doesn't exist at the end of a function or class definition and the error would appear at or near the top in the current category output order - but I still have to correct the Acecool table Args function to return the rest of the line after it reads through the args so : isn't cut off in some cases ), PHP ( The most basic of examples which tells you where the tags are and the function of the tags - it should also set active language AccessorFunc too ), and JavaScript ( Again, using my framework and custom AccessorFuncs to expand upon them, etc... See my repos in bitbucket and look at AcecoolDev_UserScripts for the ultimate site script - the js version works with that and outputs what each arg means for each setup, remembers the last _tag value to fill it in so I don't have to in code meaning it is more copy / paste friendly in code but in CodeMap it shows me exactly what it is for ) using my XCodeMapper... As you'll read below, the files get quite large which is why I want to separate Acecool library and XCodeMapper object into a different file to keep the files smaller and to make updating and management easier...

The Lua syntax in custom_languages\ file I wrote was when I believed it didn't read other syntax files ( which would've been from GMod Lua addon for ST3 ) so I copied most of the one file format to the other - simple patterns so it was easy to create.

Line 245 is

  ##
  ## <!-- important constants -->
  ##
  constants_important:
    - name: constant.language.lua
    - match: \b(CLIENT|SERVER|GAMEMODE|EFFECT|GM|SWEP|TOOL|ENT)\b

I don't see any other constants_important declared in the file. It could be because you have Lua and GMod Lua enabled? I had to disable my vanilla Lua package in order to use the GMod Lua plugin without conflicts. It could be that my lua.sublime-syntax file which is a rewrite from GMod Lua tmLanguage is interfering with your vanilla Lua language - I'd recommend removing my language file and changing the code_map.lua.py file to be directed to your Lua package tmLanguage or other file for the highlighting.

Yes. It is a generic universal mapper which is designed to work in series with your system - but it could be moved to the back-end. The way I envision it in its current state is there are still the code_map.ext.py files with the mandatory generate function which calls an instance of XCodeMapper ( can be renamed ). I do want to separate XCodeMapper and Acecool class and lib from each of the code_map.ext.py files so only the generate function exists along with the Callback class.

The Callback class is designed to be called at specific points in the XCodeMapper in order to define rules to look for in the code in addition to being able to manipulate or redirect what happens with that data - comments are ignored for most other category types ( new feature ) except for Task / TODO list category types. Others can be added if necessary by incorporating a better rule system - right now it is hard-coded for category type == x then check for the todo / note / work / task / important / etc... but multiple categories can share the same type. The Callback class is designed, as said above, to be called from strategic points within the XCodeMapper ( so I probably need to create an instance of it and pass it through because of how ST3 keeps things in memory ).

I am writing it to give ultimate freedom in deciding what to earmark in code and what to do with the code which is discovered ( which is why there is a PreOnAddEntry callback so you can rewrite the code displayed or check syntax, etc... - and for functions / class category types there are argument callbacks so you can rewrite the arguments to show the data-type expected with the arg or just the arg or just the data-type or whatever you want so in code something like function GM:PlayerDeath( _p, _w, _dmginfo ) could appear in CodeMap panel as func GM:PlayerDeath( , , ) or whatever - to get that output 2 callback functions would be used: One for the function args which is called for each argument and the returned value is what it is replaced with so if you only return arg then it stays the same, and PreOnAddEntry replacing function with func to allow more room in the code-map panel so it can be smaller while still displaying the same amount, or more, information.

The other big thing is the AccessorFunc redirect so when the mapper encounters what is designated as an AccessorFunc ( something which typically creates a Setter and Getter function, and sometimes more or less ) instead of adding that line it runs it through the AccessorFunc Expansion callback where you simply call 1 line of code to add a new entry for each entry you want. Some of mine add upwards of 10 functions and I use helper functions so I use some variables set to true / false to trigger the additional functions - ie AccessorFunc adds all, AccessorGet adds a few, AccessorSet adds a few, AccessorHelpers adds a few, etc...

Being able to have freedom and to be able to in an incredibly simple manner define what to look for and what to do with that data once found into the most concise and usable output possible is the primary goal. Right now, I can do all of that but I still want to make it better and add the features needed for other languages instead of using hacks ( ie python variant puts functions and classes in a single category and the Calc Depth callback puts them at their appropriate depth instead of having class headers in a category then a functions category with nested categories or identifiers to show class ownership... - While the current method works, there is be a nicer way to display and organize the data.. ).

As of right now, because Acecool lib and XCodeMapper object is in each code_map.ext.py file, it makes it rather big and daunting for those unfamiliar with the language which are the two reasons for removing them and putting them either in 2 files or a single file to be included in the code_map.ext.py files when using the Callback object system... The problem I'm having is because ST3 keeps things in memory the way it does, I have to restart ST3 for each test otherwise I end up with a previous version in memory which leads to everything being added to one XCodeMapper class which doesn't exist and on restart find that nothing works - no error message, just nothing displaying which is why in the new version it is partially converted to XCodeMapper instance passed through and the functions being called have it named something else such as self but the arg can be changed to XCodeMapper to see what I'm talking about for each of those functions as they call it directly in their functions.

I haven't used python in years so I'm still regaining my orientation with it which is why I'm having some of the issues I'm describing not to mention personal matters meaning less time to work on it than I'd like...

Ultimately, I'd like to have one or more callback arguments in one map so code_map.php.py would look for php tags before using php callback class ( or a GetCurrentLanguage( ) == 'php' function can be used in a single callback class ), when outside of a php tag, it would use HTML by default which there wouldn't be much to earmark except maybe the beginning of primary tags such as head, body, script, etc... When encountering Script tags, it'd parse as JavaScript.

It would be nice if I could keep code_map.php.py only python in that callback and have it read from code_map.js.py when necessary and code_map.html.py too... For this to work, some back-end work would need to be done and a single runtime object would need to be used for the data output which would basically be categories and category entries so they'd all share - but it could also be coded in a way to simply have it run multiple times on the same file ( If this is the case then I'd highly recommend adding another feature to the callback where the php callback would designate that it 'owns' certain lines for php to ensure other calls wouldn't reprocess those lines - some lines would be designated as shared such as what is popular among coders to do with forms for form-repopulation by using php short-tags or a variant to prevent setting up multiple lines for each form element so character x to y would be 'owned' by php and thereby stripped from the next processor when looking at that line )...

There are many ways to do this... The simplest is to keep it all in the same directory it is in, but moving it towards the back-end of CodeMap would have its benefits and would also ensure the memory is purged - although I could actually do that in generate after the data is generated and assigned to the variable.

I'm considering removing the CFG_ values at the top. They'd be great to keep for non coders to easily edit the configuration without going into the Callback class OnSetupConfig function and manually edit the configuration initiation - but would there be non-coders using this? Honestly, I could see CodeMap being used as a teaching tool in some cases for those looking to learn how to code as the output could map when x happens and why it does, etc.. The reason I'm considering removing them though is because I'm currently changing things around quite a bit and keeping them up to date on so many different files is meh - it is easier to simply add lines in a callback function and be done, but I'm kind of doing both right now while I figure out everything which needs a config option.... It's one of those cases where it is useful but it slows you down during the production...

What are your thoughts on everything?

Edit: Maybe you can help me with the file extraction... If I were to put the Acecool class into a file named Acecool.py and I import Acecool.py as Acecool after removing the Acecool class and unindenting all code within it... The naming sequence should remain identical for usage within the entire script - correct? It is a library so an instance isn't needed for it to work... I tried this but ended up having trouble - but then again I did it for both.... I'm going to try it again to see what happens... My include ended up looking like include User/CodeMap/Acecool.py or something...

Edit 2: Got it.. Separated Acecool from the main files ... I had to restart several times because ST3 precaches imports and even if the import changes, the changes aren't read until you restart ST3 - an annoying task...

With this, I'll probably have no problem moving XCodeMapper out - it's just annoying to restart after each change and have ST3, on startup, cycle through every single open tab....

Acecool commented 6 years ago

Making new post for this update: https://bitbucket.org/Acecool/acecooldev_sublimetext3/src

I finally started extracting like-data from ALL code_map..py files... Acecool lib is removed, and I've started removing XCodeMapper content ( such as the data-maps for categories, etc.. and more ).. now that I know I have to restart ST3 each time I make a change - if you know of a console command to force reload and flush memory, that'd be amazing... do you?

I'll be extracting XCodeMapper class from all of the files very soon!

I put my files into User/CodeMap/Acecool/ for Acecool.py Library and XCodeMapper.py Object ( which doesn't contain the object yet, and it'll likely be converted to a basic library in favor of the RunTime object containing all of the data )...

All of them are working each restart and as of this update. You may need to disable the Package named Lua and enable / install the Package GMod Lua to see the Lua system in action.

I'll add a few files to an example folder to give an idea what everything looks like - or you can goto: https://bitbucket.org/Acecool/acecooldev_framework/src - I'll upload some of the later files which have the AccessorFuncs being used....

This change will make managing things easier, but annoying if I have to restart each time to test each change - although if there is no concommand to flush / reload then I can always cut the contents from either Acecool.py or XCodeMapper.py and put them in the file while I make changes and then move them back to confirm for other files...

Keep an eye out for updates to the bitbucket link for new versions... I've also added your contact information to the help category output ( and added a cfg option so people can disable the help category easily : CFG_DISPLAY_HELP_CATEGORY )

Help & Information
    Welcome to Acecool's Universal Code Mapper, an Extension for the ST3 Package CodeMap by oleg-shilo!
    This help category is to list tips & tricks, contact information and more!
    Download:   https://bitbucket.org/Acecool/acecooldev_sublimetext3
    Support:    https://bitbucket.org/Acecool/acecooldev_sublimetext3/Issues/
    --------------------------------------------
    For help and support with CodeMap by oleg-shilo please review the following:!
    Download:   https://github.com/oleg-shilo/sublime-codemap/
    Support:    https://github.com/oleg-shilo/sublime-codemap/issues/
    --------------------------------------------
    In order to hide this message, alter in code_map.<ext>.py, near the top of the file, the following code from:
        CFG_DISPLAY_HELP_CATEGORY = True
    To:
        CFG_DISPLAY_HELP_CATEGORY = False

Forgot to hide the line-number by using '' as entry...

Which default help / support message output do you prefer - or should it be rewritten?

Help & Information
    Welcome to 'Acecool's Universal Code Mapper, an Extension for the ST3 Package CodeMap by oleg-shilo!
    This help category is to list tips & tricks in addition to providing help and support information!

    For help and support with XCodeMapper and the Acecool Development Library by Josh 'Acecool' Moser

        Download:   https://bitbucket.org/Acecool/acecooldev_sublimetext3
        Support:    https://bitbucket.org/Acecool/acecooldev_sublimetext3/Issues/

    For help and support with CodeMap by oleg-shilo:

        Download:   https://github.com/oleg-shilo/sublime-codemap/
        Support:    https://github.com/oleg-shilo/sublime-codemap/issues/

    To hide this category, update the following CFG_ value at the top of each code_map.<ext>.py file.

        Alter from:

            CFG_DISPLAY_HELP_CATEGORY = True

        To:

            CFG_DISPLAY_HELP_CATEGORY = False

or

Help & Information
    Welcome to 'Acecool's Universal Code Mapper, an Extension for the ST3 Package CodeMap by oleg-shilo!
    This help category is to list tips & tricks in addition to providing help and support information!

    For help and support with XCodeMapper and the Acecool Development Library by Josh 'Acecool' Moser
        Download:   https://bitbucket.org/Acecool/acecooldev_sublimetext3
        Support:    https://bitbucket.org/Acecool/acecooldev_sublimetext3/Issues/

    For help and support with CodeMap by oleg-shilo:
        Download:   https://github.com/oleg-shilo/sublime-codemap/
        Support:    https://github.com/oleg-shilo/sublime-codemap/issues/

    To hide this category, update the following CFG_ value at the top of each code_map.<ext>.py file.
        Alter from:
            CFG_DISPLAY_HELP_CATEGORY = True
        To:
            CFG_DISPLAY_HELP_CATEGORY = False
mg979 commented 6 years ago

@Acecool I tried your mapper/syntax. I don't know the issues you're having(no time to read all that) but:

These are the changed files: https://www.dropbox.com/s/c3pxu2u8mola941/CodeMapLua.7z?dl=0

Note that I didn't install any of your other files, a custom mapper should only need the mapper and optionally the syntax.

Please try them and tell me if they work. Also remove any "lua" among nuiversal mapper settings, otherwise the custom mapper would be overridden.

Also, there are a lot of print functions in the mapper, you may want to comment them out if the mapper works.

oleg-shilo commented 6 years ago

@mg979, thank you for looking into it. All my preliminary tests also indicated that the Lua mapper works. Thus no fundamental problems, may be just rough edges.

I am still somehow lost. Is it a Lua mapper or yet another universal mapper? Though it's not really that important. Any mapper is OK as long as it can produce a map definition from the given source code file path. And the that fact that it is syntax specific or universal is kind of irrelevant.

That's why I always insist on complete decoupling between mappers and CodeMap runtime (plugin itself).

The only exception is the current RegExp universal-mapper, which has become an "embedded mapper". Any other mapper is just a Python file that is imported dynamically at runtime. Thus no mappers require any special measures on CodeMap in order to accommodate them. Though if a specific mapper proven to be reliable and beneficial for the dev community I have no problems including such a mapper in the distro.

I will need to explain it more on wiki...

mg979 commented 6 years ago

This Lua mapper is a custom mapper, so it works if put in the custom mappers folder. Acecool stated in the readme of its file, that "syntaxes" in CodeMap settings should be commented. But this isn't necessary, his mapper works as a custom mapper without needing to disable other CodeMap syntaxes.

Anyway, there's a mistake in code_map.py at line 510, that may cause issues:

https://github.com/oleg-shilo/sublime-codemap/blob/8dfde428e1eef68dd36052910d1b1518373d4f7f/code_map.py#L510

The python mapper is not in the support file anymore (it's in custom_mappers). I don't think this is related to the issues Acecool has had, but those lines cause an error on occasions.

oleg-shilo commented 6 years ago

Yes, that line was an old code fragment, though under normal circumstances that code could never be reached.

Anyway, that code along with another similar glitching line in 'code_map_support.py' has been removed.

Will do the release in a day or two.

Acecool commented 6 years ago

Hey, I didn't know I wasn't on for so long... I just uploaded a new version to bitbucket which removes XCodeMapper Base and Callback base from all of the code_map..py files. Now there is only the generate function which creates an instance of Callback, XCodeMapper, then runs it and returns the code. I will be adding a cleanup function for sake of cleanup as I do in my projects.

https://bitbucket.org/Acecool/acecooldev_sublimetext3/downloads/?tab=tags

You will need the folder named Acecool in User/CodeMap/ along with the custom_mappers... I added basic support for MD as TS ( should be similar to the current default ones - but I need to look more at their syntax to fully and accurately support them ).

I also added a chain for map_syntax to look for defaults before looking elsewhere before defaulting to python or other... I did run into some isssues - does anyone know why JavaScript doesn't appear in installed ( I added not ignored as it should be a default package into the logic )? The same with PHP...

@mg979 I will take a look at the changes made - thanks :-)

Please take a look at the latest version - it cleans them up quite a bit and removes all of the repetition so XCodeMapper isn't in each file - I did copy all of the code to the end of the XCodeMapper base file though as some of them had minute changes I have to add in so the end is messy but the primary is not.

The purpose of this mod is to clean up the default output by categorizing data and organizing the order it is output. Additionally, to allow quick additions and changes to the data earmarked for the Code - Map panel. Because I wanted each mapper to be as small as possible - XCodeMapper / Base and Callback Base are now in an external folder.. This will make them easier to manage, update, and understand. I also added a simple 'Map' above the Callback definition to show which functions are in the Callback object in the active file. My mod adds more features so it relies on the extra files - but, yes, the XCodeMapperBase and XCodeMapperCallbackBase could be re-added to each file so only the mapper and the syntax file would be needed but to maintain all of them would be a huge chore and the file sizes would be much larger - this way, especially as ST3 keeps things in memory, the sizes are much smaller for the mappers and the imported files remain in memory are much smaller too!

I modified all of the mappers to, when possible, use the default syntax files and to fall through - ie as the main code_map.lua.py file is for GMod Lua I have it look at GMod Lua first, then Lua then python.. ( I just noticed I have to add to elif: 'Lua' in installed or 'Lua' not in ignored:...

# -- Set this to .tmLanguage / .sublime-syntax / etc.. files in order to enable syntax highlighting within the Code - Map Panel!
if 'GMod Lua' in installed:
    map_syntax  = 'Packages/GMod Lua/Lua.tmLanguage'
elif 'Lua' not in ignored:
    map_syntax  = 'Packages/Lua/Lua.sublime-syntax'
else:
    map_syntax  = 'Packages/Python/Python.tmLanguage'

Ok, to explain the purpose of my mod...

I code in quite a few languages and to make things easier I typically set up libraries of helper functions to serve as building blocks to make life easier. The problem with the default way mappers are written in CodeMap is that you have to go into the heart of the code and add a lot to get back very little. XCodeMapper mod ( name change likely as it is nearing final stable release and coming out of 'beta' ) is there to allow developers to quickly, with 1 line or so, add support for their libraries. Additionally, they can add 2 lines to check to see if python function and class definitions end with : and if not generate an error which is in the top-most category - it's easy to miss something like that when coding a lot.

So instead of 10 lines to add support for a line beginning with function to add an entry, it becomes 1: ThisMapper.AddSyntax( CATEGORY_, SEARCHMETHOD, 'function ' ) with additional callbacks applied to certain category types ( although because different languages do arguments differently I need to modify the back-end function to ensure that can be modified and resolve the issue where the end is cut off )...

I don't like spending a lot of time doing things which aren't productive due to my limited quantity of time available to me where I am actually able to do something... CodeMap is a fantastic addon ( when I used Notepad++ I used FunctionList but it had a memory-leak and was really slow ) which lets you get an overview of the code you're working on very quickly - the custom mappers were an issue though because they took too long to generate something useful and there was a lot of repetition in doing so... XCodeMapper removes the repetition...

So, yes.. It is a universal mapper which takes a set of rules applied and processes the code that way. It adds the category system to clean up the output so there isn't as much wasted space ( ie in the default mapper, the way it separated categories was by adding everything to a plain-text variable and when a different category arrived it added new lines to separate.. the problem with this is if you have a function followed by a note followed by a function followed by a class then note, etc... you'd have 10+ newlines, not counting the category line - only counting the 2x newlines to give a blank line between the previous entry and the next - and 5+ category name lines with newlines and then the data... ).

With all of the code_map..py files cleaned up and with only what is needed for each - I hope it clarifies how it all works...

Some of the TODO:

Some of the UPCOMING or possible upcoming

It doesn't matter if it is to remain as a mod to CodeMap if we merge or if I create a stand-alone system ( unlikely because of time constraints and one which is reliable and has useful features already exists ). The benefits of merging would be a proven and reliable back-end for both the CodeMap package and the XCodeMapper addon with beautiful and concise output of earmarked data coupled with the incredible ease of adding support for new languages.

If we did merge, I would probably still prefer the current method of the custom_mappers\ folder and files because the way I envision my system to be used is to allow users to modify what is earmarked quickly and easily... So instead of opening one file or so with all of them named differently based on language or extension - they open the file instead and can easily edit without having a ton of stuff in front of them... Although if it is all in one file some of the techniques I used in the .js.py file could be used to beautify the output but I'd still prefer separate files simply because of ease without distraction... I also wouldn't mind naming each of the Callback classes separately which would allow the user to simply extend that class in a custom mapper.... So many possibilities...

Let me know what you think - if you'd prefer to give it a trial run feel free to put in your readme my bitbucket link to allow users to try them out ( I could convert the repo to work with ST3 so they'd only need to add it instead of a manual install - I'll look into that )

I still have to write more code in order to support files such as htm, html for JavaScript and html, and php / asp files for html, JavaScript and php / asp along with SQL possibly being coupled in - I have already coded a database system which generates queries based on ultra-easy calls which creates ultra-complex queries so adding support for that wouldn't be overly difficult.

Once I add support to parse lines again for different language, it will make things easier because things such as comments at the end of a line will be stripped, and short-tag usage will be parsed differently, etc..

Acecool commented 6 years ago

Update - It looks like I may end up merging Callback and XCodeMapper.... Any thoughts on this?

If I merge it it'll mean I don't need to route the callback through everything which needs it... It also means the dev wouldn't need to create a new class definition to overwrite default functions... Callbacks would be easier to create.. Etc...

I haven't used python in a long time so I can't exactly recall efficiency between the two.. Any ideas on this? I suppose re-separating, if it came to it, wouldn't be too difficult...

Acecool commented 6 years ago

Anyone know how to stop Sublime Text 3 from cycling through EVERY OPEN TAB on start-up? It makes it incredibly difficult to test when you can't even find the file you were working on because of it opening every damned file and switching so fast?

Edit: I just pushed another version which combines XCodeMapper and Callback... It is a little messy with the function naming so I am working on changing those as well as cleaning up some of the callbacks and creating new ones... I should have time later today to make some additional changes after another rest-cycle...

I ended up finding the zip file - it was in a really weird place ( for those that get e-mail updates )... so I didn't have to redo the merge and all, thank goodness...

If anyone knows how to fix the above issue, I'd love to know!!!

Edit: Appears to be the SyncedSidebar addon....

mg979 commented 6 years ago

@Acecool

Appears to be the SyncedSidebar addon....

Yes it's that one, just remove it, if you didn't already.

About the rest, could you please write in just a few lines what you're doing with this XCodeMapper? I don't feel like reading all your posts, but your Lua mapper has an interesting approach, so I'd like to understand. Consider that stuff that is targeted to specific mods/environments should be extra, not included as a general custom mapper. If you have some project that makes use of a specific syntax and even mapper, that couldn't be used as generalist custom mapper.

Create a VANILLA Lua mapper ( now that the Base files are external there won't be repetition ) for those who don't use GLua

I don't know what GLua is, but if the files have the same .lua extension, CodeMap could not distinguish between normal Lua and GLua files, so there should be a single mapper for both. Maybe make it able to recognize which kind of file it is, if GLua has some peculiarities that can be recognized. I used your mapper to open a lua file and it mapped it just fine, though (the two files that I uploaded some days ago). If you rename files to .glua it's not a problem, you could enforce that.

The problem with the default way mappers are written in CodeMap is that you have to go into the heart of the code and add a lot to get back very little.

Not sure what you mean. To make a reasonable custom mapper, if you use the python or universal mapper as base, shouldn't be too hard.

XCodeMapper mod ( name change likely as it is nearing final stable release and coming out of 'beta' ) is there to allow developers to quickly, with 1 line or so, add support for their libraries.

How would that work? And how many languages would it support?

Additionally, they can add 2 lines to check to see if python function and class definitions end with : and if not generate an error which is in the top-most category - it's easy to miss something like that when coding a lot.

There are linters for that (SublimeLinter or LSP for example, plus Anaconda for Python), CodeMap shouldn't make the job of linters, unless you include such a thing in a specific custom mapper for a language that doesn't have a linter available. But checking just : at end of def/class line, isn't that much of a help.

Acecool commented 6 years ago

@mg979 Here is the shortest possible answer I can give on what it does:

XCodeMapper ( the alpha / beta dev name ) is geared towards reducing the workload required to add useful earmarks to your code / project for display in the Code - Map panel. It also displays the data as concisely as possible by introducing categories so there isn't wasted space switching from category to category to category when 2 are the same and 1 in the middle is different.

It allows quickly creating and tailoring a mapper, with the fewest possible lines, to your specific project needs. ie instead of adding 10 lines to the traditional method in an elif ( and ensuring the order is correct with all of the other cases ) you'd add 1 line and then the data would appear, if found, in the appropriate category in the Code - Map Panel. If the order is wrong ( as order is important ) you only need to move 1 line around ( ie for the MarkDown example I'm writing, if I look for starts with # before ###### then H6 would never be seen but H1 would - moving around 10+ lines in an if / elif / else structure isn't difficult, but it can be annoying ).

The goal is to support many languages. I'm adding functionality to support file extensions with multiple languages ( .htm / .html for JavaScript and HTML / .php for HTML, JS, PHP, SQL / .asp for HTML, JS, ASP, SQL )... It can be used for plain-text or for coding projects.

Acecool commented 6 years ago

@mg979 The features list is long, but I'll keep the examples short in this post..

I use a callback system to allow the greatest level of flexibility. If you have a project which has a helper-function called AccessorFunc( _tab, _name ) which creates two or more functions so _tab.Get( _default ), _tab.Set( ), _tab.GetToString( ) - instead of having to write an if statement which repeats the same code over and over and pulls the current method of adding in the custom_mappers using entry = ( x, y, z ) and added, then repeating before either continuing to the next line... There is an AccessorFunc callback which is specifically used for these situations.. Set the Category Function AccessorFunc and standard search and add

    def OnAccessorFuncExpansion( self, _mode, _category, _pattern, _line_number, _code, _depth, _args, _args_count ):
        # Turning AccessorFunc call into 3 functions while ignoring this line and not adding it...
        if ( _pattern == 'AccessorFunc' ):
            # Helper function to get the arguments of the AccessorFunc - the DEFAULT_ args are if the arg is optional so if you have a _getter_prefix to change how the Get function is created ie '' would be Blah instead of GetBlah, etc.. in that case you'd use 'Get' for the default... or 'Has' or whatever.. - 0 and 1 for the arg index, args count to ensure not going over, etc..
            _tab = Acecool.table.GetValue( _args, _args_count, 0, 'DEFAULT_STRUCT' )
            _name =Acecool.table.GetValue( _args, _args_count, 1, 'Blah' )

            # Create the functions - Get returns the data as is.. Set sets the data as is.. Get<Name>ToString returns the data inside of str( ) call... This is the basically the Python AccessorFunc I made except the pattern is Acecool.util.AccessorFunc or self.ConfigAccessorFunc or self.AccessorFunc...
            self.AddEntry( CATEGORY_FUNCTION, _line_number, 'function ' + _tab + ':Get' + _name + '( _default );', _depth, _mode, _pattern )
            self.AddEntry( CATEGORY_FUNCTION, _line_number, 'function ' + _tab + ':Set' + _name + '( _value );', _depth, _mode, _pattern )
            self.AddEntry( CATEGORY_FUNCTION, _line_number, 'function ' + _tab + ':Get' + _name + 'ToString( );', _depth, _mode, _pattern )

and that turns 1 line into 3 functions... That callback can be re-used and the more you have, you can make the code shorter by putting all of the args at the top ( which will end up defaulting out if they don't exist ) then if pattern == mine then add entry to category of my choice, etc...

The callback system is one of the helpful features - but even more helpful than easily adding the earmarks to the panel is the category system because it means a lot less wasted space... Everything is organized as you'd want it - and you can hide categories you don't want... You can even add error checking to the PreOnAddEntry which is the callback right before adding the data to a category... So if function or class in python and line doesn't end with : then add entry Error - syntax error, missing : on line xxx... double-click and fix...

I'd say those 3 are the top features: Callbacks, Categories, and ease of tailoring for your needs...

Acecool commented 6 years ago

I did just run into an issue though.. I'm not recursing the same function anywhere yet I got a recursion error...

[ XCodeMapperBase > LANG_INITIALIZING > ConfigAccessorFunc ] Creating functions: self.GetCfgDisplayAccessorFuncInternals( _default ) / self.SetCfgDisplayAccessorFuncInternals( _value ) / self.GetCfgDisplayAccessorFuncInternalsToString( ) / self.ResetCfgDisplayAccessorFuncInternals( )
Creating AccessorFuncs: GetCfgDisplayAccessorFuncInternals( _default ); / GetCfgDisplayAccessorFuncInternalsToString( ); / SetCfgDisplayAccessorFuncInternals( _value ); / ResetCfgDisplayAccessorFuncInternals( );
[ XCodeMapperBase > Markdown > Run ] 
[ XCodeMapperBase > Markdown > OnResetInternalAccessors ] 
Custom mapper failure
code_map.generate: maximum recursion depth exceeded in comparison
Traceback (most recent call last):
  File "C:\Program Files\Sublime Text 3\sublime_plugin.py", line 812, in run_
    return self.run(edit, **args)
  File "code_map in C:\Users\Acecool\AppData\Roaming\Sublime Text 3\Installed Packages\CodeMap.sublime-package", line 599, in run
  File "C:\Program Files\Sublime Text 3\sublime.py", line 823, in replace
    sublime_api.view_replace(self.view_id, edit.edit_token, r, text)
TypeError: String required

It doesn't error if I remove the AddEntry from PreOnAddEntry for the MD mapper ( I match the underline H1 / H2 ====== / ------ and then add the previous line...

For some reason, it pops up as recursion - the call is maybe 5 deep. I've tried setting sys.setrecursionlimit( 2143 ) which is the max before it crashes on all files but it still says too deep...

Does CodeMap recurse somewhere??? I don't think this error can up when I had the Callback and XCodeMapper separate... I'll have to try a few things and get the exact depth...

Acecool commented 6 years ago

@mg979 Short answer above ------ Also, regarding the Lua extension... Yes.. I will be, at the least, creating multiple versions. One would need to be renamed depending the features you'd want to use...

Vanilla Lua is standard with no C style operators.

GMod Lua / GLua is Vanilla Lua for a game called Garry's Mod - It adds C Style operators such as &&, ||, !, !=, etc.. in addition to adding the continue keyword.

AcecoolDev_Framework is an extension for GMod Lua / GLua which is to help create games / game-modes at a quicker rate. I add a lot of back-end structure such as networking, AccessorFuncs, objects, etc...

One possible / decent solution could be:

I could probably do something else such as extending the XCodeMapBase > Callback_Vanilla_Lua > Callback_GMod_Lua > Callback_AcecoolDev_Framework_Lua and put those in the same file then based on config settings the generate function would load whichever....

But right now I'm getting recursion too deep errors without recursing so.. I need to see what is going on in CodeMap base most likely or see about consolidating some of the calls even though I wanted to split them up :-(


I can easily add the support for all of them in a single file without them clashing - the only issue is likely the highlighter but with the if / elif clauses it should be fine... The main issue with adding all of this to one file is someone that doesn't use my framework or GMod Lua who is looking to modify it to their project may end up being overwhelmed by how much has been added... It could be great as a working example - but some people may simply close the file and walk away...

By default, I'll probably leave the code_map.lua.py file as Vanilla Lua - maybe GMod Lua ( as it adds one AccessorFunc and a few extra self.AddSyntax lines )...

I can add config at the top to enable / disable the features ( with them disabled, the script will run quicker despite it already parsing near instantly and I'm on a 10 year old pc )...

Worst case, I'll use vanilla as default and add 2 files... code_map.glua.py and code_map.alua.py which can be renamed ( see readme ) for the features... This would be the simplest solution and wouldn't overwhelm someone who opens it for the first time as it'd be quite small...

I could include a bat file to rename the files for the user too, or an AHK script but that'd be too much, most likely..

As said, I can easily add everything to the one file as it currently is ( pretty sure the current Lua file uploaded has everything )... but it is a large file and for people that don't need it it would just be a LOT...

mg979 commented 6 years ago

@Acecool

GMod Lua / GLua is Vanilla Lua for a game called Garry's Mod - It adds C Style operators such as &&, ||, !, !=, etc.. in addition to adding the continue keyword. Worst case, I'll use vanilla as default and add 2 files... code_map.glua.py and code_map.alua.py which can be renamed ( see readme ) for the features... This would be the simplest solution and wouldn't overwhelm someone who opens it for the first time as it'd be quite small...

Just my opinion, a lua mapper should map normal lua. If you want to add a specific for glua, it should be in a code_map.glua.py. The important is that things meant for specific projects (such as yours) don't interfere with normal mapper functioning in other contexts(other lua stuff in this case).

Also, is it a mapper+syntax all that your mapper needs? Or there are are other needed files? I think custom mappers should be mapper+syntax only. @oleg-shilo will tell you more anyway.

Acecool commented 6 years ago

@mg979 In order to keep the code_map..py files small, I extracted the Callback and set it up as a base.. To further simplify I merged the Callback and XCodeBase together... Now all they need is the code_map..py file with the generate function and the local instance of XCodeMapper ( named for each language - or not, doesn't matter - important thing is it uses the base. )..

The only other requirements are the 2 other files in Packages/User/CodeMap/Acecool/ ( AcecoolST3_Lib.py and XCodeMapper.py - however the code_map..py contains everything to map that specific language... I still need to tunnel some more of the configuration to the back-end, but other than that everything is looking good...

I'm not sure what you mean by 'mapper+syntax' or other files??

The files needed are in Acecool/ in CodeMap/ which serve as libraries / back-end which is imported into code_map..py same as sublime, sys, etc.. is imported into the code_map..py...

But those files don't get in the way - when you have them they don't need to be opened or anything - you can add categories, etc.. in the custom mapper file for that specific mapper if you want ( I've been adding all of them into XCodeMapper.py for right now though until I determine how much is cross-over and how much is local - but then again I do want to keep each mapper as small as possible so it doesn't appear overwhelming... )

@hack solution I resolved the recursive issue by calling a helper function to retrieve the data on the line above and extended OnPreAddEntry to allow returning up to 4 things: _code, _line_number, _depth, _category... The down-side is all 4 needs to be returned so I may come up with a cleaner way to do it without needing to repeat code ( ie without needing OnPreAddEntry function for each element I want to return.. )..

When I figure out why the hell it thinks I'm so deep ( AddEntry does get the script going to eventually reach OnPreAddEntry - maybe I need to add an overwrite so if AddEntry is called from within, it skips that callback ) and resolve it... But right now this solution does work...

Here's the MD file: EDIT: Check the bitbucket - User/CodeMap/examples/MarkDown.md - Since it does a lot of the current aspects it doesn't seem to work well with this.... since the three `s cancels it...

and the output

Mapping: MarkDown.md containing : 70 lines and 48 entries!

Example
    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod:63

Image
    ![Image Title](Image Source):32

Link
    [Link Title](Link Source):1

Quote
    > Put a nice, beautiful:5
    > quote here...:6

Snippet
    `Inline Code Snippet`:8

Header
    H1 using the underlined method as an example..:12
    H2 using the underlined method as an example...:15
    # Heading 1:18
    ## Heading 2:20
    ### Heading 3:22
    #### Heading 4:24
    ##### Heading 5:26
    ###### Heading 6:28

Bold
    **Bold Text**:3

Italics
    *Italic Text*:30

Strike-Through
    ~~Strike Through~~:42

Table
    | Column 1 | Column 2 |:44
    | ------------- | ------------- |:45
    | Cell 1-1 | Cell 1-2 |:46
    | Cell 2-1 | Cell 2-2 |:47

Bulleted List
    - I:49
    - Love:50
    - Markdown:51

Code
    ```language:38
    ```:40

HTML / XML Tags
    <!DOCTYPE html>:53
    <html>:54
    <head>:55
    <title></title>:56
    </head>:57
    <body>:58
    </body>:60
    </html>:61

using a very SIMPLE set of instructions...

def OnSetupSyntax( self ):
        print( "[ Callback > Markdown > OnSetupSyntax ]" )

        # -- Comments - Note: Only block-comment exists in MarkDown...
        self.AddSyntax( CATEGORY_COMMENT_BLOCK_BEGIN, SEARCH_TYPE_STARTSWITH, "<!--" )
        self.AddSyntax( CATEGORY_COMMENT_BLOCK_FINISH, SEARCH_TYPE_STARTSWITH, "-->" )

        # -- Image / Link
        self.AddSyntax( CATEGORY_FORMATTING_IMAGE, SEARCH_TYPE_STARTSWITH, "![" )
        self.AddSyntax( CATEGORY_FORMATTING_LINK, SEARCH_TYPE_STARTSWITH, "[" )

        # -- Code and Quote Blocks / Snippets
        self.AddSyntax( CATEGORY_FORMATTING_QUOTE, SEARCH_TYPE_STARTSWITH, "> " )
        self.AddSyntax( CATEGORY_FORMATTING_CODE, SEARCH_TYPE_STARTSWITH, "```" )
        self.AddSyntax( CATEGORY_FORMATTING_CODE_SNIPPET, SEARCH_TYPE_STARTSWITH, "`" )

        # -- Headers - H1 = '======', H2 = '------' underline so line - 1 needs to be used... ( and I hope to read the data )...
        self.AddSyntax( CATEGORY_FORMATTING_HEADER, SEARCH_TYPE_STARTSWITH, '======' )
        self.AddSyntax( CATEGORY_FORMATTING_HEADER, SEARCH_TYPE_STARTSWITH, '------' )

        # -- Headers
        self.AddSyntax( CATEGORY_FORMATTING_HEADER, SEARCH_TYPE_STARTSWITH, "######" )
        self.AddSyntax( CATEGORY_FORMATTING_HEADER, SEARCH_TYPE_STARTSWITH, "#####" )
        self.AddSyntax( CATEGORY_FORMATTING_HEADER, SEARCH_TYPE_STARTSWITH, "####" )
        self.AddSyntax( CATEGORY_FORMATTING_HEADER, SEARCH_TYPE_STARTSWITH, "###" )
        self.AddSyntax( CATEGORY_FORMATTING_HEADER, SEARCH_TYPE_STARTSWITH, "##" )
        self.AddSyntax( CATEGORY_FORMATTING_HEADER, SEARCH_TYPE_STARTSWITH, "#" )

        # -- Bold, Italics, Strikethrough
        self.AddSyntax( CATEGORY_FORMATTING_BOLD, SEARCH_TYPE_STARTSWITH, "**" )
        self.AddSyntax( CATEGORY_FORMATTING_ITALICS, SEARCH_TYPE_STARTSWITH, "*" )
        self.AddSyntax( CATEGORY_FORMATTING_STRIKETHROUGH, SEARCH_TYPE_STARTSWITH, "~~" )

        # -- Organization...
        self.AddSyntax( CATEGORY_FORMATTING_TABLE, SEARCH_TYPE_STARTSWITH, "|" )

        # -- Lists
        self.AddSyntax( CATEGORY_FORMATTING_LIST_BUTTONED, SEARCH_TYPE_STARTSWITH, "- " )
        self.AddSyntax( CATEGORY_FORMATTING_LIST_NUMBERED, SEARCH_TYPE_REGEX, "^\d+\.\w" )

        # -- Tags - I could use RegEx to match tags, but some can extend further than 1 line and I haven't added the feature for multiple-line scanning yet...
        self.AddSyntax( CATEGORY_FORMATTING_TAG, SEARCH_TYPE_STARTSWITH, "<" )

        # -- Other
        self.AddSyntax( CATEGORY_FORMATTING_EXAMPLE, SEARCH_TYPE_STARTSWITH, "Lorem ipsum" )

I still need to add the RegEx method to match the numbered list and to simplify matching for AutoHotkey functions, etc.. by using the tmLanguage / sublime-syntax file...

Then, the next step will likely be to read the sublime-syntax and tmLanguage files to automatically add language support without needing to do anything, unless you want to manipulate the data or use different categories, etc...

Edit: Found out why it thought I was recursing - Because I forgot to nullify _pattern on add entry meaning it did repeat - stack overflow would've been a much better error message than 'recursive too deep'... I'll remove those extra returns most likely now.. but I'm updating the bitbucket repo right now!

Acecool commented 6 years ago

Added a lot of new features since last update. Cleaned up the files a bit. Added a few helper functions to hide categories, and add vararg support for most of the AddEntry functions... I added Regex checks to AHK so it now reads objects and functions just fine. MD also has Regex syntax added to read tables better, and a few other things...

The default Lua mapper which supports GMod Lua ( also uses .lua ext ) and my project AcecoolDev_Framework wouldn't interfere with default Vanilla Lua mapping. But I may end up extending it in the same file with a config option to choose how deep to go - Vanilla, GMod Lua and Vanilla, or both with AcecoolDev_Framework added... Wouldn't be difficult as long as python supports calling parent functions... If it doesn't then I'd need to code in a piggyback system which would be somewhat annoying - or add in a replacement OnInit to just call the parent and set that object as parent then merge the data during output.. but I'm sure python supports calling parent functions directly... Additionally, because the extra layers would run first, there wouldn't be any issue with Vanilla Lua matching 'function ' before AcecoolDev_Framework match 'function Acecool.C.' -- regardless... As is, as said, the additional features won't hinder vanilla Lua mapping...

mg979 commented 6 years ago

@Acecool

Wouldn't be difficult as long as python supports calling parent functions

There is the super() function for that.

Acecool commented 6 years ago

Update: I uploaded a new version today because I saw after rebooting that I accidentally moved the config above a definition which is used by the default config... I am likely going to move the definitions for everything such as categories, etc... out of the XCodeMapper.py base file so the config can be moved to the top - and / or the config to its own file - although as it gets replaced by each mapper.. it shouldn't matter much on the defaults...

@mg979 Cheers - super( ), Excellent - then I can put the mappers in the same file and under Custom Configuration they can choose which one to use... Then depending on that option, the object created will be of the specific depth in the generate function - which means the Vanilla Lua mapper will be quite simple, the GMod Lua will have slightly more added on top, and the one for my project will have quite a bit more... I will work on that on Thursday. And because of the hierarchy, I'll call super( ) last for the parent addition so allow the child precedence over added syntax, etc...

Acecool commented 6 years ago

I've been adding little things here and there. I may add the _X for all of the maps ( so people can create their own rules adding on to the vanilla version or starting from scratch and copy / paste them into the file afterwards )..

I thought about using imports for GLua / ALua and Python / JavaScript additions - but the problem with Sublime Text 3 is that it caches them and doesn't detect changes, so the imports are never reloaded which is a shame... If I can find a way around this, or if you know of a way around this, then It'll make it easier to link multiple mappers ( such as code_map.php / htm / html / asp ) together so extended rules don't need to be put in place - ie for php if within <? ?>s then use php rules, outside use html unless inside of a script tag... And other config can be used to decide which classes to use, if not the defaults, for php / asp / html / htm files to make it easy to choose which one to use with the option of extending them in that file or in the default code_map.ext.py file...

I'm going to work on adding nested categories next, most likely... and dynamic nested categories ( ie categories created on the fly without having to be pre-defined for python classes so the class category can be used for the class headers, and the functions category would be used ( or class_information new category will be created to appear after functions ) to allow each class to have a category with additional depths allowed to be used - this is so a similar output can happen as what happens now in the .py.py code_mapper in addition to being able to take advantage of the additional features such as alphabetical sorting of entries, etc...

I hope everyone is enjoying the holidays..

Acecool commented 6 years ago

Oh - updates - A lot of updates have occurred but most specifically Python can now sort the function names nested within a class alphabetically because a simple nesting system has been added... I'll make it more advanced soon and I am going to clean up the data-stores too... The big issue right now is the naming convention used in CodeMap.

I'm working on separating out the extra classes now so code_map.lua_user.py can exist but there is an issue... The naming system being code_map.lua.py is flawed - the general idea is to not use import imp and not use file-names with decimals as decimals in import are to separate folders...

If I use import imp then locate files named code_map.xxx<ex .py> then it'll work.. For now the custom ones will be named either code_map_lua_user or xcodemapper_lua_user and the primary will use code_map.x.py or I'll end up using that for the base file and then redirecting to the proper naming sequence but then it just creates a lot of files....

I was looking into separating out the XCodeMapper_Lang_Project so the files would be shorter and the projects would be more isolated. There is a way to reload the files - import sublime_project and sublime_project.reload_plugin( name ) - right now I'm using DEVELOPER_MODE = True and if DEVELOPER_MODE then reload... this way I can edit the files in real-time but by default use the caching system for speed...

This is me asking to please update the naming sequence to either custom_mappers.code_map_lua or custom_mappers.lua so the file is code_map_lua.py or simply lua.py - It is already inside of the Packages/User/CodeMap or Packages/CodeMap/ folder thereby associated with CodeMap.

Acecool commented 6 years ago
Searching 5 files for "code_map."

C:\Users\Acecool\AppData\Roaming\Sublime Text 3\Packages\CodeMap\code_map.py:
   71          for syntax in default_mappers:
   72              if not path.isfile(mapper_path(syntax)):
   73:                 zip.extract('custom_mappers/code_map.'+syntax+'.py', dst)
   74  
   75          for syntax in custom_languages:
   ..
   86  
   87          for syntax in default_mappers:
   88:             src_mapper = path.join(plugin_dir, 'custom_mappers', 'code_map.'+syntax+'.py')
   89              dst_mapper = mapper_path(syntax)
   90              if not path.isfile(dst_mapper):
   ..
  118  
  119  def mapper_path(syntax):
  120:     return path.join(sublime.packages_path(), 'User', 'CodeMap', 'custom_mappers', 'code_map.'+syntax+'.py')
  121  
  122  
  ...
  488  
  489                  # try with mappers defined in files next
  490:                 script = 'code_map.'+extension+'.py'
  491  
  492                  # print('trying to get...', script)

7 matches across 2 files but only 4 are needed

For now I'd like to replace all instances of code_map.'+(syntax|extension)+'.py' with 'codemap'+$1+'.py' because the imported files, albeit circular, need to know about the base and the base needs to know to include it because of the generate function...

If we end up merging, the generate function can be completely removed in favor of simply loading CodeMap_' + extension Title Case or language name Title Case or keep it lower... so CodeMap_lua or CodeMap_py but the language name may seem cleaner: CodeMap_Lua and CodeMap_Python - the default file to load in would be the base then any extensions can simply be included from there. Modifying which one is to be used can simply use a CodeMapVariant = ENUMERATOR or additional name so 'User' vs 'GarrysMod' etc which would be appended to Lua by way of Lua + + Variant then we can simply import from the child through the parent getting rid of the circular imports...

Either way, the code_map.ext.py naming sequence is flawed in terms of the standards most Python developers follow.

Acecool commented 6 years ago

I'll submit a different request for renaming all of the code_map.ext.py files...

Acecool commented 6 years ago

I may switch the configuration from the top of the file to sublime-settings or something too.... It likely makes more sense this way... Then I can have the back-end load the config and the Accessors for Cfg would only need to be redirected to work...

Any thoughts on this?

oleg-shilo commented 2 months ago

Closing as no longer active