From 2456e63183ec8ef76a5c59bb6a18c825d81bce0f Mon Sep 17 00:00:00 2001
From: janneke <janneke>
Date: Sun, 15 May 2005 11:45:13 +0000
Subject: [PATCH] * scm/editor.scm (slashify): New function.
 (get-editor-command): Use it. (get-command-template): Do not alter editor
 command if environment value includes `%(file)s' magic.

* scripts/lilypond-invoke-editor.scm (unquote-uri): New function.
(dissect-uri): Use it.
(unquote-uri): Bugfix.
---
 ChangeLog                          | 11 +++++++++++
 scm/editor.scm                     | 21 +++++++++++++++------
 scm/lily.scm                       |  2 +-
 scripts/lilypond-invoke-editor.scm | 20 +++++++++++++++++---
 4 files changed, 44 insertions(+), 10 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 864de9931a..a411ffe934 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2005-05-15  Jan Nieuwenhuizen  <janneke@gnu.org>
+
+	* scm/editor.scm (slashify): New function.
+	(get-editor-command): Use it.
+	(get-command-template): Do not alter editor command if
+	environment value includes `%(file)s' magic.
+
+	* scripts/lilypond-invoke-editor.scm (unquote-uri): New function.
+	(dissect-uri): Use it.
+	(unquote-uri): Bugfix.
+
 2005-05-15  Han-Wen Nienhuys  <hanwen@xs4all.nl>
 
 	* Documentation/topdocs/README.texi (Top): remove note about
diff --git a/scm/editor.scm b/scm/editor.scm
index aeea02b615..b02d3917f4 100644
--- a/scm/editor.scm
+++ b/scm/editor.scm
@@ -22,11 +22,8 @@
       (getenv "EDITOR")
       "emacs"))
 
-(define (re-sub re sub string)
-  (regexp-substitute/global #f re string 'pre sub 'post))
-
-(define-public (get-editor-command file-name line column)
-  (define (get-command-template alist editor)
+(define (get-command-template alist editor)
+  (define (get-command-template-helper)
     (if (null? alist)
 	(if (string-match "%\\(file\\)s" editor)
 	    editor
@@ -34,12 +31,24 @@
 	(if (string-match (caar alist) editor)
 	    (cdar alist)
 	    (get-command-template (cdr alist) editor))))
+  (if (string-match "%\\(file\\)s" editor)
+      editor
+      (get-command-template-helper)))
 
+(define (re-sub re sub string)
+  (regexp-substitute/global #f re string 'pre sub 'post))
+
+(define (slashify x)
+ (if (string-index x #\/)
+     x
+     (re-sub "\\\\" "/" x)))
+
+(define-public (get-editor-command file-name line column)
   (let* ((editor (get-editor))
 	 (template (get-command-template editor-command-template-alist editor))
 	 (command
 	  (re-sub "%\\(file\\)s" (format #f "~S" file-name)
 		  (re-sub "%\\(line\\)s" (format #f "~a" line)
 			  (re-sub "%\\(column\\)s" (format #f "~a" column)
-				  template)))))
+				  (slashify template))))))
     command))
diff --git a/scm/lily.scm b/scm/lily.scm
index 565a5e3c69..23d2152f07 100644
--- a/scm/lily.scm
+++ b/scm/lily.scm
@@ -97,7 +97,7 @@
    (define (slashify x)
      (if (string-index x #\/)
 	 x
-	 (string-regexp-substitute "\\" "/" x)))
+	 (string-regexp-substitute "\\\\" "/" x)))
    ;; FIXME: this prints a warning.
   (define-public (ly-getcwd)
      (slashify (native-getcwd))))
diff --git a/scripts/lilypond-invoke-editor.scm b/scripts/lilypond-invoke-editor.scm
index 26e7e364a4..a21630053b 100755
--- a/scripts/lilypond-invoke-editor.scm
+++ b/scripts/lilypond-invoke-editor.scm
@@ -1,4 +1,4 @@
-#!@GUILE@ \
+-#!@GUILE@ \
 -e main -s
 !#
 ;;;; lilypond-invoke-editor.scm -- Invoke an editor in file:line:column mode
@@ -7,6 +7,9 @@
 ;;;;
 ;;;; (c)  2005 Jan Nieuwenhuizen <janneke@gnu.org>
 
+;; gui debug helper
+;; (define (exit x) (system "sleep 10"))
+
 (use-modules
  (ice-9 getopt-long)
  (ice-9 regex)
@@ -14,7 +17,7 @@
  (srfi srfi-14))
 
 (define PROGRAM-NAME "lilypond-invoke-editor")
-(define TOPLEVEL-VERSION "@TOPLEVEL_VERSION@")
+(define TOPLEVEL-VERSION "2.5.25")
 (define DATADIR "@DATADIR@")
 (define COMPILE-TIME-PREFIX
   (format #f "~a/lilypond/~a" DATADIR TOPLEVEL-VERSION))
@@ -53,15 +56,26 @@ Options:
     (show-version (current-error-port))
     files))
 
+;;(define (re-sub re sub string)
+;;  (let ((sub-string (if (string? sub) sub (sub re))))
+;;    (regexp-substitute/global #f re string 'pre sub-string 'post)))
 (define (re-sub re sub string)
   (regexp-substitute/global #f re string 'pre sub 'post))
 
+;; FIXME: I'm going slowly but certainly mad, I really cannot find the
+;; scm library function for this.
+(define (unquote-uri uri)
+  (re-sub "%([A-Fa-f0-9]{2})"
+	  (lambda (m)
+	    (string (integer->char (string->number (match:substring m 1) 16))))
+	  uri))
+  
 (define (dissect-uri uri)
   (let* ((ri "textedit://")
 	 (file-name:line:column (re-sub ri "" uri))
 	 (match (string-match "(.*):([^:]+):(.*)$" file-name:line:column)))
     (if match
-	(list (match:substring match 1)
+	(list (unquote-uri (match:substring match 1))
 	      (match:substring match 2)
 	      (match:substring match 3))
 	(begin
-- 
2.39.5