--- Begin Message ---
Subject: |
24.5.1: vc--add-line, vc--remove-regexp are sub-optimal |
Date: |
Sun, 25 Aug 2019 22:32:35 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 |
In a *vc-dir* buffer for mercurial, ignoring a file with `vc-dir-ignore':
- If the file `.hgignore' is not found, an error is raised:
vc--add-line: Opening input file: datei oder Verzeichnis nicht gefunden,
/srv/install/linux/emacs/check/.hgignore
This error is unnecesary and serves no real purpose.
- If the file `.hgignore' exists, `vc--add-line' reads the file
from the filesysstem into a temporary buffer and saves the
modified buffer back into the filesystem.
If the file `.hgignore' was already open in a different buffer,
a prompt is displayed, when trying to modify the contents of
that buffer:
File .hgignore changed on disk. Reread from disk? (y or n) y
This is at least annoying, if not seriously wrong.
- When adding a new entry to a `.hgignore' file that is already
terminated with a newline, `vc--add-line' produces an empty
line and the file ends without a newline, which seriously
interferes with diffs.
I fail to see any purpose for such a behavior.
Since `vc-cvs-append-to-ignore' uses `find-file-no-select', there
should be no problem applying the same semantics for mercurial.
The following patch agains the Savannah repository implements the
algorithm from `vc-cvs-append-to-ignore' in `vc--add-line' and
`vc--remove-regexp' as applicable.
diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el
index 4cac153..bd0b601 100644
--- a/lisp/vc/vc.el
+++ b/lisp/vc/vc.el
@@ -1449,20 +1449,21 @@ Argument BACKEND is the backend you are using."
;; Subroutine for `vc-git-ignore' and `vc-hg-ignore'.
(defun vc--add-line (string file)
"Add STRING as a line to FILE."
- (with-temp-buffer
- (insert-file-contents file)
+ (with-current-buffer (find-file-noselect file)
+ (goto-char (point-min))
(unless (re-search-forward (concat "^" (regexp-quote string) "$") nil t)
(goto-char (point-max))
- (insert (concat "\n" string))
- (write-region (point-min) (point-max) file))))
+ (unless (bolp) (insert "\n"))
+ (insert string "\n")
+ (save-buffer))))
(defun vc--remove-regexp (regexp file)
"Remove all matching for REGEXP in FILE."
- (with-temp-buffer
- (insert-file-contents file)
+ (with-current-buffer (find-file-noselect file)
+ (goto-char (point-min))
(while (re-search-forward regexp nil t)
(replace-match ""))
- (write-region (point-min) (point-max) file)))
+ (save-buffer)))
(defun vc-checkout (file &optional rev)
"Retrieve a copy of the revision REV of FILE.
--- End Message ---
--- Begin Message ---
Subject: |
Re: bug#37185: *** GMX Spamverdacht *** Re: bug#37185: 24.5.1: vc--add-line, vc--remove-regexp are sub-optimal |
Date: |
Wed, 25 Dec 2019 00:39:50 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 |
On 16.09.2019 20:15, Wolfgang Scherer wrote:
Am 14.09.19 um 02:45 schrieb Dmitry Gutov:
On 27.08.2019 10:37, Eli Zaretskii wrote:
Thanks, it looks good, but please wait for our VC expert to review it.
Not really an expert on those particular functions, but the changes
and the explanations look good to me as well.
Wolfgang, do you have commit access?
No, I don't.
Installed with some changes in the commit message.
Thanks you.
--- End Message ---