]> git.eshelyaron.com Git - emacs.git/commitdiff
Allow 'C-x n d' to work in texinfo-mode
authorLars Ingebrigtsen <larsi@gnus.org>
Sun, 7 Nov 2021 22:57:04 +0000 (23:57 +0100)
committerLars Ingebrigtsen <larsi@gnus.org>
Sun, 7 Nov 2021 22:57:04 +0000 (23:57 +0100)
* 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
lisp/textmodes/texinfo.el

index 7c7615a7db6877289c2ab3f36526d315a0168ddb..530634eabc0c267aa25818fbbade5c5a2892fc8e 100644 (file)
--- 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
 
 +++
index 3ddd904065706cc398fc580145e6c52f7451078f..71db33bae35f7b9575645df4931e0d5ae678a061 100644 (file)
@@ -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))))
+
 \f
 ;;; Insert string commands