unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Texinfo Mode:  node-based movement functions.
@ 2004-11-06 12:40 Alan Mackenzie
  2004-11-06 15:04 ` Alan Mackenzie
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Alan Mackenzie @ 2004-11-06 12:40 UTC (permalink / raw)


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 "^@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))
    (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)

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2004-11-09 11:14 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-11-06 12:40 Texinfo Mode: node-based movement functions Alan Mackenzie
2004-11-06 15:04 ` Alan Mackenzie
2004-11-06 21:52 ` Robert J. Chassell
2004-11-07 13:55   ` Alan Mackenzie
2004-11-07 23:52     ` Robert J. Chassell
2004-11-07  3:37 ` Richard Stallman
2004-11-08 14:47 ` Stefan
2004-11-08 20:09   ` Alan Mackenzie
2004-11-08 22:40     ` Stefan Monnier
2004-11-09 11:14   ` Richard Stallman

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).