[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/yaml-mode 4c1127c 037/124: Improve paragraph filling of bl
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/yaml-mode 4c1127c 037/124: Improve paragraph filling of block literals |
Date: |
Sun, 29 Aug 2021 11:36:08 -0400 (EDT) |
branch: elpa/yaml-mode
commit 4c1127cce8625e8e187cea7d52eea9faaa9c22c0
Author: Michal Sojka <sojkam1@fel.cvut.cz>
Commit: Michal Sojka <sojkam1@fel.cvut.cz>
Improve paragraph filling of block literals
The functionality of this patch can be demonstrated on a small
example. Consider the YAML document below:
foo: >-
block
literal
bar:
When point is inside the "block literal", pressing M-q
(fill-paragraph) results in:
foo: >- block literal bar:
This is probably not what most users want. With this patch, the result
will look like in the following:
foo: >-
block literal
bar:
---
yaml-mode.el | 41 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
diff --git a/yaml-mode.el b/yaml-mode.el
index 33b059f..6f5864f 100644
--- a/yaml-mode.el
+++ b/yaml-mode.el
@@ -224,6 +224,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
@@ -390,6 +391,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)
- [nongnu] elpa/yaml-mode cf171f4 026/124: `checkdoc' nits (including the `checkdoc-autoload' extension)., (continued)
- [nongnu] elpa/yaml-mode cf171f4 026/124: `checkdoc' nits (including the `checkdoc-autoload' extension)., ELPA Syncer, 2021/08/29
- [nongnu] elpa/yaml-mode e2befd8 027/124: Merge pull request #7 from SamB/master, ELPA Syncer, 2021/08/29
- [nongnu] elpa/yaml-mode 6d40a1d 033/124: resolved conflict, ELPA Syncer, 2021/08/29
- [nongnu] elpa/yaml-mode d1b8be6 039/124: Merge pull request #23 from Wilfred/master, ELPA Syncer, 2021/08/29
- [nongnu] elpa/yaml-mode 11df403 044/124: Merge pull request #30 from rhoml/enable-eyaml, ELPA Syncer, 2021/08/29
- [nongnu] elpa/yaml-mode 85d5c63 050/124: allow dash-newline to start a sequence, ELPA Syncer, 2021/08/29
- [nongnu] elpa/yaml-mode 6590b19 060/124: add copy of GPLv2, ELPA Syncer, 2021/08/29
- [nongnu] elpa/yaml-mode 4ae92a7 062/124: Define keymap and syntax table properly, ELPA Syncer, 2021/08/29
- [nongnu] elpa/yaml-mode c757396 066/124: Remove unnecessary refontification, ELPA Syncer, 2021/08/29
- [nongnu] elpa/yaml-mode 44f73b6 017/124: Add autoload comments., ELPA Syncer, 2021/08/29
- [nongnu] elpa/yaml-mode 4c1127c 037/124: Improve paragraph filling of block literals,
ELPA Syncer <=
- [nongnu] elpa/yaml-mode d88c80a 053/124: allow spaces before dash-newline, ELPA Syncer, 2021/08/29
- [nongnu] elpa/yaml-mode 4e69e6e 059/124: update address for FSF, ELPA Syncer, 2021/08/29
- [nongnu] elpa/yaml-mode a4794ea 070/124: Mark non-negative integer values for indent safe, ELPA Syncer, 2021/08/29
- [nongnu] elpa/yaml-mode 28c3403 085/124: Merge pull request #54 from jfrederickson/whitespace-document-separator, ELPA Syncer, 2021/08/29
- [nongnu] elpa/yaml-mode 7f41037 087/124: Merge pull request #57 from Kaali/master, ELPA Syncer, 2021/08/29
- [nongnu] elpa/yaml-mode 0aceaf3 100/124: Merge pull request #73 from tarsiiformes/typos, ELPA Syncer, 2021/08/29
- [nongnu] elpa/yaml-mode 9e8362d 110/124: Merge pull request #76 from dgutov/spf-speedup, ELPA Syncer, 2021/08/29
- [nongnu] elpa/yaml-mode 97d507f 048/124: Derive from text-mode, ELPA Syncer, 2021/08/29
- [nongnu] elpa/yaml-mode f49fb81 123/124: Add magic-mode-list entry, ELPA Syncer, 2021/08/29
- [nongnu] elpa/yaml-mode 6555018 003/124: Merged branch(TEST-MARSHALL-PATCH@17) to trunk, ELPA Syncer, 2021/08/29