From mboxrd@z Thu Jan 1 00:00:00 1970 From: Carsten Dominik Subject: Re: overzealous file link creation Date: Wed, 12 Aug 2009 18:42:36 +0200 Message-ID: <9DBEB2B1-7CB9-422E-827E-4A240A28A7D9@gmail.com> References: <87ws5aozzv.fsf@stats.ox.ac.uk> <871vnhypy8.fsf@stats.ox.ac.uk> 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 mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MbGuZ-00008t-9d for emacs-orgmode@gnu.org; Wed, 12 Aug 2009 12:42:51 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MbGuT-00006t-R8 for emacs-orgmode@gnu.org; Wed, 12 Aug 2009 12:42:50 -0400 Received: from [199.232.76.173] (port=34160 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MbGuT-00006o-HA for emacs-orgmode@gnu.org; Wed, 12 Aug 2009 12:42:45 -0400 Received: from mail-ew0-f207.google.com ([209.85.219.207]:42983) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MbGuS-0006Dp-PA for emacs-orgmode@gnu.org; Wed, 12 Aug 2009 12:42:45 -0400 Received: by ewy3 with SMTP id 3so196275ewy.42 for ; Wed, 12 Aug 2009 09:42:43 -0700 (PDT) In-Reply-To: <871vnhypy8.fsf@stats.ox.ac.uk> 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: Dan Davison Cc: emacs org-mode mailing list On Aug 12, 2009, at 6:09 PM, Dan Davison wrote: > Carsten Dominik 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