[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 5f70682 3/3: Allow 'C-x n d' to work in texinfo-mode
From: |
Lars Ingebrigtsen |
Subject: |
master 5f70682 3/3: Allow 'C-x n d' to work in texinfo-mode |
Date: |
Sun, 7 Nov 2021 17:57:14 -0500 (EST) |
branch: master
commit 5f70682d7b8a3550bf6b9366329ad3418ab0a95f
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>
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 7c7615a..530634e 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 3ddd904..71db33b 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