]> git.donarmstrong.com Git - lilypond.git/blob - scm/editor.scm
Add '-dcrop' option to ps and svg backends
[lilypond.git] / scm / editor.scm
1 ;;;; This file is part of LilyPond, the GNU music typesetter.
2 ;;;;
3 ;;;; Copyright (C) 2005--2015 Jan Nieuwenhuizen <janneke@gnu.org>
4 ;;;;
5 ;;;; LilyPond is free software: you can redistribute it and/or modify
6 ;;;; it under the terms of the GNU General Public License as published by
7 ;;;; the Free Software Foundation, either version 3 of the License, or
8 ;;;; (at your option) any later version.
9 ;;;;
10 ;;;; LilyPond is distributed in the hope that it will be useful,
11 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 ;;;; GNU General Public License for more details.
14 ;;;;
15 ;;;; You should have received a copy of the GNU General Public License
16 ;;;; along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
17
18 (define-module (scm editor))
19
20 ;; Also for standalone use, so cannot include any lily modules.
21 (use-modules
22  (ice-9 regex)
23  (srfi srfi-13)
24  (srfi srfi-14))
25
26 (define PLATFORM
27   (string->symbol
28    (string-downcase
29     (car (string-tokenize (vector-ref (uname) 0) char-set:letter)))))
30
31 (define (get-editor)
32   (or (getenv "LYEDITOR")
33       (getenv "XEDITOR")
34       (getenv "EDITOR")
35
36       ;; FIXME: how are default/preferred editors specified on
37       ;; different platforms?
38       (case PLATFORM
39         ((windows) "lilypad")
40         (else
41          "emacs"))))
42
43 (define editor-command-template-alist
44   '(("emacs" .  "emacsclient --no-wait +%(line)s:%(column)s %(file)s || (emacs +%(line)s:%(column)s %(file)s&)")
45     ("gvim" . "gvim --remote +:%(line)s:norm%(column)s %(file)s")
46     ("uedit32" . "uedit32 %(file)s -l%(line)s -c%(char)s")
47     ("nedit" . "nc -noask +%(line)s %(file)s")
48     ("gedit" . "gedit +%(line)s %(file)s")
49     ("jedit" . "jedit -reuseview %(file)s +line:%(line)s")
50     ("syn" . "syn -line %(line)s -col %(char)s %(file)s")
51     ("lilypad" . "lilypad +%(line)s:%(char)s %(file)s")))
52
53 (define (get-command-template alist editor)
54   (define (get-command-template-helper)
55     (if (null? alist)
56         (if (string-match "%\\(file\\)s" editor)
57             editor
58             (string-append editor " %(file)s"))
59         (if (string-match (caar alist) editor)
60             (cdar alist)
61             (get-command-template (cdr alist) editor))))
62   (if (string-match "%\\(file\\)s" editor)
63       editor
64       (get-command-template-helper)))
65
66 (define (re-sub re sub string)
67   (regexp-substitute/global #f re string 'pre sub 'post))
68
69 (define (slashify x)
70   (if (string-index x #\/)
71       x
72       (re-sub "\\\\" "/" x)))
73
74 (define-public (get-editor-command file-name line char column)
75   (let* ((editor (get-editor))
76          (template (get-command-template editor-command-template-alist editor))
77          (command
78           (re-sub "%\\(file\\)s" (format #f "~S" file-name)
79                   (re-sub "%\\(line\\)s" (format #f "~a" line)
80                           (re-sub "%\\(char\\)s" (format #f "~a" char)
81                                   (re-sub
82                                    "%\\(column\\)s" (format #f "~a" column)
83                                    (slashify template)))))))
84     command))