[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/lua-mode 8b9d895 311/468: Fix comments being spilled into
From: |
Philip Kaludercic |
Subject: |
[nongnu] elpa/lua-mode 8b9d895 311/468: Fix comments being spilled into the code (issue #25) |
Date: |
Thu, 5 Aug 2021 04:58:59 -0400 (EDT) |
branch: elpa/lua-mode
commit 8b9d895b4a5672377d7cc3ff80f0a8555267c2b9
Author: immerrr <immerrr+lua@gmail.com>
Commit: immerrr <immerrr+lua@gmail.com>
Fix comments being spilled into the code (issue #25)
---
lua-mode.el | 23 +++++++++++++++++++++++
test/test-fill.el | 40 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 63 insertions(+)
diff --git a/lua-mode.el b/lua-mode.el
index 6684c12..2fd79e6 100644
--- a/lua-mode.el
+++ b/lua-mode.el
@@ -731,6 +731,7 @@ Groups 6-9 can be used in any of argument regexps."
(lua--setq-local comment-start lua-comment-start)
(lua--setq-local comment-start-skip lua-comment-start-skip)
(lua--setq-local comment-use-syntax t)
+ (lua--setq-local fill-paragraph-function #'lua--fill-paragraph)
(with-no-warnings
(lua--setq-local comment-use-global-state t))
(lua--setq-local imenu-generic-expression lua-imenu-generic-expression)
@@ -776,6 +777,28 @@ Groups 6-9 can be used in any of argument regexps."
;; private functions
+(defun lua--fill-paragraph (&optional justify region)
+ ;; Implementation of forward-paragraph for filling.
+ ;;
+ ;; This function works around a corner case in the following situations:
+ ;;
+ ;; <>
+ ;; -- some very long comment ....
+ ;; some_code_right_after_the_comment
+ ;;
+ ;; If point is at the beginning of the comment line, fill paragraph code
+ ;; would have gone for comment-based filling and done the right thing, but it
+ ;; does not find a comment at the beginning of the empty line before the
+ ;; comment and falls back to text-based filling ignoring comment-start and
+ ;; spilling the comment into the code.
+ (while (and (not (eobp))
+ (progn (move-to-left-margin)
+ (looking-at paragraph-separate)))
+ (forward-line 1))
+ (let ((fill-paragraph-handle-comment t))
+ (fill-paragraph justify region)))
+
+
(defun lua-prefix-key-update-bindings ()
(let (old-cons)
(if (eq lua-prefix-mode-map (keymap-parent lua-mode-map))
diff --git a/test/test-fill.el b/test/test-fill.el
new file mode 100644
index 0000000..8b93d10
--- /dev/null
+++ b/test/test-fill.el
@@ -0,0 +1,40 @@
+;; -*- flycheck-disabled-checkers: (emacs-lisp-checkdoc) -*-
+(load (concat (file-name-directory (or load-file-name (buffer-file-name)
+ default-directory))
+ "utils.el") nil 'nomessage 'nosuffix)
+
+
+
+(defun expect-filled-as (strs etalon)
+ (expect
+ (lua-buffer-strs
+ (let ((fill-column 10))
+ (lua-insert-goto-<>
+ strs)
+ (execute-kbd-macro (kbd "M-q"))))
+ :to-equal
+ etalon))
+
+
+
+(describe "Test fill-paragraph"
+ (it "filling single-line comment"
+ (expect-filled-as '("<>-- foo bar baz qux")
+ '("-- foo bar"
+ "-- baz qux")))
+ (it "filling comment after code"
+ (expect-filled-as '("<>foo -- bar baz")
+ '("foo -- bar"
+ " -- baz")))
+ (xit "filling multiline comment"
+ (expect-filled-as '("<>--[[ foo bar baz ]]")
+ '("--[[ foo bar"
+ " baz ]]")))
+ (it "does not spill comments into code (issue #25)"
+ (expect-filled-as '("<>"
+ "-- foo bar baz qux"
+ "foo_func()")
+ '(""
+ "-- foo bar"
+ "-- baz qux"
+ "foo_func()"))))
- [nongnu] elpa/lua-mode 5995697 286/468: Merge pull request #81 from v2e4lisp/remove-lua-comment-p, (continued)
- [nongnu] elpa/lua-mode 5995697 286/468: Merge pull request #81 from v2e4lisp/remove-lua-comment-p, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 8a37fce 288/468: Merge pull request #82 from holomorph/browse-url, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode c3b103d 290/468: lua-beginning-of-proc: improve defun header regex, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 522edaf 289/468: with-lua-buffer: mark as debuggable, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode a57e25e 293/468: Update documentation, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode ceb74ae 296/468: Add file test/.nosearch, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode a7780dc 304/468: silence 25.1 byte-compiler, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 37f3c42 306/468: Silence compilation warning about referencing a variable from compile.el, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 148858c 309/468: Migrate tests to buttercup, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 0ce2b96 314/468: Allow to set lua-indent-level as file local variable, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 8b9d895 311/468: Fix comments being spilled into the code (issue #25),
Philip Kaludercic <=
- [nongnu] elpa/lua-mode cadc1ea 312/468: to-be-fontified-as: improve error messages, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 444ac2f 320/468: Merge 'stable' back into 'master', Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode cae5db6 322/468: Fix derived-mode-p test, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 6511687 323/468: Merge pull request #116 from immerrr/fix-derived-mode-p, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 563ac50 325/468: Merge pull request #115 from RobertCochran/escape-tabs, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 3019e75 327/468: Merge pull request #117 from immerrr/fix-string-parsing, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode a0d6744 331/468: travis.yml: add Emacs-25.1, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode dccda19 336/468: Wrap lua--fill-paragraph in save-excursion, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 7a97e1b 341/468: correct spelling mistake, Philip Kaludercic, 2021/08/05
- [nongnu] elpa/lua-mode 0715340 337/468: Merge pull request #131 from jorams/fill-paragraph-save-excursion, Philip Kaludercic, 2021/08/05