From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Jambunathan K Newsgroups: gmane.emacs.help Subject: Re: Emacs programming question Date: Fri, 05 Oct 2012 14:41:19 +0530 Message-ID: <87txu9nv0o.fsf@gmail.com> References: <506E51AB.6020204@cs.wisc.edu> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1349428217 20602 80.91.229.3 (5 Oct 2012 09:10:17 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 5 Oct 2012 09:10:17 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Evan Driscoll Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Oct 05 11:10:23 2012 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1TK3vH-00018h-Sc for geh-help-gnu-emacs@m.gmane.org; Fri, 05 Oct 2012 11:10:20 +0200 Original-Received: from localhost ([::1]:35840 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TK3vB-0000ky-3E for geh-help-gnu-emacs@m.gmane.org; Fri, 05 Oct 2012 05:10:13 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:47712) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TK3ux-0000fN-0j for help-gnu-emacs@gnu.org; Fri, 05 Oct 2012 05:10:05 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TK3us-000151-Hd for help-gnu-emacs@gnu.org; Fri, 05 Oct 2012 05:09:58 -0400 Original-Received: from mail-pb0-f41.google.com ([209.85.160.41]:56525) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TK3us-00014i-5d for help-gnu-emacs@gnu.org; Fri, 05 Oct 2012 05:09:54 -0400 Original-Received: by mail-pb0-f41.google.com with SMTP id rq2so1784728pbb.0 for ; Fri, 05 Oct 2012 02:09:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-type; bh=NdsHyM8SlnO6jFNCtS3Su0E63UIzZNaazMuC8dLXO7Q=; b=Tzj6w2v+VXGF+gQEUhZ0IRMXnvuvRAyjHTspM152V9NZfXfCus3aRShexrhmU2Gjki lOaoVmS155kMC/mUNof1uoSXzdh9kj3wCqy4aDUZJnzNMF3tUQ4+kIpoQWStPAe0Qa1I 61YAD0XRdI79T2tIf0m2dDQw+0FEfsh8QPVyHkx+IpiAKjpBoDF/e2gNBV7cmrJKgVpE Kbp3icp77tV5zNtyI/C74GvAo/ePFtt4BKlI6v27FQRBYiAd+znJU7NeziHa27wK/tME 1v1JpYLpB2zq3dApmKk73nYpPyPyyFwglguJN9ogNpwhyEGSXz/ShPlGFrm4NWrzFm5e utCg== Original-Received: by 10.68.190.233 with SMTP id gt9mr28723985pbc.137.1349428192809; Fri, 05 Oct 2012 02:09:52 -0700 (PDT) Original-Received: from debian-6.05 ([115.241.37.112]) by mx.google.com with ESMTPS id it5sm5782000pbc.10.2012.10.05.02.09.49 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 05 Oct 2012 02:09:52 -0700 (PDT) In-Reply-To: <506E51AB.6020204@cs.wisc.edu> (Evan Driscoll's message of "Thu, 04 Oct 2012 22:19:07 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.160.41 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 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 Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:87076 Archived-At: Consult the Elisp manual: Look at buffer-* APIs that convert a buffer to a string. (info "(elisp) Buffer Contents") Look at with with-*-buffer APIs in (info "(elisp) Current Buffer") You can also look at text properties that hide portions of text. (info "(elisp) Invisible Text") Or you just want to narrow to a region. (info "(elisp) Narrowing") Or you want some sort of composition (Search for compose etc in the manuals) One or more of the above things should suffice to accomplish the task at hand. Evan Driscoll writes: > Hi, > > I want to write an emacs mode to display a particular type of > file. However, the way I'd like to display the file isn't the literal > text contents in the file, but rather a (text) rendering of parts of > the information contained within. Unfortunately, I don't know any > modes that do something comparable; the closest ones I can think of > are what you get if you load an image. As a postscript I've included a > fairly wordy description of what I'm trying to do to set some context; > It's step (2) in that description that I foresee the most problems > with. > > What I want is something to the effect of opening the file normally > but then (1) saving the contents of the buffer into a lisp variable, > (2) clearing the buffer, (3) inserting into the buffer some computed > contents from step (1). (Fortunately, I can set the buffer to > read-only for my purposes and I don't have to worry about user edits > to it.) > > The programming reference talks about functions for visiting a file > and also inserting the contents of a file into a buffer without > visiting it (insert-file-contents), but neither of these are what I > want, really. > > Evan > > > > > What I want to do: > > Before starting, let me say that I'm not so interested in catching > lots of edge cases; something that will work for the common case is > good enough. (In case it's not clear from the following, this is going > to be a debugging aid to help trace back incorrect output to the point > in the code that created it. And don't say that point may not be where > a write(2) call is actually finally made because of buffering, because > I know, and if that's a problem in practice I'll fix it. :-) But the > emacs part can remain unchanged.) > > I have a program which will run another program under ptrace and each > time it makes a write(2) system call, will record information > consisting of (1) the size of the write, (2) the target "file" name > (could be /dev/pts/blah), (3) the offset in that file (or that it is > appended if the file is unseekable), (4) a stack trace of the program > (file/line, via debugging information). In addition, assume the actual > data of the write is available either in a separate file or in the > trace file. (I'm flexible on this point, and can pick whichever makes > things easier. I think that may mean putting the data into the trace > file.) Call the information for each write(2) call a "chunk". > > I want some functions (perhaps a whole mode?) that will load a trace > file in emacs and do the following: > > 1. Let the user choose a file of interest, and ignore the parts of the > trace not pertaining to that file. (If it would make things simpler, I > could preprocess the trace to extract the information for each file > separately.) > > 2. Reconstruct the final state of that file, displaying it to the user > in the "data" buffer. If the trace file and file contents are loaded > separately this is just loading the file. If the data is in the trace > file itself, this will mean looking at the data for each chunk and > putting the data at the appropriate place in the buffer. Set that > buffer read-only. > > 3. Open a new buffer in another window. As the user moves the point > around that buffer, find the chunk that corresponds to the (last) time > the byte under the point was written. Grab the stack trace from that > chunk, and display it in this other buffer. (Call it the "stack trace > buffer.") > > 4. If the user selects a file/line in the stack trace buffer, open the > corresponding file and navigate to that line. > > 5. Ideally, add some styling to the data buffer to show where the > chunk boundaries are, e.g. alternate between two different faces. > > --