From: Wolfgang Scherer <Wolfgang.Scherer@gmx.de>
To: 37185@debbugs.gnu.org
Subject: bug#37185: 24.5.1: vc--add-line, vc--remove-regexp are sub-optimal
Date: Sun, 25 Aug 2019 22:32:35 +0200 [thread overview]
Message-ID: <8d3275a0-149c-6f6a-ff22-c6ef27395188@gmx.de> (raw)
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.
next reply other threads:[~2019-08-25 20:32 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-25 20:32 Wolfgang Scherer [this message]
2019-08-26 6:44 ` bug#37185: 24.5.1: vc--add-line, vc--remove-regexp are sub-optimal Eli Zaretskii
2019-08-26 22:52 ` bug#37185: *** GMX Spamverdacht *** " Wolfgang Scherer
2019-08-27 7:37 ` Eli Zaretskii
2019-08-27 23:38 ` bug#37185: *** GMX Spamverdacht *** " Wolfgang Scherer
2019-09-14 0:45 ` bug#37185: " Dmitry Gutov
2019-09-16 17:14 ` Wolfgang Scherer
2019-09-16 17:15 ` Wolfgang Scherer
2019-12-24 22:39 ` Dmitry Gutov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8d3275a0-149c-6f6a-ff22-c6ef27395188@gmx.de \
--to=wolfgang.scherer@gmx.de \
--cc=37185@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).