1 ;;;; This file is part of LilyPond, the GNU music typesetter.
3 ;;;; Copyright (C) 2005--2011 Jan Nieuwenhuizen <janneke@gnu.org>
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.
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.
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/>.
18 (define-module (scm editor))
20 ;; Also for standalone use, so cannot include any lily modules.
29 (car (string-tokenize (vector-ref (uname) 0) char-set:letter)))))
32 (or (getenv "LYEDITOR")
36 ;; FIXME: how are default/preferred editors specified on
37 ;; different platforms?
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")))
53 (define (get-command-template alist editor)
54 (define (get-command-template-helper)
56 (if (string-match "%\\(file\\)s" editor)
58 (string-append editor " %(file)s"))
59 (if (string-match (caar alist) editor)
61 (get-command-template (cdr alist) editor))))
62 (if (string-match "%\\(file\\)s" editor)
64 (get-command-template-helper)))
66 (define (re-sub re sub string)
67 (regexp-substitute/global #f re string 'pre sub 'post))
70 (if (string-index x #\/)
72 (re-sub "\\\\" "/" x)))
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))
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)
82 "%\\(column\\)s" (format #f "~a" column)
83 (slashify template)))))))