emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Orgmode] overzealous file link creation


From: Dan Davison
Subject: Re: [Orgmode] overzealous file link creation
Date: Wed, 12 Aug 2009 12:09:03 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.91 (gnu/linux)

Carsten Dominik <address@hidden> writes:

> On Aug 11, 2009, at 10:29 PM, Dan Davison wrote:
>
<...>
>> Try putting the following fragment into python-mode, and getting rid
>> of
>> the asterisks. Then org-cycle issued with point at any of the
>> asterisked
>> locations eats the string 'file' and prompts for a link.
>>
>> --8<---------------cut here---------------start------------->8---
>> def f(filepath):
>>    print(
>>        *filepath*)*
>> *
>> *def g(arg):
>>    return arg
>> --8<---------------cut here---------------end--------------->8---
>>
>> This is with latest git.
>
> Hi Dan,
>
> could you please check the following variables:
>
> org-tab-first-hook

,----
| org-tab-first-hook is a variable defined in `org.el'.
| Its value is 
| (org-insert-link-maybe org-hide-block-toggle-maybe)
`----

OK, that was it, thanks. I had

(add-hook 'org-tab-first-hook 'org-insert-link-maybe)  

I believe org-insert-link-maybe (code below) is something that Eric
threw together: am I right in thinking it has not been incorporated into
org core?

In any case, could someone help me with the regexp problem I encountered
when I tried to improve it? Here's the original version

--8<---------------cut here---------------start------------->8---
  (defun org-insert-link-maybe ()
    "insert a file link depending on the context"
    (interactive)
    (let ((case-fold-search t))
      (if (save-excursion
            (when (re-search-backward "[[:space:]]" nil t) (forward-char 1)
                  (looking-at "\\[?\\[?file:?")))
          (progn (replace-match "") (org-insert-link '(4)) t)
        nil)))
--8<---------------cut here---------------end--------------->8---

I want to (a) restrict it to looking at the current line and (b) not
allow it to match words like 'filepath'. This seems to be almost there

--8<---------------cut here---------------start------------->8---
(defun org-insert-link-maybe ()
  "insert a file link depending on the context"
  (interactive)
  (let ((case-fold-search t))
    (if (save-excursion
          (backward-word)
          (looking-at "\\[?\\[?file:?[ \t\n\f\v\r]"))
        (progn (replace-match "") (org-insert-link '(4)) t)
      nil)))
--8<---------------cut here---------------end--------------->8---

But this doesn't match 'file' followed by end-of-buffer. I want a
character class that matches any of
{space,tab,newline,end-of-buffer}. How do I do that? It seems that
although "\\'" matches end-of-buffer, it doesn't work in a character
class ("[\\']")?

Dan

>
> Probably one of these contains a function that will do file link
> completion.
>
> - Carsten
>
>
> _______________________________________________
> Emacs-orgmode mailing list
> Remember: use `Reply All' to send replies to the list.
> address@hidden
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode




reply via email to

[Prev in Thread] Current Thread [Next in Thread]