X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=scm%2Feditor.scm;h=c22ff25a717c7f4baafce4a2c026df08199fdbf3;hb=91de343e1102ed270885392304dc839c58840fe2;hp=aeea02b615eb95cb432133ed256c6133bef8894a;hpb=0fcd8c283c45644a92d2308f1cd0d82a1e63380b;p=lilypond.git diff --git a/scm/editor.scm b/scm/editor.scm index aeea02b615..c22ff25a71 100644 --- a/scm/editor.scm +++ b/scm/editor.scm @@ -2,31 +2,45 @@ ;;;; ;;;; source file of the GNU LilyPond music typesetter ;;;; -;;;; (c) 2005 Jan Nieuwenhuizen +;;;; (c) 2005--2007 Jan Nieuwenhuizen (define-module (scm editor)) +;; Also for standalone use, so cannot include any lily modules. (use-modules - (ice-9 regex)) + (ice-9 regex) + (srfi srfi-13) + (srfi srfi-14)) -(define editor-command-template-alist - '(("emacs" . "emacsclient --no-wait +%(line)s:%(column)s %(file)s") - ("gvim" . "gvim --remote +:%(line)s:norm%(column)s %(file)s") - ("nedit" . "nc -noask +%(line)s %(file)s") - ("gedit" . "gedit +%(line)s %(file)s") - ("jedit" . "jedit %(file)s +line:%(line)s"))) +(define PLATFORM + (string->symbol + (string-downcase + (car (string-tokenize (vector-ref (uname) 0) char-set:letter))))) (define (get-editor) (or (getenv "LYEDITOR") (getenv "XEDITOR") (getenv "EDITOR") - "emacs")) -(define (re-sub re sub string) - (regexp-substitute/global #f re string 'pre sub 'post)) + ;; FIXME: how are default/preferred editors specified on + ;; different platforms? + (case PLATFORM + ((windows) "lilypad") + (else + "emacs")))) -(define-public (get-editor-command file-name line column) - (define (get-command-template alist editor) +(define editor-command-template-alist + '(("emacs" . "emacsclient --no-wait +%(line)s:%(column)s %(file)s || (emacs +%(line)s:%(column)s %(file)s&)") + ("gvim" . "gvim --remote +:%(line)s:norm%(char)s %(file)s") + ("uedit32" . "uedit32 %(file)s -l%(line)s -c%(char)s") + ("nedit" . "nc -noask +%(line)s %(file)s") + ("gedit" . "gedit +%(line)s %(file)s") + ("jedit" . "jedit -reuseview %(file)s +line:%(line)s") + ("syn" . "syn -line %(line)s -col %(char)s %(file)s") + ("lilypad" . "lilypad +%(line)s:%(char)s %(file)s"))) + +(define (get-command-template alist editor) + (define (get-command-template-helper) (if (null? alist) (if (string-match "%\\(file\\)s" editor) editor @@ -34,12 +48,26 @@ (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 char 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))))) + (re-sub "%\\(char\\)s" (format #f "~a" char) + (re-sub + "%\\(column\\)s" (format #f "~a" column) + (slashify template))))))) command))