From 98917430c66cf99c9ac706003056396b890319ff Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Thu, 10 Nov 2005 01:14:39 +0000 Subject: [PATCH] * Documentation/user/point-and-click.itely: simplify p&c instruction: don't configure firefox. Put lilypond-invoke-editor in front of the browser. * scripts/lilypond-invoke-editor.scm (run-editor): new function. (run-browser): new function. * lily/parser.yy (Lily_lexer): recognize Book * lily/book.cc (clone): new function * lily/parser.yy (book_body): allow BOOK_IDENTIFIER. --- ChangeLog | 15 ++++++ Documentation/user/point-and-click.itely | 45 +++------------- THANKS | 2 +- lily/book.cc | 7 +++ lily/include/book.hh | 1 + lily/parser.yy | 14 ++++- scripts/lilypond-invoke-editor.scm | 66 +++++++++++++++--------- 7 files changed, 85 insertions(+), 65 deletions(-) diff --git a/ChangeLog b/ChangeLog index cc3f322ed2..00004b40a0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2005-11-10 Han-Wen Nienhuys + + * Documentation/user/point-and-click.itely: simplify p&c + instruction: don't configure firefox. Put lilypond-invoke-editor + in front of the browser. + + * scripts/lilypond-invoke-editor.scm (run-editor): new function. + (run-browser): new function. + + * lily/parser.yy (Lily_lexer): recognize Book + + * lily/book.cc (clone): new function + + * lily/parser.yy (book_body): allow BOOK_IDENTIFIER. + 2005-11-10 Jürgen Reuter * lily/vaticana-ligature.cc, lily/vaticana-ligature-engraver.cc: diff --git a/Documentation/user/point-and-click.itely b/Documentation/user/point-and-click.itely index a4d58320d7..827e51bf5f 100644 --- a/Documentation/user/point-and-click.itely +++ b/Documentation/user/point-and-click.itely @@ -11,51 +11,22 @@ When this functionality is active, LilyPond adds hyperlinks to the PDF file. These hyperlinks are sent to the web-browser, which opens a text-editor with the cursor in the right place. -To make this chain work, the following should done: - -@itemize @bullet - -@item -The PDF viewer must be configured for following hyperlinks, preferably -using Mozilla Firefox. +To make this chain work, you should configure your PDF viewer to +follow hyperlinks using the @file{lilypond-invoke-editor} script +supplied with LilyPond. For Xpdf on Unix, the following should be present in @file{xpdfrc}@footnote{On unix, this file is found either in @file{/etc/xpdfrc} or as @file{.xpdfrc} in your home directory.} @example -urlCommand "firefox -remote 'OpenURL(%s)'" +urlCommand "lilypond-invoke-editor %s" @end example -@item Your web-browser must be configured for the @code{textedit} -protocol, - -For Mozilla and Mozilla Firefox, this is done by adding following -lines to the @file{user.js}@footnote{On a typical unix system, this -file exists or must be created in your home-directory as -@file{.mozilla/firefox/default.trn/user.js} or -@file{.firefox/default/xxxxxxxx.xxx/user.js}, -see @uref{http://@/www@/.mozilla@/.org@/support@/firefox@/edit#user,location} -and -@uref{http://@/www@/.mozilla@/.org@/support@/firefox@/edit#profile,profile}.} - -@ignore -mozilla wants us do store this in user.js: - -location on different systems: - -@end ignore - -@example -user_pref("network.protocol-handler.app.textedit", "lilypond-invoke-editor"); -user_pref("network.protocol-handler.warn-external.textedit", false); -@end example - -@end itemize - -The program @file{lilypond-invoke-editor} is a small helper program. -It tests the environment variable @code{EDITOR} for the following -patterns, +The program @file{lilypond-invoke-editor} is a small helper +program. It will invoke an editor for the special @code{textedit} +URIs, and run a web browser for others. It tests the environment +variable @code{EDITOR} for the following patterns, @table @code @item emacs diff --git a/THANKS b/THANKS index c75ab27e3e..e4c5b87e32 100644 --- a/THANKS +++ b/THANKS @@ -54,7 +54,7 @@ Scott Russell Thomas Bushnell BSG Trevor Bača Vicente Solsona Dellá -Vicenzo Colonnella +Vincenzo Colonnella Release 2.6 *********** diff --git a/lily/book.cc b/lily/book.cc index 28bdb6d5e8..e8d0252b21 100644 --- a/lily/book.cc +++ b/lily/book.cc @@ -38,6 +38,12 @@ Book::Book () smobify_self (); } +Book* +Book::clone () const +{ + return new Book (*this); +} + Book::~Book () { } @@ -136,3 +142,4 @@ Book::process (Output_def *default_paper, scm_remember_upto_here_1 (scm_key); return paper_book; } + diff --git a/lily/include/book.hh b/lily/include/book.hh index 4765f332f1..31749fbae3 100644 --- a/lily/include/book.hh +++ b/lily/include/book.hh @@ -25,6 +25,7 @@ public: Output_def *paper_; SCM scores_; + Book *clone () const; Book (); void add_score (SCM); Paper_book *process (Output_def *def_paper, diff --git a/lily/parser.yy b/lily/parser.yy index 625c107d59..70f35f5000 100644 --- a/lily/parser.yy +++ b/lily/parser.yy @@ -372,8 +372,7 @@ If we give names, Bison complains. %token E_UNSIGNED %token UNSIGNED -%token IDENTIFIER - +%token BOOK_IDENTIFIER %token CHORDMODIFIER_PITCH %token CHORD_MODIFIER %token CONTEXT_DEF_IDENTIFIER @@ -674,6 +673,10 @@ identifier_init: $$ = $1->self_scm (); $1->unprotect (); } + | book_block { + $$ = $1->self_scm (); + $1->unprotect (); + } | output_def { $$ = $1->self_scm (); $1->unprotect (); @@ -757,6 +760,10 @@ book_body: $$->paper_->unprotect (); $$->header_ = THIS->lexer_->lookup_identifier ("$defaultheader"); } + | BOOK_IDENTIFIER { + $$ = unsmob_book ($1); + $$->set_spot (@$); + } | book_body paper_block { $$->paper_ = $2; $2->unprotect (); @@ -2714,6 +2721,9 @@ Lily_lexer::try_special_identifiers (SCM *destination, SCM sid) if (scm_is_string (sid)) { *destination = sid; return STRING_IDENTIFIER; + } else if (unsmob_book (sid)) { + *destination = unsmob_book (sid)->clone ()->self_scm (); + return BOOK_IDENTIFIER; } else if (scm_is_number (sid)) { *destination = sid; return NUMBER_IDENTIFIER; diff --git a/scripts/lilypond-invoke-editor.scm b/scripts/lilypond-invoke-editor.scm index ec58591966..9fe02c467f 100755 --- a/scripts/lilypond-invoke-editor.scm +++ b/scripts/lilypond-invoke-editor.scm @@ -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) @@ -69,30 +73,29 @@ Options: (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:char:column (re-sub ri "" uri)) - (match (string-match "(.*):([^:]+):([^:]+):(.*)$" file-name:line:char: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 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:CHAR:COLUMN") ri) + (format (current-error-port) (_ "expect: textedit://FILE:LINE:CHAR:COLUMN")) (newline (current-error-port)) (exit 1))))) @@ -106,6 +109,21 @@ Options: ;; If no TTY and not using safe, assume running from GUI. (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) + + ;; TODO: make educated guess which browser to run. + (system (format #f "firefox -remote 'OpenURL(~a,new-tab)'" uri))) + (define (main args) (let ((files (parse-options args))) (if (running-from-gui?) @@ -121,11 +139,9 @@ Options: (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))))) + -- 2.39.2