Sublime Forum

Open Recent: sticky files

#1

There a three files that I open often, two with extension .html and one with extension .ps. I’d like all three to be top of the Recent files menu, always, even if the current file has a different extension (or is unsaved so has no extension). Please, how?

Indeed, to echo an old bug, I’d like all three to be top of the Recent files menu, always, even if no file is open. Presumably this is impossible.

Thank you.

0 Likes

#2

The recent files list just shows you files you’ve recently used; it’s not influenced by whether or not the current file is saved, or what the name or type of the current file is.

It’s possible to non-destructively extend the menu with additional items (packages frequently do this, for example) by creating your own Main.sublime-menu file with the appropriate content; Sublime would then load that file and add the items it contains to the menu.

That’s not directly possible if you want to add items directly to the File > Open Recent menu though; that’s not one of the menu locations that’s set up by default to allow extra items. In this case the best you could do is add new items to the file menu which would appear closer to the bottom of the File menu itself (i.e. not in the Recent Files list as you want).

To do something like that, you can do the following instead to make a modification to the main menu file:

  1. Install the OverrideAudit packge if you don’t already have it installed
  2. Open the command palette and choose OverrideAudit: Create Override
  3. Select Default, then Main.sublime-menu to open the main menu

Now that you have the file open, you can edit it to add the items that you want. Specifically you want to add lines that look like this:

{ 
    "caption": "Some File Name 1", 
    "command": "open_file", "args": {"file": "d:\\somefile1.txt"} 
},

The text in caption will be what appears in the menu as the item to choose; adjust the file name of the file to suit; note that it has to be an absolute file name (i.e. something.txt is not enough), so if you’re unsure open the file first and then right click inside of it and pick Copy file path to get it.

If you’re on Windows, then you need to either double all of the path characters as seen here, or alternatively you can use / instead (so c:\\something.txt or c:/something.txt). You can also add as many items as you want.

From looking at the menu file it should be fairy clear where you want to add each line; you would paste or edit them in right after the line with the caption that says Reopen Closed File. For example, my changes look like this; the added lines are marked by the green line in the gutter:

Here I’ve also added an extra line with a caption of - which adds a separator, but you can leave that out if you’d like.

As soon as you save the file, the change will take effect and the menu will change. If you break the file, you’ll get an error dialog that pops up and the main menu will be missing most of the entries. If that happens, close the dialog and fix the file and save again. The file has to be valid JSON, so make sure that you add commas after every menu entry you add, and that there are no \ characters.

In case of emergency you can use Preferences > Browse Packages to open the package folder, then go into the Default folder and delete the Main.sublime-menu file in there to discard the changes entirely.

When you edit a package resource in this way, the file will be used by Sublime in place of the original file, even if the original file changes somehow (like if a new version of Sublime adds new items to the menu).

The OverrideAudit package will warn you if this happens so that you can check and see what’s different. You can also just delete the file as mentioned above if you’d like to go back to the default for any reason.

1 Like

#3

That’s excellent, thank you.

    {
        "caption": "Open Favourites",
        "children":
        [
            {
                "caption": "PostScript code, placemat.ps",
                "command": "open_file", "args": {"file": "/Users/JDAW/Documents/programming/PostScript/Port_PS/placemat.ps"}
            },
            {
                "caption": "Manual, placemat.html",
                "command": "open_file", "args": {"file": "/Users/JDAW/Documents/HTML/www.jdawiseman.com/papers/placemat/placemat.html"}
            },
            {
                "caption": "Examples, placemats_list.html",
                "command": "open_file", "args": {"file": "/Users/JDAW/Documents/HTML/www.jdawiseman.com/papers/placemat/placemats_list.html"}
            },
            {"caption": "-"},
            {
                "caption": "Sublime, this menu",
                "command": "open_file", "args": {"file": "/Users/JDAW/Library/Application Support/Sublime Text 3/Packages/Default/Main.sublime-menu"}
            }
        ]
    },
0 Likes