all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Philipp Stephani <p.stephani2@gmail.com>
To: 25951@debbugs.gnu.org
Subject: bug#25951: 26.0.50; Error when ediffing files that are visited using quoted file names
Date: Fri, 21 Apr 2017 22:14:25 +0000	[thread overview]
Message-ID: <CAArVCkS7xtAu00YyjKWNgGPAQq2AS1BqqE4VpXFmmNeTzZ9kUg@mail.gmail.com> (raw)
In-Reply-To: <wvr44lzawjj3.fsf@a.muc.corp.google.com>


[-- Attachment #1.1: Type: text/plain, Size: 1207 bytes --]

Philipp Stephani <p.stephani2@gmail.com> schrieb am Fr., 3. März 2017 um
14:58 Uhr:

>
> Assuming /tmp/[ab].py are existing files.
>
> emacs -Q -f server-start /:/tmp/a.py
>
> Then:
>
> emacsclient --create-frame --eval '(ediff "/tmp/a.py" "/tmp/b.py")'
>
> will result un an error:
>
> *ERROR*: Wrong type argument: arrayp, nil
>
> Backtrace is
>
> Debugger entered--Lisp error: (wrong-type-argument arrayp nil)
>   file-name-non-special(verify-visited-file-modtime #<buffer a.py>)
>   verify-visited-file-modtime(#<buffer a.py>)
>   apply(verify-visited-file-modtime #<buffer a.py>)
>   tramp-run-real-handler(verify-visited-file-modtime (#<buffer a.py>))
>   tramp-file-name-handler(verify-visited-file-modtime #<buffer a.py>)
>   verify-visited-file-modtime(#<buffer a.py>)
>   find-file-noselect("/tmp/a.py")
>   ediff-find-file(file-A buf-A ediff-last-dir-A startup-hooks)
>   ediff-files-internal("/tmp/a.py" "/tmp/b.py" nil nil ediff-files)
>   ediff("/tmp/a.py" "/tmp/b.py")
>   eval((ediff "/tmp/a.py" "/tmp/b.py"))
>   server-eval-and-print("(ediff \"/tmp/a.py\" \"/tmp/b.py\")" #<process
> server <3>>)
>   (more uninteresting frames)
>
>
Patch is attached.

[-- Attachment #1.2: Type: text/html, Size: 1732 bytes --]

[-- Attachment #2: 0001-Fix-quoted-files-for-verify-visited-file-modtime.txt --]
[-- Type: text/plain, Size: 4467 bytes --]

From 9e5d1d09a4597885b1fc40feec6dbf64cf1e29cd Mon Sep 17 00:00:00 2001
From: Philipp Stephani <phst@google.com>
Date: Sat, 22 Apr 2017 00:12:23 +0200
Subject: [PATCH] Fix quoted files for 'verify-visited-file-modtime'

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.
---
 lisp/files.el            | 12 ++++++++++--
 test/lisp/files-tests.el | 42 +++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 51 insertions(+), 3 deletions(-)

diff --git a/lisp/files.el b/lisp/files.el
index 6848818cad..64843287e5 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -6987,8 +6987,16 @@ 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)))
-         (apply operation arguments)))
+       (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.
+         (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)))))
 
diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el
index 80bbeb1bc5..ed66533d48 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,44 @@ files-test-bug-18141-file
                       (start-file-process "foo" nil "true"))))
   (should (eq (let ((default-directory "/:/")) (shell-command "true")) 0)))
 
+(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."
+  (with-temp-buffer
+    (let* ((buffer-file-name "/:/tmp/bug25951.txt")
+           (buffer-visiting-file (current-buffer))
+           (actual-args ())
+           (log (lambda (&rest args) (push args actual-args))))
+      (set-visited-file-modtime '(1 2 3 4))
+      (should (equal (find-file-name-handler buffer-file-name
+                                             #'verify-visited-file-modtime)
+                     #'file-name-non-special))
+      (advice-add #'file-name-non-special :before log)
+      (unwind-protect
+          (progn
+            (should (stringp buffer-file-name))
+            ;; This should call the file name handler with the right
+            ;; buffer and not signal an error.  The file doesn't
+            ;; actually exist, so this should return nil.
+            (should-not (verify-visited-file-modtime))
+            (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 doesn't
+              ;; actually exist, so this should return nil.
+              (should-not (verify-visited-file-modtime buffer-visiting-file)))))
+      (advice-remove #'file-name-non-special 'bug25951)
+      ;; 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


  reply	other threads:[~2017-04-21 22:14 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-03 13:56 bug#25951: 26.0.50; Error when ediffing files that are visited using quoted file names Philipp Stephani
2017-04-21 22:14 ` Philipp Stephani [this message]
2017-04-21 22:50   ` npostavs
2017-04-22 19:43     ` Philipp Stephani
2017-04-22 20:32       ` npostavs
2017-04-23 16:54         ` Philipp Stephani
2017-04-23 17:06           ` [PATCH] Fix quoted files for 'verify-visited-file-modtime' Philipp Stephani
2017-04-26  5:38             ` Eli Zaretskii
2017-04-29 12:20               ` Philipp Stephani
2017-05-06 19:27                 ` bug#25951: " Philipp
2017-05-06 19:27                 ` Philipp
2017-05-06 20:28                   ` bug#25951: " Glenn Morris
2017-05-06 20:41                     ` npostavs
2017-05-06 21:21                       ` [PATCH] Fix bootstrap build of files.el Philipp
2017-05-07  1:24                         ` Glenn Morris
2017-05-07 11:35                           ` bug#25951: " Philipp
2017-05-07 11:35                           ` Philipp
2017-05-07  1:24                         ` bug#25951: " Glenn Morris
2017-05-06 21:21                       ` Philipp
2017-05-06 21:27                       ` bug#25951: [PATCH] Fix quoted files for 'verify-visited-file-modtime' Philipp
2017-04-29 12:20               ` Philipp Stephani
2017-04-29 11:49           ` Philipp Stephani

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAArVCkS7xtAu00YyjKWNgGPAQq2AS1BqqE4VpXFmmNeTzZ9kUg@mail.gmail.com \
    --to=p.stephani2@gmail.com \
    --cc=25951@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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.