unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#37185: 24.5.1: vc--add-line, vc--remove-regexp are sub-optimal
@ 2019-08-25 20:32 Wolfgang Scherer
  2019-08-26  6:44 ` Eli Zaretskii
  0 siblings, 1 reply; 9+ messages in thread
From: Wolfgang Scherer @ 2019-08-25 20:32 UTC (permalink / raw)
  To: 37185

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.






^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2019-12-24 22:39 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-08-25 20:32 bug#37185: 24.5.1: vc--add-line, vc--remove-regexp are sub-optimal Wolfgang Scherer
2019-08-26  6:44 ` 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

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).