From mboxrd@z Thu Jan 1 00:00:00 1970 From: Carsten Dominik Subject: Re: Unable to generate link in non-org file with org-id-store-link present Date: Tue, 2 Nov 2010 23:09:05 +0100 Message-ID: <5499816B-00C4-4A1C-9FD4-D55678618BA4@gmail.com> References: <87y69em8qr.wl%dmaus@ictsoc.de> Mime-Version: 1.0 (Apple Message framework v936) Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Return-path: Received: from [140.186.70.92] (port=57418 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PDP2W-0002tw-QY for emacs-orgmode@gnu.org; Tue, 02 Nov 2010 18:09:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PDP2U-0001vn-P5 for emacs-orgmode@gnu.org; Tue, 02 Nov 2010 18:09:12 -0400 Received: from mail-ey0-f169.google.com ([209.85.215.169]:63941) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PDP2U-0001vf-BU for emacs-orgmode@gnu.org; Tue, 02 Nov 2010 18:09:10 -0400 Received: by eydd26 with SMTP id d26so3816831eyd.0 for ; Tue, 02 Nov 2010 15:09:09 -0700 (PDT) In-Reply-To: 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: Liam Healy Cc: emacs-orgmode@gnu.org Hi Liam, On Nov 2, 2010, at 9:45 PM, Liam Healy wrote: > On Sun, Oct 31, 2010 at 5:28 PM, Liam Healy > wrote: >> On Sun, Oct 31, 2010 at 4:02 PM, David Maus wrote: >>> At Sun, 31 Oct 2010 15:09:48 -0400, >>> Liam Healy wrote: >>>> >>>> With recent versions (since about version 7) of org-mode, I cannot >>>> generate links in a non-org file when org-id-store-link is in >>>> org-store-link-functions. Either I get an error "before first >>>> headline" (makes no sense to me, since I'm not in an org file), or >>>> emacs spins forever, saturating the CPU and doing nothing. If I >>>> leave >>>> org-id-store-link out of org-store-link-functions, everything works >>>> fine but of course I get no id link in org files. Is there a fix >>>> for >>>> this? >>> >>> Which Org and Emacs version are you using? >>> >>> M-x org-version RET >> >> Org-mode version 7.02trans (release_7.02.22.gde21) >> >>> M-x emacs-version RET >> >> GNU Emacs 23.1.1 (x86_64-pc-linux-gnu, X toolkit, Xaw3d scroll bars) >> of 2009-10-19 on debian-build.int-office-er.priv, modified by Debian >> >>> >>> And can you provide a backtrace for this behavior? >>> >>> 1. reload Org mode so it runs on uncompiled files >>> >>> M-x org-reload RET >> >> Done >> >>> >>> 2. Toggle debug-on-quit and debug-on-error >>> >>> M-x toggle-debug-on-quite RET >>> M-x toggle-debug-on-error RET >>> >>> 3. Try to reproduce the bug (if Emacs spins for ever, hit C-g) >>> >>> If you encounter the error or can stop Emacs from hanging (C-g), you >>> get a buffer with the backtrace. >> >> It did, I did, here it is: >> >> Debugger entered--Lisp error: (quit) >> re-search-forward("^[ ]*" 4266 t) >> (while (re-search-forward re end t)) >> (let ((indent ...) (beg ...) (re ...) end hiddenp) >> (outline-next-heading) (setq end (point)) (goto-char beg) (while >> (re-search-forward re end t)) (setq hiddenp (org-invisible-p)) >> (end-of-line 1) (and (equal ... 10) (forward-char 1)) (while >> (looking-at "^[ ]*\\(:CLOCK:\\|:LOGBOOK:\\|CLOCK:\\|:END:\ >> \)") (if >> ... ... ... ...)) (org-skip-over-state-notes) (skip-chars-backward " >> \n >> ") (if (eq ... 42) (forward-char 1)) (let (...) (insert >> "\n:PROPERTIES:\n:END:")) (beginning-of-line 0) (org-indent-to-column >> indent) (beginning-of-line 2) (org-indent-to-column indent) >> (beginning-of-line 0) (if hiddenp (save-excursion ... ...) >> (org-flag-drawer t))) >> org-insert-property-drawer() >> (save-excursion (org-insert-property-drawer) (setq end >> (progn ... ...))) >> (if force (save-excursion (org-insert-property-drawer) (setq end >> ...)) (throw (quote exit) nil)) >> (if (re-search-forward org-property-start-re end t) (setq beg (1+ >> ...)) (if force (save-excursion ... ...) (throw ... nil)) (goto-char >> beg) (if (re-search-forward org-property-start-re end t) (setq beg >> ...))) >> (let* ((beg ...) (end ...)) (goto-char beg) (if (re-search-forward >> org-property-start-re end t) (setq beg ...) (if force ... ...) >> (goto-char beg) (if ... ...)) (if (re-search-forward >> org-property-end-re end t) (setq end ...) (or force ...) (goto-char >> beg) (setq end beg) (org-indent-line-function) (insert ":END:\n")) >> (cons beg end)) >> (save-excursion (let* (... ...) (goto-char beg) (if ... ... ... ... >> ...) (if ... ... ... ... ... ... ...) (cons beg end))) >> (catch (quote exit) (save-excursion (let* ... ... ... ... ...))) >> org-get-property-block(4037 4266 force) >> (setq range (org-get-property-block beg end (quote force))) >> (let ((buffer-invisibility-spec ...)) (setq range >> (org-get-property-block beg end ...)) (goto-char (car range)) (if >> (re-search-forward ... ... t) (progn ... ...) (goto-char ...) (insert >> "\n") (backward-char 1) (org-indent-line-function) (insert ":" >> property ":")) (and value (insert " " value)) >> (org-indent-line-function)) >> (cond ((equal property "TODO") (when ... ...) (if ... ...) (org-todo >> value) (org-set-tags nil ...)) ((equal property "PRIORITY") >> (org-priority ...) (org-set-tags nil ...)) ((equal property >> "SCHEDULED") (if ... ... ...)) ((equal property "DEADLINE") (if ... >> ... ...)) ((member property org-special-properties) (error "The %s >> property can not yet be set with `org-entry-put'" property)) (t (let >> ... ... ... ... ... ...))) >> (let ((beg ...) (end ...) range) (cond (... ... ... ... ...) (... >> ... ...) (... ...) (... ...) (... ...) (t ...))) >> (save-excursion (goto-char (or pom ...)) (org-back-to-heading t) >> (let (... ... range) (cond ... ... ... ... ... ...)) >> (run-hook-with-args (quote org-property-changed-functions) property >> value)) >> (save-excursion (if (markerp pom) (set-buffer ...)) (save-excursion >> (goto-char ...) (org-back-to-heading t) (let ... ...) >> (run-hook-with-args ... property value))) >> (org-with-point-at pom (org-back-to-heading t) (let (... ... range) >> (cond ... ... ... ... ... ...)) (run-hook-with-args (quote >> org-property-changed-functions) property value)) >> org-entry-put(4204 "ID" "b7f6dacd-3d83-492d-877e-075d3312d0a6") >> (cond ((and id ... ...) id) (create (setq id ...) (org-entry-put pom >> "ID" id) (org-id-add-location id ...) id) (t nil)) >> (let ((id ...)) (cond (... id) (create ... ... ... id) (t nil))) >> (save-excursion (goto-char (or pom ...)) (let (...) >> (cond ... ... ...))) >> (save-excursion (if (markerp pom) (set-buffer ...)) (save-excursion >> (goto-char ...) (let ... ...))) >> (org-with-point-at pom (let (...) (cond ... ... ...))) >> org-id-get(4204 create) >> org-id-get-create() >> (org-make-link "id:" (org-id-get-create)) >> (let* ((link ...) (case-fold-search nil) (desc ...)) >> (org-store-link-props :link link :description desc :type "id") link) >> org-id-store-link() >> run-hook-with-args-until-success(org-id-store-link) >> (cond ((run-hook-with-args-until-success ...) (setq link ... desc >> ...)) ((equal ... "*Org Edit Src Example*") (let ... ... ... ... ... >> ... ... ...)) ((equal ... ...) (let ... ...)) ((eq major-mode ...) >> (let ... ... ...)) ((eq major-mode ...) (setq cpltxt ... link ...) >> (org-store-link-props :type "w3" :url ...)) ((eq major-mode ...) >> (setq >> cpltxt ... link ...) (org-store-link-props :type "w3m" :url ...)) >> ((setq search ...) (setq link ...) (setq cpltxt ...)) ((eq major-mode >> ...) (setq cpltxt ... link ...) (org-store-link-props :type "image" >> :file buffer-file-name)) ((eq major-mode ...) (let ... ... ...)) >> ((and >> ... ...) (setq custom-id ...) (cond ... ... ...)) ((buffer-file-name >> ...) (setq cpltxt ...) (when ... ... ...) (setq link ...)) >> ((interactive-p) (error "Cannot link to a buffer which is not >> visiting >> a file")) (t (setq link nil))) >> (let ((outline-regexp ...) link cpltxt desc description search txt >> custom-id agenda-link) (cond (... ...) (... ...) (... ...) (... ...) >> (... ... ...) (... ... ...) (... ... ...) (... ... ...) (... ...) >> (... >> ... ...) (... ... ... ...) (... ...) (t ...)) (if (consp link) (setq >> cpltxt ... link ...)) (setq link (or link cpltxt) desc (or desc >> cpltxt)) (if (equal desc "NONE") (setq desc nil)) (if (and ... link) >> (progn ... ... ...) (or agenda-link ...))) >> org-store-link(nil) >> call-interactively(org-store-link nil nil) >> >> >> >>> >>> Best, >>> -- David >> >> Thanks, >> Liam >> > > Focusing on the high levels of the backtrace, it looks like > run-hook-with-args-until-success is calling org-id-store-link even on > non-org files. As a hack, I put a check into org-id-store-link that > is similar to the clause in org-store-link so that it refuses to do > anything if it isn't an org file: > > (defun org-id-store-link () > "Store a link to the current entry, using its ID." > (interactive) > (when (and (buffer-file-name (buffer-base-buffer)) (org-mode-p)) > (let* ((link (org-make-link "id:" (org-id-get-create))) > (case-fold-search nil) > (desc (save-excursion > (org-back-to-heading t) > (or (and (looking-at org-complex-heading-regexp) > (if (match-end 4) (match-string 4) (match-string 0))) > link)))) > (org-store-link-props :link link :description desc :type "id") > link))) > > and this fixes the problem. However, I think the root problem is that > run-hook-with-args-until-success seems to be try org-id-store-link > without qualification (that is, on non-org files). Perhaps someone > more knowledgeable about this code can place a check/skip in a better > place and patch the original source. Thanks for this correct analysis. run-hooks-with-args-until-success cannot know if a member makes sense in a given context, but org-id-store-link does. So your fix is exactly right, I have integrated it. Thanks! - Carsten