Disable root node refresh on window focus - macvim

Whenever I focus my MacVim window it freezes for several seconds. It seems that this is due to NERDTree refreshing it's root node (It prints NERDTree: Refreshing root node. This could take a while... DONE)
Since I often switch in and out of MacVim this is very annoying and slows down my workflow. Is there a way of configuring NERDTree not to do this automatically?
EDIT: I am using janus

I'm going to go out on a limb and say that you're using janus. Janus adds a FocusGained event, and so when you do :au FocusGained as Kazuki mentioned, you'll see something like:
AuNERDTreeCmd FocusGained
* call s:UpdateNERDTree()
You can remove that focus event binding by adding the following to your .vimrc.after:
autocmd! AuNERDTreeCmd FocusGained

I think NERDTree itself doesn't do refresh the root node automatically. Actually I can't reproduce the problem. You need to input R key (default) to refresh the root node.
Whenever I focus my MacVim window it freezes for several seconds
It sounds you are using FocusGained autocommand event to do something. You can check it using the following command.
:au FocusGained
You will get the list of FocusGained autocommand events.
--- Auto-Commands ---
FocusGained
* ...
For example, you can auto-refresh NERDTree root like this.

Related

Invoking series of commands in a new tab in cmder

TLDR:
I want to use something like -new_console:t:tabname to open a new named tab in cmder and then transfer focus/control to that tab so that the rest of the commands I'm sending from a Python script run in that console instead. Or, I want to rename a cmder tab from a script running in the console.
DETAILS:
I often have to execute a series of commands in cmder in order to test the latest code from our continuous integration environment. Because there are several applications I often have to have running at a time, it would be helpful for me to have the cmder tabs named according to which application they are running.
The only way I've found to set a tab name from within cmder (apart from manually with mouse clicks) is to do so with the -new_console:t:tab_name command. But that only runs the next command in the newly opened tab, and not all the things that come after it.
I kick off all my commands with a Python script that accepts parameters to let me control which application opens and how things behave. I'd like to do something like this:
os.system('pwd "-new-console:t:' + args.app + '"')
so that a new tab opens with the name of the app I'm about to invoke in it, starting with an indication of the present working directory. But then I'd like all the commands that follow from the Python script to be run in this new tab instead of in the tab used to kick off the Python script. This includes printing some flowerboxed comments, but also invoking a local application server that will continue running.
Is there any way to, as you create a new (named) tab in cmder, transfer focus to that tab so that all future commands run in that tab instead of the initiating tab? Alternately, is there any way from within a cmder console to rename the cmder tab it's running in? That would be just as good.
Thanks!
Thanks for looking, but I found the answer.
In the bottom right corner is a hamburger stack. Click on that and select Settings. In General --> Tab bar, change the Console setting from the default %n to %s. Then the "title" command will change the tab name.

CreateProcess returns handle different than launched Chrome.exe

I am using CreateProcess and giving Chrome.exe as the argument.
I am getting the handle of the process I created using PROCESS_INFORMATION which internally has hProcess
When I print the PID using GetProcessId(handle) I am getting a different PID than the ones showing in the task manager.
I have tried setting callback function to trigger after Chrome.exe exists, but it triggers anyway. This is expected (not desired) since Chrome.exe PID is different.
It seems like when I use CreateProcess on Chrome.exe, chrome takes liberty to start its own new process and render all my control useless.
I have tried using it with FireFox.exe and it worked well, I got the handle it pointed to the correct process.
Is it not possible to get handles to Chrome processes I spawn?
The Chrome process you are spawning with CreateProcess() is, in turn, spawning its own child process(es) and then terminating itself. Your Firefox is not doing that, at least not initially (Firefox does use child processes for browser tabs - most modern browsers do, for security and stability).
So, the Chrome PID/handle you get from CreateProcess(), albeit valid, is short-lived and clearly useless for your needs.
But, all is not lost. You can get notified about the child PID(s) that Chrome itself spawns. Add your spawned Chrome process to a job object, then use SetInformationJobObject() to assign that job to an I/O completion port, then use GetQueuedCompletionStatus() to receive events from the job, in particular JOB_OBJECT_MSG_NEW_PROCESS whenever a new process is created in the job, and JOB_OBJECT_MSG_ACTIVE_PROCESS_ZERO when all processes in the job have ended. See How do I wait until all processes in a job have exited? for more details.

PHPstorm console input not working during debug sessions

I'm using a PHP script which expects user input from a command like fgets(STDIN). The problem is it no longer works in the newest version of PHPStorm (10).
The same works when I run it directly (without debugger enabled) and anything I enter in the console is sent to the script (on direct run).
But during a debug session, when I try to input text at the script's prompt, it does not go to the script. My best guess is that the new REPL feature is overriding user input in console during debugging. I say this because pressing the UP/DOWN arrows opens up a popup with all PHP function names.
It used to work correctly with last version.
How can I send user input to my PHP script with this new version? Am I missing something here?
I'm not sure if this is the same thing, but I was running into this same problem, and I was able to get it working by deselecting the "Use Console Input" checkbox in the PHPStorm Console.
John's answer is perfect.
I want to mention that the Use Console Input is a tiny icon in sidebar of the debug console. I provide you by this image

Is there a way to refresh the task list in VSCode?

The first time I open VSCode, it scans my gulpfile and populates the task list. However, if I add a new task to my gulpfile, and then Run Task, it will only show the initially loaded tasks. Is there a way to manually refresh the task list? Right now I've resorted to restarting VSCode everytime I need to run a new task.
It is not a very convenient way of reloading - but try Command Palette -> Reload Window instead of restarting VSCode.
Rather than reloading the entire window, you can edit (or create) /.vscode/tasks.json, which will trigger a refresh on all tasks in your gulpfile.js.
Adding or removing a blank line will count as an edit for purposes of refreshing your task list, so this seems faster and more efficient than reloading the window or opening/closing the IDE.

Vim: Make chrome refresh anytime I :write

I want a solution that does what's described in the vim wiki here, but that works on Chrome.
That is, I'm trying to avoid this:
Edit your HTML/CSS file.
Hit save in Vim.
CMD/CNTRL/ALT + TAB over to Firefox.
Press Ctrl-R in Firefox to refresh.
CMD/CNTRL/ALT + TAB back to Vim.
Do it again and again, wincing a little bit each time.
The vim wiki solution is for firefox, and other scripts and solutions I've found on the web are Mac only. But I'm on windows, and will often have vim open on the left half of the screen (editing html) and chrome open on the right half of the screen (displaying the file I'm editing).
A really "dumb" solution would work fine for me. That is, there wouldn't even need to be communication of the filename between vim and the browser. If I could just turn on a mode in vim, call it "auto-refresh", and now anytime I do a :w the currently active tab in chrome refreshes itself, without taking focus off the vim window. That would be perfect. Is it possible?
I don't know how to reload a give chrome page from shell, however, I agree with Chiel92 that if you need to see your changes when file changes, you can do that from browser.
See LiveReload, works with Windows & Mac (not for me then) and supports Safari & Chrome.
LiveReload will check your main page as well all css and javscript that it depends from, if any of those changes, it will reload it.
They seems to have launched a second version, however official site of version 2 it's offline and doesn't seem version 2 it's on github either. (Version 1 it's it's on github)
a solution that might work for you is in your html coding include the line in the head tag
<meta http-equiv="refresh" content="30" />
this will reload the page every 30 seconds directly taking from
w3schools.com
now when you want to deploy it just remove that line
If you are working on mac, then a bit of apple script does the job.
putting this function in your vim configuration will let you automate the process of switching between windows and refreshing you described.
function! ReloadBrowser()
silent exe "!osascript -e 'tell app \"Firefox\" to activate\<cr>
\tell app \"System events\"\<cr> keystroke \"r\" using command down\<cr>
\end tell'"
silent exe "!osascript -e 'tell app \"Iterm2\" to activate'"
endfunction
Calling that function will change system focus to Firefox, hit CMD-R to refresh the page, then change focus back to Iterm2.
Change 'Firefox' and 'Iterm2' to fit your workflow.
You can type the function into the vim command prompt like :call ReloadBrowser() or trigger the call with a mapping like this:
nnoremap <leader>rl call ReloadBrowser()<cr>
To trigger the call any time you write the file you could use an autocommand.
augroup AutoReload
au!
autocmd BufWritePost *.filetype call ReloadBrowser()
augroup END
That could get a bit annoying though so if you really want that behavior I think it would be best to make it toggle-able like this:
let s:auto_reload = v:false
function! ToggleAutoReload()
if s:auto_reload
augroup AutoReload
au!
autocmd BufWritePost *.filetype call ReloadBrowser()
augroup END
else
augroup AutoReload
au!
augroup END
endif
let s:auto_reload = !s:auto_reload
endfunction
with that in place you can either manually trigger the reload with <leader>rl or use :call ToggleAutoReload() to enable automatic reloading when you save the file, and a second :call ToggleAutoReload() will disable it when you're done.
I've tried LiveReload in the past but it wasn't a very dependable solution: it was very buggy and unstable and the installation process was too involved for too little effect.
Since then, (more than a year) I've been using a small Chrome extension that automatically reloads the webpage every x seconds. It's not "smart" at all but it works well both for local files and hosted files. I've used it countless times without any side effects whatsoever.
That Solution on the Vim Wiki is possible because of MozREPL which allows an external process to interact with Firefox. From there it's quite trivial to write an autocmd that triggers a refresh on :w or on CursorHold. But AFAIK there's no such tool for Chrome/Chromium and they don't offer an external API. LiveReload is a brilliant but failed hack and I believe that you'll have to settle with the dumb solution if you must work with Chrome.
edit
I just remembered a script that works very well on this Linux box but is a little bit limited on Mac OS X and doesn't seem to work on Windows. Essentially you register a window/tab with a part of it's name:
$ webrf setup-by-search test.html
then you simply do:
$ webrf refresh
to refresh the page.
I use WSL and two screens so for me this works. (as with every :write is a bit too much)
nmap <leader>t :silent !powershell.exe -command "Add-Type -AssemblyName System.Windows.Forms; [Windows.Forms.Cursor]::Position = \"-1290,50\"; Add-Type -MemberDefinition '[DllImport(\"user32.dll\")] public static extern void mouse_event(int flags, int dx, int dy, int cButtons, int info);' -Name U32 -Namespace W; [W.U32]::mouse_event(6,0,0,0,0); [Windows.Forms.Cursor]::Position = \"40,40\"; [W.U32]::mouse_event(6,0,0,0,0);"<CR><CR>
It basicly tells vim through a powershell command to have the mouse cursor go to:
position -1290, 50 ( which is where the refresh button of chrome is)
left mouse click
position 40,40 (which is where my vim is in full screen)
left mouse click
Step 3 and 4 is needed to refocus vim I tried to sent ALT-TAB but my vimrc disliked the % symbol.
On Windows OS you can utilize an AutoHotKey script that will automate that for a key press.
For example, the following script will bind Left Alt + r to switch to the browser window, send a Control + r(Refresh) and then get back to your previous window.
Replace Title_of_your_webpage with your browser's window title string after your page has loaded in it.
!r::
WinGet, winid, , Title_of_your_webpage
WinActivate, ahk_id %winid%
Send ^r
Send !{Tab}
Return