Sublime Forum

Open Package Control page / Add Word to Dictionary

#1

Hello everybody!

This is my first post here and since I have two very basic questions, I thought I’d ask them in a single topic. Please let me know if this is not a good practice.

So:

  1. Is there any way to open the Package Control or Github page of a package from within the Command Palette? I mean, say I want to search for a package but its name or description from within the small command palette is not enough. Can I open directly from there the Github or Package control page of that selected package to read more?

  2. This may sound lazy, but can I add a word to the “added_words” list from my preference file using just the keyboard? I see in the Documentation on spell checking listed as a command add_word: Adds the word given by the word argument to the add list. What does this mean? How can I make use of it?

I have close to zero experience on programming, so if your answer will involve me writing some kind of code, please be as explicit as possible. :slightly_smiling:

Thank you.

1 Like

#2

I personally prefer separate topics, mainly because it is easier to follow a thread about one specific subject than try to decipher a long thread about multiple topics - “which part of the thread does this [part of this] reply relate to?”


Regarding the Package Control -> List Packages command palette entry:

  • currently, it only opens the Packages folder and isn’t configurable to open the relevant page on packagecontrol.io or the GitHub page.
  • it has been requested as a feature here: https://github.com/wbond/package_control/issues/867 but hasn’t been implemented yet unfortunately
  • there is a long winded workaround to get the GitHub url if you don’t want to type it…
    • from the Command Palette, choose Package Control - List Packages
    • select the package you are interested in
    • open the sublime-package file in a zip utility
    • open the package-metadata.json file
    • find the "url": value, and copy and paste it into a browser window… I did say it was long winded!

Regarding adding a word to your spelling preferences, if I understand right, you basically want to perform the same thing as opening the right click context menu and choosing "Add [word]". A simple answer would be to open the context menu with the keyboard (some keyboards have a dedicated button for it, on others you can press Shift+F10 on Windows. Then it is just a case of using the arrow keys (Down Arrow over all the suggestions) to select the Add word menu item and pressing Enter.

This could obviously be done with less keypresses using a custom keybinding, which is where the add_word command would come in handy. However, as far as I know, keybindings can’t use the text under the cursor or the selection as an argument, so a small Python plugin would need to be created for this. (There are exceptions where the command being executed supports it, like insert_snippet supporting a $SELECTION placeholder in the contents argument.)

2 Likes

#3

Thank you for the useful replies.

Regarding opening the page in Package Control, I understand. The workaround you mentioned is quite lengthy, so I’d better search for it in GitHub.


You understood correctly my question regarding adding words. The problem is that I don’t have the command “Add Word” in my menu bar. I may have installed some packages which conflicted with it or I don’t know, but I only have this:

Nothing comes from searching in the Help menu either.

I’ve read about making small Python plugins, but I don’t think I’m able to. But if I need it strongly enough, I may look it up.

0 Likes

#4

Here is how to create a Python script that will add the words at the cursors to the dictionary:

  1. From the Tools menu -> Developer -> New Plugin

  2. Paste in the following:

     import sublime
     import sublime_plugin
     
     class AddWordsAtCursorsToDictionaryCommand(sublime_plugin.TextCommand):
         def run(self, edit):
             for sel in self.view.sel():
                 region = None
                 if sel.empty():
                     region = self.view.word(sel.begin())
                 else:
                     region = sel
                 word = self.view.substr(region)
                 self.view.run_command('add_word', { 'word': word })
    
  3. Save it, in the default folder it suggests, as something like add_word.py - the file extension is very important, the base name itself isn’t.

  4. Goto Preferences -> Key Bindings - User or Key Bindings depending on which version of ST3 you have.

  5. Enter the following:

     { "keys": ["f8"], "command": "add_words_at_cursors_to_dictionary" }
    
  6. If the file was previously empty, ensure the text above is surrounded by square brackets. i.e. [ and ].

  7. Save it

  8. Press F8 to add the word at the cursor to the dictionary. Obviously, you can change this to whatever key you desire.

3 Likes

#5

It only appears in the context menu, when right clicking on a underlined/misspelled word, and doesn’t ever appear in the menu bar.

I prefer to search on the Package Control website and click on the link to the GitHub site from there - saves wading through irrelevant GitHub search results that don’t relate to ST3 packages.

2 Likes

#6

Thanks a million for all your help, Keith! I know it was a small and irrelevant annoyance, but this way not only you helped me solve it, but I also learned quite a lot! :slightly_smiling:

0 Likes