Gedit: function, array, object, ... block wrapping - text-editor

Is there any plugin for the Gedit text editor that enables wrapping of blocks of codes (like functions, loops, conditions, arrays, ...) inside a bordered or colored are? as in kate for example.
Here is a scrennshot of what I want (note that this wrapping is created by another plugin: code completion)
[Please open the image in a new tab/window to see it]

Related

Sublime Key Binding Arguments

Sublime's key bindings accept arguments, where can I find the list of arguments I can pass for user defined key bindings?
Documentation doesn't make it clear, google is not helping, I can't find source of this dictionary, where is it all being defined? How can I review what I can use or not?
The arguments that a command takes depend on the command itself, which is true not only for default commands that ship with Sublime but also any commands added by plugins or third party packages.
The unofficial documentation has a list of commands internal to Sublime, including what they do and what arguments they take which can be of help here. For example, given this text:
new_window
Opens a new window.
The command new_window takes no arguments. On the other hand:
expand_selection
Extends the selection up to predefined limits.
to [Enum]: Values: bol, hardbol, eol, hardeol, bof, eof, brackets, line, tag, scope, indentation.
The expand_selection command takes an argument named to, and also has a list of predefined values that it can take, e.g. "to": "bol" to expand the selection to the beginning of the line.
To my knowledge there's no official list of internal commands with the exception that they're used in the default key bindings (which appear in the left hand pane of the key bindings window when you open it).
Third party packages that define commands sometimes outline them in their README file, but many also choose to go the same route as Sublime and just document them in the key bindings files.
It's also possible for commands to appear in other places (e.g. in menus and in the command palette), which is another place to look. You can use the internal View Package File command to view sublime-command and sublime-menu files to see what they're doing as well, if you're curious.
Lastly, if you open the Sublime console and enter the command sublime.log_commands(True), Sublime will log commands as they execute, telling you what they are and what arguments they took. Note however that there is currently an issue in more recent builds where commands from the command palette are not always logged.

Unwanted text appears every time I close a bracket in VIM using VimTex

I am typesetting a latex file in VIM using the Vimtex plugin.
Every time I close a bracket, this text shows up automatically in the <++>.
For example:
\section{This is one}<++>
\section{The variable $V_L$<++> explains things}<++>
\begin{equation}
<+content+>
\label{<+label+>}
\end{equation}<++>
LaTeX compiles my text with those printed out in the pdf so I have to manually remove the every time. This behavior goes from $$ to {} to others also and even inside certain areas when using autocompletion features wit F5.
I did look add this question but it did not provide much help as to how to solve my issue.
How can I prevent the from being added to my tex files?
If they are a feature meant for something I do not understand, how do I prevent them from compiling in my pdf's?
This part of the documentation on the vim-latex (not Vimtex) repo on github
explains how the macro system works, how it's useful and solely meant for editing
NOTE: Place Holders
-------------
Almost all macros provided in Latex-Suite implement Stephen Riem's
bracketing system and Gergely Kontra's JumpFunc() for handling
place-holders. This consists of using "place-holders" to mark off
locations where the next relevant editing has to be done. As an example,
when you type EFI in |insert-mode|, you will get the following: >
\begin{figure}[<+htpb+>]
\centering
\includegraphics{<+file+>}
\caption{<+caption text+>}
\label{fig:<+label+>}
\end{figure}<++>
The text <+htpb+> will be selected and you will be left in |select-mode|
so that you can continue typing straight away. After having typed in the
placement specifier, you can press <Ctrl-J> (while still in insert-mode).
This will take you directly to the next "place-holder". i.e, <+file+> will
be visually selected with Vim in select mode again for typing in the file
aaaa. This saves on a lot of key presses.
Note: Upon testing I realized that the placeholder only appears when the bracketing is empty.

Writing an autocomplete plugin in Sublime Text

Within my company we have an XML-based notation. Among other features, it is possible to define references from one XML document into another. I would like to enable autocompletion in Sublime so that whenever I am adding a reference, the possible files (i.e. XML files within the same project) and link points (i.e. symbols within that file) get offered as recommendations.
So far, I have found a lot of plugins that enable autocomplete for, say, HTML, PHP or LaTeX. However, I have the feeling the code base is too complex for a somewhat simple task. Is there, for instance, some vanilla function that generates completions based on an arbitrary array received as parameter? I would create the logic to determine what is a symbol and derive said array, but the whole process seems somewhat cumbersome to me.
(As a note: I can program in Python and have fiddled with other Sublime features, such as snippets, but these packages seem to be much more complex than it feels necessary.)
The base to create the completions entry is not to complicated. You now need to fill the array with the correct values (this could be done via a project setting or parsing other files).
import sublime
import sublime_plugin
# Your array, which contains the completions
arr = ["foo", "bar", "baz"]
class MyCompletionsListener(sublime_plugin.EventListener):
def on_query_completions(self, view, prefix, locations):
loc = locations[0]
# limit you completions scope
if not view.score_selector(loc, "text"):
return
completions = [(v + "\tYour Description", v) for v in arr]
return completions
OP's note: The answer works as advertised. However, the integration is so seamless that I thought for a while that something was missing. If the Python script above is on the right folder, all of the completions returned by the completions array will be suggested (depending on Sublime settings, it might be necessary to trigger the completions menu with Ctrl+Space). Also worth noting:
The completions may be None, in which case they just don't add any completion option, or an array of 2-tuples, where the first element is the description (which will be shown in the drop-down menu and trigger the completion) and the second is the value (i.e. the text that will be input if the completion is selected).
The score_selector method can be used to determine if the cursor position is within a given scope.

Quick console.log insertion in Sublime

Many times when I'm debugging I like to log out a line like this:
console.log("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
console.log(dataThatImTryingToSee);
console.log("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
However, it gets annoying having to type in the console.log line's contents all the time. Is there a way to add hotkeys in Sublime that would insert a line such as the console.log one?
Sublime can do this with something called Snippets, which allow you to re-use bits of text in a variety of ways to make your coding life easier.
To get started, select Tools > Developer > New Snippet... from the menu, and replace what you see there with the following, and then save it in the location that Sublime will select by default, which is your User package. The name doesn't matter as long as it ends in sublime-snippet, but remember what name you used because you're going to need it in a minute.
<snippet>
<content><![CDATA[
console.log("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
console.log(${1:$SELECTION});
console.log("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");${0}
]]></content>
<description>Debug log an item to the console</description>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>dlog</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.js</scope>
</snippet>
If you're not familiar with snippets, the text inside of the CDATA part of the XML is the body of the snippet, which will get inserted into the document.
${0} and ${1} are "fields", which you will be able to tab through entering text as you go. Fields are traversed in numerical order, but the special field ${0} indicates the location where the cursor should ultimately end up, which in this case is at the end of the last line so you can continue coding.
Fields can have the form ${#:default}, where the text initially displayed for the field is default. This will appear automatically in the snippet when it triggers, but it will be selected for you to type over it if you want.
The special field $SELECTION will be replaced with any text that happens to be selected when the snippet triggers (more on that in a second).
With the snippet saved you already have a couple of options open to you to trigger it, as long as you're in a JavaScript file (the syntax has to be set to JavaScript, so be sure to save any new files first).
First, if you open the command palette and enter the text Snippet to filter the list of commands to those which contain that text, you will see all snippets that apply to your current file, and in that list is an entry that says Snippet: Debug log an item to the console, which will trigger the snippet when you select it.
In this case, if you have any text selected, it will automatically be placed into the second console.log, so you can select a variable or what have you and trigger the snippet to log it directly.
Secondly, you can just enter the text dlog and press Tab to expand the snippet as well. The command palette entry mentioned above has text to the right that says dlog,tab to remind you. Depending on your settings, you may also get offered an auto completion popup as well.
Your question specifically talks about adding a hotkey, which is also possible. In that case you want to add a binding something similar to this to your custom key bindings:
{
"keys": ["alt+shift+d"],
"command": "insert_snippet",
"args": {
"name": "Packages/User/data_log.sublime-snippet"
},
"context":
[
{ "key": "selector", "operator": "equal", "operand": "source.js" },
]
},
You can change the key to whatever you would like, naturally. Note also that the name of the snippet you provide has to match what you saved the file as. If you followed the directions above it will have been saved in Packages\User already.
Now when you press the key, the snippet triggers. As above, if you have any text selected, it will automatically be inserted into the second console.log.
Note that in all cases when the snippet triggers, you will first have your cursor set inside the second console.log (possibly with some selected text already there), and Sublime is waiting for you to finish typing text for that field, so press Tab again to skip to the end of the snippet.
As a reminder of this, you'll notice that the status line (if you have it turned on) tells you Field 1 of 2 to let you know that you're inside a snippet.
This example assumes that you're working with JavaScript, so the snippet above and the key bindings will both only trigger when the current file is JavaScript. If you're using some other language, you can remove the scope from the snippet and/or the context part of the key binding to make them apply in all files, or modify the scope there to match the language you want to target.
This just scratches the surface of what you can pull off with a snippet. You can also do things like use the same field more than once to have the same text appear in multiple places, do regular expression substitutions, and much more. Check out the link above for more information.

How to change the Sublime Text 3 StatusBar message in a command or macro (no plugin)?

addressing Sublime Text 3 users here.
I wrote a couple of macros to enable spell-check and load a specific dictionary, as I constantly swap between French and English and I wanted a simple shortcut for this (instead of browsing the menu or two successive commands in the command pallet).
My macros work as expected (french-spellcheck.sublime-macro, english-spellcheck.sublime-macro).
But I would like to display a message in the Status Bar, for instance "Switched to French" or "Switched to English" (for some time, let say 5 sec).
I looked everywhere I know and I tried for some time, but apparently there is no way to do this in a command (that could be added at the end of the macro), as the set_status internal ST3's Python API command (from Window package) is only available for plugins...
Does any one has an idea of how to display a message to the SublimeText3 StatusBar in a command/macro and not with a plugin? Thanks!
There is no built in command that invokes the API methods for doing this (at least not a documented one), so there's no way to go about this without a plugin of some sort.
That said, in order to do what you want, the following is all you would need to save into a file named e.g. set_status.py in your Packages/User folder (alongside your macros). This provides a set_status command that takes a value named value for the text to display, as mentioned in the commented out portion of your macro file.
import sublime, sublime_plugin
class SetStatusCommand(sublime_plugin.TextCommand):
def run(self, edit, value="set_status: use arg 'value' to set text"):
self.view.window ().status_message (value)
This uses a different API than the one you mention in your macro file comments; status_message does the work of displaying a message in the status bar, waiting a few seconds, and then removing it, which makes the command simple to implement.
If you wanted more control (i.e. to change the duration) you would need to modify this to invoke the API commands your macro files already mention: view.set_status() and sublime.set_timeout().

Resources