unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#25951: [PATCH] Fix quoted files for 'verify-visited-file-modtime'
       [not found] <83fugvpw24.fsf@gnu.org>
@ 2017-04-29 12:20 ` Philipp Stephani
       [not found] ` <20170429122027.39318-1-phst@google.com>
  1 sibling, 0 replies; 8+ messages in thread
From: Philipp Stephani @ 2017-04-29 12:20 UTC (permalink / raw)
  To: 25951, npostavs, emacs-devel, eliz; +Cc: Philipp Stephani

Fixes Bug#25951.

* lisp/files.el (file-name-non-special): Set the file name for the
correct buffer.

* test/lisp/files-tests.el (files-tests--file-name-non-special--buffers):
Add unit test.
(files-tests--with-advice, files-tests--with-temp-file): New helper
macros.
---
 lisp/files.el            |  9 ++++++-
 test/lisp/files-tests.el | 64 +++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 71 insertions(+), 2 deletions(-)

diff --git a/lisp/files.el b/lisp/files.el
index 6848818cad..2e9ab1aad1 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -28,6 +28,8 @@
 
 ;;; Code:
 
+(eval-when-compile (require 'cl-lib))
+
 (defvar font-lock-keywords)
 
 (defgroup backup nil
@@ -6987,7 +6989,12 @@ file-name-non-special
            (when (and visit buffer-file-name)
              (setq buffer-file-name (concat "/:" buffer-file-name))))))
       (`unquote-then-quote
-       (let ((buffer-file-name (substring buffer-file-name 2)))
+       (cl-letf* ((buffer (or (car arguments) (current-buffer)))
+                  ((buffer-local-value 'buffer-file-name buffer)
+                   (substring (buffer-file-name buffer) 2)))
+         ;; `unquote-then-quote' is only used for the
+         ;; `verify-visited-file-modtime' action, which takes a buffer
+         ;; as only optional argument.
          (apply operation arguments)))
       (_
        (apply operation arguments)))))
diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el
index 80bbeb1bc5..4583b1af3c 100644
--- a/test/lisp/files-tests.el
+++ b/test/lisp/files-tests.el
@@ -1,4 +1,4 @@
-;;; files-tests.el --- tests for files.el.
+;;; files-tests.el --- tests for files.el.  -*- lexical-binding: t; -*-
 
 ;; Copyright (C) 2012-2017 Free Software Foundation, Inc.
 
@@ -20,6 +20,7 @@
 ;;; Code:
 
 (require 'ert)
+(require 'nadvice)
 
 ;; Set to t if the local variable was set, `query' if the query was
 ;; triggered.
@@ -251,5 +252,66 @@ files-test-bug-18141-file
                       (start-file-process "foo" nil "true"))))
   (should (eq (let ((default-directory "/:/")) (shell-command "true")) 0)))
 
+(defmacro files-tests--with-advice (symbol where function &rest body)
+  (declare (indent 3))
+  (cl-check-type symbol symbol)
+  (cl-check-type where keyword)
+  (cl-check-type function function)
+  (macroexp-let2 nil function function
+    `(progn
+       (advice-add #',symbol ,where ,function)
+       (unwind-protect
+           (progn ,@body)
+         (advice-remove #',symbol ,function)))))
+
+(defmacro files-tests--with-temp-file (name &rest body)
+  (declare (indent 1))
+  (cl-check-type name symbol)
+  `(let ((,name (make-temp-file "emacs")))
+     (unwind-protect
+         (progn ,@body)
+       (delete-file ,name))))
+
+(ert-deftest files-tests--file-name-non-special--buffers ()
+  "Check that Bug#25951 is fixed.
+We call `verify-visited-file-modtime' on a buffer visiting a file
+with a quoted name.  We use two different variants: first with
+the buffer current and a nil argument, second passing the buffer
+object explicitly.  In both cases no error should be raised and
+the `file-name-non-special' handler for quoted file names should
+be invoked with the right arguments."
+  (files-tests--with-temp-file temp-file-name
+    (with-temp-buffer
+     (let* ((buffer-visiting-file (current-buffer))
+            (actual-args ())
+            (log (lambda (&rest args) (push args actual-args))))
+       (insert-file-contents (concat "/:" temp-file-name) :visit)
+       (should (stringp buffer-file-name))
+       (should (string-prefix-p "/:" buffer-file-name))
+       (should (consp (visited-file-modtime)))
+       (should (equal (find-file-name-handler buffer-file-name
+                                              #'verify-visited-file-modtime)
+                      #'file-name-non-special))
+       (files-tests--with-advice file-name-non-special :before log
+         ;; This should call the file name handler with the right
+         ;; buffer and not signal an error.  The file hasn't been
+         ;; modified, so `verify-visited-file-modtime' should return
+         ;; t.
+         (should (equal (verify-visited-file-modtime) t))
+         (with-temp-buffer
+           (should (stringp (buffer-file-name buffer-visiting-file)))
+           ;; This should call the file name handler with the right
+           ;; buffer and not signal an error.  The file hasn't been
+           ;; modified, so `verify-visited-file-modtime' should return
+           ;; t.
+           (should (equal (verify-visited-file-modtime buffer-visiting-file)
+                          t))))
+       ;; Verify that the handler was actually called.  We called
+       ;; `verify-visited-file-modtime' twice, so both calls should be
+       ;; recorded in reverse order.
+       (should (equal actual-args
+                      `((verify-visited-file-modtime ,buffer-visiting-file)
+                        (verify-visited-file-modtime nil))))))))
+
 (provide 'files-tests)
 ;;; files-tests.el ends here
-- 
2.12.2






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

* bug#25951: [PATCH] Fix quoted files for 'verify-visited-file-modtime'
       [not found] ` <20170429122027.39318-1-phst@google.com>
@ 2017-05-06 19:27   ` Philipp
       [not found]   ` <CAArVCkQ_mFGskvFHG9cVw=2fTxfROkDEshaxgGjrgk=oRBe4jA@mail.gmail.com>
  1 sibling, 0 replies; 8+ messages in thread
From: Philipp @ 2017-05-06 19:27 UTC (permalink / raw)
  To: npostavs, emacs-devel, eliz, 25951-done; +Cc: Philipp Stephani

[-- Attachment #1: Type: text/plain, Size: 5380 bytes --]

Philipp Stephani <p.stephani2@gmail.com> schrieb am Sa., 29. Apr. 2017 um
14:20 Uhr:

> Fixes Bug#25951.
>
> * lisp/files.el (file-name-non-special): Set the file name for the
> correct buffer.
>
> * test/lisp/files-tests.el (files-tests--file-name-non-special--buffers):
> Add unit test.
> (files-tests--with-advice, files-tests--with-temp-file): New helper
> macros.
> ---
>  lisp/files.el            |  9 ++++++-
>  test/lisp/files-tests.el | 64
> +++++++++++++++++++++++++++++++++++++++++++++++-
>  2 files changed, 71 insertions(+), 2 deletions(-)
>
> diff --git a/lisp/files.el b/lisp/files.el
> index 6848818cad..2e9ab1aad1 100644
> --- a/lisp/files.el
> +++ b/lisp/files.el
> @@ -28,6 +28,8 @@
>
>  ;;; Code:
>
> +(eval-when-compile (require 'cl-lib))
> +
>  (defvar font-lock-keywords)
>
>  (defgroup backup nil
> @@ -6987,7 +6989,12 @@ file-name-non-special
>             (when (and visit buffer-file-name)
>               (setq buffer-file-name (concat "/:" buffer-file-name))))))
>        (`unquote-then-quote
> -       (let ((buffer-file-name (substring buffer-file-name 2)))
> +       (cl-letf* ((buffer (or (car arguments) (current-buffer)))
> +                  ((buffer-local-value 'buffer-file-name buffer)
> +                   (substring (buffer-file-name buffer) 2)))
> +         ;; `unquote-then-quote' is only used for the
> +         ;; `verify-visited-file-modtime' action, which takes a buffer
> +         ;; as only optional argument.
>           (apply operation arguments)))
>        (_
>         (apply operation arguments)))))
> diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el
> index 80bbeb1bc5..4583b1af3c 100644
> --- a/test/lisp/files-tests.el
> +++ b/test/lisp/files-tests.el
> @@ -1,4 +1,4 @@
> -;;; files-tests.el --- tests for files.el.
> +;;; files-tests.el --- tests for files.el.  -*- lexical-binding: t; -*-
>
>  ;; Copyright (C) 2012-2017 Free Software Foundation, Inc.
>
> @@ -20,6 +20,7 @@
>  ;;; Code:
>
>  (require 'ert)
> +(require 'nadvice)
>
>  ;; Set to t if the local variable was set, `query' if the query was
>  ;; triggered.
> @@ -251,5 +252,66 @@ files-test-bug-18141-file
>                        (start-file-process "foo" nil "true"))))
>    (should (eq (let ((default-directory "/:/")) (shell-command "true"))
> 0)))
>
> +(defmacro files-tests--with-advice (symbol where function &rest body)
> +  (declare (indent 3))
> +  (cl-check-type symbol symbol)
> +  (cl-check-type where keyword)
> +  (cl-check-type function function)
> +  (macroexp-let2 nil function function
> +    `(progn
> +       (advice-add #',symbol ,where ,function)
> +       (unwind-protect
> +           (progn ,@body)
> +         (advice-remove #',symbol ,function)))))
> +
> +(defmacro files-tests--with-temp-file (name &rest body)
> +  (declare (indent 1))
> +  (cl-check-type name symbol)
> +  `(let ((,name (make-temp-file "emacs")))
> +     (unwind-protect
> +         (progn ,@body)
> +       (delete-file ,name))))
> +
> +(ert-deftest files-tests--file-name-non-special--buffers ()
> +  "Check that Bug#25951 is fixed.
> +We call `verify-visited-file-modtime' on a buffer visiting a file
> +with a quoted name.  We use two different variants: first with
> +the buffer current and a nil argument, second passing the buffer
> +object explicitly.  In both cases no error should be raised and
> +the `file-name-non-special' handler for quoted file names should
> +be invoked with the right arguments."
> +  (files-tests--with-temp-file temp-file-name
> +    (with-temp-buffer
> +     (let* ((buffer-visiting-file (current-buffer))
> +            (actual-args ())
> +            (log (lambda (&rest args) (push args actual-args))))
> +       (insert-file-contents (concat "/:" temp-file-name) :visit)
> +       (should (stringp buffer-file-name))
> +       (should (string-prefix-p "/:" buffer-file-name))
> +       (should (consp (visited-file-modtime)))
> +       (should (equal (find-file-name-handler buffer-file-name
> +
> #'verify-visited-file-modtime)
> +                      #'file-name-non-special))
> +       (files-tests--with-advice file-name-non-special :before log
> +         ;; This should call the file name handler with the right
> +         ;; buffer and not signal an error.  The file hasn't been
> +         ;; modified, so `verify-visited-file-modtime' should return
> +         ;; t.
> +         (should (equal (verify-visited-file-modtime) t))
> +         (with-temp-buffer
> +           (should (stringp (buffer-file-name buffer-visiting-file)))
> +           ;; This should call the file name handler with the right
> +           ;; buffer and not signal an error.  The file hasn't been
> +           ;; modified, so `verify-visited-file-modtime' should return
> +           ;; t.
> +           (should (equal (verify-visited-file-modtime
> buffer-visiting-file)
> +                          t))))
> +       ;; Verify that the handler was actually called.  We called
> +       ;; `verify-visited-file-modtime' twice, so both calls should be
> +       ;; recorded in reverse order.
> +       (should (equal actual-args
> +                      `((verify-visited-file-modtime
> ,buffer-visiting-file)
> +                        (verify-visited-file-modtime nil))))))))
> +
>  (provide 'files-tests)
>  ;;; files-tests.el ends here
> --
> 2.12.2
>
>
No further comments, so I've pushed this as 5e47c2e52b.

[-- Attachment #2: Type: text/html, Size: 6629 bytes --]

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

* bug#25951: [PATCH] Fix quoted files for 'verify-visited-file-modtime'
       [not found]   ` <CAArVCkQ_mFGskvFHG9cVw=2fTxfROkDEshaxgGjrgk=oRBe4jA@mail.gmail.com>
@ 2017-05-06 20:28     ` Glenn Morris
  2017-05-06 20:41       ` npostavs
  0 siblings, 1 reply; 8+ messages in thread
From: Glenn Morris @ 2017-05-06 20:28 UTC (permalink / raw)
  To: 25951; +Cc: p.stephani2


This fails to build: http://hydra.nixos.org/build/52549555





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

* bug#25951: [PATCH] Fix quoted files for 'verify-visited-file-modtime'
  2017-05-06 20:28     ` Glenn Morris
@ 2017-05-06 20:41       ` npostavs
  2017-05-06 21:21         ` bug#25951: [PATCH] Fix bootstrap build of files.el Philipp
                           ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: npostavs @ 2017-05-06 20:41 UTC (permalink / raw)
  To: Glenn Morris; +Cc: 25951, p.stephani2

Glenn Morris <rgm@gnu.org> writes:

> This fails to build: http://hydra.nixos.org/build/52549555

    Loading /tmp/nix-build-emacs-tarball-unknown.drv-0/x1vxdahi72zl4bj2yd676ichh4iwi9iw-git-export/lisp/files.el (source)...
    Warning: Unknown defun property `gv-setter' in cl-fifth
    Warning: Unknown defun property `gv-setter' in cl-sixth
    Warning: Unknown defun property `gv-setter' in cl-seventh
    Warning: Unknown defun property `gv-setter' in cl-eighth
    Warning: Unknown defun property `gv-setter' in cl-ninth
    Warning: Unknown defun property `gv-setter' in cl-tenth
    Symbol's function definition is void: gv-define-simple-setter
    make[1]: *** [bootstrap-emacs] Error 255

Looks like my suggestion of using cl-letf doesn't work because it's too
early in the bootstrap process.  Should work with the original code (but
perhaps add a comment about why we can't use cl-letf).





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

* bug#25951: [PATCH] Fix bootstrap build of files.el
  2017-05-06 20:41       ` npostavs
@ 2017-05-06 21:21         ` Philipp
  2017-05-06 21:27         ` bug#25951: [PATCH] Fix quoted files for 'verify-visited-file-modtime' Philipp
       [not found]         ` <20170506212157.62158-1-phst@google.com>
  2 siblings, 0 replies; 8+ messages in thread
From: Philipp @ 2017-05-06 21:21 UTC (permalink / raw)
  To: rgm, npostavs, emacs-devel, 25951; +Cc: Philipp

* lisp/files.el (file-name-non-special): Don't use cl-letf.
---
 lisp/files.el | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/lisp/files.el b/lisp/files.el
index 7e627d36d4..8ac1993754 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -29,7 +29,6 @@
 ;;; Code:
 
 (eval-when-compile
-  (require 'cl-lib)
   (require 'pcase)
   (require 'easy-mmode)) ; For `define-minor-mode'.
 
@@ -7032,13 +7031,18 @@ file-name-non-special
            (when (and visit buffer-file-name)
              (setq buffer-file-name (concat "/:" buffer-file-name))))))
       (`unquote-then-quote
-       (cl-letf* ((buffer (or (car arguments) (current-buffer)))
-                  ((buffer-local-value 'buffer-file-name buffer)
-                   (substring (buffer-file-name buffer) 2)))
+       ;; We can't use `cl-letf' with `(buffer-local-value)' here
+       ;; because it wouldn't work during bootstrapping.
+       (let ((buffer (current-buffer)))
          ;; `unquote-then-quote' is only used for the
          ;; `verify-visited-file-modtime' action, which takes a buffer
          ;; as only optional argument.
-         (apply operation arguments)))
+         (with-current-buffer (or (car arguments) buffer)
+           (let ((buffer-file-name (substring buffer-file-name 2)))
+             ;; Make sure to hide the temporary buffer change from the
+             ;; underlying operation.
+             (with-current-buffer buffer
+               (apply operation arguments))))))
       (_
        (apply operation arguments)))))
 
-- 
2.12.2






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

* bug#25951: [PATCH] Fix quoted files for 'verify-visited-file-modtime'
  2017-05-06 20:41       ` npostavs
  2017-05-06 21:21         ` bug#25951: [PATCH] Fix bootstrap build of files.el Philipp
@ 2017-05-06 21:27         ` Philipp
       [not found]         ` <20170506212157.62158-1-phst@google.com>
  2 siblings, 0 replies; 8+ messages in thread
From: Philipp @ 2017-05-06 21:27 UTC (permalink / raw)
  To: npostavs, Glenn Morris; +Cc: 25951

[-- Attachment #1: Type: text/plain, Size: 1041 bytes --]

<npostavs@users.sourceforge.net> schrieb am Sa., 6. Mai 2017 um 22:39 Uhr:

> Glenn Morris <rgm@gnu.org> writes:
>
> > This fails to build: http://hydra.nixos.org/build/52549555
>
>     Loading
> /tmp/nix-build-emacs-tarball-unknown.drv-0/x1vxdahi72zl4bj2yd676ichh4iwi9iw-git-export/lisp/files.el
> (source)...
>     Warning: Unknown defun property `gv-setter' in cl-fifth
>     Warning: Unknown defun property `gv-setter' in cl-sixth
>     Warning: Unknown defun property `gv-setter' in cl-seventh
>     Warning: Unknown defun property `gv-setter' in cl-eighth
>     Warning: Unknown defun property `gv-setter' in cl-ninth
>     Warning: Unknown defun property `gv-setter' in cl-tenth
>     Symbol's function definition is void: gv-define-simple-setter
>     make[1]: *** [bootstrap-emacs] Error 255
>
> Looks like my suggestion of using cl-letf doesn't work because it's too
> early in the bootstrap process.  Should work with the original code (but
> perhaps add a comment about why we can't use cl-letf).
>

Installed commit cea3b22bc7.

[-- Attachment #2: Type: text/html, Size: 1586 bytes --]

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

* bug#25951: [PATCH] Fix bootstrap build of files.el
       [not found]         ` <20170506212157.62158-1-phst@google.com>
@ 2017-05-07  1:24           ` Glenn Morris
       [not found]           ` <5gfugho3vw.fsf@fencepost.gnu.org>
  1 sibling, 0 replies; 8+ messages in thread
From: Glenn Morris @ 2017-05-07  1:24 UTC (permalink / raw)
  To: Philipp; +Cc: Philipp, 25951, npostavs, emacs-devel


We have a diffs mailing list, so you don't need to send your patches to
two other mailing lists as well.





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

* bug#25951: [PATCH] Fix bootstrap build of files.el
       [not found]           ` <5gfugho3vw.fsf@fencepost.gnu.org>
@ 2017-05-07 11:35             ` Philipp
  0 siblings, 0 replies; 8+ messages in thread
From: Philipp @ 2017-05-07 11:35 UTC (permalink / raw)
  To: Glenn Morris; +Cc: Philipp, 25951, emacs-devel, npostavs

[-- Attachment #1: Type: text/plain, Size: 323 bytes --]

Glenn Morris <rgm@gnu.org> schrieb am So., 7. Mai 2017 um 03:25 Uhr:

>
> We have a diffs mailing list, so you don't need to send your patches to
> two other mailing lists as well.
>
>

Yes, I just wanted to have my patch reviewed before committing, but since
it broke bootstrapping I decided to install it without review.

[-- Attachment #2: Type: text/html, Size: 618 bytes --]

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

end of thread, other threads:[~2017-05-07 11:35 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <83fugvpw24.fsf@gnu.org>
2017-04-29 12:20 ` bug#25951: [PATCH] Fix quoted files for 'verify-visited-file-modtime' Philipp Stephani
     [not found] ` <20170429122027.39318-1-phst@google.com>
2017-05-06 19:27   ` Philipp
     [not found]   ` <CAArVCkQ_mFGskvFHG9cVw=2fTxfROkDEshaxgGjrgk=oRBe4jA@mail.gmail.com>
2017-05-06 20:28     ` Glenn Morris
2017-05-06 20:41       ` npostavs
2017-05-06 21:21         ` bug#25951: [PATCH] Fix bootstrap build of files.el Philipp
2017-05-06 21:27         ` bug#25951: [PATCH] Fix quoted files for 'verify-visited-file-modtime' Philipp
     [not found]         ` <20170506212157.62158-1-phst@google.com>
2017-05-07  1:24           ` bug#25951: [PATCH] Fix bootstrap build of files.el Glenn Morris
     [not found]           ` <5gfugho3vw.fsf@fencepost.gnu.org>
2017-05-07 11:35             ` Philipp

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