diff options
| author | Po Lu | 2024-01-28 16:31:33 +0800 |
|---|---|---|
| committer | Po Lu | 2024-01-28 16:58:28 +0800 |
| commit | 78fc49407b8ef8ec649fe70fcce09101801dbc05 (patch) | |
| tree | bcc0394b9cf19241afb4ea87566f57608e989fa1 | |
| parent | ad2c81082a62f9f781e4f5771fc223520d91cefd (diff) | |
| download | emacs-78fc49407b8ef8ec649fe70fcce09101801dbc05.tar.gz emacs-78fc49407b8ef8ec649fe70fcce09101801dbc05.zip | |
Improve filling of ChangeLog entries
* lisp/vc/log-edit.el (log-edit--insert-filled-defuns): Rewrite
completely.
(log-edit-fill-entry): Abandon pcase and cl-lib.
| -rw-r--r-- | lisp/vc/log-edit.el | 133 |
1 files changed, 101 insertions, 32 deletions
diff --git a/lisp/vc/log-edit.el b/lisp/vc/log-edit.el index 72867f14d2f..5f370511b14 100644 --- a/lisp/vc/log-edit.el +++ b/lisp/vc/log-edit.el | |||
| @@ -575,19 +575,79 @@ the \\[vc-prefix-map] prefix for VC commands, for example). | |||
| 575 | "Insert FUNC-NAMES, following ChangeLog formatting." | 575 | "Insert FUNC-NAMES, following ChangeLog formatting." |
| 576 | (if (not func-names) | 576 | (if (not func-names) |
| 577 | (insert ":") | 577 | (insert ":") |
| 578 | ;; Insert a space unless this list of file names is being inserted | ||
| 579 | ;; at the start of a line or after a space character. | ||
| 578 | (unless (or (memq (char-before) '(?\n ?\s)) | 580 | (unless (or (memq (char-before) '(?\n ?\s)) |
| 579 | (> (current-column) fill-column)) | 581 | (> (current-column) fill-column)) |
| 580 | (insert " ")) | 582 | (insert " ")) |
| 581 | (cl-loop for first-fun = t then nil | 583 | (let ((inside-paren-pair nil) |
| 582 | for def in func-names do | 584 | (first-line t) |
| 583 | (when (> (+ (current-column) (string-width def)) fill-column) | 585 | name) |
| 584 | (unless first-fun | 586 | ;; Now insert the functions names one by one, inserting newlines |
| 585 | (insert ")")) | 587 | ;; as appropriate. |
| 586 | (insert "\n")) | 588 | (while func-names |
| 587 | (insert (if (memq (char-before) '(?\n ?\s)) | 589 | (setq name (car func-names)) |
| 588 | "(" ", ") | 590 | (setq func-names (cdr func-names)) |
| 589 | def)) | 591 | ;; If inserting `name' in at the current column would overflow |
| 590 | (insert "):"))) | 592 | ;; the fill column, place it on its own line. |
| 593 | (if (and first-line | ||
| 594 | (> (+ (current-column) | ||
| 595 | (string-width name) | ||
| 596 | ;; If this be the last name, the column must be | ||
| 597 | ;; followed by an extra colon character. | ||
| 598 | (if func-names 1 2)) | ||
| 599 | fill-column)) | ||
| 600 | (progn | ||
| 601 | (insert "\n") | ||
| 602 | ;; Iterate over this function name again. | ||
| 603 | (setq func-names (cons name func-names))) | ||
| 604 | (if inside-paren-pair | ||
| 605 | ;; If `name' is not the first item in a list of defuns | ||
| 606 | ;; and inserting it would overflow the fill column, | ||
| 607 | ;; start a new list of defuns on the next line. | ||
| 608 | (if (> (+ (current-column) | ||
| 609 | (string-width name) | ||
| 610 | ;; If this be the last name, the column must | ||
| 611 | ;; be followed by an extra colon character; | ||
| 612 | ;; however, there are two separator characters | ||
| 613 | ;; that will be deleted, so the number of | ||
| 614 | ;; columns to add to this in the case of | ||
| 615 | ;; `name' being final and in other cases are | ||
| 616 | ;; -1 and -2 respectively. | ||
| 617 | (if func-names -1 -2)) | ||
| 618 | fill-column) | ||
| 619 | (progn | ||
| 620 | (delete-char -2) | ||
| 621 | (insert ")\n") | ||
| 622 | (setq inside-paren-pair nil | ||
| 623 | ;; Iterate over this function name again. | ||
| 624 | func-names (cons name func-names))) | ||
| 625 | ;; Insert this file name with a separator attached. | ||
| 626 | (insert name ", ")) | ||
| 627 | ;; Otherwise, decide whether to start a list of defuns or | ||
| 628 | ;; to insert `name' on its own line. | ||
| 629 | (if (> (+ (current-column) | ||
| 630 | (string-width name) | ||
| 631 | (if func-names 1 2)) ; The column number of | ||
| 632 | ; line after inserting | ||
| 633 | ; `name'... | ||
| 634 | fill-column) | ||
| 635 | ;; ...would leave insufficient space for any subsequent | ||
| 636 | ;; file names, so insert it on its own line. | ||
| 637 | (insert (if func-names | ||
| 638 | (format "(%s)\n" name) | ||
| 639 | (format "(%s):" name))) | ||
| 640 | ;; Insert a new defun list, unless `name' is the last | ||
| 641 | ;; function name. | ||
| 642 | (insert (if (not func-names) | ||
| 643 | (format "(%s):" name) | ||
| 644 | (setq inside-paren-pair t) | ||
| 645 | (format "(%s, " name)))))) | ||
| 646 | (setq first-line nil)) | ||
| 647 | ;; Close any open list of defuns. | ||
| 648 | (when inside-paren-pair | ||
| 649 | (delete-char -2) | ||
| 650 | (insert "):"))))) | ||
| 591 | 651 | ||
| 592 | (defun log-edit-fill-entry (&optional justify) | 652 | (defun log-edit-fill-entry (&optional justify) |
| 593 | "Like \\[fill-paragraph], but for filling ChangeLog-formatted entries. | 653 | "Like \\[fill-paragraph], but for filling ChangeLog-formatted entries. |
| @@ -595,32 +655,41 @@ Consecutive function entries without prose (i.e., lines of the | |||
| 595 | form \"(FUNCTION):\") will be combined into \"(FUNC1, FUNC2):\" | 655 | form \"(FUNCTION):\") will be combined into \"(FUNC1, FUNC2):\" |
| 596 | according to `fill-column'." | 656 | according to `fill-column'." |
| 597 | (save-excursion | 657 | (save-excursion |
| 598 | (pcase-let ((`(,beg ,end) (log-edit-changelog-paragraph))) | 658 | (let* ((range (log-edit-changelog-paragraph)) |
| 659 | (beg (car range)) | ||
| 660 | (end (cadr range))) | ||
| 599 | (if (= beg end) | 661 | (if (= beg end) |
| 600 | ;; Not a ChangeLog entry, fill as normal. | 662 | ;; Not a ChangeLog entry, fill as normal. |
| 601 | nil | 663 | nil |
| 602 | (cl-callf copy-marker end) | 664 | (setq end (copy-marker end)) |
| 603 | (goto-char beg) | 665 | (goto-char beg) |
| 604 | (cl-loop | 666 | (let* ((defuns-beg nil) |
| 605 | for defuns-beg = | 667 | (defuns nil)) |
| 606 | (and (< beg end) | 668 | (while |
| 607 | (re-search-forward | 669 | (progn |
| 608 | (concat "\\(?1:" change-log-unindented-file-names-re | 670 | (setq defuns-beg |
| 609 | "\\)\\|^\\(?1:\\)[[:blank:]]*(") | 671 | (and (< beg end) |
| 610 | end t) | 672 | (re-search-forward |
| 611 | (copy-marker (match-end 1))) | 673 | (concat "\\(?1:" |
| 612 | ;; Fill prose between log entries. | 674 | change-log-unindented-file-names-re |
| 613 | do (let ((fill-indent-according-to-mode t) | 675 | "\\)\\|^\\(?1:\\)[[:blank:]]*(") |
| 614 | (end (if defuns-beg (match-beginning 0) end)) | 676 | end t) |
| 615 | (beg (progn (goto-char beg) (line-beginning-position)))) | 677 | (copy-marker (match-end 1)))) |
| 616 | (when (<= (line-end-position) end) | 678 | (let ((fill-indent-according-to-mode t) |
| 617 | (fill-region beg end justify))) | 679 | (end (if defuns-beg |
| 618 | while defuns-beg | 680 | (match-beginning 0) end)) |
| 619 | for defuns = (progn (goto-char defuns-beg) | 681 | (beg (progn (goto-char beg) |
| 620 | (change-log-read-defuns end)) | 682 | (line-beginning-position)))) |
| 621 | do (progn (delete-region defuns-beg (point)) | 683 | (when (<= (line-end-position) end) |
| 622 | (log-edit--insert-filled-defuns defuns) | 684 | (fill-region beg end justify))) |
| 623 | (setq beg (point)))) | 685 | defuns-beg) |
| 686 | (goto-char defuns-beg) | ||
| 687 | (setq defuns (change-log-read-defuns end)) | ||
| 688 | (progn | ||
| 689 | (delete-region defuns-beg (point)) | ||
| 690 | (log-edit--insert-filled-defuns defuns) | ||
| 691 | (setq beg (point)))) | ||
| 692 | nil) | ||
| 624 | t)))) | 693 | t)))) |
| 625 | 694 | ||
| 626 | (defun log-edit-hide-buf (&optional buf where) | 695 | (defun log-edit-hide-buf (&optional buf where) |