emacs-devel
[Top][All Lists]
Advanced

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

Texinfo Mode: node-based movement functions.


From: Alan Mackenzie
Subject: Texinfo Mode: node-based movement functions.
Date: Sat, 6 Nov 2004 12:40:21 +0000 (GMT)

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.?

########################################################################
(defconst acm-texinfo-node-start "address@hidden .")
(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))
    (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))
    (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
    (let ((start
           (progn
             (unless (looking-at acm-texinfo-node-start)
               (end-of-line)
               (search-backward-regexp acm-texinfo-node-start nil 'limit))
             (point))))
      (end-of-line)
      (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)






reply via email to

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