Make paragraph/filling functions in texinfo-mode work better

* lisp/textmodes/texinfo.el (texinfo-mode): Make paragraph
definitions more traditional.  This makes (forward-paragraph 1)
behave better.
(texinfo-mode): Set a new filling function.
(texinfo--fill-paragraph): New filling function.
(texinfo-fillable-commands): New variable (bug#49558).
This commit is contained in:
Lars Ingebrigtsen 2021-11-07 23:47:47 +01:00
parent 67276f3403
commit dde591571a
3 changed files with 142 additions and 3 deletions

View file

@ -411,11 +411,9 @@ value of `texinfo-mode-hook'."
"\\)\\>"))
(setq-local require-final-newline mode-require-final-newline)
(setq-local indent-tabs-mode nil)
(setq-local paragraph-separate
(concat "@[a-zA-Z]*[ \n]\\|"
paragraph-separate))
(setq-local paragraph-start (concat "@[a-zA-Z]*[ \n]\\|"
paragraph-start))
(setq-local fill-paragraph-function 'texinfo--fill-paragraph)
(setq-local sentence-end-base "\\(@\\(end\\)?dots{}\\|[.?!]\\)[]\"'”)}]*")
(setq-local fill-column 70)
(setq-local comment-start "@c ")
@ -457,6 +455,44 @@ value of `texinfo-mode-hook'."
prevent-filling
(concat auto-fill-inhibit-regexp "\\|" prevent-filling)))))
(defvar texinfo-fillable-commands '("@noindent")
"A list of commands that can be filled.")
(defun texinfo--fill-paragraph (justify)
"Function to fill a paragraph in `texinfo-mode'."
(let ((command-re "\\(@[a-zA-Z]+\\)[ \t\n]"))
(catch 'no-fill
(save-restriction
;; First check whether we're on a command line that can be
;; filled by itself.
(or
(save-excursion
(beginning-of-line)
(when (looking-at command-re)
(let ((command (match-string 1)))
(if (member command texinfo-fillable-commands)
(progn
(narrow-to-region (point) (progn (forward-line 1) (point)))
t)
(throw 'no-fill nil)))))
;; We're not on such a line, so fill the region.
(save-excursion
(let ((regexp (concat command-re "\\|^[ \t]*$\\|\f")))
(narrow-to-region
(if (re-search-backward regexp nil t)
(progn
(forward-line 1)
(point))
(point-min))
(if (re-search-forward regexp nil t)
(match-beginning 0)
(point-max)))
(goto-char (point-min)))))
;; We've now narrowed to the region we want to fill.
(let ((fill-paragraph-function nil)
(adaptive-fill-mode nil))
(fill-paragraph justify))))
t))
;;; Insert string commands

View file

@ -0,0 +1,70 @@
Code:
(lambda ()
(texinfo-mode)
(fill-paragraph))
Name: fill1
Point-Char: |
=-=
@noindent Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
=-=
@noindent Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
=-=-=
Name: fill2
Point-Char: |
=-=
@cindex relative| remapping, faces
@cindex base remapping, faces
The following functions implement a higher-level interface to @code{face-remapping-alist}.
=-=-=
Name: fill3
Point-Char: |
=-=
@cindex relative remapping, faces
@cindex base remapping, faces|
The following functions implement a higher-level interface to @code{face-remapping-alist}.
=-=-=
Name: fill4
Point-Char: |
=-=
@cindex relative remapping, faces
@cindex base remapping, faces
The following functions| implement a higher-level interface to @code{face-remapping-alist}.
=-=
@cindex relative remapping, faces
@cindex base remapping, faces
The following functions| implement a higher-level interface to
@code{face-remapping-alist}.
=-=-=
Name: fill5
Point-Char: |
=-=
@defun face-remap-add-relative face &rest specs
|This function adds the face spec in @var{specs} as relative
remappings for face @var{face} in the current buffer. The remaining
arguments, @var{specs}, should form either a list of face names, or a
property list of attribute/value pairs.
=-=
@defun face-remap-add-relative face &rest specs
This function adds the face spec in @var{specs} as relative remappings
for face @var{face} in the current buffer. The remaining arguments,
@var{specs}, should form either a list of face names, or a property
list of attribute/value pairs.
=-=-=
Name: fill6
=-=
@subsection This is a very very very very very very very very very very long subsection name
=-=-=

View file

@ -0,0 +1,33 @@
;;; texinfo-tests.el --- Tests for texinfo.el -*- lexical-binding: t; -*-
;; Copyright (C) 2021 Free Software Foundation, Inc.
;; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;;
;;; Code:
(require 'texinfo)
(require 'ert)
(require 'ert-x)
(ert-deftest test-filling ()
(ert-test-erts-file (ert-resource-file "fill.erts")))
;;; texinfo-tests.el ends here