lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Point and Click does not work on Windows


From: ArnoldTheresius
Subject: Re: Point and Click does not work on Windows
Date: Mon, 22 Apr 2013 00:13:20 -0700 (PDT)

Eluze wrote
> ...
> maybe my hope to find the needed information in thess tables was to
> optimistic - does somebody know how the "correct" way is?
> 
> Eluze

Well, at least here is what I did try this weekend - posted before I read
all messeages which were added in the meantime.
This code is still "dirty but quick, incomplete but big" 
Editors 'context' and 'pspad' are still missing.
Hopefully still good enough for some testing.

Also to clearify:
- Which of the listed editors are available for windows?
- Which one needs to be started into the background (like lilypad)?

Now, here is my code sinippet for scm/editor.scm:

/(use-modules (ice-9 rdelim)) /*;;!! this module is also required - add it
to the modules list*/

(define PLATFORM  /*;; no change*/
  (string->symbol
   (string-downcase
    (car (string-tokenize (vector-ref (uname) 0) char-set:letter)))))

(define (winreg-read key attribute)  /*;;!! new function*/
 ;;;; this is a workaround, reading the windows registry by examination
 ;;;; of command line output (via a temorary file)
 ;;;; I know, the output depends on the users language!
 ;;;; Hopefully there are only 7bit-ASCII characters used,
 ;;;; and the "not defined" message for standard attribute is
 ;;;;  parenthesized for all languages,
 ;;;; and no other value for the standard attrbute will be parentzesized,
 ;;;; and no empty string will be defined for an attribute
 ;;;;
 ;;;; input 'key' is either a string for the registry path (use backslash!)
 ;;;;  or a list of strings (multiple elements which are to be concatenated
 ;;;;  to define the input path)
 ;;;; input 'attribute' is the attribute to look for it's value,
 ;;;;  or the empty string ("") to read the standard attribute.
 ;;;; result is a string if the operation could be executed successfully,
 ;;;;  or #f if not,
 ;;;;  or '() if the default attribute seems to be undefined
 (define (concat-stringlist-with-bs root-string trail-list)
  (if (null? trail-list)
   root-string
   (concat-stringlist-with-bs
    (string-append root-string "\\" (car trail-list))
    (cdr trail-list))))
 (define (slash-to-bs s)
  (string-map (lambda (x) (if (equal? x #\/) #\\ x)) s))
 (let* ((look-for-default-value (and (string? attribute)
                                     (> (string-length attribute) 0)))
        ;;; (tmpnam) of MinGW on Win7/64 did not use the
        ;;;  windows default temp folder(s)
        ;;; so I prefer to build temp-dir and temp-file on my own:
        (temp-dir (or (getenv "TEMP")
                      (getenv "TMP")
                      (let* ((prefix (getenv "LOCALAPPDATA")))
                       (if (string? prefix)
                        (let ((temp-path-trial
                               (string-append prefix "\\Temp")))
                         (if (access? temp-path-trial W_OK)
                          temp-path-trial
                          (let ((temp-path-trial
                                 (string-append prefix "\\Tmp")))
                           (if (access? temp-path-trial W_OK)
                            temp-path-trial #f))))
                        #f))
                      "."))
        (temp-file (slash-to-bs
                    (let* ((delim (if (or (string-suffix? "\\" temp-dir)
                                          (string-suffix? "/" temp-dir))
                                   "_" "\\_"))
                           (ct 0)
                           (test-name (string-append temp-dir delim "lily"
                                       (number->string (getpid)) "."
                                       (number->string ct) ".tmp")))
                     (while (and (access? test-name F_OK) (< ct 99999))
                      (set! ct (1+ ct))
                      (set! test-name (string-append temp-dir delim "lily"
                                       (number->string (getpid)) "."
                                       (number->string ct) ".tmp")))
                     test-name)))
        (command-to-execute
         (string-append
          "( FOR /F \"usebackq skip=1 tokens=2*\" %i IN (`REG QUERY "
          (if (pair? key)
           (concat-stringlist-with-bs (car key) (cdr key))
           key)
          (if look-for-default-value (string-append " /v " attribute) "
/ve")
          "`) DO @echo %j) > "
          temp-file
          " 2>nul"))
        (execution-result (system command-to-execute)))
  (if (> execution-result 0)
   (begin
    (false-if-exception (delete-file temp-file))
    #f)
   (let ((file-port (false-if-exception (open-file temp-file "r"))))
    (if (port? file-port)
     (let ((text-line (read-line file-port 'trim)))
      (close-port file-port)
      (false-if-exception (delete-file temp-file))
      ;;debug: (for-each display (list "\ncommand-result = '" text-line
"'\n"))
      (if (string? text-line)
       (if (and look-for-default-value
                (string-prefix? "(" text-line)
                (string-suffix? ")" text-line))
        '()
        text-line)
       #f))
     (begin
      (false-if-exception (delete-file temp-file))
      #f))))))

(define (users-default-editor-on-windows)  /*;;!! new function*/
 (define (false-if-null x) (if (null? x) #f x))
 (let ((users-editor '())
       (user-choice (winreg-read (list
     "HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer"
     "FileExts\\.ly\\userchoice") "Progid")))
  ;;debug: (set! user-choice "Applications\\notepad++.exe")
  ;;debug: (set! user-choice "Applications\\gvim.exe")
  ;;debug: (set! user-choice #f)
  ;;debug: (for-each display (list "\nuser-choice (Explorer) = '"
user-choice "'\n"))
  ;; if 'user-choice' starts with "Applications\\" followed
  ;;  by the executable name, then we allmost got the result
  (if (and (string? user-choice) (string-prefix-ci? "Applications\\"
user-choice))
   (if (string-suffix-ci? "\\gvim.exe" user-choice)
    (set! users-editor "gvim")
    (if (string-suffix-ci? "\\notepad++.exe" user-choice)
     (set! users-editor "notepad++")
     (if (string-suffix-ci? "\\lilypad.exe" user-choice)
      (set! users-editor "lilypad")
  ))))
  ;; if 'user-choice' is another index value,
  ;; we'll have to look at another place
  ;; but if 'user-choice' was not found,
  ;; there's another place to get an equivalent index value
  (if (and (null? users-editor) (not (string? user-choice)))
   (set! user-choice (or
     (false-if-null (winreg-read "HKCU\\SOFTWARE\\Classes\\.ly" ""))
     (false-if-null (winreg-read "HKLM\\SOFTWARE\\Classes\\.ly" ""))
  )))
  ;;debug: (for-each display (list "\nuser-choice (Classes) = '" user-choice
"'\n"))
  ;; then try to get the 'edit' or the 'open' command line
  (if (and (null? users-editor)
           (string? user-choice)
           (not (string-contains user-choice "\\")))
   (let ((users-file-command (or
       (false-if-null (winreg-read (list "HKCU\\SOFTWARE\\Classes"
          user-choice "shell\\edit\\command") ""))
       (false-if-null (winreg-read (list "HKLM\\SOFTWARE\\Classes"
          user-choice "shell\\edit\\command") ""))
       (false-if-null (winreg-read (list "HKCU\\SOFTWARE\\Classes"
          user-choice "shell\\open\\command") ""))
       (false-if-null (winreg-read (list "HKLM\\SOFTWARE\\Classes"
          user-choice "shell\\open\\command") ""))
    )))
    ;;debug: (set! users-file-command
"\"C:\\Programs_privat_32\\editors\\gvim.exe\" \"%1\"")
    ;;debug: (set! users-file-command
"\"C:\\Programs_privat_32\\editors\\notepad++.exe\" \"%1\"")
    ;;debug: (for-each display (list "\nusers-file-command = '"
users-file-command "'\n"))
    ;; and which executable is in the command line?
    (if (string? users-file-command)
     (if (string-contains-ci users-file-command "\\gvim.exe")
      (set! users-editor "gvim")
      (if (string-contains-ci users-file-command "\\notepad++.exe")
       (set! users-editor "notepad++")
       (if (string-contains-ci users-file-command "\\lilypad.exe")
        (set! users-editor "lilypad")
  ))))))
  (false-if-null users-editor)))

(define (get-editor)  /*;;!! modified*/
  (or (getenv "LYEDITOR")
      (getenv "XEDITOR")
      (getenv "EDITOR")

      ;; FIXME: how are default/preferred editors specified on
      ;; different platforms?
      (case PLATFORM
        ((windows) (or (users-default-editor-on-windows)  /*;;!! modified here*/
                       "lilypad"))  /*;;!! modified here*/
        (else
         "emacs"))))/

As originally in scm/editor.scm, the functions /get-editor/ nor
/users-default-editor-on-windows/ have an argument to specify you're looking
for the editor of a specific file extension other than ".ly".

ArnoldTheresius



--
View this message in context: 
http://lilypond.1069038.n5.nabble.com/Point-and-Click-does-not-work-on-Windows-tp115986p144833.html
Sent from the Dev mailing list archive at Nabble.com.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]