3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 2005 Jan Nieuwenhuizen <janneke@gnu.org>
7 (define-module (scm editor))
9 ;; Also for standalone use, so cannot include any lily modules.
18 (car (string-tokenize (vector-ref (uname) 0) char-set:letter)))))
21 (or (getenv "LYEDITOR")
25 ;; FIXME: how are default/preferred editors specified on
26 ;; different platforms?
32 (define editor-command-template-alist
33 '(("emacs" . "emacsclient --no-wait +%(line)s:%(column)s %(file)s || (emacs +%(line)s:%(column)s %(file)s&)")
34 ("gvim" . "gvim --remote +:%(line)s:norm%(column)s %(file)s")
35 ("uedit32" . "uedit32 %(file)s -l%(line)s -c%(column)s")
36 ("nedit" . "nc -noask +%(line)s %(file)s")
37 ("gedit" . "gedit +%(line)s %(file)s")
38 ("jedit" . "jedit -reuseview %(file)s +line:%(line)s")
39 ("lilypad" . "lilypad +%(line)s:%(column)s %(file)s")))
41 (define (get-command-template alist editor)
42 (define (get-command-template-helper)
44 (if (string-match "%\\(file\\)s" editor)
46 (string-append editor " %(file)s"))
47 (if (string-match (caar alist) editor)
49 (get-command-template (cdr alist) editor))))
50 (if (string-match "%\\(file\\)s" editor)
52 (get-command-template-helper)))
54 (define (re-sub re sub string)
55 (regexp-substitute/global #f re string 'pre sub 'post))
58 (if (string-index x #\/)
60 (re-sub "\\\\" "/" x)))
62 (define-public (get-editor-command file-name line column)
63 (let* ((editor (get-editor))
64 (template (get-command-template editor-command-template-alist editor))
66 (re-sub "%\\(file\\)s" (format #f "~S" file-name)
67 (re-sub "%\\(line\\)s" (format #f "~a" line)
68 (re-sub "%\\(column\\)s" (format #f "~a" column)
69 (slashify template))))))