emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Jan Böcker" <jan.boecker@jboecker.de>
To: dmg <dmg@uvic.ca>
Cc: emacs-orgmode <emacs-orgmode@gnu.org>
Subject: Re: Re: org-protocol: non-ASCII characters
Date: Sat, 13 Feb 2010 14:22:25 +0100	[thread overview]
Message-ID: <4B76A791.1090808@jboecker.de> (raw)
In-Reply-To: <16e9be801002121423y5bdff5bdy2e9e7503f8deb154@mail.gmail.com>

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

On 12.02.2010 23:23, dmg wrote:

> For evince, I think I have found a problem in the parsing of the link.
> Evince already encodes
> the URL, but it does not encode the '/', hence you will get a link like this:
> 
> emacsclient 'org-protocol://remember://docview/tmp/00%C3%A1%C3%A9%C3%AD%C3%B3%C3%BA.pdf::1'
> 
> the filename is  /tmp/00áéíóú.pdf
> 
> But emacs incorrectly stops parsing the link after tmp/

I think I have found the proper way to handle this in evince.
Check out the attached patch or pull from:

git://github.com/jboecker/evince.git

This code first retrieves the non-URI-encoded UTF-8 filename and passes
that to uri_encode. Should g_file_get_path return NULL, we abort,
because the URI specifies something in gnomes VFS layer that has no
local path, so the link would not work, anyway.

> By the way, xournal now supports store-link

Works as advertised, thanks!

The only problem I have left now is a cosmetic one: when I store a link
to, say, /tmp/test.xoj, in Org it becomes file://tmp/test.xoj instead of
file:/tmp/test.xoj. (I have patched xournal and evince to generate file:
instead of docview: links.)

This is because org-protocol-sanitize-uri is called after decoding the
string, allegedly because emacsclient compresses multiple slashes in a
row to one. However, it seems that this function should be applied
/before/ the string is URL-decoded. Is this a bug?


[-- Attachment #2: 0001-bugfix-in-encode_uri-cast-to-unsigned-char-to-get-th.patch --]
[-- Type: text/plain, Size: 913 bytes --]

From f777bca64fd23066f626bc55cee6a81d6e03dac5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20B=C3=B6cker?= <jan.boecker@jboecker.de>
Date: Sat, 13 Feb 2010 12:38:39 +0100
Subject: [PATCH 1/2] bugfix in encode_uri: cast to unsigned char to get the correct byte value

---
 libview/ev-view.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/libview/ev-view.c b/libview/ev-view.c
index c334fdc..1130d39 100644
--- a/libview/ev-view.c
+++ b/libview/ev-view.c
@@ -5775,8 +5775,8 @@ static void encode_uri(gchar *encoded_uri, gint bufsize, const gchar *uri)
       if (k + 4 >= bufsize)
         break;
       encoded_uri[k++] = '%';
-      encoded_uri[k++] = hexa[uri[i] / 16];
-      encoded_uri[k++] = hexa[uri[i] % 16];
+      encoded_uri[k++] = hexa[(unsigned char)uri[i] / 16];
+      encoded_uri[k++] = hexa[(unsigned char)uri[i] % 16];
     }
   }
   encoded_uri[k] = 0;
-- 
1.6.6.1


[-- Attachment #3: 0002-URI-encode-the-utf-8-filename-instead-of-a-partially.patch --]
[-- Type: text/plain, Size: 2258 bytes --]

From 1003e7809fbf2823e23b8dc8c7e3b46dfad0bcd5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20B=C3=B6cker?= <jan.boecker@jboecker.de>
Date: Sat, 13 Feb 2010 12:37:31 +0100
Subject: [PATCH 2/2] URI-encode the utf-8 filename instead of a partially URI-encoded gnome vfs uri

---
 libview/ev-view.c |   28 ++++++++++++++++------------
 1 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/libview/ev-view.c b/libview/ev-view.c
index 1130d39..4fda860 100644
--- a/libview/ev-view.c
+++ b/libview/ev-view.c
@@ -5800,9 +5800,18 @@ ev_view_annotate (EvView *ev_view, gchar *uri, int page)
 
 	EvDocumentInfo  *p = ev_document_get_info(ev_view->document);
 
+	// get the real file path from evince
+	GFile *gfile = g_file_new_for_uri(uri);
+	char *filePath = g_file_get_path(gfile);
+	g_object_unref (gfile);
+	if (!filePath) {
+		printf("invalid file path");
+		return;
+	}
+	
 	tempSel = g_malloc(ANN_MAX_BUFFER_LEN);
 	tempFileName = g_malloc(strlen(uri) * 4);
-
+	
 	if (!EV_IS_SELECTION (ev_view->document))  {
 		strcmp(tempSel,  ""); 
 		text = "";
@@ -5811,20 +5820,13 @@ ev_view_annotate (EvView *ev_view, gchar *uri, int page)
 		text = get_selected_text (ev_view);
 		encode_uri(tempSel, ANN_MAX_BUFFER_LEN, text);
 	}
-	/// encode filename
-#define ANN_FILE_PREFIX "file://"
-	if (strncmp(uri,ANN_FILE_PREFIX, strlen(ANN_FILE_PREFIX) ) == 0) {
-		// skip the prefix
-		encode_uri(tempFileName, 
-			   ANN_MAX_BUFFER_LEN, uri+strlen(ANN_FILE_PREFIX));
-	} else {
-		encode_uri(tempFileName, ANN_MAX_BUFFER_LEN, uri);
-	}
-
+		
+	encode_uri(tempFileName, ANN_MAX_BUFFER_LEN, filePath);
+	
 	tempCommandLine = g_malloc(strlen(tempSel) + strlen(tempFileName) + 200);
 
-	printf("remember::::%s::::%s::::%s::::%d\n", p->title, uri, text, page);
 	sprintf(tempCommandLine, "emacsclient 'org-protocol://remember://docview:%s::%d'", tempFileName, page+1);
+	printf("remember::::%s::::%s::::%s::::%d\n", p->title, filePath, text, page);
 	printf("temp: [%s]\n", tempCommandLine);
 
 	if (!g_spawn_command_line_async (tempCommandLine, &error)) {
@@ -5836,6 +5838,8 @@ ev_view_annotate (EvView *ev_view, gchar *uri, int page)
 	g_free (tempSel);
 	g_free (tempCommandLine);
 	g_free (tempFileName);
+	g_free (filePath);
+	
 
 
 #ifdef fork
-- 
1.6.6.1


[-- Attachment #4: Type: text/plain, Size: 201 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

  reply	other threads:[~2010-02-13 13:22 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-31  8:39 org-remember support in xournal D M German
2010-01-31  8:45 ` dmg
2010-02-03  9:19 ` Jan Böcker
2010-02-03  9:22   ` dmg
2010-02-04 18:43   ` org-protocol: non-ASCII characters D M German
2010-02-06 13:50     ` Jan Böcker
2010-02-06 14:35       ` Jan Böcker
2010-02-08 11:30         ` Sebastian Rose
2010-02-12 22:23           ` dmg
2010-02-13 13:22             ` Jan Böcker [this message]
2010-02-15  9:41               ` Sebastian Rose

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.orgmode.org/

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

  git send-email \
    --in-reply-to=4B76A791.1090808@jboecker.de \
    --to=jan.boecker@jboecker.de \
    --cc=dmg@uvic.ca \
    --cc=emacs-orgmode@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/org-mode.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).