From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rafal Subject: Re: regexp link on windows problem Date: Fri, 11 Mar 2011 13:41:45 +0000 (UTC) Message-ID: References: <87r5aenj02.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Return-path: Received: from [140.186.70.92] (port=34104 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Py2eT-0007sN-Qm for emacs-orgmode@gnu.org; Fri, 11 Mar 2011 08:45:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Py2eS-0006iq-4Q for emacs-orgmode@gnu.org; Fri, 11 Mar 2011 08:45:09 -0500 Received: from lo.gmane.org ([80.91.229.12]:53173) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Py2eR-0006iW-Ph for emacs-orgmode@gnu.org; Fri, 11 Mar 2011 08:45:08 -0500 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1Py2eO-0000jz-JG for emacs-orgmode@gnu.org; Fri, 11 Mar 2011 14:45:05 +0100 Received: from gate-il27.motorola.com ([136.182.2.25]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 11 Mar 2011 14:45:04 +0100 Received: from raf by gate-il27.motorola.com with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 11 Mar 2011 14:45:04 +0100 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 Bastien altern.org> writes: Hi Bastien, > > Can you give an example? > So I'm trying to write a custom function to set regexp search string for c/c++ code by writing org-create-file-search-functions hook. (code #1 below ) After using the hook by issuing org-store-link in c/c++ buffer, and org-insert-link in org-mode buffer I noticed that the link has slashes instead of backslashes in my regexp. So I delved into the org-insert-link code and found out that it calls expand-file-name on the whole link (filename::regexp) which translates my regexp's backslashes to slashes. It happens only on emacs on windows, under linux it is ok. I also experimented by changing the culprit lines of org-store-link and it helped (code #2 below) but it seems to be too destructive. So I'm wondering if it is a bug that may be fixed or my way of doing it is wrong? regards, Rafal GNU Emacs 23.2.1 (i386-mingw-nt5.1.2600) of 2010-05-08 on G41R2F1 Org-mode version 7.4 ;; code #1 (defun make-token-regexp-1() (let ((WS "") curpos-tmp) (setq curpos (point)) (beginning-of-line) (setq curpos-tmp (point)) (c-end-of-statement 1 nil t) (or (eq curline (line-number-at-pos)) (goto-char curpos)) (setq curpos (point)) (c-beginning-of-statement 1 nil t) (while (and (eq curline (line-number-at-pos)) (not (eq curpos (point)))) (setq curpos (point)) (setq curpos-tmp (point)) (c-beginning-of-statement 1 nil t)) (or (eq curline (line-number-at-pos)) (goto-char curpos-tmp)) (setq curpos (point)) (c-forward-token-2) (while (and (eq curline (line-number-at-pos)) (not (eq curpos (point)))) (setq linkv (concat linkv WS (regexp-quote (org-trim (buffer-substring curpos (point)))))) (setq curpos (point)) (and (< 0 (length linkv)) (setq WS "[ \\t]*")) (c-forward-token-2))) (goto-char curpos) (end-of-line) (and linkv (setq linkv (concat linkv "[ \\t]*" (regexp-quote (org-trim (buffer-substring curpos (point))))))) linkv) (defun make-token-regexp() (interactive) (c-save-buffer-state ((savepos (point)) linkv tokens curpos (curline (line-number-at-pos))) (make-token-regexp-1) (goto-char savepos) (setq description "code-1") (and linkv (setq linkv (concat "/" linkv "/"))) linkv )) (add-hook 'org-create-file-search-functions 'make-token-regexp) ;; code #2 ;; original piece of code ;; We are linking a file with relative path name. (setq path (substring (expand-file-name path) (match-end 0))) (setq path (abbreviate-file-name (expand-file-name path))))))) ;;my changes ;; We are linking a file with relative path name. (setq path (substring (expand-file-name path) (match-end 0))) (let ((path-1) (search-1)) (if (string-match "::\\(.+\\)\\'" path) (progn (setq search-1 (match-string 1 path) path-1 (substring path 0 (match-beginning 0)) path (concat (abbreviate-file-name (expand-file-name path-1)) "::" search-1)))) (setq path (abbreviate-file-name (expand-file-name path)))))))