Permalink
Browse files

Version 0.1: Initial upload

  • Loading branch information...
Jeremy Collins authored and vim-scripts committed Jul 13, 2001
0 parents commit d066d08d7e47d7ab41e2944bccc6d7dd68c5ebe1
Showing with 104 additions and 0 deletions.
  1. +29 −0 README
  2. +75 −0 vimrc.tcl
29 README
@@ -0,0 +1,29 @@
+This is a mirror of http://www.vim.org/scripts/script.php?script_id=33
+
+This small hack requires Tcl to be compiled into your
+copy of Vim.
+
+The default settings will allow this hack to work on
+the default SQL*Plus temp file, afiedt.buf, only.
+
+To use simply highlight the query you would like to
+run and press Enter. You should drop back down to
+SQL*Plus. Do the usual '/' and your good to go.
+
+Have not tried this hack with PL/SQL or multiple
+Query's but I cannot see why it won't work, or why it
+would for that matter.
+
+BUGS
+----
+1) :wq causes an error message about writing the file.
+ Safe to ignore but would be nice to get rid of this.
+
+2) No checks to make sure you have highlighted a valid
+ Query. Hence all hell breaks loose if you don't.
+
+3) You *HAVE* to have a trailing ';' on your Query for
+ this hack to work. Would be nice if you didn't have
+ to have that. Would also be nice if you could run
+ a group of statements.
+
@@ -0,0 +1,75 @@
+proc sqlplus { } {
+
+ set buf $::vim::current(buffer)
+
+ if { [file tail [$buf name]] != "afiedt.buf" } {
+ puts "Must use file named afiedt.buf"
+ return
+ }
+
+ set Query [$buf get $::vim::range(start) $::vim::range(end)]
+
+ $buf command "w! ~/.sqlplus.hack"
+ $buf delete first last
+
+ foreach line $Query {
+ $buf append end $line
+ }
+
+ # Save state.
+ set fh [open ~/.sqlplus.hackrc w]
+ puts $fh "set ::__SQLPLUS_ROW $::vim::range(start)"
+ close $fh
+
+ set ::__SQLPLUS_LOADED 0
+
+ $buf command "set noai"
+ $buf command "/;"
+ $buf command "normal $"
+ $buf command "normal xj0"
+ $buf command "normal o/"
+ $buf command "w! [$buf name]"
+ $buf command "wq!"
+}
+
+proc sqlplus_force_save { } {
+ set buf $::vim::current(buffer)
+
+ # Only force save if they typed :wq
+ if [info exists ::__SQLPLUS_LOADED] {
+ if { $::__SQLPLUS_LOADED == 1 } {
+ set fh [open ~/.sqlplus.hackrc w]
+ puts $fh "set ::__SQLPLUS_ROW $::vim::range(start)"
+ close $fh
+ $buf command "set writeany"
+ $buf command "w! ~/.sqlplus.hack"
+ $buf command "wq!"
+ }
+ }
+
+}
+
+proc sqlplus_reload { } {
+
+ set buf $::vim::current(buffer)
+ set win $::vim::current(window)
+
+ if { [file tail [$buf name]] != "afiedt.buf" } {
+ puts "Must use file named afiedt.buf"
+ return
+ }
+
+ $buf delete first last
+ $buf command "read ~/.sqlplus.hack"
+ $buf delete first
+
+ # Load a saved state, and set cursor back to original position.
+ catch { source ~/.sqlplus.hackrc } error
+ if [info exists ::__SQLPLUS_ROW] {
+ $win cursor $::__SQLPLUS_ROW 0
+ }
+
+ set ::__SQLPLUS_LOADED 1
+ $win delcmd [list sqlplus_force_save]
+
+}

0 comments on commit d066d08

Please sign in to comment.