]> git.donarmstrong.com Git - lilypond.git/blob - scm/editor.scm
* lily/main.cc (setup_paths)[__MINGW32__]: Normalize LILYPONDPREFIX.
[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 ;; Also for standalone use, so cannot include any lily modules.
10 (use-modules
11  (ice-9 regex)
12   (srfi srfi-13)
13   (srfi srfi-14))
14
15 (define PLATFORM
16   (string->symbol
17    (string-downcase
18     (car (string-tokenize (vector-ref (uname) 0) char-set:letter)))))
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 editor-command-template-alist
33   '(("emacs" .  "emacsclient --no-wait +%(line)s:%(column)s %(file)s")
34     ("gvim" . "gvim --remote +:%(line)s:norm%(column)s %(file)s")
35     ("nedit" . "nc -noask +%(line)s %(file)s")
36     ("gedit" . "gedit +%(line)s %(file)s")
37     ("jedit" . "jedit %(file)s +line:%(line)s")
38     ("lilypad" . "lilypad +%(line)s:%(column)s %(file)s")))
39
40 (define (get-command-template alist editor)
41   (define (get-command-template-helper)
42     (if (null? alist)
43         (if (string-match "%\\(file\\)s" editor)
44             editor
45             (string-append editor " %(file)s"))
46         (if (string-match (caar alist) editor)
47             (cdar alist)
48             (get-command-template (cdr alist) editor))))
49   (if (string-match "%\\(file\\)s" editor)
50       editor
51       (get-command-template-helper)))
52
53 (define (re-sub re sub string)
54   (regexp-substitute/global #f re string 'pre sub 'post))
55
56 (define (slashify x)
57  (if (string-index x #\/)
58      x
59      (re-sub "\\\\" "/" x)))
60
61 (define-public (get-editor-command file-name line column)
62   (let* ((editor (get-editor))
63          (template (get-command-template editor-command-template-alist editor))
64          (command
65           (re-sub "%\\(file\\)s" (format #f "~S" file-name)
66                   (re-sub "%\\(line\\)s" (format #f "~a" line)
67                           (re-sub "%\\(column\\)s" (format #f "~a" column)
68                                   (slashify template))))))
69     command))