How to execute multiple commands in a keymapping? - vim

I am trying to execute multiple commands with a keymap using Which Key:
Open a file (<cmd>ZkNew { title = 'inbox', dir = '' }<cr>)
Goto end of the opened file (<S-g>)
Goto the end of the last line ($)
Goto insert mode (<Insert>)
I tried executing a chain command like below:
t = { "<cmd>ZkNew { title = 'inbox', dir = '' }<cr>|<S-g>$<Insert><cr>", "Add todo" },
The <cmd>ZkNew { title = 'inbox', dir = '' }<cr> opens the file but the other <S-g>$<Insert><cr> commands seem not to be executed after opening the file.
Any hint on how this could be achieved?

You can do something like this.
['t'] = {
function()
vim.cmd("--[[ paste your command here 1]]")
vim.cmd("--[[ paste your command here 2]]")
end,
'SomeCommand',
},
or you can write your own command and then use WhichKey to execute it. 
vim.api.nvim_create_user_command('SomeCommand', function()
-- paste you command here
end, {})

Related

Get active cell type in JupyterLab extension

I'm trying to write a simple extension with commands to navigate cells. The point of these commands is to automatically enter edit mode after movement unless target cell is of text or markdown type. Following this guide I've added command that executes sequence of some pre-built commands. But I'm stuck on creating condition for cell type, where can I get info about current cell?
import {
JupyterFrontEnd,
JupyterFrontEndPlugin,
} from '#jupyterlab/application';
/**
* Initialization data for the commands example.
*/
const extension: JupyterFrontEndPlugin<void> = {
id: 'commands',
autoStart: true,
activate: (app: JupyterFrontEnd) => {
const { commands } = app;
const command = 'my_command';
// Add a command
commands.addCommand(command, {
label: 'Move down & enter edit mode',
caption: 'Move down & enter edit mode',
execute: (args: any) => {
commands.execute('notebook:enter-command-mode');
commands.execute('notebook:move-cursor-down');
// here I need to check if we are on the code cell
commands.execute('notebook:enter-edit-mode');
},
});
},
};
export default extension;

vim - I'm looking for plugin what adds tabulation inside block

This feature is available in Intelij, and works like this:
I have for example some code (| is a cursor in this example):
|
doSomething();
variable = "foo";
And I'm adding it inside block, for example if:
if (true)
{
doSomething();
variable = "foo";
|
Now after type closing bracket, plugin should add tabulation for code inside block:
if (true)
{
doSomething();
variable = "foo";
}|
I hope I explained how it should work. Is there plugin for this?
In-order to indent a block of code inside {}, you can use =%.
It's just a matter of an insert mode mapping for } to insert }, and run the command =%
It can be done with
:inoremap } }<esc>k :normal =%<cr>

Select text between two bookmarks in Komodo Edit

Let's say I have the following (example) code in combined.js:
/* jQuery, Moment.js, Bootstrap, etc. */
Child.prototype.doSchool = function(data) { // Bookmarked
var essay = data.essay || {};
if (essay) {
var spelling = checkSpelling(essay, EN_US_GRADE_7);
return spelling.grade();
}
}
/* Extensive and Turing-complete code base */
var burt = new Child();
if (burt.doSchool({essay: "i like trains"}) < .65) burt.comfort(); // Bookmarked
/* jQuery extensions, Fallout 4, etc. */
The file is bookmarked in Komodo Edit 9.3.x in the locations marked by // inline comments.
Any /* block comments */ indicate thousands of lines of code.
The source between the bookmarks exists in another file, school.inc.js. I want to know if there is an easy way to select all the text between the bookmarks, so that combined.js can be easily updated by pasting the contents of school.inc.js over it without having to use a combining utility.
There is no built in way to do this but you could possible do it by writing a Userscript.
You'll want to use the Komodo Editor SDK.
// This assumes you're running the Userscript starting at the first bookmark
var editor = require("ko/editor");
var startSelect;
var endSelect;
var done = false;
function selectBookmarkRegion(){
if(editor.bookmarkExists()) { // check if bookmark is set on current line
startSelect = { // save it's line start
line: editor.getLineNumber(),
ch: 0
};
} else {
alert("Start me on a line with a Bookmark");
}
editor.goLineDown();
while(!done){
if(editor.bookmarkExists())
{
endSelect = {
line: editor.getLineNumber(),
ch: editor.getLineSize()
};// Save line end
done = true;
}
editor.goLineDown();
// found a bug as I was writing this. Will be fixed in the next releases
if (editor.getLineNumber() + 1 == editor.lineCount())
{
done = true;
}
}
editor.setSelection(startSelect, endSelect); // Wrap the selection
}
selectBookmarkRegion();

When I close a window and then open a different one, the selected tab is recreated by Chrome

I am writing a Chrome extension that saves/restores your browsers window state - So, I save the state of a given window:
var properties = [ "top",
"left",
"width",
"height",
"incognito",
"focused",
"type"
];
var json = {};
var cache = chrome_window_object;
// copy only the keys we care about:
_.each(properties,function(key,value) {
json[key] = cache[key];
});
// then copy the URLs of the tabs, if they exist:
if(cache.tabs) {
json.url = [];
_.each(cache.tabs,function(tab) {
json.url.push(tab.url);
});
}
return json;
At some point in the future, I remove all windows:
closeAllWindows: function(done_callback) {
function got_all(windows) {
var index = 0;
// use a closure to only close one window at a time:
function close_next() {
if(windows.length <= index) return;
var window = windows[index++];
chrome.windows.remove(window,close_next);
}
// start closing windows:
close_next();
}
chrome.windows.getAll(got_all);
}
and then I restore the window using:
chrome.windows.create(json_from_before);
The window that is created has an extra tab in it, whatever was in the window that I just closed... I am completely floored, and I assume the problem is something that I am doing in the code that I haven't posted (it's a big extension). I've spent a few hours checking code line by line and making sure I'm not explicitly asking for this tab to be created. So - has anybody seen anything like this before?

How to find application scripts in node inspector faster?

While watching node-inspector screencasts I noticed app scripts on top of scripts list and they contains full path.
But when I using it - all scripts are shuffled with system scipts and it very hard to find ones that relates only to my app.
What I do wrong?
You don't do anything wrong, the code has just evolved between the screencasts and now...
To re-enable the full path files visible you could apply the following :
At the line 192 in the file node-inspector/lib/session.js you will find this function call :
scripts.forEach(function(s) {
var hidden = config.hidden &&
config.hidden.some(function(r) { return r.test(s.url); }),
item = { hidden: hidden, path: s.url };
if (s.path.length > 1) s.url = shorten(s.path);
item.url = s.url;
sourceIDs[s.sourceID] = item;
delete s.path;
if (!hidden) {
sendEvent('parsedScriptSource', s);
}
});
To have the full path of the file in the debugger just remove the line where the url is shortened like this :
//if (s.path.length > 1) s.url = shorten(s.path);
This will do the job even if not an optimal solution.
PS : you will find the source of this file here : https://github.com/dannycoates/node-inspector/blob/master/lib/session.js

Resources