From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sebastian Rose Subject: Re: org-protocol://remember:// question Date: Fri, 03 Apr 2009 14:34:04 +0200 Message-ID: <87y6uhyj25.fsf@kassiopeya.MSHEIMNETZ> References: <87ocvfh7lc.fsf@thinkpad.tsdh.de> <8763hn48gj.fsf@kassiopeya.MSHEIMNETZ> <1B37177B-3E1E-41CF-BAB7-85EB815432F1@gmail.com> <87ocvfgclq.fsf@kassiopeya.MSHEIMNETZ> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LpjCH-0005aC-EJ for emacs-orgmode@gnu.org; Fri, 03 Apr 2009 09:12:37 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LpjCB-0005YA-48 for emacs-orgmode@gnu.org; Fri, 03 Apr 2009 09:12:35 -0400 Received: from [199.232.76.173] (port=60636 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LpjCA-0005Xu-Gi for emacs-orgmode@gnu.org; Fri, 03 Apr 2009 09:12:30 -0400 Received: from mail.gmx.net ([213.165.64.20]:33558) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1LpjC9-0002M6-N9 for emacs-orgmode@gnu.org; Fri, 03 Apr 2009 09:12:30 -0400 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Carsten Dominik Cc: Tassilo Horn , emacs-orgmode@gnu.org --=-=-= I encountered another problem: Using `C-c C-k' in the remember buffer is OK. But if the user interupts `org-remember' by `C-g' (e.g. when reading some text interactively), emacsclient will be waiting for ever. Unfortunately, there seems no easy way to fix this in a way, that we could mix org-protocol arguments and filenames for emacsclient. A solution for this problem is, to introduce a new property: (defconst org-protocol-protocol-alist-default '(("org-remember" :protocol "remember" :function org-protocol-remember :kill-client t) ... and unconditionally kill the client, once a sub-protocol with a non-nil `:kill-client' property is detected. The appended patch does all the changes we need: - call org-remember the right way - kill emacsclient for org-protocol-remember and all those handlers, which have the `:kill-client' property set to a non-nil value. Regards, Sebastian --=-=-= Content-Type: application/emacs-lisp Content-Disposition: inline; filename=patch-org-protocol.el Content-Transfer-Encoding: quoted-printable diff --git a/lisp/org-protocol.el b/lisp/org-protocol.el index 1593764..6b1d61b 100644 --- a/lisp/org-protocol.el +++ b/lisp/org-protocol.el @@ -129,9 +129,9 @@ (require 'cl)) =20 (declare-function org-publish-initialize-files-alist "org-publish" - (&optional refresh)) + (&optional refresh)) (declare-function org-publish-get-project-from-filename "org-publish" - (filename &optional up)) + (filename &optional up)) =20 (defgroup org-protocol nil "Intercept calls from emacsclient to trigger custom actions. @@ -147,7 +147,7 @@ for `org-protocol-the-protocol' and sub-procols defined= in ;;; Variables: =20 (defconst org-protocol-protocol-alist-default - '(("org-remember" :protocol "remember" :function org-protocol-reme= mber) + '(("org-remember" :protocol "remember" :function org-protocol-reme= mber :kill-client t) ("org-store-link" :protocol "store-link" :function org-protocol-stor= e-link) ("org-open-source" :protocol "open-source" :function org-protocol-open= -source)) "Default protocols to use. @@ -216,7 +216,7 @@ Consider using the interactive functions `org-protocol-= create' and =20 Each element of this list must be of the form: =20 - (module-name :protocol protocol :function func) + (module-name :protocol protocol :function func :kill-client nil) =20 protocol - protocol to detect in a filename without trailing colon and sla= shes. See rfc1738 section 2.1 for more on this. @@ -235,6 +235,12 @@ function - function that handles requests with protoco= l and takes exactly one if you stay with the conventions used for the standard handlers= in `org-protocol-protocol-alist-default'. See `org-protocol-split-= data'. =20 +kill-client - If t, kill the client immediately, once the sub-protocol is + detected. This is neccessary for actions that can be interupted= by + `C-g' to avoid dangeling emacsclients. Note, that all other com= mand + line arguments but the this one will be discarded, greedy handl= ers + still receive the whole list of arguments though. + Here is an example: =20 (setq org-protocol-protocol-alist @@ -324,33 +330,26 @@ URL with a character and a slash like so: javascript:location.href=3D'org-protocol://org-store-link://b/'+ ... =20 Now template ?b will be used." - (if (and (boundp 'org-stored-links) - (fboundp 'org-remember)) - (let* ((b (generate-new-buffer "*org-protocol*")) - (parts (org-protocol-split-data info t)) - (template (or (and (=3D 1 (length (car parts))) (pop parts)) "w= ")) - (url (org-protocol-sanitize-uri (car parts))) - (type (if (string-match "^\\([a-z]+\\):" url) - (match-string 1 url))) - (title (cadr parts)) - (region (caddr parts)) - orglink) - (setq orglink (org-make-link-string url title)) - (org-store-link-props :type type - :link url - :region region - :description title) - (setq org-stored-links - (cons (list url title) org-stored-links)) - ;; FIXME can't access %a in the template -- how to set annotation? - (raise-frame) - (kill-new orglink) - (set-buffer b) - (insert region) - (mark-whole-buffer) - (org-remember nil (string-to-char template)) - (kill-buffer b)) + (fboundp 'org-remember)) + (let* ((parts (org-protocol-split-data info t)) + (template (or (and (=3D 1 (length (car parts))) (pop parts)) = "w")) + (url (org-protocol-sanitize-uri (car parts))) + (type (if (string-match "^\\([a-z]+\\):" url) + (match-string 1 url))) + (title (cadr parts)) + (region (caddr parts)) + (orglink (org-make-link-string url title)) + remember-annotation-functions) + (setq org-stored-links + (cons (list url title) org-stored-links)) + (kill-new orglink) + (org-store-link-props :type type + :link url + :description title + :initial region) + (raise-frame) + (org-remember nil (string-to-char template))) (message "Org-mode not loaded.")) nil) =20 @@ -393,7 +392,7 @@ The location for a browser's bookmark should look like = this: =20 ;;; Core functions: =20 -(defun org-protocol-check-filename-for-protocol (fname restoffiles) +(defun org-protocol-check-filename-for-protocol (fname restoffiles client) "Detect if `org-protocol-the-protocol' and a known sub-protocol is used = in fname. Sub-protocols are registered in `org-protocol-protocol-alist' and `org-protocol-protocol-alist-default'. @@ -420,6 +419,8 @@ as filename." (greedy (plist-get (cdr prolist) :greedy)) (splitted (split-string fname proto)) (result (if greedy restoffiles (cadr splitted)))) + (if (plist-get (cdr prolist) :kill-client) + (server-delete-client client t)) (when (fboundp func) (unless greedy (throw 'fname (funcall func result))) @@ -433,11 +434,12 @@ as filename." "Advice server-visit-flist to call `org-protocol-modify-filename-for-pro= tocol'." (let ((flist (if org-protocol-reverse-list-of-files (reverse (ad-get-arg 0)) - (ad-get-arg 0)))) + (ad-get-arg 0))) + (client (ad-get-arg 1))) (catch 'greedy (dolist (var flist) (let ((fname (expand-file-name (car var)))) ;; `\' to `/' on wind= ows. FIXME: could this be done any better? - (setq fname (org-protocol-check-filename-for-protocol fname (mem= ber var flist))) + (setq fname (org-protocol-check-filename-for-protocol fname (mem= ber var flist) client)) (if (eq fname t) ;; greedy? We need the `t' return value. (progn (ad-set-arg 0 nil) --=-=-= Carsten Dominik writes: > On Apr 2, 2009, at 8:00 PM, Sebastian Rose wrote: > >> Carsten Dominik writes: >>> Hi Sebastian, Tassilo, >>> >>> this can be easily fixed. >>> >>> Org-protocol may add arbitrary properties to the link properties. >>> For example, after a call >>> >>> (org-store-link-props :type type >>> :link url >>> :region region >>> :description title >>> :hello "Hello world") >>> >>> a template could use "%:hello" to access and insert this >>> string. I have just changed org-remember so that the >>> property :annotation will be the default for %a. >>> Sebastian, could you please add >>> >>> :annotation (concat "[[" url "][" title "]]") >>> >>> or something similar to the call to org-store-link-props? >>> >>> Also, feel free to add any other properties that might >>> provide useful information for a template. >> >> >> Doesn't that apply to certain link types only? >> >> Also, the situation seems to be different for org-protocol-remember. I >> think it's the way remember is used inside that function that has to be >> changed. >> Maybe I can figure that out. > > Sorry my mistake. Indeed, the way you call org-remember > overwrites the link property list. What you need to do is this: > > (let (remember-annotation-functions) > (org-remember nil (string-to-char template))) > > Now, another advantage of doing it like this is that you > do not even have to create a temporary buffer from which you > launch org-remember. Right now you do this, only for > the effect to get the region inserted for %i. > > Much easier will not be to set the :initial property in the > call to org-store-link-props. > > Thus, don't even create the *org-protocol* buffer and then do this: > > (org-store-link-props :type type > :link url > :annotation (concat "[[" url "][" title "]]") > :initial (or region "") > :description title) > (setq org-stored-links > (cons (list url title) org-stored-links)) > (raise-frame) > (kill-new orglink) > (let (remember-annotation-functions) > (org-remember nil (string-to-char template))) > > I hope that this will take care of it. > > - Carsten > -- Sebastian Rose, EMMA STIL - mediendesign, Niemeyerstr.6, 30449 Hannover Tel.: +49 (0)511 - 36 58 472 Fax: +49 (0)1805 - 233633 - 11044 mobil: +49 (0)173 - 83 93 417 Email: s.rose@emma-stil.de, sebastian_rose@gmx.de Http: www.emma-stil.de --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-orgmode mailing list Remember: use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode --=-=-=--