Thursday, June 19, 2014

Custom Vorax Status Line

Vorax does a pretty well job when it comes to display the status line of the output window. It shows a lot of stuff like: the current output funnel (PAGEZIP, VERTICAL or TABLEZIP), the APPEND or STICKY flag and, of course, the current Oracle connection.


However, it looks a bit too minimalist, especially with all these nice statusline management plugins around:
I've played a little with all the above plugins and in the end I decided on Airline. Even Lighline is more KISS oriented, I didn't want to spend too much time on configuring everything: NERDTree, quickfix window etc. Unlike Lighline, Airline is designed to be extensible and plugins like NERDTree, vim-fugitive etc. may contribute with their own airline extensions in order to configure the look of the status line.

So, below is Vorax with airline:


It'a nice improvement, and the information from the status line is better highlighted. In addition, I configured the current Oracle connection to be also displayed in a Vorax buffer (sql or plsql), just to be sure we know where we're connected to, especially if the output window is not shown (it can be toggled, I'm sure you know this).

So, let's see how we can achieve this. I put the following in my .vimrc file:

" Let me choose the statusbar
let g:vorax_output_force_overwrite_status_line = 0

function! VoraxOutputFlags()
  let funnel = ["", "VERTICAL", "PAGEZIP", "TABLEZIP"][vorax#output#GetFunnel()]
  let append = g:vorax_output_window_append ? "APPEND" : ""
  let sticky = g:vorax_output_window_sticky_cursor ? "STICKY" : ""
  let heading = g:vorax_output_full_heading ? "HEADING" : ""
  let top = g:vorax_output_cursor_on_top ? "TOP" : ""
  return join(filter([funnel, append, sticky, heading, top], 'v:val != ""'), ' ')
endfunction

function! VoraxAirPlugin(...)
  let session = '%{vorax#sqlplus#SessionOwner()}'
  let txn = '%{vorax#utils#IsOpenTxn() ? "!" . g:vorax_output_txn_marker : ""}'
  if vorax#utils#IsVoraxBuffer()
    let w:airline_section_b = get(w:, 'airline_section_b', g:airline_section_b) . session
    let w:airline_section_warning = get(w:, 'airline_section_warning', g:airline_section_warning) . txn
  endif
  if &ft == 'outputvorax'
    let lrows = '%{exists("g:vorax_limit_rows") ? " [LIMIT ROWS <=" . g:vorax_limit_rows . "] " : ""}'
    let w:airline_section_a = '%{vorax#utils#Throbber()}'
    let w:airline_section_b = airline#section#create_left([session])
    let w:airline_section_c = 'Output window'
    let w:airline_section_x = ''
    let w:airline_section_y = g:airline_section_z
    let w:airline_section_z = airline#section#create(["%{VoraxOutputFlags()}"])
    let w:airline_section_warning = get(w:, 'airline_section_warning', g:airline_section_warning)
    let w:airline_section_warning .= airline#section#create([lrows, txn])
  elseif (&ft == 'connvorax') || (&ft == 'explorervorax') || (&ft == 'oradocvorax')
    let w:airline_section_a = ''
    let w:airline_section_b = ''
    let w:airline_section_c = (&ft == 'connvorax' ? 'Connection Profiles' : &ft == 'explorervorax' ? 'DB Explorer' : 'Oracle Documentation')
    let w:airline_section_x = ''
    let w:airline_section_y = ''
    let w:airline_section_z = ''
  endif
endfunction
call airline#add_statusline_func('VoraxAirPlugin')

" Let the statusbar as it is for inactive windows
let g:airline_inactive_collapse=0
That's all! The next logical step would be to defeat my lazyness and submit a real Airline extension for Vorax. I'm going to add this to my procrastination list.

Tuesday, October 22, 2013

Vorax 4.0 Preview

Well, it's been awhile since I posted my last Vorax article here. Funny enough, it was about Vorax 3.0 improvements ideas. Meanwhile Vorax 3.0 was released into the wild, but at that time I didn't want to make such a big fuss because I wasn't sure it had the right implementation.

Now Vorax4 is in beta-testing and I'm quite pleased by the results: it's much faster, it has a smarter code completion and it's more KISS compliant.

So, please check it on: http://talek.github.io/vorax4/
Your feedback is highly appreciated!

Tuesday, May 3, 2011

Ideas for a completely rewritten VoraX 3.0

One year ago the first version of VoraX was released. It initially started as a proof of concept tool but, step by step, evolved into a more complex application. Unfortunately, at that time, my experience in writing Vim plugins was a bit poor. Now, when I'm looking to the code I wrote for implementing several functionalities I don't feel very proud: it's rude, not DRY and hard to maintain/understand. That's one of the reasons I think VoraX 3.0 should be a completely rewritten version. There are also some new features/improvements that I have in mind, the most important ones being:
  • a better DbExplorer tree. The main improvement I see here is the possibility to register custom plugins to provide additional functionality. For example, an user may write a very simple plugin to display DBMS_SPACE statistics for various objects within the tree. The same functionality provided by NERDTree via plugins may be also implemented for DbExplorer.
  • a tree based connection profile window with a XML file behind to store all profiles. I think this would be better than the actual implementation where these profiles are spread out in several files which, of course, is not very intuitive.
  • all VoraX config files should reside in $HOME/.vorax instead of directly in $HOME, messing up the user's home folder.
  • the possibility to configure one output window per tab. Sometimes is useful to open another tab and querying the database from there while preserving the old tab, including the output window.
  • text HTML output. The idea is to display the output of a query in a more friendly format without a lot of "column format" trickery. The main benefit would be that all columns will have the right size. The drawback is that the user must wait for the query to finish and only after that the output will be displayed. That's different than the way it is now when you have immediate feedback and the result is spit out as soon as it is available into the sqlplus out buffer. However, the user should have an easy option to switch from one type of output to another.
  • support for ruby 1.9? I don't know if both versions, 1.8.7 and 1.9 should be supported or not. The problem is that the PTY mechanism used by VoraX for Unix systems has changed in ruby 1.9. As far as Windows platforms are concerned, I must check if win32-api.gem can be used on ruby 1.9. However, being prepared for ruby 1.9 doesn't sound like a bad idea, does it?
  • move to GitHub. I already created a repository for VoraX 3.0. Despite I have little experience with this versioning system I'm eager to learn it because it seems more open to collaboration.
  • completion for various VoraX commands. For example, the :VoraxConnect command may provide completion based on registered connection profiles.
  • new commands. It would be nice to have the possibility to open packages or triggers directly using VoraX commands instead of navigating through the DbExplorer. This may be really handy, especially combined with a smart completion.
  • testing. It would be really nice to have a regression test suite or something in order to validate that the changes made to the code doesn't hurt the current functionality. There are some VIM plugins which may be used to test VimL code but I don't have any experience with any of them. Nevertheless, investing effort in this area would be really helpful.
If you have other ideas (or useful hints) please let me know. VoraX is an open source project therefore everybody is welcome to contribute.

Friday, April 1, 2011

VoraX on MAC OS

A few weeks ago I received an issue about the fact that VoraX doesn't work on MAC OS. For me it wasn't such a big surprise as I never tested VoraX on MAC OS, simply because I didn't have this platform available.

"It's time for action!" I said to myself having in mind the possibility to install this OS as a virtual machine and test VoraX on it. So, I grabbed a vmware MAC OS image and I tried to run it using vmware player. It's not a big deal, isn't it? Well, apparently this can't be done on my old PC because a CPU with VM-x stuff is needed. Damn it! Yeap, it's time for a CPU upgrade. I ordered an Intel Dual Core Duo 8400 and I patiently waited to arrive. Yesterday the new CPU was on my desk, ready to be installed. The installation was a piece of cake, the new CPU being recognised by my old motherboard except for the virtualization feature, that VT-x I was looking for. Buying a new motherboard didn't sound very appealing so I decided to look for a BIOS update. My MB is a Gygabyte and it already had the last stable BIOS installed. There was also a beta firmware available but that "beta" seemed a little bit scary. However, I had nothing to loose therefore I decided to go with the beta version. Aaand, after the upgrade, what a surprise! A brand new option called "Virtualization" was available in BIOS. Yesss! With this VT-x feature available I was able to run the vmware MAC OS image.

Hmmm... my very first time on MAC OS. It looks nice, kind of glossy but nothing to complain of. Well, maybe my lack of knowledge about this OS. However, having previous experience with a *NIX system is a big advantage. As soon as you get a terminal window it's like an usual *NIX box. I was able to check for ruby version and to install antlr3 gem. Mac OS 1.6.X is quite ready for VoraX. Then I downloaded macvim which has ruby support enabled. Then I installed the oracle instant client. I was a little bit surprised about the fact that the last available version for MAC is 10.2.0.4 and not 11.2.0.2. In the end I installed VoraX (the linux way into the ~/.vim dir) and I created a very basic .vimrc file:

set nocompatible
filetype plugin on


Below is the final result.


Yeap, VoraX on MAC. It's time to update the site/documentation to let people know that VoraX is also supported on MAC. Have fun guys!

Monday, January 24, 2011

Knock, Knock... Who's there?... VoraX 2.8

Hey folks! I feel bad for VoraX 2.7. It really had a short life, just a week... If you're the kind-hearted type then you may choose to keep VoraX 2.7 and make it happy. But, would you be also happy without these new VoraX 2.8 goodies? Well, let's see...

First of all, VoraX 2.8 is faster because it has a redesigned OS interface. This becomes obvious especially on Cygwin. Till now, there was an annoying delay immediately after a statement was finished executing. That was because another call was made in order to get connection information, which was further used to update the VoraX title. In VoraX 2.8 this is no longer true, the connection info is gathered in one step, as part of the statement execution itself.

Another useful feature is the monitoring capability of the results window. If you have a long running statement and you want to be notified when it's done then this is perfectly doable in VoraX 2.8. And because a picture worths one thousands words, below is a screen-shot showing this feature on my Ubuntu box:


Just put the following snippet into your .vimrc:
" Nice notification for my monitored long runinng queries
function VoraxNotification()
  let cmd = "notify-send -i 'terminal' 'VoraX' 'Execution of your monitored statement on ". 
            \ &titlestring . " has just finished.'" 
  exe 'silent! !' . cmd
endfunction
let g:vorax_notify_command = "call VoraxNotification()"

On Windows I have no idea how to configure this but I guess there are some "cool" command line programs to display those annoying balloons in your tray.

And that's not all. Did you noticed the re-polished status line for the results window? Much better, isn't it?

As far as bug fixes are concerned I recommend you to upgrade because this version has a fix for a quite critical bug reported by Shaun Batterton. The bug description goes like this: if your statement has an "end" somewhere in between then a "/" will be appended. For example, if you execute something like:

alter tablespace muci_tbs add datafile size 100m autotextend on;

behind VoraX will rewrite (in a wrong way because of the bug) as:

alter tablespace muci_tbs add datafile size 100m autoextend on;
/

I know it's stupid but because the statement has an "end" (in autoextend) we end up adding two datafiles which, of course, is not what we've meant. Thanks Shaun for this bug report.

There's also another bug fix in connection with virtualedit setting but that's not something to pay too much attention in this post.

Okey, that's all. You may find additional details about these new features within the VoraX updated documentation.

Monday, January 17, 2011

VoraX 2.7 Released

By this post I want to let you know that VoraX 2.7 is available for download. The most important improvement this version brings out to light is a better way to define your key mappings for VoraX commands. No more VoraX event handler bullshit! Starting with this version you may define these mappings using a few g:vorax_key_for_* global variables. For example, my vimrc file contains now the following:

let g:vorax_key_for_exec_buffer = "<F8>"
let g:vorax_key_for_exec_sql = "<Leader>e"
let g:vorax_key_for_exec_one = "<Leader>1"
let g:vorax_key_for_describe = "<Leader>d"
let g:vorax_key_for_describe_verbose = "<Leader>D"
let g:vorax_key_for_explain_plan = "<F5>"
let g:vorax_key_for_explain_only = "<S-F5>"
let g:vorax_key_for_fuzzy_search = "??"
let g:vorax_key_for_goto_def = "gd"
let g:vorax_key_for_toggle_logging = "<Leader>l"

Of course, you're free to choose whatever you want. You are no longer bound to the default VoraX key mappings.

There are also a couple of bug fixes. They are detailed into the changelog.

Wednesday, January 5, 2011

VoraX on Vim 7.3

Apparently the VIM pack from Lucid repository has a nasty bug which causes VoraX to crash on my Ubuntu box with VTALRM signal (Virtual timer expired). I can't reproduce this behavior at will but it happens quite often to encounter this crash which, of course, is very annoying as I also loose all the work I did into my unsaved buffers.

So, I decided to compile the latest VIM version (7.3 at the time of writing this post) in order to get rid of this bug. Below are the steps I've done:

1. remove the actual VIM packages:
FITS\alec@tia ~ $ dpkg --list | grep vim
vim-common                            2:7.2.330-1ubuntu3                    Vi IMproved - Common files
vim-gnome                             2:7.2.330-1ubuntu3                    Vi IMproved - enhanced vi editor - with GNOM
vim-gui-common                        2:7.2.330-1ubuntu3                    Vi IMproved - Common GUI files
vim-runtime                           2:7.2.330-1ubuntu3                    Vi IMproved - Runtime files
vim-tiny                              2:7.2.330-1ubuntu3                    Vi IMproved - enhanced vi editor - compact v

FITS\alec@tia ~  # sudo apt-get remove vim-common vim-gnome vim-gui-common vim-runtime vim-tiny

2. install dependencies
sudo apt-get install libncurses5-dev libgnome2-dev libgnomeui-dev \ 
libgtk2.0-dev libatk1.0-dev libbonoboui2-dev \ 
libcairo2-dev libx11-dev libxpm-dev libxt-dev

3. download vim7.3 from: ftp://ftp.vim.org/pub/vim/unix/vim-7.3.tar.bz2

4. unpack the archive: tar -jxvf vim-7.3.tar.bz2

5. configure, make and install:
cd vim73/src/
./configure --with-features=huge --enable-gui=gnome2 --enable-rubyinterp
make
sudo make install

Simple as that! VoraX seems to be stable now. I didn't experience any VTALRM crashes since then.

Update 1: Ups, today I received a VTALRM crash. I think the problem is not Vim but ruby itself. On Ubuntu ruby is compiled with libthread which may cause troubles. I will try with a pthread-less ruby to see if it makes any difference.

Update 2: I asked Vim community for help here. With the provided patch I didn't experience any new VTALRM crashes.

Update 3: The fix is included in Vim 7.3.118.