From: Lars Ingebrigtsen Date: Sun, 7 Nov 2021 22:57:04 +0000 (+0100) Subject: Allow 'C-x n d' to work in texinfo-mode X-Git-Tag: emacs-29.0.90~3671^2~92 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=5f70682d7b8a3550bf6b9366329ad3418ab0a95f;p=emacs.git 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. --- 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