Permalink
Browse files

Source whole files and formatting changes.

Source the file when TclEval is executed without a range or selection.
Changes to formatting.
Feedback to the user when executing code with TclEval.
Minor update to the documentation to note TclEval operates on lines.
  • Loading branch information...
1 parent 18bd425 commit 745bf4378e28c9b83baa066886f303c434141da7 @LStinson committed Mar 19, 2012
Showing with 59 additions and 39 deletions.
  1. +14 −11 autoload/TclShell.tcl
  2. +37 −20 autoload/TclShell.vim
  3. +4 −3 doc/TclShell.txt
  4. +4 −5 plugin/TclShell.vim
View
@@ -1,7 +1,7 @@
# vim:foldmethod=marker
# ============================================================================
# File: TclShell.tcl (Autoload)
-# Last Changed: Sat Mar 17 01:37 PM 2012 EDT
+# Last Changed: Mon Mar 19 09:12 AM 2012 EDT
# Maintainer: LoranceStinson@gmail.com
# License: Public Domain
#
@@ -12,7 +12,7 @@
# Only define the procedures once.
if {[info procs ::_TclShellEval] eq ""} {
- # _TclShellAppend -- Append text to the TclShell buffer.
+ # _TclShellAppend -- Append text to the TclShell buffer. {{{1
#
# Arguments:
# $text The text to append to the buffer.
@@ -31,8 +31,9 @@ if {[info procs ::_TclShellEval] eq ""} {
$buf append end $line
}
}
+ # }}}
- # _TclShellPuts -- Send output to the TclShell buffer.
+ # _TclShellPuts -- Send output to the TclShell buffer. {{{1
# Appends the output to the global variable _TclShellOutput or to the
# TclShell buffer depending on the presence of -noewline.
#
@@ -69,22 +70,23 @@ if {[info procs ::_TclShellEval] eq ""} {
}
return ""
}
+ # }}}
- # _TclShellEval -- Evaluates Tcl code.
+ # _TclShellEval -- Evaluates Tcl code. {{{1
# Reads Tcl code from the TclShell buffer.
# The results and output are placed back into the buffer.
#
# Arguments:
- # None
+ # $tclcode The Tcl code to execute.
#
# Result:
# None
#
# Side effect:
# The TclShell buffer is modified.
- proc ::_TclShellEval {command} {
- # Clean the Command to execute of carriage returns.
- set command [string map {\r \n} $command]
+ proc ::_TclShellEval {tclcode} {
+ # Clean the code of carriage returns.
+ set tclcode [string map {\r \n} $tclcode]
# Temporarily replace 'puts' with a special one.
rename puts _TclShellPutsReal
@@ -95,13 +97,13 @@ if {[info procs ::_TclShellEval] eq ""} {
set _TclShellOutput ""
# Special handling for variables.
- if {[string index $command 0] eq {$}} {
- set command "return $command"
+ if {[string index $tclcode 0] eq {$}} {
+ set tclcode "return $tclcode"
}
# Attempt to evaluate the Tcl code.
catch {
- uplevel 1 eval [list $command]
+ uplevel 1 eval [list $tclcode]
} result
# Write any held output to the TclShell buffer.
@@ -119,5 +121,6 @@ if {[info procs ::_TclShellEval] eq ""} {
rename _TclShellPutsReal puts
unset _TclShellOutput
}
+ # }}}
}
View
@@ -1,7 +1,7 @@
" vim:foldmethod=marker
" ============================================================================
" File: TclShell.vim (Autoload)
-" Last Changed: Sun Mar 18 12:17 AM 2012 EDT
+" Last Changed: Mon Mar 19 09:33 AM 2012 EDT
" Maintainer: Lorance Stinson AT Gmail...
" License: Public Domain
"
@@ -16,7 +16,7 @@ if exists("g:loadedTclShellAuto") || &cp || !has('tcl')
finish
endif
let g:loadedTclShellAuto= 1
-
+" }}}
" Defaults {{{1
@@ -60,36 +60,53 @@ let s:promptlen = len(s:prompttext)
" Start with no history.
let s:TclShellHistory=[]
let s:TclShellHistPtr=-1
-"}}}1
+" }}}
" Section: Functions.
" Function: TclShell#Eval(...) -- Evaluates Tcl Code. {{{1
function! TclShell#Eval(...) range
- " Note the current buffer in case a range was passed..
+ " Note the current buffer information if a range is passed.
let l:curbufnr = bufnr('%')
+ let l:lastline = line('$')
+ let l:fname = expand('%:p')
" Open the Tcl window.
call TclShell#OpenShell()
" Get the code to execute.
if a:0 != 0 && a:1 != ''
" Code was passed.
- let l:code = substitute(a:1, '[\r\n]*$', '', '')
+ call setline('$', getline('$') . a:1)
+ call TclShell#Exec()
+ elseif a:firstline == 1 && a:lastline == l:lastline
+ " Source the file.
+ call setline('$', getline('$') . 'source {' . l:fname . '}')
+ call TclShell#Exec()
else
" Process a range.
let l:lines = getbufline(l:curbufnr, a:firstline, a:lastline)
let l:code = join(l:lines, "\n")
- endif
- " Execute the Tcl code.
- execute 'tcl ::_TclShellEval {' . l:code . '}'
+ " Tell the user what we are doing.
+ let l:descr = '# Evaluating line'
+ if a:firstline == a:lastline
+ let l:descr .= ' ' . a:firstline
+ else
+ let l:descr .= 's ' . a:firstline . ' to ' . a:lastline
+ endif
+ let l:descr .= ' of file ' . l:fname
+ call setline('$', getline('$') . l:descr)
- " Redisplay the prompt.
- call TclShell#Prompt()
-endfunction
+ " Execute the Tcl code.
+ execute 'tcl ::_TclShellEval {' . l:code . '}'
+
+ " Redisplay the prompt.
+ call TclShell#Prompt()
+ endif
+endfunction " }}}
-" Function: TclShell#OpenShell(...) -- Create or switch to the Tcl Shell buffer. {{{1
+" Function: TclShell#OpenShell(...) -- Open the Tcl Shell buffer. {{{1
function! TclShell#OpenShell()
" If not already in the buffer create/open it.
if expand("%:p:t") != "_TclShell_"
@@ -114,7 +131,7 @@ function! TclShell#OpenShell()
setlocal noswapfile
call TclShell#Prompt()
endif
-endfunction
+endfunction " }}}
" Function: TclShell#Init() -- Initialize a new buffer. {{{1
function! TclShell#Init()
@@ -163,12 +180,12 @@ function! TclShell#Init()
\ s:prompttext . '" end=+$+ contains=@TclSyn'
exec "hi link TclShell Comment"
if g:TclShellInsert
- au BufEnter <buffer> startinsert!
+ autocmd BufEnter <buffer> startinsert!
endif
" Load the TCL code to execute Tcl Shell input.
execute ':tclfile ' . g:TclShellTclFile
-endfunction
+endfunction " }}}
" Function: TclShell#Prompt() -- Display the prompt. {{{1
function! TclShell#Prompt()
@@ -184,7 +201,7 @@ function! TclShell#Prompt()
startinsert!
endif
let s:TclShellHistPtr=-1
-endfunction
+endfunction " }}}
" Function: TclShell#Hist(dir) -- Move in the history. {{{1
" Move forward and back in history.
@@ -210,13 +227,13 @@ function! TclShell#Hist(dir)
if g:TclShellInsert
startinsert!
endif
-endfunction
+endfunction " }}}
" Function: TclShell#Clear() -- Clear the shell buffer. {{{1
function! TclShell#Clear()
normal ggdG
:call TclShell#Prompt()
-endfunction
+endfunction " }}}
" Function: TclShell#Exec() -- Execute a line of Tcl code. {{{1
function! TclShell#Exec()
@@ -228,7 +245,7 @@ function! TclShell#Exec()
let l:tclcode = substitute(l:line, s:prompttext, '', '')
if l:tclcode == ""
return TclShell#Prompt()
- elseif l:tclcode =~ "^clear\\>"
+ elseif l:tclcode =~ '^\s*clear\s*$'
return TclShell#Clear()
else
if g:TclShellHistMax
@@ -241,4 +258,4 @@ function! TclShell#Exec()
endif
call TclShell#Prompt()
endif
-endfunction
+endfunction " }}}
View
7 doc/TclShell.txt 100644 → 100755
@@ -1,6 +1,6 @@
*TclShell.txt* Tcl Shell for Vim
For Vim version 7.x.
- Last Changed: Sun Mar 18 12:14 AM 2012 EDT
+ Last Changed: Mon Mar 19 09:41 AM 2012 EDT
https://github.com/LStinson/TclShell-Vim
http://www.vim.org/scripts/script.php?script_id=3750
http://wiki.tcl.tk/28782
@@ -23,7 +23,7 @@ Creates a new buffer and window that resembles a shell. Tcl code can be
entered and is executed once Enter is pressed. The window has key mappings
that make it behave like a normal shell on a terminal.
-Note: Only one line of code can be entered. Once enter is pressed the code is
+Note: Only one line of code can be entered. Once Enter is pressed the code is
executed. You can still enter multiple statements separated by a
semicolon ';'.
@@ -49,8 +49,9 @@ Commands created for user use.
:TclEval
Opents the Tcl Shell window and evaluates TCL code.
- By default will evaluate the current file.
+ By default will source the current file.
Will operate on a range or visual selection.
+ Note: TclEval operates on whole lines only.
Tcl can be passed in, without quotes.
Examples: >
" Execute Tcl code.
View
@@ -1,6 +1,6 @@
-" =============================================================================
+" ============================================================================
" File: TclShell.vim (Plugin)
-" Last Changed: Sun Mar 18 12:15 AM 2012 EDT
+" Last Changed: Mon Mar 19 08:49 AM 2012 EDT
" Maintainer: Lorance Stinson AT Gmail...
" License: Public Domain
"
@@ -17,7 +17,7 @@
"
" Note: Can only enter one line of code.
" Pressing Enter executes the code.
-" =============================================================================
+" ============================================================================
if v:version < 700
echoerr 'TclShell requires Vim 7 or later.'
@@ -29,8 +29,7 @@ let g:loadedTclShell= 1
" End user commands.
command! TclShell :call TclShell#OpenShell()
-command! -nargs=? -range=% TclEval
- \ <line1>,<line2>call TclShell#Eval(<f-args>)
+command! -nargs=? -range=% TclEval <line1>,<line2>call TclShell#Eval(<f-args>)
" Default key map prefix.
if !exists("g:TclShellKey")

0 comments on commit 745bf43

Please sign in to comment.