emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* overzealous file link creation
@ 2009-08-11 20:29 Dan Davison
  2009-08-11 21:36 ` Nick Dokos
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Dan Davison @ 2009-08-11 20:29 UTC (permalink / raw)
  To: emacs org-mode mailing list

Recently I've been randomly losing the string 'file' from all sorts of
documents. Up until now I had no explanation. It's not the sort of
question one wants to ask on public mailing lists.

OK, so if you call org-cycle "in the vicinity" of a word that starts
with the string 'file', then it eats up 'file' and prompts for link
insertion. This is true in buffers that are not in org-mode or
orgstruct*-mode. (I call org-cycle the whole time in order to use
outline-minor-mode, but o-m-m doesn't have to be turned on to cause
this.)

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.

Dan

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: overzealous file link creation
  2009-08-11 20:29 overzealous file link creation Dan Davison
@ 2009-08-11 21:36 ` Nick Dokos
  2009-08-12  7:52 ` Manish
  2009-08-12  8:30 ` Carsten Dominik
  2 siblings, 0 replies; 7+ messages in thread
From: Nick Dokos @ 2009-08-11 21:36 UTC (permalink / raw)
  To: Dan Davison; +Cc: emacs org-mode mailing list

Dan Davison <davison@stats.ox.ac.uk> wrote:

> Recently I've been randomly losing the string 'file' from all sorts of
> documents. Up until now I had no explanation. It's not the sort of
> question one wants to ask on public mailing lists.
> 
> OK, so if you call org-cycle "in the vicinity" of a word that starts
> with the string 'file', then it eats up 'file' and prompts for link
> insertion. This is true in buffers that are not in org-mode or
> orgstruct*-mode. (I call org-cycle the whole time in order to use
> outline-minor-mode, but o-m-m doesn't have to be turned on to cause
> this.)
> 
> 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.
> 
> def f(filepath):
>     print(
>         *filepath*)*
> *
> *def g(arg):
>     return arg
> 
> This is with latest git.
> 

I cannot reproduce this. I created foo.py with the above contents, deleted
the asterisks, saved the file and then tried M-x org-cycle at the various
places indicated by the asterisks. In no case does a "file" disappear.

At the three places around filepath in function f(), nothing happens.

At the beginning of the def g(...), it folds the function (I also tried
at the beginning of the definition of f, with the same result). In all of
these cases, the buffer does not get modified.

The only case where the buffer is modified is at the beginning of the empty
line between the functions: I get a tab added (actually a bunch of spaces -
not sure whether it makes a difference but I set indent-tabs-mode to nil).

I think we need more people to try out the experiment!-)

HTH,
Nick

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: overzealous file link creation
  2009-08-11 20:29 overzealous file link creation Dan Davison
  2009-08-11 21:36 ` Nick Dokos
@ 2009-08-12  7:52 ` Manish
  2009-08-12  8:32   ` Carsten Dominik
  2009-08-12  8:30 ` Carsten Dominik
  2 siblings, 1 reply; 7+ messages in thread
From: Manish @ 2009-08-12  7:52 UTC (permalink / raw)
  To: Dan Davison; +Cc: emacs org-mode mailing list

On Wed, Aug 12, 2009 at 1:59 AM, Dan Davison wrote:
> Recently I've been randomly losing the string 'file' from all sorts of
> documents. Up until now I had no explanation. It's not the sort of
> question one wants to ask on public mailing lists.
>
> OK, so if you call org-cycle "in the vicinity" of a word that starts
> with the string 'file', then it eats up 'file' and prompts for link
> insertion. This is true in buffers that are not in org-mode or
> orgstruct*-mode. (I call org-cycle the whole time in order to use
> outline-minor-mode, but o-m-m doesn't have to be turned on to cause
> this.)
>
> 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.

Tried the test with following text with numbers removed.

--8<---------------cut here---------------start------------->8---
def f(filepath):
 print(
   1filepath2)3
4
5def g(arg):
 return arg
--8<---------------cut here---------------end--------------->8---

With buffer in python mode, I executed org-cycle at the positions marked with
numbers and got the results below:

at 1,2,3: nothing happens
at 4: inserts a tab (four spaces in my case)
at 5: eats the line with "return arg" (also can not revert this change
with undo.)

The buffer "looks" as if it ends at "def g(arg):" line but when I tried to
paste the resultant buffer with "return arg" removed, I got the following
strange result.

--8<---------------cut here---------------start------------->8---
def f(filepath):
   print(
       filepath)

def g(arg):
   return arg
   return arg

   return arg

--8<---------------cut here---------------end--------------->8---

I tried it several times, also tried saving the buffer and opening it in that
other editor as well.

Tested with git commit 5834ad01b617430c0207627ad425758bcf9b921a of
"Tue Aug 11 16:32:05 2009 +0200"

-- 
Manish

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: overzealous file link creation
  2009-08-11 20:29 overzealous file link creation Dan Davison
  2009-08-11 21:36 ` Nick Dokos
  2009-08-12  7:52 ` Manish
@ 2009-08-12  8:30 ` Carsten Dominik
  2009-08-12 16:09   ` Dan Davison
  2 siblings, 1 reply; 7+ messages in thread
From: Carsten Dominik @ 2009-08-12  8:30 UTC (permalink / raw)
  To: Dan Davison; +Cc: emacs org-mode mailing list


On Aug 11, 2009, at 10:29 PM, Dan Davison wrote:

> Recently I've been randomly losing the string 'file' from all sorts of
> documents. Up until now I had no explanation. It's not the sort of
> question one wants to ask on public mailing lists.
>
> OK, so if you call org-cycle "in the vicinity" of a word that starts
> with the string 'file', then it eats up 'file' and prompts for link
> insertion. This is true in buffers that are not in org-mode or
> orgstruct*-mode. (I call org-cycle the whole time in order to use
> outline-minor-mode, but o-m-m doesn't have to be turned on to cause
> this.)
>
> 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-after-check-for-table-hook
org-tab-after-check-for-cycling-hook

Probably one of these contains a function that will do file link  
completion.

- Carsten

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: overzealous file link creation
  2009-08-12  7:52 ` Manish
@ 2009-08-12  8:32   ` Carsten Dominik
  0 siblings, 0 replies; 7+ messages in thread
From: Carsten Dominik @ 2009-08-12  8:32 UTC (permalink / raw)
  To: Manish; +Cc: Dan Davison, emacs org-mode mailing list


On Aug 12, 2009, at 9:52 AM, Manish wrote:

> On Wed, Aug 12, 2009 at 1:59 AM, Dan Davison wrote:
>> Recently I've been randomly losing the string 'file' from all sorts  
>> of
>> documents. Up until now I had no explanation. It's not the sort of
>> question one wants to ask on public mailing lists.
>>
>> OK, so if you call org-cycle "in the vicinity" of a word that starts
>> with the string 'file', then it eats up 'file' and prompts for link
>> insertion. This is true in buffers that are not in org-mode or
>> orgstruct*-mode. (I call org-cycle the whole time in order to use
>> outline-minor-mode, but o-m-m doesn't have to be turned on to cause
>> this.)
>>
>> 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.
>
> Tried the test with following text with numbers removed.
>
> --8<---------------cut here---------------start------------->8---
> def f(filepath):
> print(
>   1filepath2)3
> 4
> 5def g(arg):
> return arg
> --8<---------------cut here---------------end--------------->8---
>
> With buffer in python mode, I executed org-cycle at the positions  
> marked with
> numbers and got the results below:
>
> at 1,2,3: nothing happens
> at 4: inserts a tab (four spaces in my case)
> at 5: eats the line with "return arg" (also can not revert this change
> with undo.)

Hi Manish,

the line is not eaten, it is hidden by outline.  However, since you  
have not turned on outline-minor-mode, you do not see the ellipsis.

A TAB is inserted because in places where org-cycle cannot do  
anything, it emulates TAB.

I guess I should refactor org-cycle into a function that does only  
cycling, and one that does all the rest...

- Carsten

>
> The buffer "looks" as if it ends at "def g(arg):" line but when I  
> tried to
> paste the resultant buffer with "return arg" removed, I got the  
> following
> strange result.
>
> --8<---------------cut here---------------start------------->8---
> def f(filepath):
>   print(
>       filepath)
>
> def g(arg):
>   return arg
>   return arg
>
>   return arg
>
> --8<---------------cut here---------------end--------------->8---
>
> I tried it several times, also tried saving the buffer and opening  
> it in that
> other editor as well.
>
> Tested with git commit 5834ad01b617430c0207627ad425758bcf9b921a of
> "Tue Aug 11 16:32:05 2009 +0200"
>
> -- 
> Manish
>
>
> _______________________________________________
> Emacs-orgmode mailing list
> Remember: use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: overzealous file link creation
  2009-08-12  8:30 ` Carsten Dominik
@ 2009-08-12 16:09   ` Dan Davison
  2009-08-12 16:42     ` Carsten Dominik
  0 siblings, 1 reply; 7+ messages in thread
From: Dan Davison @ 2009-08-12 16:09 UTC (permalink / raw)
  To: Carsten Dominik; +Cc: emacs org-mode mailing list

Carsten Dominik <carsten.dominik@gmail.com> 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.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: overzealous file link creation
  2009-08-12 16:09   ` Dan Davison
@ 2009-08-12 16:42     ` Carsten Dominik
  0 siblings, 0 replies; 7+ messages in thread
From: Carsten Dominik @ 2009-08-12 16:42 UTC (permalink / raw)
  To: Dan Davison; +Cc: emacs org-mode mailing list


On Aug 12, 2009, at 6:09 PM, Dan Davison wrote:

> Carsten Dominik <carsten.dominik@gmail.com> 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 ("[\\']")?

"\\(?:[ \t\n]\\|\\'\\)"

HTH

- Carsten

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2009-08-12 16:42 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-11 20:29 overzealous file link creation Dan Davison
2009-08-11 21:36 ` Nick Dokos
2009-08-12  7:52 ` Manish
2009-08-12  8:32   ` Carsten Dominik
2009-08-12  8:30 ` Carsten Dominik
2009-08-12 16:09   ` Dan Davison
2009-08-12 16:42     ` Carsten Dominik

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).