From 08315346370f1274f8267d2eb83b7a394b865e9a Mon Sep 17 00:00:00 2001 From: James Wang Date: Mon, 15 Feb 2016 15:01:00 +0000 Subject: [PATCH] Hot fix: fix bug caused by last commit Last commit will cause some serious issue. While saving buffer, some text will be replaced randomly. I believe it is due to org's parsing mechanism which will change match data during parsing. It is fixed now, by some save-match-data magic. --- packages.el | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/packages.el b/packages.el index 2b03720..1c35ef6 100755 --- a/packages.el +++ b/packages.el @@ -150,15 +150,16 @@ "Replace regexp with match in buffer." (if (eq 'org-mode (buffer-local-value 'major-mode (current-buffer))) (pangu-spacing-search-buffer regexp (point-min) (point-max) - (if (member 'link - (mapcar - (lambda (point) - (save-excursion - (goto-char point) - (org-element-type (org-element-context)))) - (list (match-beginning 0) (match-end 0)))) - (goto-char (match-end 0)) - (replace-match match nil nil))) + (when (not (member 'link + (save-match-data + (save-excursion + (let ((p1 (match-beginning 1)) + (p2 (match-beginning 2))) + (mapcar (lambda (pt) (goto-char pt) + (org-element-type + (org-element-context))) + (list p1 p2))))))) + (replace-match match nil nil))) ad-do-it)))))) (defun han/init-visual-fill-column ()