diff options
| author | Wolfgang Scherer | 2019-08-27 00:45:48 +0200 |
|---|---|---|
| committer | Dmitry Gutov | 2019-12-25 00:33:36 +0200 |
| commit | c3be58a8f599de32e15fd350dc2b8730a13c1923 (patch) | |
| tree | adbdd94e90b19a423c4201237ffe5099d6d6d5f7 | |
| parent | 9ea9ac9a61067995a3f7a38f62766f32a8c38bb2 (diff) | |
| download | emacs-c3be58a8f599de32e15fd350dc2b8730a13c1923.tar.gz emacs-c3be58a8f599de32e15fd350dc2b8730a13c1923.zip | |
Improve vc--add-line, vc--remove-regexp
* lisp/vc/vc.el (vc--add-line): Create file if it does not exist.
Use existing buffer to avoid discrepancies with filesytem. Make sure
that the file ends with a newline.
(vc--remove-line): Do not create file if it does not exist. Use
existing buffer to avoid discrepancies with filesytem. (bug#37185)
| -rw-r--r-- | lisp/vc/vc.el | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el index 132278e8230..c5584188b31 100644 --- a/lisp/vc/vc.el +++ b/lisp/vc/vc.el | |||
| @@ -1460,20 +1460,22 @@ Argument BACKEND is the backend you are using." | |||
| 1460 | ;; Subroutine for `vc-git-ignore' and `vc-hg-ignore'. | 1460 | ;; Subroutine for `vc-git-ignore' and `vc-hg-ignore'. |
| 1461 | (defun vc--add-line (string file) | 1461 | (defun vc--add-line (string file) |
| 1462 | "Add STRING as a line to FILE." | 1462 | "Add STRING as a line to FILE." |
| 1463 | (with-temp-buffer | 1463 | (with-current-buffer (find-file-noselect file) |
| 1464 | (insert-file-contents file) | 1464 | (goto-char (point-min)) |
| 1465 | (unless (re-search-forward (concat "^" (regexp-quote string) "$") nil t) | 1465 | (unless (re-search-forward (concat "^" (regexp-quote string) "$") nil t) |
| 1466 | (goto-char (point-max)) | 1466 | (goto-char (point-max)) |
| 1467 | (insert (concat "\n" string)) | 1467 | (unless (bolp) (insert "\n")) |
| 1468 | (write-region (point-min) (point-max) file)))) | 1468 | (insert string "\n") |
| 1469 | (save-buffer)))) | ||
| 1469 | 1470 | ||
| 1470 | (defun vc--remove-regexp (regexp file) | 1471 | (defun vc--remove-regexp (regexp file) |
| 1471 | "Remove all matching for REGEXP in FILE." | 1472 | "Remove all matching for REGEXP in FILE." |
| 1472 | (with-temp-buffer | 1473 | (if (file-exists-p file) |
| 1473 | (insert-file-contents file) | 1474 | (with-current-buffer (find-file-noselect file) |
| 1474 | (while (re-search-forward regexp nil t) | 1475 | (goto-char (point-min)) |
| 1475 | (replace-match "")) | 1476 | (while (re-search-forward regexp nil t) |
| 1476 | (write-region (point-min) (point-max) file))) | 1477 | (replace-match "")) |
| 1478 | (save-buffer)))) | ||
| 1477 | 1479 | ||
| 1478 | (defun vc-checkout (file &optional rev) | 1480 | (defun vc-checkout (file &optional rev) |
| 1479 | "Retrieve a copy of the revision REV of FILE. | 1481 | "Retrieve a copy of the revision REV of FILE. |