Is it possible to add root level menu of SublimeText? - sublimetext2

I know we can configure SublimeText menu via sublime-menu files.
Is it possible to add a root level menu of SublimeText instead of subtree of the root menu?
The reason I ask is SublimeText is all about customize and configuration; and since I access to Sublime Text > Preferences so frequently, that I want the Preferences at not the subtree but the root level, where menu bar shows.
I use SublimeText3.

In ST2/3, configurations are JSON. Create a Main.sublime-menu file in your user directory. This contains a list of object entries. As an example,
[
{
"caption": "Custom",
"mnemonic": "m",
"id": "custom"
}
]
This will create a "Custom" menu (at the top level). Of course, there aren't any sub menu entries so it's a little less useful. Below is a portion of the Menu file from one of my plugins (just to show how to specify a command). I listed under the "Custom" menu as an example.
[
{
"caption": "Custom",
"mnemonic": "m",
"id": "custom",
"children":
[
{
"caption": "Package Settings",
"mnemonic": "P",
"id": "package-settings",
"children":
[
{
"caption": "AdvancedNewFile",
"children":
[
{
"command": "open_file",
"args": {"file": "${packages}/AdvancedNewFile/README.md"},
"caption": "README"
}
]
}
]
}
]
}
]
I did this in ST3 on W7. I'm unsure how it will behave in other OS's, but I assume it would work.

Related

use a different .zshrc for vscode internal terminal

I'm using zsh from vscode integrated terminal
i also use hyper terminal, warp and iterm2 for other purposes but i like to use the integreated terminal while in vscode. i actually enjoy my heavy .zshrc config on external terminals, but i often get the popup "your shell environment is taking too long to load" from vscode. Tbh, i don't mind the popup itself, but i think that a lot of the features that are useful outside vscode are not needed inside.
How can i set a different .zshrc to load only to be used by the vscode integreated terminal ?
tried conditional loading from my .zshrc but don't like it
tried setting it in the vscode-settings.json
this self-answer confused me more
this i think points in the right direction but i am not sure how to use task.json
my env:
macOS 13.1 22C65 arm64
Apple M1 Max
vscode (1.74.11ad8d514439d5077d2b0b7ee64d2ce82a9308e5a for arm64)
zsh 5.9 (arm-apple-darwin22.1.0)
These are the settings to change in “settings.json”:
I created 3 profiles:
zsh-minimal with the vscode minimal config -> new ZDOTDIR
zsh-full with my usual heavy config -> probably not necessary since it is $HOME by default i think
bash, just in case i fu everything
set to null old profiles ( zsh and zsh(2)) to delete them from profiles selection dropdown menu, as per official documentation.
“terminal.integrated.defaultProfile.osx”: “zsh-minimal”,
“terminal.integrated.profiles.osx”: {
"zsh-minimal": {
"title": "zsh-minimal",
"path": "/opt/homebrew/bin//zsh",
"icon": "terminal",
"color": "terminal.ansiMagenta",
"args": [
"-l",
"-i"
],
"cwd": "${workspaceFolder}",
"env": {
"ZDOTDIR": "/Users/MYUSERNAME/.homesick/repos/MYUSERNAME-dotfiles/home/vscode_zsh"
},
},
"zsh-full": {
"title": "zsh-full",
"path": "/opt/homebrew/bin//zsh",
"icon": "terminal",
"color": "terminal.ansiCyan",
"args": [
"-l",
"-i"
],
"cwd": "${workspaceFolder}",
"env": {
"ZDOTDIR": "/Users/MYUSERNAME/"
},
},
"bash": {
"title": "bash",
"path": "/bin/bash",
"icon": "terminal",
"color": "terminal.ansiWhite",
"args": [
"-l",
"-i"
],
"cwd": "${workspaceFolder}",
},
"zsh": null,
"zsh (2)": null,
}

How do I append a setting to the defaults in Visual Studio Code?

I believe this is a general question about JSON and how VS-code handles settings, but I will give a specific example below that regards the LaTeXWorkshop extension.
I am used to overwriting settings in settings.json by adding lines such as "option": value".
But what if "option" expects a list, and I just want to append a new element to the defaults, without removing the defaults. How do I do that?
Specific Example using LaTeXWorkshop
The default for the latex-workshop-latex-recipe option is given by this (see here):
[
{
"name": "latexmk 🔃",
"tools": [
"latexmk"
]
},
{
"name": "pdflatex ➞ bibtex ➞ pdflatex`×2",
"tools": [
"pdflatex",
"bibtex",
"pdflatex",
"pdflatex"
]
}
]
I want to add the following item to this list without removing the two defaults:
{
"names": ".Rnw: knitr -> latexmk",
"tools": [
"knitr",
"latexmk"
]
}
If I add this to my settings, the default recipes seem to be deleted:
"latex-workshop.latex.recipes" : [{
"names": ".Rnw: knitr -> latexmk",
"tools": [
"knitr",
"latexmk"
]
}],
How do I append instead of replacing?

Visual Studio Code: Comments not being detected while trying to add support for a new language/filetype

So I am working on a research project that involves using a very specific piece of software that uses its own filetype; XPPAUT using .ode files. To prevent me and my team of not-neuroscientists from ripping our hair out trying to work with this, I decided to write a syntax highlighter for these .ode files.
To start I just wanted to be able to recognize and color linecomments, which are delineated with a #, similar to Python, however when I run the development environment, the comments are not highlighted with the color I set my dev workspace to use, or highlighted at all. I'm very new to this, so any help would be appreciated.
Here is my package.json file
{
"name": "ode",
"displayName": "XPP ODE",
"description": "ODE files to be used with XPP/XPPAUT",
"version": "0.0.1",
"publisher": "wjmccann",
"engines": {
"vscode": "^1.22.0"
},
"categories": [
"Languages"
],
"contributes": {
"languages": [{
"id": "xpp",
"aliases": ["XPP ODE", "XPP", "XPPAUT"],
"extensions": [".ode"],
"configuration": "./language-configuration.json"
}],
"grammars": [{
"language": "xpp",
"scopeName": "source.xpp",
"path": "./syntaxes/xpp.tmLanguage.json"
}]
}
}
and the corresponding language-configuration.json
{
"comments": {
// symbol used for single line comment. Remove this entry if your language does not support line comments
"lineComment": "#",
},
// symbols used as brackets
"brackets": [
["{", "}"],
["[", "]"],
["(", ")"]
],
// symbols that are auto closed when typing
"autoClosingPairs": [
["{", "}"],
["[", "]"],
["(", ")"],
["\"", "\""],
["'", "'"]
],
// symbols that that can be used to surround a selection
"surroundingPairs": [
["{", "}"],
["[", "]"],
["(", ")"],
["\"", "\""],
["'", "'"]
]
}
The language-configuration.json file defines text patterns used in a variety of standard features of VS Code such as comment toggling as described here.
Syntax highlighting/colouring is via the grammars contribution point in package.json as described here.
Based on your package.jsonyou will need to create a new file at ./syntaxes/xpp.tmLanguage.json with the following content for your comments to be coloured appropriately. The actual colour used will depend on your current theme.
{
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
"name": "xpp",
"scopeName": "source.xpp",
"patterns": [
{
"include": "#comments"
}
],
"repository": {
"comments": {
"patterns": [{
"name": "comment.line.number-sign.xpp",
"match": "#.*"
}]
}
}
}

How do I add my configuration to Sublime Text 2's menu?

I've written a plugin for Sublime Text 2, which talks to a binary that I wrote. I expose the flags to the binary through as settings file, but I cannot figure out how to get the settings file placed into the menu bar.
Here is my best attempt so far.
Here are the docs on settings (not sure where the ones on menus are).
From what I can tell, in order to add your own items to a menu, its original declaration must have a pre-existing id value, which must then be included in any package-specific menu expansions. For example, consider the default definition for Preferences:
{
"caption": "Preferences",
"mnemonic": "n",
"id": "preferences",
"children": [ ... ]
},
Notably, the Settings – More object in Packages/Default/Main.sublime-menu does not have an id.
{
"caption": "Settings – More",
"children": [ ... ]
},
You can prove this requirement yourself by adding an id value to Settings – More in the default Main.sublime-menu and including that id in your package's Main.sublime-menu, similarly to how Preferences' id is referenced. Your custom menu will then show up under Settings – More.
Based upon the exclusion of an id for Settings – More, I would assume that the creators of Sublime Text 2 did not intend for third party packages to be able to edit the menu in question. Also, note that the – in Settings – More is not a hyphen (-); that's not the cause of your problem, but I initially suspected that it might have been.
The standard practice for adding one's own package settings to Preferences appears to be inserting a new item into Preferences -> Package Settings, which can be accomplished with a Main.sublime-menu file like this:
[
{
"caption": "Preferences",
"mnemonic": "n", // The mnemonics are for quick keyboard access
"id": "preferences",
"children": [
{
"caption": "Package Settings",
"mnemonic": "P", // On windows, Alt+N (above) followed by Alt+P would open this menu
"id": "package-settings",
"children": [
{
"caption": "Seeing Is Believing",
"children": [
{
"command": "open_file",
"args": {"file": "${packages}/Seeing Is Believing/Seeing Is Believing.sublime-settings"},
"caption": "Settings – Default"
}
]
}
]
}
]
}
]
I would highly recommend referencing a menu-rich plugin's Main.sublime-menu to figure out what else you should include and how you should do it. For my research I examined both Sublime Text 2's Main.sublime-menu and AdvancedNewFile's.

Adding Custom Menus in Sublime Text

How to add a custom Menu item in SublimeText 2 .
Any Ideas ??
I see there is a Main.sublime-menu file but dont know how to edit it.
Thanks!
The *.sublime-menu file is simply JSON. You can create a Main.sublime-menu in your user directory and it will be merged with other menu entries. It may be beneficial to look through the Main.sublime-menu files third party plugins have. These are generally much shorter, so may be easier to understand some of the things you need to define in each entry.
edit
You can use the following as a plugin to open notepad with an arbitrary file.
import sublime
import sublime_plugin
import subprocess
import threading
class OpenNotepadCommand(sublime_plugin.TextCommand):
def run(self, edit, filename=None):
th = NotepadThread(filename)
th.start()
class NotepadThread(threading.Thread):
def __init__(self, filename=None):
self.filename = filename
threading.Thread.__init__(self)
def run(self):
if self.filename is not None:
subprocess.call("notepad.exe %s" % self.filename)
else:
subprocess.call("notepad.exe")
When you are creating a menu item use something like the following for the command and arguments.
{
"command": "open_notepad",
"args": { "filename": "<the absolute path here>"}
}
Easier option if what you want is just run a command. Create a file Context.sublime-menu inside your Packages/User directory, and add the following:
[
{ "caption": "<Your caption here>", "command": "exec", "args": {"cmd": ["<your cmd name>", "<arg1>", "<arg2>", <...>]} }
]
Exemple: Adding a menu item to the context menu that just run dir:
[
{ "caption": "List files in current dir", "command": "exec", "args": {"cmd": ["dir"]} }
]
I know this way too late to join the party and add my 2 cents. Anyway, Main.sublime-menu is a file that allows you to add menu items to the top menu i.e [File, Edit, Selection, Find, View, Goto, etc.]
I recently added a new section "Dev" just to figure it out. I also wanted a way to trigger browser previews for a specific browser. Check it out.
[
{
"caption": "Dev",
"mnemonic": "Z",
"id": "dev",
"children": [
{
"caption" : "Previews",
"children": [
{ "caption": "Markdown Live Preview", "command": "new_markdown_live_preview", "id": "markdown_live_preview" },
{ "caption": "Preview in Default Browser", "command": "view_in_browser", "id": "markdown_live_preview" },
{ "caption": "Preview in Firefox", "command": "view_in_browser", "args": { "browser": "firefox" }, "id": "markdown_live_preview" },
{ "caption": "Preview in Chrome","command": "view_in_browser", "args": { "browser": "chrome" }, "id": "markdown_live_preview" },
{ "caption": "Preview in Safari", "command": "view_in_browser", "args": { "browser": "safari" }, "id": "markdown_live_preview" },
]
},
]
}
]
Anyway, this still works in ST3. Just in case anyone stumbles around here.