Sublime Forum

Problems with syntax selection

#1

currently doing a lot of work in riscv assembler, I have a ricv assembler syntax package installed but when I click on a file it has x86 assembler selected. I select riscv and edit… i then click on another file and that too is x86 assembler. I click on riscv and editt. I then click on the original file… and it is x86 assembler.,

The syntax selection only seems to last for as long as you are editing a file. the instant you go to edit some other file the editor forgets what syntax was selected. am i doing something wrong or is this somehow considered correct behavior?

i would also like to be able to specify "all files in this projects source tree are “c” or “asm” or “java” etc instead of having to select each one, one at a time and selecting the desired syntax rules.

0 Likes

#2

ST allows you to set syntax with file extension: main menu -> View -> Syntax -> Open all with current extension as…

If it doesn’t fit your needs, then you most likely need a plugin:

0 Likes

#3

so i set all .S files to x86 then all .X files to armv7 then i set all .S files to avr or RISCV or MIPS… setting by extension is not helpful, i would have though that the project file could specify the type of each file on a project by project basis

0 Likes

#4

Both plugins support this.

0 Likes

#5

installed your plugin but there is a problem…

i have multiple projects…

a x86 nasm based 32 bit Linux forth
an x86 nasm based 64 bit Linux forth
a gnu assembler based 32 bit arm Linux forth (never published)
a gnu assembler based thumb2 Linux forth
a gnu assembler based aarch64 Linux forth (not yet published)
a gnu assembler based riscv stand alone forth that I am currently working on

The documentation for your plugin states… “If a file whose name has no . and its first line satisfies any of following conditions, …”

But they ALL do have a . in their names, in fact every single source file in every single assembler based project has a .s file extension and im somewhat anal retentive about source formatting and consistency.

The first line of the source files in every single one of my source files follows exactly the same format across all projects… it would be very difficult for me to change these just to get something that i think should be built in. When i set RISCV assembly on an individual file that setting should be SET not disappear when i go look at some other file in the project.

I am constantly flipping between every one of these projects and others that are coded in C and when I do this the syntax I have selected on files disappears when i select another file… nothing is remembered.

I do not think this is something that can be fixed by a plugin but then i have no idea how to create plugins for sublime text. I think this can only be fixed up stream byt tyvm for the responses, i just cant see a way for your plugin to help

so… went through every file in my riscv sources and set them to riscv assembly and most of them stuck. went through the ones that got flipped and now more stuck on riscv asm… kept doing this and now every source file in evey single project is riscv assembly and i cant set the arm sources to arm assembly, as soon as i select any other file its automatically riscv assembly.

slightly frustrated.

0 Likes

#6

Not sure where you see it but you can create fairly complex rules: https://github.com/jfcherng-sublime/ST-AutoSetSyntax/blob/d2d1d3d579e675a3c2553d1c4d31b9b2a657b3be/AutoSetSyntax.sublime-settings#L61-L445 , unless you don’t know what you want. And if that is not complex enough, you can even write your own rule in Python.

Here is a short example for project settings:

{
    "folders":
    [
        {
            "path": "C:\\Users\\jfcherng\\Desktop\\new_folder"
        }
    ],
    "settings": {
        "AutoSetSyntax": {
            "project_syntax_rules": [
                {
                    // if the current scope matches `selector` 
                    // (an empty string `selector` is always matched),
                    // and numbers `rules` are satisfied with `match`, 
                    // then change the syntax to first found `syntaxes`.
                    "match": "any",
                    "syntaxes": ["RISC-V Assembly"],
                    "selector": "text.plain",
                    "rules": [
                        {
                            "constraint": "is_extension",
                            "args": [".hahaha"] // file extension `.hahah`
                        }
                    ]
                }
            ]
        }
    }
}
1 Like

#7

problem is the extension would be .s and for arm assembly the extension would be .s and for x86 assembly the extension would be .s etc etc etc
this can not be based off of either file contents or the file name it must be a project setting for each and every single file on an individual basis in every project. Obviously a makefile or other such well known files should still be colored according to their syntax rules but my source files on every project need to be set according to the project or else every file in every project is going to be colored as the same thing which they are not.
right now after fighting this every single source file in my arm forth, my thumb2 forth, my aarch64 forth and both my x86 forths are defined as riscv assembler. I can change any file to the correct thing but once again, the instant i select some new file and switch back to it it has reverted to being riscv.

something is very VERY seriously broken here and it is above my pay grade to figure out :confused:

0 Likes

#8

also, i do not program python, i spent 3 months trying to wrap my head around it and at every stage my brain just rejected everything there is about it. I have spent close to 40 years doing low level development in assembler and forth. i am so low level i consider C to be an ultra high level language (with warts :slight_smile:

I dont code pyton, or javascript or xml or yaml or … … . I code C, assembler and forth and i consider C to be a horrendously over complexificated environment to develop in. Also, im pig headed, this should just work. Im blown away by the fact that every time i set a rule the editor throws it away when im not looking. (no im not being pissy with the dev team and i truly appreciate their work, its just ultra frustrating)

0 Likes

#9

i don’t get it. i provide a project-based solution but you are still complaining manually switching syntax for every file. i don’t even know you’ve tried it or not.

maybe there is a plugin which makes selected syntax persisted but i personally wont like to select syntax for every file in every project manually… a project-based solution will be more easing.

0 Likes

#10

thought I had replied to this, i tried your solution and it was not working, i cannot get settings to stick or i cannot get them to unstick. Went through my risccv project and changed every source file to riscv. went through the project files again and set all the files that had reset and repeated till they all stuck.
now, every file in every other project is also riscv assembler and if i go through the above procedure to fix the arm assembler or the x86 assembler sources the… im sure my riscv source files will all change too.

0 Likes

#11

this rule seems to be based on file extension so I cant see it working for me, ALL my files for all my projects are .s because they are all assembly language sources, they are just not all the SAME assembly language.

0 Likes

#12

True. If there is no characteristic (like file content, path, etc…) among files then both mentioned plugin cannot help. is_extension is just an example, there are many other constraint in my plugin. https://jfcherng-sublime.github.io/ST-AutoSetSyntax/configurations/#built-in-constraints

But maybe they all won’t for you, only you know since no further information is provided.

0 Likes

#13

your plugin is every well presented but I dont think it can help me either. Thing is, i do not think this is “rocket surgery”. When i select a file and say THIS IS part of gorup X what ever X is then sublime text should remember that for that file it has been specified that it is part of the group X.

Sublime text is not doing that and I dont know if a plugin has the ability to fix this but then i dont know how to create plugins for ST so maybe it can. If not hopefully john will see this thread and take heart :slight_smile:

0 Likes

#14

Making a plugin that keeps a simple list of files and their associated syntax is fairly trivial, though from earlier posts it seems like you want a solution that doesn’t require setting the syntax manually on every file (if even just once). Note also that such a list would expand indefinitely over time and can’t handle files being moved around - which is why ST doesn’t do this.

2 Likes