From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Phillip Lord Newsgroups: gmane.emacs.help Subject: Re: A couple of lisp questions Date: 12 Nov 2003 16:29:15 +0000 Organization: Dept of Computer Science, University of Manchester, U.K. Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: References: NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1068663141 24194 80.91.224.253 (12 Nov 2003 18:52:21 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 12 Nov 2003 18:52:21 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Nov 12 19:52:17 2003 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1AK06D-0004YL-00 for ; Wed, 12 Nov 2003 19:52:17 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.24) id 1AK13L-0001sJ-AF for geh-help-gnu-emacs@m.gmane.org; Wed, 12 Nov 2003 14:53:23 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.stueberl.de!solnet.ch!solnet.ch!news.imp.ch!news.imp.ch!zen.net.uk!130.88.203.18.MISMATCH!peernews.mcc.ac.uk!cs.man.ac.uk!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 105 Original-NNTP-Posting-Host: rpc71.cs.man.ac.uk Original-X-Trace: wapping.cs.man.ac.uk 1068654555 11655 130.88.198.228 (12 Nov 2003 16:29:15 GMT) Original-X-Complaints-To: news@wapping.cs.man.ac.uk Original-NNTP-Posting-Date: Wed, 12 Nov 2003 16:29:15 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2.93 Original-Xref: shelby.stanford.edu gnu.emacs.help:118171 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:14111 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:14111 >>>>> "Stefan" == Stefan Monnier writes: >> First, I want to call a function everytime a new word has been >> typed into a buffer. The only way that I can think of doing this >> at the Stefan> As you can imagine there's no perfect answer here, since Stefan> words can be typed piecemeal, or backwards, or split into Stefan> two, or joined, or modified in some other way. So it's not Stefan> even clear what you mean by "everytime a new word has been Stefan> typed". This is the case. I've been thinking about this a bit more, and think I have a somewhat better solution, which is to move somewhat behind point, gathering words, and then mark them up with text properties to say that they have been found. >> This does not work in all cases, so better ideas would be >> welcome. Stefan> Take a look at how flyspell does it. Or maybe auto-fill. I will. I think auto-fill cheats though, as its tied directly in to the command loop. I seem to remember reading that somewhere. >> Second, my data structures are current using a hashtable, and a >> set of lists. The hashtable has a nice feature which is key/value >> weakness. I would really like to use this feature, but over an >> ordered list structure rather than a hash. As far as I can tell >> the only way I can use a weak reference is through the >> hashtable. There are no other weak data structures? >> Third, is there a good way of serializing hashtables, so that I >> can load them again next time from a file? To get my system to >> work I need multiple hashtables sharing the same objects not just >> objects with the same values, so its fairly complicated. Stefan> As you probably know, the answer to both is "no can do". Stefan> But if you provide more info about what you're trying to do Stefan> (rather than how you're trying to do it), maybe there's a Stefan> good answer that does not involve the usual "patches Stefan> welcome". I'm building up a dictionary of words used as the user types, along with word usage statistics. I have two hashes like so.... usage-hash: "the" --> ("the" . 4) "and" --> ("and" . 6) which records the usages of a specific word. Then a suffix hash suffix-hash: "t" --> (("the" . 4) ("then" . 3) ("talk" . 2) etc) "th" --> (("the" . 4) etc ) "the" --> (("the" . 4) etc ) which records suffixes of the words. In this case the cons cells for each word are shared between the hashes, so this is not a massive memory waste as the written version appears. Ideally I would want to build up these word usage statistics as they are typed, but as you say its hard to do this. I think a flyspell like approach combined with text properties should work okay. Anyway the idea with the weakness is that I want to garbage collect the dictionary periodically, throwing away old, or rarely used words. But currently I have to keep the two hashes in sync by hand. I was wondering whether it would be possible to use weakness to do this automatically. But the second of the two hashes has values which are in an alist, which would defeat this. I'm not sure that this is too much of a problem. The performance that I an getting from these data structures is fairly good. The serialization would be to enable saving across sessions. Most of the packages I know that do this depend on their objects having a read syntax, which doesn't work with hashes. I think the solution here is to convert the thing into a big alist to save it, and then reconstruct the hashes on loading. Anyway the idea for all of this was to do a nifty version of abbreviation expansion, something like dabbrev-expand, but instead of searching local buffers, it would grab word stats as its going, and use these to offer appropriate suggestions. I was thinking of a user interface a little bit like the buffer/file switching of ido.el, of which I have become a committed user. Its just an idea at the moment, with the basic data structures. As is the way, building an decent UI around this will probably take 10 times as much code! I think the chances are it will be to intrusive to be off any use for most users. But you never know till you try. Cheers Phil