emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/yaml-mode 67b8355 042/124: Merge pull request #21 from wen


From: ELPA Syncer
Subject: [nongnu] elpa/yaml-mode 67b8355 042/124: Merge pull request #21 from wentasah/fill-paragraph
Date: Sun, 29 Aug 2021 11:36:09 -0400 (EDT)

branch: elpa/yaml-mode
commit 67b8355c57549ad875b82c346aceb978311a267d
Merge: 210b075 4c1127c
Author: Yoshiki Kurihara <clouder@gmail.com>
Commit: Yoshiki Kurihara <clouder@gmail.com>

    Merge pull request #21 from wentasah/fill-paragraph
    
    Improve paragraph filling of block literals
---
 yaml-mode.el | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/yaml-mode.el b/yaml-mode.el
index d0c60a5..80dbdbe 100644
--- a/yaml-mode.el
+++ b/yaml-mode.el
@@ -222,6 +222,7 @@ that key is pressed to begin a block literal."
   (set (make-local-variable 'comment-start-skip) "#+ *")
   (set (make-local-variable 'indent-line-function) 'yaml-indent-line)
   (set (make-local-variable 'indent-tabs-mode) nil)
+  (set (make-local-variable 'fill-paragraph-function) 'yaml-fill-paragraph)
   (set (make-local-variable 'font-lock-defaults)
        '(yaml-font-lock-keywords
          nil nil nil nil
@@ -388,6 +389,46 @@ margin."
     (if (and (not arg) (looking-at yaml-document-delimiter-re))
         (delete-horizontal-space))))
 
+(defun yaml-narrow-to-block-literal ()
+  "Narrow the buffer to block literal if the point is in it,
+otherwise do nothing."
+  (interactive)
+  (save-excursion
+    (goto-char (point-at-bol))
+    (while (and (looking-at-p yaml-blank-line-re) (not (bobp)))
+      (forward-line -1))
+    (let ((nlines yaml-block-literal-search-lines)
+         (min-level (current-indentation))
+         beg)
+      (forward-line -1)
+      (while (and (/= nlines 0)
+                 (/= min-level 0)
+                 (not (looking-at-p yaml-block-literal-re))
+                 (not (bobp)))
+       (set 'nlines (1- nlines))
+       (unless (looking-at-p yaml-blank-line-re)
+         (set 'min-level (min min-level (current-indentation))))
+       (forward-line -1))
+      (when (and (< (current-indentation) min-level)
+                 (looking-at-p yaml-block-literal-re))
+       (set 'min-level (current-indentation))
+       (forward-line)
+       (setq beg (point))
+       (while (and (not (eobp))
+                   (or (looking-at-p yaml-blank-line-re)
+                       (> (current-indentation) min-level)))
+         (forward-line))
+       (narrow-to-region beg (point))))))
+
+(defun yaml-fill-paragraph (&optional justify region)
+  "Fill paragraph.
+This behaves as `fill-paragraph' except that filling does not
+cross boundaries of block literals."
+  (interactive "*P")
+  (save-restriction
+    (yaml-narrow-to-block-literal)
+    (let ((fill-paragraph-function nil))
+      (fill-paragraph justify region))))
 
 (defun yaml-set-imenu-generic-expression ()
   (make-local-variable 'imenu-generic-expression)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]