[TxMt] Latex grammar and snippet or command

Brad Miller bmiller at luther.edu
Sat Sep 22 19:51:17 UTC 2007


Alain,

Here is a command I wrote to run Python code that is in a lstlisting
environment.

Save: Nothing
Input: Selected Text or Scope
Output: show as tooltip
Scope: source.python
------------------------------------------------
#!/usr/bin/env python
import sys
import string


# find first non-blank line
# determine indent
# remove indent from rest of the lines.
# run the code using doctest

def allWhite(s):
    allWhite = True
    count = 0
    for ch in s:
        if ch not in string.whitespace:
            allWhite = False
            return count
        count += 1
    if allWhite == True:
        return -1

prog = sys.stdin.read()

lineList = prog.split('\n')
i = 0
nonWhite = allWhite(lineList[i])
while nonWhite < 0:
    i = i + 1
    nonWhite = allWhite(lineList[i])

for i in range(len(lineList)):
    lineList[i] = lineList[i][nonWhite:]

#print "<pre>"
#print "\n".join(lineList)
tester = """
def _test():
   import doctest
   doctest.testmod(verbose=True,optionflags=doctest.NORMALIZE_WHITESPACE)
_test()
"""
exec  "\n".join(lineList) + tester

#print "</pre>"
------------------------------------------------

-- 
Brad Miller
Assistant Professor, Computer Science
Luther College

On 9/22/07, Alain Matthes <alain.matthes at mac.com> wrote:
>
>
> Le 22 sept. 07 à 04:18, Charilaos Skiadas a écrit :
>
> > On Sep 21, 2007, at 7:01 PM, Alain Matthes wrote:
> >
> >> hello:)
> >>
> >> I would like to know if in a macro we can use the latex grammar to
> >> know for example if we are in an environment or in displaymath
> >> etc... to adapt the command to this situation ?
> >>
> > If I understand your question, then yes, that's what scope
> > selectors are for.
> >>
>
> Thanks the idea is "when i'm in an environment like pspicture or
> tikzpicture" to have a commmand to compile only the code between
>
> begin{tikzpicture}
> .....
> end{tikzpicture}
>
> I know that is possible with emacs and this is very useful if you
> works with emacs, idem for listings.
>
> Ruby is perhaps the best tool to make that like some examples in the
> LaTeX Bundle ? Perhaps you know an example more simple ?
>
> Regards  Alain
> ______________________________________________________________________
> For new threads USE THIS: textmate at lists.macromates.com
> (threading gets destroyed and the universe will collapse if you don't)
> http://lists.macromates.com/mailman/listinfo/textmate
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macromates.com/textmate/attachments/20070922/7bd6a9de/attachment.html>


More information about the textmate mailing list