summaryrefslogtreecommitdiffstats
path: root/fix-expand-file-name.patch
blob: 491a8fb760e97acf34b5b68706e30ea64cc4384f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
From 18b7b900901ec8cb4641ad96917d0fa8e2972fa9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20Lassieur?= <clement.lassieur@parrot.com>
Date: Thu, 27 Dec 2018 16:35:06 +0100
Subject: [PATCH] fix expand-file-name

---
 dropbox.el | 38 ++++++++++++++++++++++++++------------
 1 file changed, 26 insertions(+), 12 deletions(-)

diff --git a/dropbox.el b/dropbox.el
index 443a8f3..b737de7 100644
--- a/dropbox.el
+++ b/dropbox.el
@@ -342,18 +342,32 @@ debugging but otherwise very intrusive."
     (match-string 1 filename))
    (t (substring filename 4))))
 
-(defun dropbox-handle-expand-file-name (filename &optional default-directory)
-  "Return the canonicalized, absolute version of FILENAME"
-
-  (if (or (file-name-absolute-p filename)
-          (not (dropbox-file-p default-directory)))
-      filename
-    (concat
-     dropbox-prefix
-     (substring
-      (expand-file-name filename
-                        (concat "/" (dropbox-strip-prefix default-directory)))
-      1))))
+(defun dropbox-remove-slash (filename)
+  "Transform /db:/notes into /db:notes."
+  (if (dropbox-file-p filename)
+      (if (string-match "^/db:/\\(.*\\)$" filename)
+          (concat dropbox-prefix (match-string 1 filename))
+        filename)
+    filename))
+
+(defun dropbox-run-real-handler (operation args)
+  "Invoke normal file name handler for OPERATION.
+First arg specifies the OPERATION, second arg is a list of arguments to
+pass to the OPERATION."
+  (let* ((inhibit-file-name-handlers
+          `(dropbox-handler
+            .
+            ,(and (eq inhibit-file-name-operation operation)
+                  inhibit-file-name-handlers)))
+         (inhibit-file-name-operation operation))
+    (apply operation args)))
+
+(defun dropbox-handle-expand-file-name (filename &optional dir)
+  "Like the normal operation, except that slashes are removed from
+dropbox-like files (/db:/something is transformed into /db:something)."
+  (dropbox-run-real-handler 'expand-file-name
+                            (list (dropbox-remove-slash filename)
+                                  (dropbox-remove-slash dir))))
 
 (defun dropbox-handle-file-truename (filename)
   filename)
-- 
2.19.1