]> git.donarmstrong.com Git - lilypond.git/blob - scm/editor.scm
Run `make grand-replace'.
[lilypond.git] / scm / editor.scm
1 ;;;; editor.scm --
2 ;;;;
3 ;;;;  source file of the GNU LilyPond music typesetter
4 ;;;; 
5 ;;;; (c) 2005--2008 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 || (emacs +%(line)s:%(column)s %(file)s&)")
34     ("gvim" . "gvim --remote +:%(line)s:norm%(char)s %(file)s")
35     ("uedit32" . "uedit32 %(file)s -l%(line)s -c%(char)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     ("syn" . "syn -line %(line)s -col %(char)s %(file)s")
40     ("lilypad" . "lilypad +%(line)s:%(char)s %(file)s")))
41
42 (define (get-command-template alist editor)
43   (define (get-command-template-helper)
44     (if (null? alist)
45         (if (string-match "%\\(file\\)s" editor)
46             editor
47             (string-append editor " %(file)s"))
48         (if (string-match (caar alist) editor)
49             (cdar alist)
50             (get-command-template (cdr alist) editor))))
51   (if (string-match "%\\(file\\)s" editor)
52       editor
53       (get-command-template-helper)))
54
55 (define (re-sub re sub string)
56   (regexp-substitute/global #f re string 'pre sub 'post))
57
58 (define (slashify x)
59  (if (string-index x #\/)
60      x
61      (re-sub "\\\\" "/" x)))
62
63 (define-public (get-editor-command file-name line char column)
64   (let* ((editor (get-editor))
65          (template (get-command-template editor-command-template-alist editor))
66          (command
67           (re-sub "%\\(file\\)s" (format #f "~S" file-name)
68                   (re-sub "%\\(line\\)s" (format #f "~a" line)
69                           (re-sub "%\\(char\\)s" (format #f "~a" char)
70                                   (re-sub
71                                    "%\\(column\\)s" (format #f "~a" column)
72                                    (slashify template)))))))
73     command))