X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=scripts%2Flilypond-invoke-editor.scm;h=b07304e232cea1fda9d0d005a58929899d3f228b;hb=0a3bf6ccc46e213a24eeee74b6f1722a6f3ffec4;hp=e61d10f779ff5f4574c2210023da68a8219456d7;hpb=b6970d44a8b11d1499e0054a98e9359ca3db5d93;p=lilypond.git diff --git a/scripts/lilypond-invoke-editor.scm b/scripts/lilypond-invoke-editor.scm index e61d10f779..b07304e232 100755 --- a/scripts/lilypond-invoke-editor.scm +++ b/scripts/lilypond-invoke-editor.scm @@ -5,7 +5,7 @@ ;;;; ;;;; source file of the GNU LilyPond music typesetter ;;;; -;;;; (c) 2005 Jan Nieuwenhuizen +;;;; (c) 2005--2006 Jan Nieuwenhuizen ;; gui debug helper ;; (define (exit x) (system "sleep 10")) @@ -23,15 +23,19 @@ (format #f "~a/lilypond/~a" DATADIR TOPLEVEL-VERSION)) ;; argv0 relocation -- do in wrapper? + + (define LILYPONDPREFIX - (or (getenv "LILYPONDPREFIX") - (let* ((bindir (dirname (car (command-line)))) - (prefix (dirname bindir)) - (lilypond-prefix - (if (eq? prefix (dirname DATADIR)) COMPILE-TIME-PREFIX - (format #f "~a/share/lilypond/~a" - prefix TOPLEVEL-VERSION)))) - lilypond-prefix))) + (let* ((prefix + (or (getenv "LILYPONDPREFIX") + (dirname (dirname (car (command-line))))))) + + + (if (eq? prefix (dirname DATADIR)) COMPILE-TIME-PREFIX + (format #f "~a/share/lilypond/~a" + prefix TOPLEVEL-VERSION)))) + + ;; gettext wrapper for guile < 1.7.2 (if (defined? 'gettext) @@ -42,13 +46,13 @@ (format port "~a (GNU LilyPond) ~a \n" PROGRAM-NAME TOPLEVEL-VERSION)) (define (show-help port) - (format port (_ "Usage: lilypond-invoke-editor [textedit://]FILE:LINE:COLUMN + (format port (_ "Usage: lilypond-invoke-editor [textedit://]FILE:LINE:CHAR:COLUMN -Visit a file and position the cursor +Visit a file and position the cursor. Options: - -h,--help show this help - -v,--version show version + -h, --help show this help + -v, --version show version "))) (define (parse-options args) @@ -66,35 +70,32 @@ 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 +;; 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 (is-textedit-uri? uri) + (string-match "^textedit://" uri)) + (define (dissect-uri uri) - (let* ((ri "textedit://") - (file-name:line:column (re-sub ri "" uri)) - (match (string-match "(.*):([^:]+):(.*)$" file-name:line:column))) + (let* ((match (string-match "textedit://(.*):([^:]+):([^:]+):(.*)$" uri))) (if match (list (unquote-uri (match:substring match 1)) (match:substring match 2) - (match:substring match 3)) + (match:substring match 3) + (match:substring match 4)) (begin - ;; FIXME: why be so strict wrt :LINE:COLUMN, - ;; esp. considering omitting textedit:// is explicitly - ;; allowed. - (format (current-error-port) (_ "invalid URI: ~a") uri) + (format (current-error-port) (_ "invalid textedit URI: ~a") uri) (newline (current-error-port)) - (format (current-error-port) (_ "expect: ~aFILE:LINE:COLUMN") ri) + (format (current-error-port) (_ "expect: textedit://FILE:LINE:CHAR:COLUMN")) (newline (current-error-port)) (exit 1))))) @@ -106,9 +107,23 @@ Options: (define (running-from-gui?) (let ((have-tty? (isatty? (current-input-port)))) ;; If no TTY and not using safe, assume running from GUI. - ;; for mingw, the test must be inverted. - (if (eq? PLATFORM 'windows) - have-tty? (not have-tty?)))) + (not have-tty?))) + +(define (run-editor uri) + (let* + ((command (apply get-editor-command (dissect-uri uri))) + (status (system command))) + (if (not (= status 0)) + (begin + (format (current-error-port) + (_ "failed to invoke editor: ~a") command) + (exit 1))))) + +(define (run-browser uri) + (system + (if (getenv "BROWSER") + (format "~a ~a" (getenv "BROWSER") uri) + (format #f "firefox -remote 'OpenURL(~a,new-tab)'" uri)))) (define (main args) (let ((files (parse-options args))) @@ -122,14 +137,12 @@ Options: (if (not (= (length files) 1)) (begin (show-help (current-error-port)) - (exit 1))) + (exit 2))) (set! %load-path (cons LILYPONDPREFIX %load-path)) (primitive-eval '(use-modules (scm editor))) - (let* ((uri (car files)) - (command (apply get-editor-command (dissect-uri uri))) - (status (system command))) - (if (not (= status 0)) - (begin - (format (current-error-port) - (_ "failed to invoke editor: ~a") command) - (exit 1)))))) + + (let* ((uri (car files))) + (if (is-textedit-uri? uri) + (run-editor uri) + (run-browser uri))))) +