]> git.eshelyaron.com Git - emacs.git/commitdiff
Prevent filling from mangling ChangeLog defun lists
authorPo Lu <luangruo@yahoo.com>
Mon, 29 Jan 2024 02:54:49 +0000 (10:54 +0800)
committerEshel Yaron <me@eshelyaron.com>
Wed, 31 Jan 2024 20:15:33 +0000 (21:15 +0100)
* 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.

(cherry picked from commit e9cf215d7067d5375425e605461b155216ed23b5)

lisp/vc/log-edit.el
test/lisp/vc/log-edit-tests.el

index b847fb953f2c00f3a68dedcf7327a2e297849125..644ea691a76662af2c8a115f8cccaf95bd983953 100644 (file)
@@ -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:
index 5b555809f4c60a4d85d2c991a567992711a55f11..57407d47ca847f3246539e84c0a6ef692f3a4332 100644 (file)
@@ -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