branch: elpa/adoc-mode
commit 11f0428adc05a0b96ed283499cf307cd6c6619fc
Author: Bozhidar Batsov <[email protected]>
Commit: Bozhidar Batsov <[email protected]>
[Fix #52] Prevent auto-fill from breaking section titles
Add adoc-fill-nobreak-p as a fill-nobreak-predicate that returns
non-nil on lines starting with = (section titles), preventing
auto-fill-mode from inserting line breaks in them.
---
CHANGELOG.md | 1 +
adoc-mode.el | 13 +++++++++++++
2 files changed, 14 insertions(+)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7d2815c89d..9ceb4ed759 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -26,6 +26,7 @@
- Fix duplicate `face` key in `adoc-kw-delimited-block` plist.
- [#57](https://github.com/bbatsov/adoc-mode/issues/57): Fix Emacs hang on
escaped curly braces in attribute reference regex.
- [#54](https://github.com/bbatsov/adoc-mode/issues/54): Fix multiline
font-lock for inline formatting by extending fontification region to paragraph
boundaries.
+- [#52](https://github.com/bbatsov/adoc-mode/issues/52): Prevent
`auto-fill-mode` from breaking section title lines.
## 0.7.0 (2023-03-09)
diff --git a/adoc-mode.el b/adoc-mode.el
index 670c51f124..a20df38ca8 100644
--- a/adoc-mode.el
+++ b/adoc-mode.el
@@ -3769,6 +3769,9 @@ Turning on Adoc mode runs the normal hook
`adoc-mode-hook'."
(skip-chars-forward "=")
(current-column))))
+ ;; fill
+ (add-hook 'fill-nobreak-predicate #'adoc-fill-nobreak-p nil t)
+
;; misc
(setq-local page-delimiter "^<<<+$")
(setq-local require-final-newline mode-require-final-newline)
@@ -3797,6 +3800,16 @@ Turning on Adoc mode runs the normal hook
`adoc-mode-hook'."
(adoc-calc)
+;; Auto-fill
+
+(defun adoc-fill-nobreak-p ()
+ "Return non-nil if the current line is a section title.
+Used as a `fill-nobreak-predicate' to prevent `auto-fill-mode'
+from breaking section title lines."
+ (save-excursion
+ (beginning-of-line)
+ (looking-at-p "=\\{1,6\\}[ \t]")))
+
;; Flyspell
(defun adoc-flyspell-p ()