From mboxrd@z Thu Jan 1 00:00:00 1970 From: Liam Healy Subject: Re: Unable to generate link in non-org file with org-id-store-link present Date: Tue, 2 Nov 2010 16:45:23 -0400 Message-ID: References: <87y69em8qr.wl%dmaus@ictsoc.de> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Return-path: Received: from [140.186.70.92] (port=55007 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PDNjT-0006s3-QR for emacs-orgmode@gnu.org; Tue, 02 Nov 2010 16:45:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PDNjQ-0006SB-VO for emacs-orgmode@gnu.org; Tue, 02 Nov 2010 16:45:27 -0400 Received: from mail-iw0-f169.google.com ([209.85.214.169]:44887) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PDNjQ-0006S6-Oi for emacs-orgmode@gnu.org; Tue, 02 Nov 2010 16:45:24 -0400 Received: by iwn38 with SMTP id 38so8549396iwn.0 for ; Tue, 02 Nov 2010 13:45:23 -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: emacs-orgmode@gnu.org On Sun, Oct 31, 2010 at 5:28 PM, Liam Healy wr= ote: > 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. =A0Either 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. =A0If I leav= e >>> org-id-store-link out of org-store-link-functions, everything works >>> fine but of course I get no id link in org files. =A0Is 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? >> >> =A01. reload Org mode so it runs on uncompiled files >> >> =A0 =A0M-x org-reload RET > > Done > >> >> =A02. Toggle debug-on-quit and debug-on-error >> >> =A0 =A0M-x toggle-debug-on-quite RET >> =A0 =A0M-x toggle-debug-on-error RET >> >> =A03. 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) > =A0re-search-forward("^[ =A0 =A0 =A0 =A0 ]*" 4266 t) > =A0(while (re-search-forward re end t)) > =A0(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 "^[ =A0 =A0 =A0 =A0 ]*\\(:CLOCK:\\|:LOGBOOK:\\|CLOCK:\\|:END:= \\)") (if > ... ... ... ...)) (org-skip-over-state-notes) (skip-chars-backward " > =A0 =A0 =A0 =A0\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))) > =A0org-insert-property-drawer() > =A0(save-excursion (org-insert-property-drawer) (setq end (progn ... ...)= )) > =A0(if force (save-excursion (org-insert-property-drawer) (setq end > ...)) (throw (quote exit) nil)) > =A0(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 > ...))) > =A0(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)) > =A0(save-excursion (let* (... ...) (goto-char beg) (if ... ... ... ... > ...) (if ... ... ... ... ... ... ...) (cons beg end))) > =A0(catch (quote exit) (save-excursion (let* ... ... ... ... ...))) > =A0org-get-property-block(4037 4266 force) > =A0(setq range (org-get-property-block beg end (quote force))) > =A0(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)) > =A0(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 > ... ... ... ... ... ...))) > =A0(let ((beg ...) (end ...) range) (cond (... ... ... ... ...) (... > ... ...) (... ...) (... ...) (... ...) (t ...))) > =A0(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)) > =A0(save-excursion (if (markerp pom) (set-buffer ...)) (save-excursion > (goto-char ...) (org-back-to-heading t) (let ... ...) > (run-hook-with-args ... property value))) > =A0(org-with-point-at pom (org-back-to-heading t) (let (... ... range) > (cond ... ... ... ... ... ...)) (run-hook-with-args (quote > org-property-changed-functions) property value)) > =A0org-entry-put(4204 "ID" "b7f6dacd-3d83-492d-877e-075d3312d0a6") > =A0(cond ((and id ... ...) id) (create (setq id ...) (org-entry-put pom > "ID" id) (org-id-add-location id ...) id) (t nil)) > =A0(let ((id ...)) (cond (... id) (create ... ... ... id) (t nil))) > =A0(save-excursion (goto-char (or pom ...)) (let (...) (cond ... ... ...)= )) > =A0(save-excursion (if (markerp pom) (set-buffer ...)) (save-excursion > (goto-char ...) (let ... ...))) > =A0(org-with-point-at pom (let (...) (cond ... ... ...))) > =A0org-id-get(4204 create) > =A0org-id-get-create() > =A0(org-make-link "id:" (org-id-get-create)) > =A0(let* ((link ...) (case-fold-search nil) (desc ...)) > (org-store-link-props :link link :description desc :type "id") link) > =A0org-id-store-link() > =A0run-hook-with-args-until-success(org-id-store-link) > =A0(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))) > =A0(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 ...))) > =A0org-store-link(nil) > =A0call-interactively(org-store-link nil nil) > > > >> >> Best, >> =A0-- 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, Liam