help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: shell-command in Windows 7


From: 42 147
Subject: Re: shell-command in Windows 7
Date: Sat, 15 Apr 2017 23:33:39 +0200
User-agent: Mozilla/5.0 (Windows NT 6.1; rv:45.0) Gecko/20100101 Thunderbird/45.8.0

I was under the impression that setup-cygwin.el was needed to run a Cygwin
shell within Emacs.

I'll admit that I set Cygwin-Emacs up by mechanically following the first
set of instructions I found online. As with everything there are apparently
many different ways of getting the same result.

Am 4/15/2017 um 10:08 PM schrieb John Mastro:
John Mastro <john.b.mastro@gmail.com> wrote:
42 147 <aeuster@gmail.com> wrote:
setup-cygwin.el is perfectly compatible with the code that John Mastro
suggested (which works better than what I had previously anyway). I need
setup-cygwin.el to run cygwin in Emacs. No way I'll stop loading it!
I've been using native Windows builds of Emacs together with Cygwin for
several years now. (Eli recommends against it for very sensible reasons,
but I haven't found anything better and it works well enough for me).

During that time, I've never used setup-cygwin.el. I don't even know
what it does, so I could be missing out, but I wanted to mention that
(at least in my use case) setup-cygwin.el isn't necessary to use Cygwin
with Emacs.
I should mention that I do have some home-grown Cygwin-related settings
though.

I do not claim this is the best or right way to do it, but it's what I
ended up with over time, so I'll share it FWIW.

(defvar cygwin-path-directories
   '("/bin" "/usr/bin" "/usr/local/bin"
     "/Windows" "/ProgramData/Oracle/Java/javapath"))

(defun cygwinize-file-name (name)
   (if (string-match "\\`\\([A-Za-z]\\):\\(/\\|\\\\\\)" name)
       (let* ((drive (match-string 1 name))
              (sep   (match-string 2 name))
              (more  (substring name (match-end 2))))
         (concat (if (member drive '("c" "C")) "" (concat "/" drive))
                 "/"
                 (if (equal sep "\\")
                     (replace-regexp-in-string "\\\\" "/" more)
                   more)))
     name))

(defun init-for-cygwin ()
   (let* ((home (cygwinize-file-name (or (getenv "HOME")
                                         (error "HOME not defined"))))
          (home/bin (concat home
                            (unless (string-suffix-p "/" home) "/")
                            "bin"))
          (path (cons home/bin cygwin-path-directories)))
     (setenv "PATH" (mapconcat #'identity path ":"))
     (setq exec-path (mapcar (lambda (dir) (concat "c:" dir)) path))
     (let ((shell (or (executable-find "zsh")
                      (executable-find "bash")
                      (error "Can't find zsh or bash"))))
       (setq shell-file-name shell)
       (setq explicit-shell-file-name shell)
       (setq ediff-shell shell)
       (setq null-device "/dev/null")
       (setenv "SHELL" shell))))

(when (and (eq system-type 'windows-nt)
            (file-executable-p "c:/bin/bash.exe"))
   (init-for-cygwin))




reply via email to

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