]> git.donarmstrong.com Git - lilypond.git/blob - scm/editor.scm
* scm/editor.scm (get-editor): Add platform defaults.
[lilypond.git] / scm / editor.scm
1 ;;;; editor.scm --
2 ;;;;
3 ;;;;  source file of the GNU LilyPond music typesetter
4 ;;;; 
5 ;;;; (c) 2005 Jan Nieuwenhuizen <janneke@gnu.org>
6
7 (define-module (scm editor))
8
9 (use-modules
10  (ice-9 regex))
11
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")))
19
20 (define (get-editor)
21   (or (getenv "LYEDITOR")
22       (getenv "XEDITOR")
23       (getenv "EDITOR")
24
25       ;; FIXME: how are default/preferred editors specified on
26       ;; different platforms?
27       (case PLATFORM
28         ((windows) "lilypad")
29         (else
30          "emacs"))))
31
32 (define (get-command-template alist editor)
33   (define (get-command-template-helper)
34     (if (null? alist)
35         (if (string-match "%\\(file\\)s" editor)
36             editor
37             (string-append editor " %(file)s"))
38         (if (string-match (caar alist) editor)
39             (cdar alist)
40             (get-command-template (cdr alist) editor))))
41   (if (string-match "%\\(file\\)s" editor)
42       editor
43       (get-command-template-helper)))
44
45 (define (re-sub re sub string)
46   (regexp-substitute/global #f re string 'pre sub 'post))
47
48 (define (slashify x)
49  (if (string-index x #\/)
50      x
51      (re-sub "\\\\" "/" x)))
52
53 (define-public (get-editor-command file-name line column)
54   (let* ((editor (get-editor))
55          (template (get-command-template editor-command-template-alist editor))
56          (command
57           (re-sub "%\\(file\\)s" (format #f "~S" file-name)
58                   (re-sub "%\\(line\\)s" (format #f "~a" line)
59                           (re-sub "%\\(column\\)s" (format #f "~a" column)
60                                   (slashify template))))))
61     command))