sprig / org-capture-extension

A Chrome and firefox extension facilitating org-capture in emacs
MIT License
538 stars 56 forks source link

Greedy org-protocol handler #72

Open vzaliva opened 4 years ago

vzaliva commented 4 years ago

When trying to campute link from the browser I am getting the following error message in my emacs console:

Greedy org-protocol handler.  Killing client.
No server buffers remain to edit

I am testing on URL of this git repository: https://github.com/sprig/org-capture-extension/

GNU Emacs 25.2.2 (x86_64-pc-linux-gnu, GTK+ Version 3.22.21) of 2017-09-22, modified by Debian. Running Chrome on Ubuntu using i3 window manager. My org-mode init as follows:

(use-package org
  :ensure t
  :init
  (progn
    (setq org-log-done 'time)
    (setq org-directory "~/Dropbox/Notes"))
  (use-package org-bullets
    :ensure t
    :init (add-hook 'org-mode-hook (lambda () (org-bullets-mode 1))))
  (add-hook 'org-mode-hook
            (lambda ()
              (progn
                (define-key org-mode-map [(control tab)] nil) ; release C-tab
                (define-key org-mode-map "\C-cb" 'org-iswitchb)
                (setq org-hide-emphasis-markers t)
                (if (image-type-available-p 'imagemagick)
                    (setq org-image-actual-width 500))

                ;; Capture templates for links to pages having [ and ]
                ;; characters in their page titles - notably ArXiv
                ;; From https://github.com/sprig/org-capture-extension
                (defun transform-square-brackets-to-round-ones(string-to-transform)
                  "Transforms [ into ( and ] into ), other chars left unchanged."
                  (concat 
                   (mapcar #'(lambda (c) (if (equal c ?[) ?\( (if (equal c ?]) ?\) c))) string-to-transform)))
                (setq org-capture-templates `(
                                              ("p" "Protocol" entry (file+headline ,(concat org-directory "notes.org") "Inbox")
                                               "* %^{Title}\nSource: %u, %c\n #+BEGIN_QUOTE\n%i\n#+END_QUOTE\n\n\n%?")  
                                              ("L" "Protocol Link" entry (file+headline ,(concat org-directory "notes.org") "Inbox")
                                               "* %? [[%:link][%(transform-square-brackets-to-round-ones \"%:description\")]]\n")
                                              ))

                ))))

;; TODO: move inside "use-package org" section above
(require 'org-protocol)
vzaliva commented 4 years ago

I partially fixed this problem. There was missing slash at the end of org-directory. It should be:

    (setq org-directory "~/Dropbox/Notes/")

After this change "L" template is working. However "p" (when I select some text) still gives me "Greedy org-protocol handler" error. Any suggestions on how can I debug this? Can I see the URLs fed to the handler? I will appreciate any help on this. Thanks!

vzaliva commented 4 years ago

I've changed "p" template as follows to solve this issue:

("p" "Protocol" entry (file+headline ,(concat org-directory "notes.org") "Inbox")
                                               "* %^{Title}\nSource: [[%:link][%(transform-square-brackets-to-round-ones \"%:description\")]]\n#+BEGIN_QUOTE\n%i\n#+END_QUOTE\n\n\n%?")
vzaliva commented 4 years ago

I think you should fix a handler example in the readme, because the currently suggested "p" template does not handle square brackets in titles.

Thaodan commented 2 years ago

I've noticed that using a file rather than a string for the template can also make things like foo in the selection break the creation of the file buffer as emacs will kill it greedy protocol handler.