emacs-diffs
[Top][All Lists]
Advanced

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

master e9cf215d706: Prevent filling from mangling ChangeLog defun lists


From: Po Lu
Subject: master e9cf215d706: Prevent filling from mangling ChangeLog defun lists
Date: Sun, 28 Jan 2024 22:00:39 -0500 (EST)

branch: master
commit e9cf215d7067d5375425e605461b155216ed23b5
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>

    Prevent filling from mangling ChangeLog defun lists
    
    * lisp/vc/log-edit.el (log-edit-fill-entry): Replace space
    characters within defun lists with NBSPs for the duration of
    `fill-region''s execution, so that they are never considered
    break points.
    
    * test/lisp/vc/log-edit-tests.el
    (log-edit-fill-entry-space-substitution): New test.
---
 lisp/vc/log-edit.el            |  37 +++++++++-
 test/lisp/vc/log-edit-tests.el | 149 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 184 insertions(+), 2 deletions(-)

diff --git a/lisp/vc/log-edit.el b/lisp/vc/log-edit.el
index b847fb953f2..644ea691a76 100644
--- a/lisp/vc/log-edit.el
+++ b/lisp/vc/log-edit.el
@@ -668,6 +668,9 @@ according to `fill-column'."
                (defuns nil))
           (while
               (progn
+                ;; Match a regexp against the next ChangeLog entry.
+                ;; `defuns-beg' will be the end of the file name,
+                ;; which marks the beginning of the list of defuns.
                 (setq defuns-beg
                       (and (< beg end)
                            (re-search-forward
@@ -676,13 +679,39 @@ according to `fill-column'."
                                     "\\)\\|^\\(?1:\\)[[:blank:]]*(")
                             end t)
                            (copy-marker (match-end 1))))
+                ;; Fill the intervening prose between the end of the
+                ;; last match and the beginning of the current match.
                 (let ((fill-indent-according-to-mode t)
                       (end (if defuns-beg
                                (match-beginning 0) end))
                       (beg (progn (goto-char beg)
-                                  (line-beginning-position))))
+                                  (line-beginning-position)))
+                      space-beg space-end)
                   (when (<= (line-end-position) end)
-                    (fill-region beg end justify)))
+                    ;; Replace space characters within parentheses
+                    ;; that resemble ChangeLog defun names between BEG
+                    ;; and END with non-breaking spaces to prevent
+                    ;; them from being considered break points by
+                    ;; `fill-region'.
+                    (save-excursion
+                      (goto-char beg)
+                      (when (re-search-forward
+                             "^[[:blank:]]*(.*\\([[:space:]]\\).*):"
+                             end t)
+                        (replace-regexp-in-region "[[:space:]]" " "
+                                                  (setq space-beg
+                                                        (copy-marker
+                                                         (match-beginning 0)))
+                                                  (setq space-end
+                                                        (copy-marker
+                                                         (match-end 0))))))
+                    (fill-region beg end justify))
+                  ;; Restore the spaces replaced by NBSPs.
+                  (when space-beg
+                    (replace-string-in-region " " " "
+                                              space-beg space-end)
+                    (set-marker space-beg nil)
+                    (set-marker space-end nil)))
                 defuns-beg)
             (goto-char defuns-beg)
             (setq defuns (change-log-read-defuns end))
@@ -1358,3 +1387,7 @@ line of MSG."
 (provide 'log-edit)
 
 ;;; log-edit.el ends here
+
+;; Local Variables:
+;; coding: utf-8-unix
+;; End:
diff --git a/test/lisp/vc/log-edit-tests.el b/test/lisp/vc/log-edit-tests.el
index 5b555809f4c..57407d47ca8 100644
--- a/test/lisp/vc/log-edit-tests.el
+++ b/test/lisp/vc/log-edit-tests.el
@@ -185,4 +185,153 @@ lines."))))
                      "* file2.txt 
 (abcdefghijklmnopqrstuvwxyz):")))))
 
+(ert-deftest log-edit-fill-entry-space-substitution ()
+  ;; This test verifies that filling the paragraph surrounding the
+  ;; last line of defuns does not break between defun lists with
+  ;; spaces in identifiers.
+  (setq string "
+* src/sfnt.c (xmalloc, xrealloc): Improve behavior upon allocation
+failures during test.
+(sfnt_table_names): Add prep.
+(sfnt_transform_coordinates): Allow applying offsets during
+coordinate transform.
+(sfnt_decompose_compound_glyph): Defer offset computation until
+any component compound glyph is loaded, then apply it during the
+transform process.
+(sfnt_multiply_divide): Make available everywhere.  Implement on
+64 bit systems.
+(sfnt_multiply_divide_signed): New function.
+(sfnt_mul_fixed): Fix division overflow.
+(sfnt_curve_to_and_build_1, sfnt_build_glyph_outline): Remove
+outdated comment.
+(sfnt_build_outline_edges): Fix coding style.
+(sfnt_lookup_glyph_metrics): Allow looking up metrics without
+scaling.
+(struct sfnt_cvt_table): Fix type of cvt values.
+(struct sfnt_prep_table): New structure.
+(sfnt_read_cvt_table): Read cvt values in terms of fwords, not
+longs (as Apple's doc seems to say).
+(sfnt_read_fpgm_table): Fix memory allocation for font program
+table.
+(sfnt_read_prep_table): New function.
+(struct sfnt_interpreter_zone): New structure.
+(struct sfnt_interpreter_graphics_state): New fields `project',
+`move', `vector_dot_product'.  Rename to `sfnt_graphics_state'.
+(struct sfnt_interpreter, sfnt_mul_f26dot6): Stop doing rounding
+division.
+(sfnt_init_graphics_state, sfnt_make_interpreter, MOVE, SSW, RAW)
+(SDS, ADD, SUB, ABS, NEG, WCVTF, _MIN, S45ROUND, SVTCAx)
+(sfnt_set_srounding_state, sfnt_skip_code)
+(sfnt_interpret_unimplemented, sfnt_interpret_fdef)
+(sfnt_interpret_idef, sfnt_interpret_if, sfnt_interpret_else)
+(sfnt_round_none, sfnt_round_to_grid, sfnt_round_to_double_grid)
+"
+        wanted "
+* src/sfnt.c 
+(xmalloc, xrealloc):
+Improve behavior
+upon allocation
+failures during
+test.
+(sfnt_table_names):
+Add prep.
+
+(sfnt_transform_coordinates):
+Allow applying
+offsets during
+coordinate
+transform.
+
+(sfnt_decompose_compound_glyph):
+Defer offset
+computation until
+any component
+compound glyph is
+loaded, then apply
+it during the
+transform process.
+
+(sfnt_multiply_divide):
+Make available
+everywhere.
+Implement on 64 bit
+systems.
+
+(sfnt_multiply_divide_signed):
+New function.
+(sfnt_mul_fixed):
+Fix division
+overflow.
+
+(sfnt_curve_to_and_build_1)
+(sfnt_build_glyph_outline):
+Remove outdated
+comment.
+
+(sfnt_build_outline_edges):
+Fix coding style.
+
+(sfnt_lookup_glyph_metrics):
+Allow looking up
+metrics without
+scaling.
+
+(struct sfnt_cvt_table):
+Fix type of cvt
+values.
+
+(struct sfnt_prep_table):
+New structure.
+
+(sfnt_read_cvt_table):
+Read cvt values in
+terms of fwords, not
+longs (as Apple's
+doc seems to say).
+
+(sfnt_read_fpgm_table):
+Fix memory
+allocation for font
+program table.
+
+(sfnt_read_prep_table):
+New function.
+
+(struct sfnt_interpreter_zone):
+New structure.
+
+(struct sfnt_interpreter_graphics_state):
+New fields
+`project', `move',
+`vector_dot_product'.
+Rename to
+`sfnt_graphics_state'.
+
+(struct sfnt_interpreter)
+(sfnt_mul_f26dot6):
+Stop doing rounding
+division.
+
+(sfnt_init_graphics_state)
+(sfnt_make_interpreter)
+(MOVE, SSW, RAW, SDS)
+(ADD, SUB, ABS, NEG)
+(WCVTF, _MIN)
+(S45ROUND, SVTCAx)
+(sfnt_set_srounding_state)
+(sfnt_skip_code)
+(sfnt_interpret_unimplemented)
+(sfnt_interpret_fdef)
+(sfnt_interpret_idef)
+(sfnt_interpret_if)
+(sfnt_interpret_else)
+(sfnt_round_none)
+(sfnt_round_to_grid)
+(sfnt_round_to_double_grid):
+")
+  (with-temp-buffer
+    (insert string)
+    (let ((fill-column 20)) (log-edit-fill-entry))
+    (should (equal (buffer-string) wanted))))
+
 ;;; log-edit-tests.el ends here



reply via email to

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