From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.devel Subject: Re: Texinfo Mode: node-based movement functions. Date: Sat, 6 Nov 2004 15:04:07 +0000 (GMT) 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 1099753334 9449 80.91.229.6 (6 Nov 2004 15:02:14 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 6 Nov 2004 15:02:14 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Nov 06 16:02:01 2004 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1CQS4n-00030l-00 for ; Sat, 06 Nov 2004 16:02:01 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1CQSD2-000503-Fe for ged-emacs-devel@m.gmane.org; Sat, 06 Nov 2004 10:10:32 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1CQSCt-0004zO-PX for emacs-devel@gnu.org; Sat, 06 Nov 2004 10:10:23 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1CQSCt-0004yt-AC for emacs-devel@gnu.org; Sat, 06 Nov 2004 10:10:23 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1CQSCr-0004ym-VD for emacs-devel@gnu.org; Sat, 06 Nov 2004 10:10:23 -0500 Original-Received: from [193.149.49.134] (helo=acm.acm) by monty-python.gnu.org with esmtp (Exim 4.34) id 1CQS4S-0007X7-Jk for emacs-devel@gnu.org; Sat, 06 Nov 2004 10:01:41 -0500 Original-Received: from localhost (root@localhost) by acm.acm (8.8.8/8.8.8) with SMTP id PAA00442 for ; Sat, 6 Nov 2004 15:04:08 GMT X-Sender: root@acm.acm Original-To: emacs-devel@gnu.org In-Reply-To: X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:29479 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:29479 Sorry! I forgot to save the match data. Here's a corrected version of the code. On Sat, 6 Nov 2004, Alan Mackenzie wrote: >Hi, Emacs! > >In Texinfo Mode we have functions for moving to the beginning and end of >a "page" (i.e. a @chapter) and for narrowing to a @chapter (together with >its @sections). > >I think there should also be functions for moving to the beginning and >end of an individual @node, and for narrowing to it. "Obviously", a >@node in a file.texi is analogous to a defun in a file.el. So the >natural key bindings are C-M-a, C-M-e, and C-x n d. > >The following code is a first shot at implementing this functionality. >It is currently not bullet proof - in particular, it doesn't take account >of @ignore commands. That would not, however, be hard to remedy. > >Should I develop this into a production quality patch, complete with an >amendment to texinfo.txi, ChangeLog entry, etc.? Corrected code: ######################################################################## (defconst acm-texinfo-node-start "^@node .") (defun acm-texinfo-beginning-of-node (&optional count) "Move backward to the beginning of a node. With COUNT, do it that many times. A negative COUNT will move forward. A node starts at the \"@node\" command." (interactive "p") (if (< count 0) (acm-texinfo-end-of-node (- count)) (save-match-data (unless (bolp) (end-of-line)) ; in case we're already inside "@node" (search-backward-regexp acm-texinfo-node-start nil 'limit count)))) (defun acm-texinfo-end-of-node (&optional count) "Move forward to the end of the current node. With COUNT, do it that many times. A negative COUNT will move backwards. The end of a node is the \"@node\" which begins the next node or EOF." (interactive "p") (if (< count 0) (acm-texinfo-beginning-of-node (- count)) (save-match-data (end-of-line) ; to make sure we move. (search-forward-regexp acm-texinfo-node-start nil 'limit count) (beginning-of-line)))) (defun acm-texinfo-narrow-to-node () "Make the text outside the current node invisible. This node is the one that contains point or follows point." (interactive) (widen) (save-excursion (save-match-data (let ((start (progn (end-of-line) (search-backward-regexp acm-texinfo-node-start nil 'limit) (point)))) (end-of-line) (if (search-forward-regexp acm-texinfo-node-start nil 'limit) (beginning-of-line)) (narrow-to-region start (point)))))) (eval-after-load "texinfo" '(progn (define-key texinfo-mode-map "\C-\M-a" 'acm-texinfo-beginning-of-node) (define-key texinfo-mode-map "\C-\M-e" 'acm-texinfo-end-of-node) (define-key texinfo-mode-map "\C-xnd" 'acm-texinfo-narrow-to-node))) ######################################################################### -- Alan Mackenzie (Munich, Germany)