From mboxrd@z Thu Jan 1 00:00:00 1970 From: Robert Adesam Subject: Re: org-store-link calls external link type store functions twice? Date: Tue, 14 May 2013 15:04:52 +0200 Message-ID: References: <87ip2mlyp0.fsf@bzg.ath.cx> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Return-path: Received: from eggs.gnu.org ([208.118.235.92]:52879) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UcEue-0004zx-Ju for emacs-orgmode@gnu.org; Tue, 14 May 2013 09:05:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UcEuU-00023p-8y for emacs-orgmode@gnu.org; Tue, 14 May 2013 09:05:04 -0400 Received: from mail-pa0-f47.google.com ([209.85.220.47]:37530) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UcEuU-00023R-1F for emacs-orgmode@gnu.org; Tue, 14 May 2013 09:04:54 -0400 Received: by mail-pa0-f47.google.com with SMTP id kl13so501220pab.34 for ; Tue, 14 May 2013 06:04:52 -0700 (PDT) In-Reply-To: <87ip2mlyp0.fsf@bzg.ath.cx> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Bastien Cc: emacs-orgmode@gnu.org Hi, I made a small example where I added an external link type, "counter" that always works and updates a counter. It is quite crude but shows my point: (org-add-link-type "counter" 'ra/org-counter-open) (add-hook 'org-store-link-functions 'ra/org-counter-store-link) (defun ra/org-counter-store-link () "Store a dummy counter link." (if (boundp 'counter) (setq counter (1+ counter)) (setq counter 1)) (let* ((link (concat "counter:" (number-to-string counter))) (desc (format "Calls to ra/org-counter-store-link: %d" counter))) (org-store-link-props :type "counter" :link link :description desc))) (defun ra/org-counter-open (path) "Print and reset the counter." (message (format "Calls to ra/org-counter-store-link: %d. Resetting counter." counter)) (makunbound 'counter)) Running org-capture with the above external link type will result in counter to be set to 2 before inserting the link in the *Capture* buffer. I have also tried the example "A.3 Adding hyperlinks types" in the manual -- same result when debugging org-man-store-link. In the definition of org-store-link the interesting part is paste below. I have marked the calls to external link types store function, ie ra/org-counter-store-link above. ; Store a link using an external link type ((and (not (equal arg '(16))) (setq sfuns (delq nil (mapcar (lambda (f) (let (fs) (if (funcall f) (push f fs)))) ;;; <-- first call to ra/org-counter-store-link org-store-link-functions)) sfunsn (mapcar (lambda (fu) (symbol-name (car fu))) sfuns)) (or (and (cdr sfuns) (funcall (intern (completing-read "Which function for creating the link? " sfunsn t (car sfunsn))))) (funcall (caar sfuns))) ;;; <-- second call to ra/org-counter-store-link (setq link (plist-get org-store-link-plist :link) desc (or (plist-get org-store-link-plist :description) link)))) This "problem" only shows up in version 8 of org-mode, not version 7. Please let me know if I can provide you with even more information. Thanks for listening, /robert On Tue, May 14, 2013 at 10:41 AM, Bastien wrote: > Hi Robert, > > Robert Adesam writes: > >> I am not sure this is a bug but in version 8.x storing a link using >> an external link type, org-store-link seems to call the external link >> type's store function twice... I noticed this as I use an external >> link type that asynchronous updates an external filedatabase and >> started to get random file lock errors -- the org-store-link second >> call to the external link type's store function sometimes came too >> quickly after the first one. :-) Also, I do not have this problem in >> version 7.x of orgmode. >> >> Instead of reverting back to a previous version of orgmode I started >> to investigate -- attaching a patch that seems to help me anyway. >> It's not that well tested and maybe, as I am not that familiar with >> everything going on when storing a link using an external link type, >> it will break other things... > > I re-read `org-store-link' and I don't see how the external function > can be called twice... maybe you can give more details on what this > external function looks like, when it is called (within a script or > something), etc? > > Thanks! > > -- > Bastien