emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Skim.app support for org-mac-link-grabber.el
@ 2013-05-12 18:29 Daniil Frumin
  2013-05-13  0:39 ` Ivan Andrus
  2013-05-13  6:34 ` Carsten Dominik
  0 siblings, 2 replies; 9+ messages in thread
From: Daniil Frumin @ 2013-05-12 18:29 UTC (permalink / raw)
  To: emacs-orgmode

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

Hi, all!

I use org-mac-link-grabber.el <http://orgmode.org/worg/org-contrib/org-mac-link-grabber.html> almost every day. However, it lacks support for an app that I'd like to use together with org-mode. 

Skim.app is a light and fast PDF reader for Mac OS X with a note-taking ability. I wrote a little patch for org-mac-link-grabber.el to support grabbing links to documents.

What it does:

* Grabs not just the link to file, but a page

* Inserts the selected text as a description, if present. Otherwise
  inserts "<filename>, p. <page #>"

* The shortcut is set to [S]

* Defines a new "skim" link type

It would be interesting to also add some support for importing notes from Skim to org.

Since Skim.app is not present in clean OS X installs, by default support for grabbing links from it is disabled. You can enable it by customizing group `org-mac-link-grabber'.

So, maybe it's possible to get this patch into the tree? It's my first time hacking on org (or even any major elisp extension), so it's probably that I've messed up somewhere with a commit format or whatnot.

Cheers.

-- Daniil Frumin

[-- Attachment #2: 0001-Adding-Skim.app-support-to-org-mac-link-grabber.el.patch --]
[-- Type: application/octet-stream, Size: 5000 bytes --]

From 1326cb78bfcc2111e4fd59789a3960d09cb4a694 Mon Sep 17 00:00:00 2001
From: Daniil <ohwow@cpan.org>
Date: Sun, 12 May 2013 22:11:09 +0400
Subject: [PATCH] Adding Skim.app support to org-mac-link-grabber.el

* The shortcut is set to [S]

* Grabs not just the link to file, but a page

* Inserts the selected text as a description, if present. Otherwise
  inserts "<filename>, p. <page #>"

* Defines a new "skim" link type
---
 contrib/lisp/org-mac-link-grabber.el | 83 ++++++++++++++++++++++++++++++++----
 1 file changed, 75 insertions(+), 8 deletions(-)

diff --git a/contrib/lisp/org-mac-link-grabber.el b/contrib/lisp/org-mac-link-grabber.el
index 0598617..e71fc15 100644
--- a/contrib/lisp/org-mac-link-grabber.el
+++ b/contrib/lisp/org-mac-link-grabber.el
@@ -128,21 +128,28 @@ applications and inserting them in org documents"
   :group 'org-mac-link-grabber
   :type 'boolean)
 
+(defcustom org-mac-grab-Skim-app-p t
+  "Enable menu option [S]kim to grab page links from Skim.app"
+  :tag "Grab Skim.app page links"
+  :group 'org-mac-link-grabber
+  :type 'boolean)
+
 \f
 (defun omlg-grab-link ()
   "Prompt the user for an application to grab a link from, then go grab the link, and insert it at point"
   (interactive)
   (let* ((descriptors `(("F" "inder" org-mac-finder-insert-selected ,org-mac-grab-Finder-app-p)
-						("m" "ail" org-mac-message-insert-selected ,org-mac-grab-Mail-app-p)
-						("a" "ddressbook" org-mac-addressbook-insert-selected ,org-mac-grab-Addressbook-app-p)
-						("s" "afari" org-mac-safari-insert-frontmost-url ,org-mac-grab-Safari-app-p)
-						("f" "irefox" org-mac-firefox-insert-frontmost-url ,org-mac-grab-Firefox-app-p)
-						("v" "imperator" org-mac-vimperator-insert-frontmost-url ,org-mac-grab-Firefox+Vimperator-p)
-						("c" "hrome" org-mac-chrome-insert-frontmost-url ,org-mac-grab-Chrome-app-p)
-						("t" "ogether" org-mac-together-insert-selected ,org-mac-grab-Together-app-p)))
+			("m" "ail" org-mac-message-insert-selected ,org-mac-grab-Mail-app-p)
+			("a" "ddressbook" org-mac-addressbook-insert-selected ,org-mac-grab-Addressbook-app-p)
+			("s" "afari" org-mac-safari-insert-frontmost-url ,org-mac-grab-Safari-app-p)
+			("f" "irefox" org-mac-firefox-insert-frontmost-url ,org-mac-grab-Firefox-app-p)
+			("v" "imperator" org-mac-vimperator-insert-frontmost-url ,org-mac-grab-Firefox+Vimperator-p)
+			("c" "hrome" org-mac-chrome-insert-frontmost-url ,org-mac-grab-Chrome-app-p)
+			("t" "ogether" org-mac-together-insert-selected ,org-mac-grab-Together-app-p)
+			("S" "kim" org-mac-skim-insert-page ,org-mac-grab-Skim-app-p)))
 		 (menu-string (make-string 0 ?x))
 		 input)
-
+    
 	;; Create the menu string for the keymap
 	(mapc '(lambda (descriptor)
 			(when (elt descriptor 3)
@@ -460,6 +467,66 @@ applications and inserting them in org documents"
   (interactive)
   (insert (org-mac-addressbook-item-get-selected)))
 
+;;
+;;
+;; Handle links from Skim.app
+;;
+;; A rewriting of some code originally by Christopher Suckling from org-mac-protocol
+
+(org-add-link-type "skim" 'org-mac-skim-open)
+
+(defun org-mac-skim-open (uri)
+  "Visit page of pdf in Skim"
+  (let* ((page (when (string-match "::\\(.+\\)\\'" uri)
+		 (match-string 1 uri)))
+	 (document (substring uri 0 (match-beginning 0))))
+    (do-applescript
+     (concat
+      "tell application \"Skim\"\n"
+         "activate\n"
+	 "set theDoc to \"" document "\"\n"
+		     "set thePage to " page "\n"
+	 "open theDoc\n"
+	 "go document 1 to page thePage of document 1\n"
+      "end tell"))))
+
+
+(defun as-get-skim-page-link ()
+  (do-applescript
+   (concat
+    "tell application \"Skim\"\n"
+       "set theDoc to front document\n"
+       "set theTitle to (name of theDoc)\n"
+       "set thePath to (path of theDoc)\n"
+       "set thePage to (get index for current page of theDoc)\n"
+       "set theSelection to selection of theDoc\n"
+       "set theContent to contents of (get text for theSelection)\n"
+       "if theContent is missing value then\n"
+          "set theContent to theTitle & \", p. \" & thePage\n"
+       "end if\n"
+       "set theLink to \"skim://\" & thePath & \"::\" & thePage & "
+       "\"::split::\" & theContent\n"
+    "end tell\n"
+    "return theLink as string\n")))
+
+(defun org-mac-skim-get-page ()
+  (interactive)
+  (message "Applescript: Getting Skim page link...")
+  (let* ((url-and-title (as-get-skim-page-link))
+         (split-link (split-string url-and-title "::split::"))
+         (URL (car split-link))
+         (description (cadr split-link))
+         (org-link))
+    (when (not (string= URL ""))
+      (setq org-link (org-make-link-string URL description)))
+    (kill-new org-link)
+    org-link))
+
+(defun org-mac-skim-insert-page ()
+  (interactive)
+  (insert (org-mac-skim-get-page)))
+
+
 \f
 (provide 'org-mac-link-grabber)
 
-- 
1.7.12.4 (Apple Git-37)


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

* Re: Skim.app support for org-mac-link-grabber.el
  2013-05-12 18:29 Skim.app support for org-mac-link-grabber.el Daniil Frumin
@ 2013-05-13  0:39 ` Ivan Andrus
  2013-05-13  6:34 ` Carsten Dominik
  1 sibling, 0 replies; 9+ messages in thread
From: Ivan Andrus @ 2013-05-13  0:39 UTC (permalink / raw)
  To: Daniil Frumin; +Cc: emacs-orgmode

Just two comments from someone who didn't know org-mac-link-grabber existed until today (I'm gonna try it out) and hasn't (yet) contributed to org-mode.

1. It looks like it's actually enabled by default
2. You can detect whether it should be enabled by default with something like

(< 0 (length (shell-command-to-string
              "mdfind kMDItemCFBundleIdentifier == 'net.sourceforge.skim-app.skim'")))

which will tell whether you have skim installed.  I haven't looked at org-mac-link-grabber to see if other similar changes could be made.  So the defcustom would be changed to

(defcustom org-mac-grab-Skim-app-p
  (< 0 (length (shell-command-to-string
                "mdfind kMDItemCFBundleIdentifier == 'net.sourceforge.skim-app.skim'")))
  "Enable menu option [S]kim to grab page links from Skim.app"
  :tag "Grab Skim.app page links"
  :group 'org-mac-link-grabber
  :type 'boolean)

-Ivan

On May 12, 2013, at 12:29 PM, Daniil Frumin <difrumin@gmail.com> wrote:

> Hi, all!
> 
> I use org-mac-link-grabber.el <http://orgmode.org/worg/org-contrib/org-mac-link-grabber.html> almost every day. However, it lacks support for an app that I'd like to use together with org-mode. 
> 
> Skim.app is a light and fast PDF reader for Mac OS X with a note-taking ability. I wrote a little patch for org-mac-link-grabber.el to support grabbing links to documents.
> 
> What it does:
> 
> * Grabs not just the link to file, but a page
> 
> * Inserts the selected text as a description, if present. Otherwise
>  inserts "<filename>, p. <page #>"
> 
> * The shortcut is set to [S]
> 
> * Defines a new "skim" link type
> 
> It would be interesting to also add some support for importing notes from Skim to org.
> 
> Since Skim.app is not present in clean OS X installs, by default support for grabbing links from it is disabled. You can enable it by customizing group `org-mac-link-grabber'.
> 
> So, maybe it's possible to get this patch into the tree? It's my first time hacking on org (or even any major elisp extension), so it's probably that I've messed up somewhere with a commit format or whatnot.
> 
> Cheers.
> 
> -- Daniil Frumin
> <0001-Adding-Skim.app-support-to-org-mac-link-grabber.el.patch>

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

* Re: Skim.app support for org-mac-link-grabber.el
  2013-05-12 18:29 Skim.app support for org-mac-link-grabber.el Daniil Frumin
  2013-05-13  0:39 ` Ivan Andrus
@ 2013-05-13  6:34 ` Carsten Dominik
  2013-05-13  9:53   ` Daniel F
  2013-05-13 20:35   ` Daniil Frumin
  1 sibling, 2 replies; 9+ messages in thread
From: Carsten Dominik @ 2013-05-13  6:34 UTC (permalink / raw)
  To: Daniil Frumin, anthony.lander; +Cc: emacs-orgmode@gnu.org Mode

Hi Daniil,

I like this a lot and would like to take the patch after you have taken Ivans feedback, and maybe more feedback if you get any.

I would like it even more if following the link would rehighlight the selected text.  Is there any way to achieve this?

I have another question, this would maybe be for the original author, Anthony Lander?  I see that there are functions with prefixes that are not "org-".  This is dangerous because there might be packages around that use that name space.  I also think it violates coding rules in Emacs.  I think this should be changed - unless you know of a convention that all functions dealing with applescripts are supposed to have an "as-" prefix.

I can fix this - but I wanted your feedback first.

Thanks.

- Carsten

On 12 mei 2013, at 20:29, Daniil Frumin <difrumin@gmail.com> wrote:

> Hi, all!
> 
> I use org-mac-link-grabber.el <http://orgmode.org/worg/org-contrib/org-mac-link-grabber.html> almost every day. However, it lacks support for an app that I'd like to use together with org-mode. 
> 
> Skim.app is a light and fast PDF reader for Mac OS X with a note-taking ability. I wrote a little patch for org-mac-link-grabber.el to support grabbing links to documents.
> 
> What it does:
> 
> * Grabs not just the link to file, but a page
> 
> * Inserts the selected text as a description, if present. Otherwise
>  inserts "<filename>, p. <page #>"
> 
> * The shortcut is set to [S]
> 
> * Defines a new "skim" link type
> 
> It would be interesting to also add some support for importing notes from Skim to org.
> 
> Since Skim.app is not present in clean OS X installs, by default support for grabbing links from it is disabled. You can enable it by customizing group `org-mac-link-grabber'.
> 
> So, maybe it's possible to get this patch into the tree? It's my first time hacking on org (or even any major elisp extension), so it's probably that I've messed up somewhere with a commit format or whatnot.
> 
> Cheers.
> 
> -- Daniil Frumin
> <0001-Adding-Skim.app-support-to-org-mac-link-grabber.el.patch>

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

* Re: Skim.app support for org-mac-link-grabber.el
  2013-05-13  6:34 ` Carsten Dominik
@ 2013-05-13  9:53   ` Daniel F
  2013-05-13 10:54     ` Carsten Dominik
  2013-05-13 20:35   ` Daniil Frumin
  1 sibling, 1 reply; 9+ messages in thread
From: Daniel F @ 2013-05-13  9:53 UTC (permalink / raw)
  To: emacs-orgmode@gnu.org Mode

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

Hi Carsten, Ivan.

Thanks for the feedback. The issue that Ivan mentioned does look important
and I'll try to fix it asap and incorporate the check.
I'll also look into the rehilighting thing, I am not sure if that's
possible. I guess it also would be nice to scroll not just to the right
page, but also to the right line in the text.

As for the "as-" prefix I just assumed that this is legit because the
package was already present in the org-mode.

Cheers.

- Dan


On Mon, May 13, 2013 at 10:34 AM, Carsten Dominik <carsten.dominik@gmail.com
> wrote:

> Hi Daniil,
>
> I like this a lot and would like to take the patch after you have taken
> Ivans feedback, and maybe more feedback if you get any.
>
> I would like it even more if following the link would rehighlight the
> selected text.  Is there any way to achieve this?
>
> I have another question, this would maybe be for the original author,
> Anthony Lander?  I see that there are functions with prefixes that are not
> "org-".  This is dangerous because there might be packages around that use
> that name space.  I also think it violates coding rules in Emacs.  I think
> this should be changed - unless you know of a convention that all functions
> dealing with applescripts are supposed to have an "as-" prefix.
>
> I can fix this - but I wanted your feedback first.
>
> Thanks.
>
> - Carsten
>
> On 12 mei 2013, at 20:29, Daniil Frumin <difrumin@gmail.com> wrote:
>
> > Hi, all!
> >
> > I use org-mac-link-grabber.el <
> http://orgmode.org/worg/org-contrib/org-mac-link-grabber.html> almost
> every day. However, it lacks support for an app that I'd like to use
> together with org-mode.
> >
> > Skim.app is a light and fast PDF reader for Mac OS X with a note-taking
> ability. I wrote a little patch for org-mac-link-grabber.el to support
> grabbing links to documents.
> >
> > What it does:
> >
> > * Grabs not just the link to file, but a page
> >
> > * Inserts the selected text as a description, if present. Otherwise
> >  inserts "<filename>, p. <page #>"
> >
> > * The shortcut is set to [S]
> >
> > * Defines a new "skim" link type
> >
> > It would be interesting to also add some support for importing notes
> from Skim to org.
> >
> > Since Skim.app is not present in clean OS X installs, by default support
> for grabbing links from it is disabled. You can enable it by customizing
> group `org-mac-link-grabber'.
> >
> > So, maybe it's possible to get this patch into the tree? It's my first
> time hacking on org (or even any major elisp extension), so it's probably
> that I've messed up somewhere with a commit format or whatnot.
> >
> > Cheers.
> >
> > -- Daniil Frumin
> > <0001-Adding-Skim.app-support-to-org-mac-link-grabber.el.patch>
>
>


-- 
Sincerely yours,
-- Daniil

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

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

* Re: Skim.app support for org-mac-link-grabber.el
  2013-05-13  9:53   ` Daniel F
@ 2013-05-13 10:54     ` Carsten Dominik
  0 siblings, 0 replies; 9+ messages in thread
From: Carsten Dominik @ 2013-05-13 10:54 UTC (permalink / raw)
  To: Daniel F; +Cc: emacs-orgmode@gnu.org Mode

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


On 13 mei 2013, at 11:53, Daniel F <difrumin@gmail.com> wrote:

> Hi Carsten, Ivan.
> 
> Thanks for the feedback. The issue that Ivan mentioned does look important and I'll try to fix it asap and incorporate the check.
> I'll also look into the rehilighting thing, I am not sure if that's possible. I guess it also would be nice to scroll not just to the right page, but also to the right line in the text.
> 
> As for the "as-" prefix I just assumed that this is legit because the package was already present in the org-mode.

Yes, I see that this is also done in org-mac-message.el. Hmmmm.

- Carsten

> 
> Cheers.
> 
> - Dan
> 
> 
> On Mon, May 13, 2013 at 10:34 AM, Carsten Dominik <carsten.dominik@gmail.com> wrote:
> Hi Daniil,
> 
> I like this a lot and would like to take the patch after you have taken Ivans feedback, and maybe more feedback if you get any.
> 
> I would like it even more if following the link would rehighlight the selected text.  Is there any way to achieve this?
> 
> I have another question, this would maybe be for the original author, Anthony Lander?  I see that there are functions with prefixes that are not "org-".  This is dangerous because there might be packages around that use that name space.  I also think it violates coding rules in Emacs.  I think this should be changed - unless you know of a convention that all functions dealing with applescripts are supposed to have an "as-" prefix.
> 
> I can fix this - but I wanted your feedback first.
> 
> Thanks.
> 
> - Carsten
> 
> On 12 mei 2013, at 20:29, Daniil Frumin <difrumin@gmail.com> wrote:
> 
> > Hi, all!
> >
> > I use org-mac-link-grabber.el <http://orgmode.org/worg/org-contrib/org-mac-link-grabber.html> almost every day. However, it lacks support for an app that I'd like to use together with org-mode.
> >
> > Skim.app is a light and fast PDF reader for Mac OS X with a note-taking ability. I wrote a little patch for org-mac-link-grabber.el to support grabbing links to documents.
> >
> > What it does:
> >
> > * Grabs not just the link to file, but a page
> >
> > * Inserts the selected text as a description, if present. Otherwise
> >  inserts "<filename>, p. <page #>"
> >
> > * The shortcut is set to [S]
> >
> > * Defines a new "skim" link type
> >
> > It would be interesting to also add some support for importing notes from Skim to org.
> >
> > Since Skim.app is not present in clean OS X installs, by default support for grabbing links from it is disabled. You can enable it by customizing group `org-mac-link-grabber'.
> >
> > So, maybe it's possible to get this patch into the tree? It's my first time hacking on org (or even any major elisp extension), so it's probably that I've messed up somewhere with a commit format or whatnot.
> >
> > Cheers.
> >
> > -- Daniil Frumin
> > <0001-Adding-Skim.app-support-to-org-mac-link-grabber.el.patch>
> 
> 
> 
> 
> -- 
> Sincerely yours,
> -- Daniil


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

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

* Re: Skim.app support for org-mac-link-grabber.el
  2013-05-13  6:34 ` Carsten Dominik
  2013-05-13  9:53   ` Daniel F
@ 2013-05-13 20:35   ` Daniil Frumin
  2013-05-14  4:33     ` Carsten Dominik
  1 sibling, 1 reply; 9+ messages in thread
From: Daniil Frumin @ 2013-05-13 20:35 UTC (permalink / raw)
  To: Carsten Dominik; +Cc: emacs-orgmode@gnu.org Mode, anthony.lander

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

So I've been researching this problem and it seems that there is no sane way to re-select a text. 

The problem is that `(do-applescript ..)' only interacts with AppleScript well if the return type of the string is either a number or a string. If I try to convert the selection object (which is not really an object but a list of specifiers) it just returns the selected text. 

There is also `selection bounds' but it only covers rectangle selections.

It's possible to save the selected text and try to `find' it later, but that won't work well (e.g.: there are several repetitions of the same text on one page). 

I've also tried to implement an auto-scrolling to the selected text, but to no avail.

The option that seems to me the most reasonable is to add a highlight note to the selected text (which is actually possible). What do you think? 

For now, the patch to the problem mentioned by Ivan.
I have actually fixed a small bug in the code for getting links from Firefox:
Prior to the fix the firefox link grabber won't work correctly if a cursor has been already positioned in the URL field. The fix works by adding an additional keystore for selecting all the text in that field.

The problem is that I've committed it before committing the stuff that Ivan told us about, so I am not sure what to do in this case.

Thanks

-- Daniil


[-- Attachment #2: 0002-Fixing-a-bug-in-as-mac-firefox-get-frontmost-url.patch --]
[-- Type: application/octet-stream, Size: 1287 bytes --]

From 05982f42efbc27df5db10a6b244ab5dccdd31987 Mon Sep 17 00:00:00 2001
From: Daniil Frumin <difrumin@gmail.com>
Date: Mon, 13 May 2013 22:36:50 +0400
Subject: [PATCH 2/3] Fixing a bug in as-mac-firefox-get-frontmost-url

Prior to the fix the firefox link grabber won't work correctly if a cursor has been already positioned in the URL field. The fix works by adding an additional keystore for selecting all the text in that field.
---
 contrib/lisp/org-mac-link-grabber.el | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/contrib/lisp/org-mac-link-grabber.el b/contrib/lisp/org-mac-link-grabber.el
index e71fc15..f816c76 100644
--- a/contrib/lisp/org-mac-link-grabber.el
+++ b/contrib/lisp/org-mac-link-grabber.el
@@ -216,8 +216,9 @@ applications and inserting them in org documents"
 					 "	activate\n"
 					 "	delay 0.15\n"
 					 "	tell application \"System Events\"\n"
-					 "		keystroke \"l\" using command down\n"
-					 "		keystroke \"c\" using command down\n"
+					 "		keystroke \"l\" using {command down}\n"
+					 "		keystroke \"a\" using {command down}\n"
+					 "		keystroke \"c\" using {command down}\n"
 					 "	end tell\n"
 					 "	delay 0.15\n"
 					 "	set theUrl to the clipboard\n"
-- 
1.7.12.4 (Apple Git-37)


[-- Attachment #3: 0003-Automatic-detection-of-the-presence-of-Skim.app.patch --]
[-- Type: application/octet-stream, Size: 3119 bytes --]

From 32c21fea9dd417a4405f0c6741d86c3c71f06a2b Mon Sep 17 00:00:00 2001
From: Daniil Frumin <difrumin@gmail.com>
Date: Tue, 14 May 2013 00:11:14 +0400
Subject: [PATCH 3/3] Automatic detection of the presence of Skim.app

Automatically detect whether the option for Skim.app should be enabled
by default or not. Thanks to Ivan Andurs.
---
 contrib/lisp/org-mac-link-grabber.el | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/contrib/lisp/org-mac-link-grabber.el b/contrib/lisp/org-mac-link-grabber.el
index f816c76..cb92b44 100644
--- a/contrib/lisp/org-mac-link-grabber.el
+++ b/contrib/lisp/org-mac-link-grabber.el
@@ -128,7 +128,9 @@ applications and inserting them in org documents"
   :group 'org-mac-link-grabber
   :type 'boolean)
 
-(defcustom org-mac-grab-Skim-app-p t
+(defcustom org-mac-grab-Skim-app-p
+  (< 0 (length (shell-command-to-string
+		"mdfind kMDItemCFBundleIdentifier == 'net.sourceforge.skim-app.skim'")))
   "Enable menu option [S]kim to grab page links from Skim.app"
   :tag "Grab Skim.app page links"
   :group 'org-mac-link-grabber
@@ -472,7 +474,7 @@ applications and inserting them in org documents"
 ;;
 ;; Handle links from Skim.app
 ;;
-;; A rewriting of some code originally by Christopher Suckling from org-mac-protocol
+;; Original code & idea by Christopher Suckling (org-mac-protocol)
 
 (org-add-link-type "skim" 'org-mac-skim-open)
 
@@ -486,7 +488,7 @@ applications and inserting them in org documents"
       "tell application \"Skim\"\n"
          "activate\n"
 	 "set theDoc to \"" document "\"\n"
-		     "set thePage to " page "\n"
+	 "set thePage to " page "\n"
 	 "open theDoc\n"
 	 "go document 1 to page thePage of document 1\n"
       "end tell"))))
@@ -503,7 +505,7 @@ applications and inserting them in org documents"
        "set theSelection to selection of theDoc\n"
        "set theContent to contents of (get text for theSelection)\n"
        "if theContent is missing value then\n"
-          "set theContent to theTitle & \", p. \" & thePage\n"
+       "    set theContent to theTitle & \", p. \" & thePage\n"
        "end if\n"
        "set theLink to \"skim://\" & thePath & \"::\" & thePage & "
        "\"::split::\" & theContent\n"
@@ -513,13 +515,13 @@ applications and inserting them in org documents"
 (defun org-mac-skim-get-page ()
   (interactive)
   (message "Applescript: Getting Skim page link...")
-  (let* ((url-and-title (as-get-skim-page-link))
-         (split-link (split-string url-and-title "::split::"))
-         (URL (car split-link))
+  (let* ((link-and-descr (as-get-skim-page-link))
+         (split-link (split-string link-and-descr "::split::"))
+         (link (car split-link))
          (description (cadr split-link))
          (org-link))
-    (when (not (string= URL ""))
-      (setq org-link (org-make-link-string URL description)))
+    (when (not (string= link ""))
+      (setq org-link (org-make-link-string link description)))
     (kill-new org-link)
     org-link))
 
-- 
1.7.12.4 (Apple Git-37)


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




On May 13, 2013, at 10:34 AM, Carsten Dominik <carsten.dominik@gmail.com> wrote:

> Hi Daniil,
> 
> I like this a lot and would like to take the patch after you have taken Ivans feedback, and maybe more feedback if you get any.
> 
> I would like it even more if following the link would rehighlight the selected text.  Is there any way to achieve this?
> 
> I have another question, this would maybe be for the original author, Anthony Lander?  I see that there are functions with prefixes that are not "org-".  This is dangerous because there might be packages around that use that name space.  I also think it violates coding rules in Emacs.  I think this should be changed - unless you know of a convention that all functions dealing with applescripts are supposed to have an "as-" prefix.
> 
> I can fix this - but I wanted your feedback first.
> 
> Thanks.
> 
> - Carsten
> 
> On 12 mei 2013, at 20:29, Daniil Frumin <difrumin@gmail.com> wrote:
> 
>> Hi, all!
>> 
>> I use org-mac-link-grabber.el <http://orgmode.org/worg/org-contrib/org-mac-link-grabber.html> almost every day. However, it lacks support for an app that I'd like to use together with org-mode. 
>> 
>> Skim.app is a light and fast PDF reader for Mac OS X with a note-taking ability. I wrote a little patch for org-mac-link-grabber.el to support grabbing links to documents.
>> 
>> What it does:
>> 
>> * Grabs not just the link to file, but a page
>> 
>> * Inserts the selected text as a description, if present. Otherwise
>> inserts "<filename>, p. <page #>"
>> 
>> * The shortcut is set to [S]
>> 
>> * Defines a new "skim" link type
>> 
>> It would be interesting to also add some support for importing notes from Skim to org.
>> 
>> Since Skim.app is not present in clean OS X installs, by default support for grabbing links from it is disabled. You can enable it by customizing group `org-mac-link-grabber'.
>> 
>> So, maybe it's possible to get this patch into the tree? It's my first time hacking on org (or even any major elisp extension), so it's probably that I've messed up somewhere with a commit format or whatnot.
>> 
>> Cheers.
>> 
>> -- Daniil Frumin
>> <0001-Adding-Skim.app-support-to-org-mac-link-grabber.el.patch>
> 


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

* Re: Skim.app support for org-mac-link-grabber.el
  2013-05-13 20:35   ` Daniil Frumin
@ 2013-05-14  4:33     ` Carsten Dominik
  2013-05-14  6:18       ` Daniil Frumin
  0 siblings, 1 reply; 9+ messages in thread
From: Carsten Dominik @ 2013-05-14  4:33 UTC (permalink / raw)
  To: Daniil Frumin; +Cc: emacs-orgmode@gnu.org Mode, anthony.lander


On 13.5.2013, at 22:35, Daniil Frumin <difrumin@gmail.com> wrote:

> So I've been researching this problem and it seems that there is no sane way to re-select a text. 

OK, thanks for looking into it.

> 
> The problem is that `(do-applescript ..)' only interacts with AppleScript well if the return type of the string is either a number or a string. If I try to convert the selection object (which is not really an object but a list of specifiers) it just returns the selected text. 
> 
> There is also `selection bounds' but it only covers rectangle selections.
> 
> It's possible to save the selected text and try to `find' it later, but that won't work well (e.g.: there are several repetitions of the same text on one page). 
> 
> I've also tried to implement an auto-scrolling to the selected text, but to no avail.
> 
> The option that seems to me the most reasonable is to add a highlight note to the selected text (which is actually possible). What do you think? 

Interesting idea!  I think this should be implemented, but with a user option to turn it off.

> 
> For now, the patch to the problem mentioned by Ivan.
> I have actually fixed a small bug in the code for getting links from Firefox:
> Prior to the fix the firefox link grabber won't work correctly if a cursor has been already positioned in the URL field. The fix works by adding an additional keystore for selecting all the text in that field.
> 
> The problem is that I've committed it before committing the stuff that Ivan told us about, so I am not sure what to do in this case.

So you mean the patch you would like to send to me is several commits?  That is no problem, just specify with git which range of commits should be part of the patch, for example

    git diff HEAD^^

will include the changes from two commits.  You could also amend the previous commit if it has not yet been push to another repository - there are many ways to deal with this.

- Carsten

> 
> Thanks
> 
> -- Daniil
> 
> <0002-Fixing-a-bug-in-as-mac-firefox-get-frontmost-url.patch><0003-Automatic-detection-of-the-presence-of-Skim.app.patch>
> 
> 
> On May 13, 2013, at 10:34 AM, Carsten Dominik <carsten.dominik@gmail.com> wrote:
> 
>> Hi Daniil,
>> 
>> I like this a lot and would like to take the patch after you have taken Ivans feedback, and maybe more feedback if you get any.
>> 
>> I would like it even more if following the link would rehighlight the selected text.  Is there any way to achieve this?
>> 
>> I have another question, this would maybe be for the original author, Anthony Lander?  I see that there are functions with prefixes that are not "org-".  This is dangerous because there might be packages around that use that name space.  I also think it violates coding rules in Emacs.  I think this should be changed - unless you know of a convention that all functions dealing with applescripts are supposed to have an "as-" prefix.
>> 
>> I can fix this - but I wanted your feedback first.
>> 
>> Thanks.
>> 
>> - Carsten
>> 
>> On 12 mei 2013, at 20:29, Daniil Frumin <difrumin@gmail.com> wrote:
>> 
>>> Hi, all!
>>> 
>>> I use org-mac-link-grabber.el <http://orgmode.org/worg/org-contrib/org-mac-link-grabber.html> almost every day. However, it lacks support for an app that I'd like to use together with org-mode. 
>>> 
>>> Skim.app is a light and fast PDF reader for Mac OS X with a note-taking ability. I wrote a little patch for org-mac-link-grabber.el to support grabbing links to documents.
>>> 
>>> What it does:
>>> 
>>> * Grabs not just the link to file, but a page
>>> 
>>> * Inserts the selected text as a description, if present. Otherwise
>>> inserts "<filename>, p. <page #>"
>>> 
>>> * The shortcut is set to [S]
>>> 
>>> * Defines a new "skim" link type
>>> 
>>> It would be interesting to also add some support for importing notes from Skim to org.
>>> 
>>> Since Skim.app is not present in clean OS X installs, by default support for grabbing links from it is disabled. You can enable it by customizing group `org-mac-link-grabber'.
>>> 
>>> So, maybe it's possible to get this patch into the tree? It's my first time hacking on org (or even any major elisp extension), so it's probably that I've messed up somewhere with a commit format or whatnot.
>>> 
>>> Cheers.
>>> 
>>> -- Daniil Frumin
>>> <0001-Adding-Skim.app-support-to-org-mac-link-grabber.el.patch>
>> 
> 

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

* Re: Skim.app support for org-mac-link-grabber.el
  2013-05-14  4:33     ` Carsten Dominik
@ 2013-05-14  6:18       ` Daniil Frumin
  2013-05-14  7:12         ` Carsten Dominik
  0 siblings, 1 reply; 9+ messages in thread
From: Daniil Frumin @ 2013-05-14  6:18 UTC (permalink / raw)
  To: Carsten Dominik, emacs-orgmode@gnu.org Mode

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

OK, here's a patch which adds the ability to highlight the selected text.

It makes new highlight notes only if `org-mac-Skim-highlight-selection-p' is set to t.


- Dan


[-- Attachment #2: 0004-Add-the-ability-to-highlight-the-selected-text-in-Sk.patch --]
[-- Type: application/octet-stream, Size: 1925 bytes --]

From cb943216ae4d4a5ff2ab0295d0d026b6cbdfb4ea Mon Sep 17 00:00:00 2001
From: Daniil Frumin <difrumin@gmail.com>
Date: Tue, 14 May 2013 10:13:50 +0400
Subject: [PATCH 4/4] Add the ability to highlight the selected text in
 Skim.app

Make a 'highlight note' upon grabbing a link from Skim.app if the
option 'org-mac-Skim-highlight-selection-p' is t.
---
 contrib/lisp/org-mac-link-grabber.el | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/contrib/lisp/org-mac-link-grabber.el b/contrib/lisp/org-mac-link-grabber.el
index cb92b44..59f4820 100644
--- a/contrib/lisp/org-mac-link-grabber.el
+++ b/contrib/lisp/org-mac-link-grabber.el
@@ -136,6 +136,12 @@ applications and inserting them in org documents"
   :group 'org-mac-link-grabber
   :type 'boolean)
 
+(defcustom org-mac-Skim-highlight-selection-p nil
+  "Highlight (using notes) the selection (if present) when grabbing the a link from Skim.app"
+  :tag "Highlight selection in Skim.app"
+  :group 'org-mac-link-grabber
+  :type 'boolean)
+
 \f
 (defun omlg-grab-link ()
   "Prompt the user for an application to grab a link from, then go grab the link, and insert it at point"
@@ -506,6 +512,13 @@ applications and inserting them in org documents"
        "set theContent to contents of (get text for theSelection)\n"
        "if theContent is missing value then\n"
        "    set theContent to theTitle & \", p. \" & thePage\n"
+       (when org-mac-Skim-highlight-selection-p
+	 (concat
+	  "else\n"
+          "    tell theDoc\n"
+          "        set theNote to make note with properties {type:highlight note, selection:theSelection}\n"
+          "         set text of theNote to (get text for theSelection)\n"
+          "    end tell\n"))
        "end if\n"
        "set theLink to \"skim://\" & thePath & \"::\" & thePage & "
        "\"::split::\" & theContent\n"
-- 
1.7.12.4 (Apple Git-37)


[-- Attachment #3: Type: text/plain, Size: 4655 bytes --]


On May 14, 2013, at 8:33 AM, Carsten Dominik <carsten.dominik@gmail.com> wrote:

> 
> On 13.5.2013, at 22:35, Daniil Frumin <difrumin@gmail.com> wrote:
> 
>> So I've been researching this problem and it seems that there is no sane way to re-select a text. 
> 
> OK, thanks for looking into it.
> 
>> 
>> The problem is that `(do-applescript ..)' only interacts with AppleScript well if the return type of the string is either a number or a string. If I try to convert the selection object (which is not really an object but a list of specifiers) it just returns the selected text. 
>> 
>> There is also `selection bounds' but it only covers rectangle selections.
>> 
>> It's possible to save the selected text and try to `find' it later, but that won't work well (e.g.: there are several repetitions of the same text on one page). 
>> 
>> I've also tried to implement an auto-scrolling to the selected text, but to no avail.
>> 
>> The option that seems to me the most reasonable is to add a highlight note to the selected text (which is actually possible). What do you think? 
> 
> Interesting idea!  I think this should be implemented, but with a user option to turn it off.
> 
>> 
>> For now, the patch to the problem mentioned by Ivan.
>> I have actually fixed a small bug in the code for getting links from Firefox:
>> Prior to the fix the firefox link grabber won't work correctly if a cursor has been already positioned in the URL field. The fix works by adding an additional keystore for selecting all the text in that field.
>> 
>> The problem is that I've committed it before committing the stuff that Ivan told us about, so I am not sure what to do in this case.
> 
> So you mean the patch you would like to send to me is several commits?  That is no problem, just specify with git which range of commits should be part of the patch, for example
> 
>    git diff HEAD^^
> 
> will include the changes from two commits.  You could also amend the previous commit if it has not yet been push to another repository - there are many ways to deal with this.
> 
> - Carsten
> 
>> 
>> Thanks
>> 
>> -- Daniil
>> 
>> <0002-Fixing-a-bug-in-as-mac-firefox-get-frontmost-url.patch><0003-Automatic-detection-of-the-presence-of-Skim.app.patch>
>> 
>> 
>> On May 13, 2013, at 10:34 AM, Carsten Dominik <carsten.dominik@gmail.com> wrote:
>> 
>>> Hi Daniil,
>>> 
>>> I like this a lot and would like to take the patch after you have taken Ivans feedback, and maybe more feedback if you get any.
>>> 
>>> I would like it even more if following the link would rehighlight the selected text.  Is there any way to achieve this?
>>> 
>>> I have another question, this would maybe be for the original author, Anthony Lander?  I see that there are functions with prefixes that are not "org-".  This is dangerous because there might be packages around that use that name space.  I also think it violates coding rules in Emacs.  I think this should be changed - unless you know of a convention that all functions dealing with applescripts are supposed to have an "as-" prefix.
>>> 
>>> I can fix this - but I wanted your feedback first.
>>> 
>>> Thanks.
>>> 
>>> - Carsten
>>> 
>>> On 12 mei 2013, at 20:29, Daniil Frumin <difrumin@gmail.com> wrote:
>>> 
>>>> Hi, all!
>>>> 
>>>> I use org-mac-link-grabber.el <http://orgmode.org/worg/org-contrib/org-mac-link-grabber.html> almost every day. However, it lacks support for an app that I'd like to use together with org-mode. 
>>>> 
>>>> Skim.app is a light and fast PDF reader for Mac OS X with a note-taking ability. I wrote a little patch for org-mac-link-grabber.el to support grabbing links to documents.
>>>> 
>>>> What it does:
>>>> 
>>>> * Grabs not just the link to file, but a page
>>>> 
>>>> * Inserts the selected text as a description, if present. Otherwise
>>>> inserts "<filename>, p. <page #>"
>>>> 
>>>> * The shortcut is set to [S]
>>>> 
>>>> * Defines a new "skim" link type
>>>> 
>>>> It would be interesting to also add some support for importing notes from Skim to org.
>>>> 
>>>> Since Skim.app is not present in clean OS X installs, by default support for grabbing links from it is disabled. You can enable it by customizing group `org-mac-link-grabber'.
>>>> 
>>>> So, maybe it's possible to get this patch into the tree? It's my first time hacking on org (or even any major elisp extension), so it's probably that I've messed up somewhere with a commit format or whatnot.
>>>> 
>>>> Cheers.
>>>> 
>>>> -- Daniil Frumin
>>>> <0001-Adding-Skim.app-support-to-org-mac-link-grabber.el.patch>
>>> 
>> 
> 


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

* Re: Skim.app support for org-mac-link-grabber.el
  2013-05-14  6:18       ` Daniil Frumin
@ 2013-05-14  7:12         ` Carsten Dominik
  0 siblings, 0 replies; 9+ messages in thread
From: Carsten Dominik @ 2013-05-14  7:12 UTC (permalink / raw)
  To: Daniil Frumin; +Cc: emacs-orgmode@gnu.org Mode

This looks great.

Can you now make a single patch for all the changes?  Then I will apply it.

- Carsten

On 14 mei 2013, at 08:18, Daniil Frumin <difrumin@gmail.com> wrote:

> OK, here's a patch which adds the ability to highlight the selected text.
> 
> It makes new highlight notes only if `org-mac-Skim-highlight-selection-p' is set to t.
> 
> 
> - Dan
> 
> <0004-Add-the-ability-to-highlight-the-selected-text-in-Sk.patch>
> On May 14, 2013, at 8:33 AM, Carsten Dominik <carsten.dominik@gmail.com> wrote:
> 
>> 
>> On 13.5.2013, at 22:35, Daniil Frumin <difrumin@gmail.com> wrote:
>> 
>>> So I've been researching this problem and it seems that there is no sane way to re-select a text. 
>> 
>> OK, thanks for looking into it.
>> 
>>> 
>>> The problem is that `(do-applescript ..)' only interacts with AppleScript well if the return type of the string is either a number or a string. If I try to convert the selection object (which is not really an object but a list of specifiers) it just returns the selected text. 
>>> 
>>> There is also `selection bounds' but it only covers rectangle selections.
>>> 
>>> It's possible to save the selected text and try to `find' it later, but that won't work well (e.g.: there are several repetitions of the same text on one page). 
>>> 
>>> I've also tried to implement an auto-scrolling to the selected text, but to no avail.
>>> 
>>> The option that seems to me the most reasonable is to add a highlight note to the selected text (which is actually possible). What do you think? 
>> 
>> Interesting idea!  I think this should be implemented, but with a user option to turn it off.
>> 
>>> 
>>> For now, the patch to the problem mentioned by Ivan.
>>> I have actually fixed a small bug in the code for getting links from Firefox:
>>> Prior to the fix the firefox link grabber won't work correctly if a cursor has been already positioned in the URL field. The fix works by adding an additional keystore for selecting all the text in that field.
>>> 
>>> The problem is that I've committed it before committing the stuff that Ivan told us about, so I am not sure what to do in this case.
>> 
>> So you mean the patch you would like to send to me is several commits?  That is no problem, just specify with git which range of commits should be part of the patch, for example
>> 
>>   git diff HEAD^^
>> 
>> will include the changes from two commits.  You could also amend the previous commit if it has not yet been push to another repository - there are many ways to deal with this.
>> 
>> - Carsten
>> 
>>> 
>>> Thanks
>>> 
>>> -- Daniil
>>> 
>>> <0002-Fixing-a-bug-in-as-mac-firefox-get-frontmost-url.patch><0003-Automatic-detection-of-the-presence-of-Skim.app.patch>
>>> 
>>> 
>>> On May 13, 2013, at 10:34 AM, Carsten Dominik <carsten.dominik@gmail.com> wrote:
>>> 
>>>> Hi Daniil,
>>>> 
>>>> I like this a lot and would like to take the patch after you have taken Ivans feedback, and maybe more feedback if you get any.
>>>> 
>>>> I would like it even more if following the link would rehighlight the selected text.  Is there any way to achieve this?
>>>> 
>>>> I have another question, this would maybe be for the original author, Anthony Lander?  I see that there are functions with prefixes that are not "org-".  This is dangerous because there might be packages around that use that name space.  I also think it violates coding rules in Emacs.  I think this should be changed - unless you know of a convention that all functions dealing with applescripts are supposed to have an "as-" prefix.
>>>> 
>>>> I can fix this - but I wanted your feedback first.
>>>> 
>>>> Thanks.
>>>> 
>>>> - Carsten
>>>> 
>>>> On 12 mei 2013, at 20:29, Daniil Frumin <difrumin@gmail.com> wrote:
>>>> 
>>>>> Hi, all!
>>>>> 
>>>>> I use org-mac-link-grabber.el <http://orgmode.org/worg/org-contrib/org-mac-link-grabber.html> almost every day. However, it lacks support for an app that I'd like to use together with org-mode. 
>>>>> 
>>>>> Skim.app is a light and fast PDF reader for Mac OS X with a note-taking ability. I wrote a little patch for org-mac-link-grabber.el to support grabbing links to documents.
>>>>> 
>>>>> What it does:
>>>>> 
>>>>> * Grabs not just the link to file, but a page
>>>>> 
>>>>> * Inserts the selected text as a description, if present. Otherwise
>>>>> inserts "<filename>, p. <page #>"
>>>>> 
>>>>> * The shortcut is set to [S]
>>>>> 
>>>>> * Defines a new "skim" link type
>>>>> 
>>>>> It would be interesting to also add some support for importing notes from Skim to org.
>>>>> 
>>>>> Since Skim.app is not present in clean OS X installs, by default support for grabbing links from it is disabled. You can enable it by customizing group `org-mac-link-grabber'.
>>>>> 
>>>>> So, maybe it's possible to get this patch into the tree? It's my first time hacking on org (or even any major elisp extension), so it's probably that I've messed up somewhere with a commit format or whatnot.
>>>>> 
>>>>> Cheers.
>>>>> 
>>>>> -- Daniil Frumin
>>>>> <0001-Adding-Skim.app-support-to-org-mac-link-grabber.el.patch>
>>>> 
>>> 
>> 
> 

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

end of thread, other threads:[~2013-05-14  7:12 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-12 18:29 Skim.app support for org-mac-link-grabber.el Daniil Frumin
2013-05-13  0:39 ` Ivan Andrus
2013-05-13  6:34 ` Carsten Dominik
2013-05-13  9:53   ` Daniel F
2013-05-13 10:54     ` Carsten Dominik
2013-05-13 20:35   ` Daniil Frumin
2013-05-14  4:33     ` Carsten Dominik
2013-05-14  6:18       ` Daniil Frumin
2013-05-14  7:12         ` Carsten Dominik

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