Sometimes I have one file embedded in another and would like to
see an option or ability in vim to auto detect (?*somehow*?) the
change in syntax.
Examples: one I encounter in other code, often, is HTML, that often
includes other types of embedded 'code' (like 'css', 'javascript', even
other script languages) where really, the syntax rules could often,
_usefully_, be dynamically reset for the appropriate section.
Another I run into VERY often, by my own creation, are little
"proglets", that usually start as 1-liners developed via re-edits
of one line that add filtering code written in another language.
These *aren't* stored in files, but are simply typed lines that represent
a chain of commands to do 1 thing. Then then, usually, due to an error in
the filter code, or a recognition that I might want to actually save the
'1-liner'. And NOTE, when I say 1-liner, I really am talking about a
1-liner that is literally, throw-away code. I.e. code that that was
only intended for use in my current session, that wouldn't even be saved
in a file (I was just using the bash "re-edit previous line feature" -- then I
hit 'return, execute, and then re-edit previous line". So it wouldn't ever
be seen by anyone else, or even myself at some later time (beyond the
current session's edit-exec-re-edit cycle -- so brevity is usually the
highest priority.
When using 'bash' to re-edit a line, I start out using the 'in-line' vi
editor, that allows you to edit the previous line. So everything is on
one-line (another reason brevity is key. So the expanded proglet, shown
below (with comments, even) started out looking something like this
(prepared to be scared and/or confused if you don't know shell & perl
syntax):
for ((i=1;i<=10;++i)); do time dd if=/dev/zero of=bigfile bs=256M count=1
flag=direct;done 2>&1 |pcregrep 'bytes'|tee /dev/tty|perl
-e'$l=0;$m=999999999.9;$t=0.0;while(<>){/^(\d+)\s.*copied,\s([\d\.]+)\ss/&&do{$t=$2+0.0;$l=$1;if($t<$m){$m=$t;}};}printf
"mt=%f,sz=%d,rt=%f\n",$t,$l,$l/$t;'
At that point, I got some error in in the perl part one on "line 1" and
needed to expand the perl code to multiple lines to figure where the error
was -- still didn't need to save it to a file, at that point, so short
var names were still there and no comments. I just broke up the lines
at the semicolons, initially -- no tabbing. Bash'es next level of line
re-editing is to re-edit the previous line and hit 'v', to run the _v_isual
editor of your choice on the line. Of course at that point, I'm seeing
my single line of code in vim, where I proceed to break statements into
lines using ":s/;/;^M/g". I write that out (it writes it to a bash created
tmp file -- bash transparently handles(interprets) embedded 'newlines' as
spaces for it's purposes -- but when the perl program is passed to the
interpreter, now can see the error is on "line 10", re-edit, go back into
my 'v'isual editor and go down to the first line containing the single
quote after my "perl -e", then go down X-1 (9) lines and I'd be on
the correct line.
After any length of time editing/re-editing I might decide I want to store
the scriplet as a proglet -- so I'll expand the variables to something that'll
remind me what they are for, may add a comment if needed (in the below I
added more just to explain to reading public a bit more about what it is
doing -- since I know bash and perl scripting fairly well, I wouldn't bother
for myself or other similarly knowledgeable folk -- as still, it's not really
meant to be a "published program" -- just a "proglet" designed for a single
purpose. (I'm emphasizing differences here only from the standpoint that
I use different standards of coding for different purposes, that's all,
sorry for the extra verbiage about what's common knowledge for those that it
is :-).
Anyway -- the REAL point of the original subject continues after
the actual code. I felt I needed to explain how got from not really caring
about 'vim syntax' to a point where vim syntax, with a need for 'variable
'vim syntax' within the same file, would be a useful feature.
The above scriptlet, formatted, with more than normal comments, saved to
a file look as follows:
Code:
----------
#!/bin/bash
# proglet 'meas.sh'
#
# run dd write loop 10 times, filter output only for the summary line
# containing word 'bytes'; filter(echo) it to the terminal, as well as
# passing it to the perl program that reads the output and eventually
# shows me the fastest speed of the 100 lines.
#
for ((i=1;i<=10;++i)); do
time dd if=/dev/zero of=bigfile bs=256M count=1 oflag=direct 2>&1 | \
pcregrep 'bytes'
done | tee /dev/tty \ | \
perl -e '
# input lines should look like:
# 268435456 bytes (268 MB) copied, 1.84251 s, 146 MB/s
my $len=0;
my $min=9999999999.9 ;
my $count=0;
my $time=0.0;
while (<>) {
++$count;
/^(\d+)\s.*copied,\s([\d\.]+)\ss/ && do {
$time=$2+0.0;
$len=$1;
if ($time<$min) {
$min=$time;
}
};
}
print "$count iterations: ";
if ($time) {
printf "mintime=%f, sz=%d, rate=%f\n", $time, $len, $len/$time;
} else {
printf "mintime=%f, sz=%d\n", $time, $len;
}
'
--------------
Under normal vim's "syntax=sh" coloring rules, all of the
perl code is treated is a 'string constant'.
It would be *VERY* excellent, if this could be enhanced with a
'sub syntax detection', they could automatically activate the correct syntax
for the delineated subsection.
Remember -- this wouldn't necessarily apply (if it was automatically
working/implemented across all
I'd love to see the perl portion, even if it were a
requirement to have a "#!/usr/bin/perl" on a line by itself
after the comment (though that wouldn't work for 'css' and such
embedded in html), colored with perl syntax, rather than all in
the mono-color of a literal.
Would definitely be an toggle-able option, since one might
still want to see such sections as strings. But I suppose this
might also be implemented (or only available) on a per-language
basis, as not all syntaxes would have the possibility of other,
embeddable syntaxes...
Thanks!
linda
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---