3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 2005 Jan Nieuwenhuizen <janneke@gnu.org>
7 (define-module (scm editor))
12 (define editor-command-template-alist
13 '(("emacs" . "emacsclient --no-wait +%(line)s:%(column)s %(file)s")
14 ("gvim" . "gvim --remote +:%(line)s:norm%(column)s %(file)s")
15 ("nedit" . "nc -noask +%(line)s %(file)s")
16 ("gedit" . "gedit +%(line)s %(file)s")
17 ("jedit" . "jedit %(file)s +line:%(line)s")
18 ("lilypad" . "lilypad +%(line)s:%(column)s %(file)s")))
21 (or (getenv "LYEDITOR")
26 (define (get-command-template alist editor)
27 (define (get-command-template-helper)
29 (if (string-match "%\\(file\\)s" editor)
31 (string-append editor " %(file)s"))
32 (if (string-match (caar alist) editor)
34 (get-command-template (cdr alist) editor))))
35 (if (string-match "%\\(file\\)s" editor)
37 (get-command-template-helper)))
39 (define (re-sub re sub string)
40 (regexp-substitute/global #f re string 'pre sub 'post))
43 (if (string-index x #\/)
45 (re-sub "\\\\" "/" x)))
47 (define-public (get-editor-command file-name line column)
48 (let* ((editor (get-editor))
49 (template (get-command-template editor-command-template-alist editor))
51 (re-sub "%\\(file\\)s" (format #f "~S" file-name)
52 (re-sub "%\\(line\\)s" (format #f "~a" line)
53 (re-sub "%\\(column\\)s" (format #f "~a" column)
54 (slashify template))))))