Sublime Forum

Changing comment character definition

#1

Newbie here, have a question about changing the comment character for a language,
specifically so that Toggle Comment command works across a block. It works fine
for C of course but I am using PowerBasic so I need the comment character to be a " ’ ".

I have the colorscheme syntax highlighting working well using my own PowerBasic.sublime-syntax
file in …\AppData\Roaming\Sublime Text 3\Packages\User.

So I’ve tried to add a tmPreferences file to this directory with the following but it doesn’t work!
I’ve tried the file name as PowerBasic.tmPreferences and Comments.tmPreferences/Comment.tmPreferences

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
   <key>name</key>
   <string>Comment</string>
   <key>scope</key>
   <string>source.PowerBasic</string>
   <key>settings</key>
   <dict>
      <string></string>
      <key>shellVariables</key>
      <array>
         <dict>
            <key>name</key>
            <string>TM_COMMENT_START</string>
            <key>value</key>
            <string>' </string>
         </dict>
      </array>
   </dict>
</dict>
</plist>

The console output I get is:
key evt: control+/
command: toggle_comment {“block”: false}

I get the same console output when the // is put into a c file though. Can anyone suggest what I’m doing wrong?
Thanks!

J

0 Likes

#2

the filename doesn’t matter. Does your Packages/User/PowerBasic.sublime-syntax define a base scope of source.PowerBasic with that casing? maybe try source.powerbasic in your tmPreferences file and see if it makes any difference?

0 Likes

#3

Hi kingkeith,

thanks for helping out. The top of my PowerBasic.sublime-syntax file is:
%YAML 1.2

# See http://www.sublimetext.com/docs/3/syntax.html
name: PowerBasic
file_extensions: [.bas, .bi, .inc]
scope: source.PowerBasic

contexts:
  # The prototype context is prepended to all contexts but those setting
  # meta_include_prototype: false.
  prototype:
    - include: comments
0 Likes

#4

are there any errors in the ST console (View menu -> Show Console)? maybe the <string></string> in your tmPreferences makes the dict invalid? try removing it.
and install https://packagecontrol.io/packages/PackageDev to help catch these errors in the future :wink:

0 Likes

#5

Now working. Changed a few things but I think the main one was that the tmPreferences file had a duplicate filetype so two .tmPreferences.tmPreferences (thanks Microsoft). Removing the extra one seemed to do the trick. I did remove the <string></string> also but that code came from the documentation so it was probably ok.
http://docs.sublimetext.info/en/latest/reference/comments.html
Anyway - thanks for the support - it’s doing what I need. :slight_smile:

0 Likes