speechd-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

OT: Actually Implementing the Email Ideas, Trying to Learn Elisp (Was: M


From: Veli-Pekka Tätilä
Subject: OT: Actually Implementing the Email Ideas, Trying to Learn Elisp (Was: Mode for Speechd-el Quoting)
Date: Sat, 23 Aug 2008 23:17:34 +0300

Hi, I've been pondering my e-mail idea I recently posted here, and it would 
be easy to implement. To test out some things related to it, I coded some 
core functionality in Lua. Now the hardest part is learning enough Elisp and 
understanding enough Emacs, to be able to do a new major mode for e-mail 
re-quoting, navigation an deletion as described in my original post. I guess 
this is pretty much OT, though, so appologies in advance, I'll try to stay 
more on topic in the future.

My NMTP server doesn't carry gnu.emacs but using a free server I found in an 
on-line DB, seems to show that there's not much traffic there. Otherwise 
that group would be the ideal media to post this in.

My question here would be, is there a middle ground between macroes and good 
old Elisp hacking? Can I, for example, turn macroes into lisp code and only 
add some conditions and loops as needed?

At this point the biggest hurdles are:

* trying to tolerate the Lisp syntax and learn the basics, I've seen 
functional stuff that's so much more speech readable, yuck. The only major 
advantage I can think of is viewing code as lists, many script langs have 
other bits of the functional stuff like closures and tailcalls (Lua for 
instance).

* easily getting the names of functions Emacs calls when I hit a key, maybe 
put them in the kill ring directly.

* fancier operations such as temporarily setting the fill prefix, word wrap 
column etc..., doing some prefix filling and getting back to normal again.

* How to do major or minor modes, or modify an existing one

Are there short tutorials that would only let me know the bare minimum to 
get a thing like this done? I still have a similar attitude to LIsp than I 
have with Python, heavily disliking its syntax compared to Ruby and Lua.

Obviously there's a lot to learn still.

IS there anything that would make the Lisp syntax more nicer to listen to? A 
friend of mine suggested pauses between list items and in stead of reading 
parentheses, mapping the nesting level to musical pitch, in a user definable 
scale with a monotone intonation. That let us into thinking Lisp songs 
analogously with Perl poetry.

When I think of how to achieve things in Emacs I think in terms of keyboard 
commands, that are actually interactive functions bound to them. To kill a 
region that's well defined by a regexp and some cursoring in lines, however, 
would require that the macro can pause and check for a condition before it 
does a deletion. The same thing applise to jumps when you consider 
navigation. It would be far easier for me to work mostly with macroes and do 
a minimum of actual lisp coding at this point, bad laziness! Obviously, no 
conditionals are doable in macroes - I've read that section of the Emacs 
manual.

As to why Lua, well, Lisp is horibly speech readable compared to it, and I 
thought Lua would be a simple enough language, compared to Perl, to 
demonstrate the ideas.

First of all, consider getting the quote level and index of unquoted text, 
given an array of lines. It is just a matter of counting how many regexp 
matches for a quote regexp you can do where the previous succesful search 
left off. In Lua. Find here is a  method returning the indeces of a match 
given a regexp:

function QuoteLevelFor(line)
   local quote_level, search_pos = 0, 1 -- indeces are 1-based in Lua.
   while true do
      starting, ending = line:find("^>%s?", search_pos) -- % is like \
      if not starting then return quote_level, search_pos end
      quote_level, search_pos  = quote_level + 1, ending + 1
end end

Then to navigate to a particular quoting level, you just scan the lines 
forward or back, until there are no more lines or the above quote level 
function reports that the line we found has the desired quoting level. 
Here's the forward search, returning nil on failure:

function FirstLineOfLevel(level, lines, number)
   for i = number, # lines do -- # means length.
      if QuoteLevelFor(lines[i]) == level then return i end
end end

Then for killing stuff quickly, one has to identify a branch of quotes in a 
discussion I decided to call a fibre. The following function finds a fibre 
boundary so calling it twice, continuing where it left off and making sure 
to skip level 0 quotes, should do the trick in most cases. The idea is that 
you identify the end of the current fibre by looking for either a level 0 
quote, or when encountering a quote level larger than the smallest so far, 
indicating a quote from another fibre. Here we go:

function NextFibre(lines, number)
   local previous = QuoteLevelFor( lines[number] )
   if previous == 0 then return end
   for i = number + 1, # lines do
      local current = QuoteLevelFor( lines[i] )
      if current == 0 or current > previous then return number, i - 1 end
      previous = current
   end
   return number, # lines
end

I also did some code to do word wrapping and prefix filling but I'm leaving 
it out here, since Emacs probably already does it much better than I do, and 
there's no point reinventing the wheel. One final bit of code could be used 
to unquote mail before rewrapping and filling. Since I already had a 
function for finding the index of unquoted text, this is just a substring 
operation:

function StripQuotesFrom(line)
   local quote_level, unquoted_start = QuoteLevelFor(line)
   return quote_level == 0 and line or  line:sub(unquoted_start)
end

Of course, porting this thing and expanding it using lisp should be easier 
than coding in LUa, if I knew it. That is, you have commands for moving 
lines directly rather than having to go and index an array (actually a hash 
in Lua, everything is a hash). You can also probably go through all regexp 
matches quite easily, and regexp search backwards which even Perl cannot do.

PS: In a way I do find the Emacs keyboard notation mnemonic. I think of it 
as words spoken by a speech synth:
Consider C-x C-c: it is something like "see ex see see" to me, only then do 
I translate to the actual key strokes. Far easier to recall as words than 
control+x control+c. To press it I just let my left forefinger slide from x 
to c while using the pinky for meta, so it is more like a sweep, too, neat.v

-- 
With kind regards Veli-Pekka T?til?
Accessibility, Apps and Coding plus Synths and Music:
http://vtatila.kapsi.fi




reply via email to

[Prev in Thread] Current Thread [Next in Thread]