From 5f70682d7b8a3550bf6b9366329ad3418ab0a95f Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Sun, 7 Nov 2021 23:57:04 +0100 Subject: [PATCH] Allow 'C-x n d' to work in texinfo-mode * lisp/textmodes/texinfo.el (texinfo-mode): Set beginning/end-of-defun functions to allow narrowing to the current node. (texinfo--beginning-of-defun, texinfo--end-of-defun): New functions. --- etc/NEWS | 6 ++++++ lisp/textmodes/texinfo.el | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/etc/NEWS b/etc/NEWS index 7c7615a7db6..530634eabc0 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -222,6 +222,12 @@ If non-nil, 'C-c C-a' will put attached files at the end of the message. --- *** HTML Mode now supports text/html and image/* yanking. +** Texinfo Mode + +--- +*** 'texinfo-mode' now has a specialised 'narrow-to-defun' definition. +It narrows to the current node. + ** eww +++ diff --git a/lisp/textmodes/texinfo.el b/lisp/textmodes/texinfo.el index 3ddd9040657..71db33bae35 100644 --- a/lisp/textmodes/texinfo.el +++ b/lisp/textmodes/texinfo.el @@ -416,6 +416,8 @@ value of `texinfo-mode-hook'." (setq-local fill-paragraph-function 'texinfo--fill-paragraph) (setq-local sentence-end-base "\\(@\\(end\\)?dots{}\\|[.?!]\\)[]\"'”)}]*") (setq-local fill-column 70) + (setq-local beginning-of-defun-function #'texinfo--beginning-of-defun) + (setq-local end-of-defun-function #'texinfo--end-of-defun) (setq-local comment-start "@c ") (setq-local comment-start-skip "@c +\\|@comment +") (setq-local words-include-escapes t) @@ -494,6 +496,20 @@ value of `texinfo-mode-hook'." (fill-paragraph justify)))) t)) +(defun texinfo--beginning-of-defun (&optional arg) + "Go to the previous @node line." + (while (and (> arg 0) + (re-search-backward "^@node " nil t)) + (setq arg (1- arg)))) + +(defun texinfo--end-of-defun () + "Go to the start of the next @node line." + (when (looking-at-p "@node") + (forward-line)) + (if (re-search-forward "^@node " nil t) + (goto-char (match-beginning 0)) + (goto-char (point-max)))) + ;;; Insert string commands -- 2.39.2