emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Carsten Dominik <carsten.dominik@gmail.com>
To: Liam Healy <lnp@healy.washington.dc.us>
Cc: emacs-orgmode@gnu.org
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	[thread overview]
Message-ID: <5499816B-00C4-4A1C-9FD4-D55678618BA4@gmail.com> (raw)
In-Reply-To: <AANLkTikNspUDgA_LmOcDXFkjOjtNYwQ-wz7ZSemHnL2e@mail.gmail.com>

Hi Liam,

On Nov 2, 2010, at 9:45 PM, Liam Healy wrote:

> On Sun, Oct 31, 2010 at 5:28 PM, Liam Healy <lnp@healy.washington.dc.us 
> > wrote:
>> On Sun, Oct 31, 2010 at 4:02 PM, David Maus <dmaus@ictsoc.de> 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

      reply	other threads:[~2010-11-02 22:09 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-31 19:09 Unable to generate link in non-org file with org-id-store-link present Liam Healy
2010-10-31 20:02 ` David Maus
2010-10-31 21:28   ` Liam Healy
2010-11-02 20:45     ` Liam Healy
2010-11-02 22:09       ` Carsten Dominik [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5499816B-00C4-4A1C-9FD4-D55678618BA4@gmail.com \
    --to=carsten.dominik@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=lnp@healy.washington.dc.us \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).