From 8390fb808bbbef1fe085b4ef3075454d495249ec Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Fri, 25 Sep 2009 17:57:09 +0000 Subject: [PATCH] (log-edit-changelog-entries): Avoid inf-loops. Try and avoid copying twice the same paragraph. (log-edit-changelog-paragraph, log-edit-changelog-subparagraph): Remove save-excursion. (log-edit-changelog-entry): Do it here instead. --- lisp/ChangeLog | 15 +++++++++++---- lisp/log-edit.el | 45 +++++++++++++++++++++++++-------------------- 2 files changed, 36 insertions(+), 24 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 5c248e94cd2..6b064509986 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,11 @@ +2009-09-25 Stefan Monnier + + * log-edit.el (log-edit-changelog-entries): Avoid inf-loops. + Try and avoid copying twice the same paragraph. + (log-edit-changelog-paragraph, log-edit-changelog-subparagraph): + Remove save-excursion. + (log-edit-changelog-entry): Do it here instead. + 2009-09-25 Juanma Barranquero * bs.el (bs--get-file-name): Use `list-buffers-directory' @@ -16,8 +24,8 @@ 2009-09-25 Devon Sean McCullough - * comint.el (comint-exec, comint-run, make-comint): Doc - fixes (Bug#4542). + * comint.el (comint-exec, comint-run, make-comint): + Doc fixes (Bug#4542). 2009-09-25 Glenn Morris @@ -58,8 +66,7 @@ * textmodes/sgml-mode.el: Remove xml-mode alias. * files.el (auto-mode-alist, conf-mode-maybe) - (magic-fallback-mode-alist): Revert 2009-09-18 and 2009-09-21 - changes. + (magic-fallback-mode-alist): Revert 2009-09-18 and 2009-09-21 changes. 2009-09-24 Alan Mackenzie diff --git a/lisp/log-edit.el b/lisp/log-edit.el index a9816ea6649..f648d1f1fb4 100644 --- a/lisp/log-edit.el +++ b/lisp/log-edit.el @@ -560,23 +560,21 @@ A \"page\" in a ChangeLog file is the area between two dates." (defun log-edit-changelog-paragraph () "Return the bounds of the ChangeLog paragraph containing point. If we are between paragraphs, return the previous paragraph." - (save-excursion - (beginning-of-line) - (if (looking-at "^[ \t]*$") - (skip-chars-backward " \t\n" (point-min))) - (list (progn - (if (re-search-backward "^[ \t]*\n" nil 'or-to-limit) - (goto-char (match-end 0))) - (point)) - (if (re-search-forward "^[ \t\n]*$" nil t) - (match-beginning 0) - (point-max))))) + (beginning-of-line) + (if (looking-at "^[ \t]*$") + (skip-chars-backward " \t\n" (point-min))) + (list (progn + (if (re-search-backward "^[ \t]*\n" nil 'or-to-limit) + (goto-char (match-end 0))) + (point)) + (if (re-search-forward "^[ \t\n]*$" nil t) + (match-beginning 0) + (point-max)))) (defun log-edit-changelog-subparagraph () "Return the bounds of the ChangeLog subparagraph containing point. A subparagraph is a block of non-blank lines beginning with an asterisk. If we are between sub-paragraphs, return the previous subparagraph." - (save-excursion (end-of-line) (if (search-backward "*" nil t) (list (progn (beginning-of-line) (point)) @@ -585,16 +583,17 @@ If we are between sub-paragraphs, return the previous subparagraph." (if (re-search-forward "^[ \t]*[\n*]" nil t) (match-beginning 0) (point-max)))) - (list (point) (point))))) + (list (point) (point)))) (defun log-edit-changelog-entry () "Return the bounds of the ChangeLog entry containing point. The variable `log-edit-changelog-full-paragraphs' decides whether an \"entry\" is a paragraph or a subparagraph; see its documentation string for more details." - (if log-edit-changelog-full-paragraphs - (log-edit-changelog-paragraph) - (log-edit-changelog-subparagraph))) + (save-excursion + (if log-edit-changelog-full-paragraphs + (log-edit-changelog-paragraph) + (log-edit-changelog-subparagraph)))) (defvar user-full-name) (defvar user-mail-address) @@ -663,11 +662,17 @@ where LOGBUFFER is the name of the ChangeLog buffer, and each pattern "\\($\\|[^[:alnum:]]\\)")) - (let (texts) - (while (re-search-forward pattern nil t) + (let (texts + (pos (point))) + (while (and (not (eobp)) (re-search-forward pattern nil t)) (let ((entry (log-edit-changelog-entry))) - (push entry texts) - (goto-char (elt entry 1)))) + (if (< (elt entry 1) (max (1+ pos) (point))) + ;; This is not relevant, actually. + nil + (push entry texts)) + ;; Make sure we make progress. + (setq pos (max (1+ pos) (elt entry 1))) + (goto-char pos))) (cons (current-buffer) texts)))))))) -- 2.39.5