Running emacs in cygwin

10,180

Solution 1

Need to have an X-server running and install the x-version of emacs, cygwin includes both (if you select the correct packages during installation).

The X-server is probably started with the command startx once it's installed.

Solution 2

A non-X solution is emacs-w32 package under Editors in the cygwin setup. It runs emacs as a native Windows application but is still pure Cygwin. If you launch it directly from a shortcut, you'll maybe like these settings in ~/.emacs:

Add cygwin to path and exec path if cygwin isn't in your PATH by default:

(setenv "PATH" (concat "/bin:/usr/bin:/usr/local/bin:" (getenv "PATH")))
(nconc exec-path '("/bin" "/usr/bin" "/usr/local/bin"))

If you compile java or other things that generate filenames like C:\whatever, you may first like to edit /etc/fstab and add a mount from C:\ to /c such as:

C: /c ntfs binary,user 1 1

And then treat files beginning with C: as "magic filenames" that get translated to Cygwin style filenames with this in ~/.emacs. Here I'm simply doing two regex replacements on the first argument and ignoring the rest. Someone probably should create an .el for this, make it more robust and post it to http://www.emacswiki.org/emacs/ElispArea :

; When in cygwin, allow C:\whatever to turn into /c/whatever
(defun cygwin-name-hook (operation &rest args)
  "Turn Windows filenames into Cygwin filenames."
  ;; Handle all operations the same
  (let ((first (car args))
        (inhibit-file-name-handlers
         (cons 'cygwin-name-hook
               (and (eq inhibit-file-name-operation operation)
                    inhibit-file-name-handlers)))
        (inhibit-file-name-operation operation))
    (setq first (replace-regexp-in-string "^C:" "/c" first t))
    (setq first (replace-regexp-in-string "\\\\" "/" first t))
    (apply operation (cons first (cdr args)))))

(add-to-list 'file-name-handler-alist '("^[Cc]:" . cygwin-name-hook))

Then if you run emacs -nw inside mintty, you may like it to recognize more keys, place into ~/.emacs:

;***** For mintty
(define-key function-key-map "\e[1;5m" [(control ?-)])
(define-key function-key-map "\e[1;5k" [(control ?=)])
(define-key function-key-map "\e[1;5q" [(control ?1)])
(define-key function-key-map "\e[1;5s" [(control ?3)])
(define-key function-key-map "\e[1;5t" [(control ?4)])
(define-key function-key-map "\e[1;5u" [(control ?5)])
(define-key function-key-map "\e[1;5w" [(control ?7)])
(define-key function-key-map "\e[1;5x" [(control ?8)])
(define-key function-key-map "\e[1;5y" [(control ?9)])
(define-key function-key-map "\e[1;5p" [(control ?0)])
Share:
10,180

Related videos on Youtube

starcorn
Author by

starcorn

Updated on September 17, 2022

Comments

  • starcorn
    starcorn over 1 year

    I have installed Emacs which comes with Cygwin. How can I get Cygwin to run Emacs in its own window instead from the Cygwin's console window.

    I like how, in Ubuntu, when I run Emacs from the terminal, it will open Emacs's GUI.

    • Admin
      Admin over 12 years
      I'm curious: Why don't you install the windows version of Emacs?
    • Admin
      Admin over 12 years
      That's certainly an option, but if you work mostly in the Cygwin environment it's useful to have an Emacs that understands Cygwin-style paths (/home/username/foo.txt vs. C:\cygwin\home\username\foo.txt).
    • Admin
      Admin over 12 years
      Because cygwin gives me the feel of unix in windows box. And your response should be a comment rather than an answer.
  • Julian
    Julian over 13 years
    @klw - No xemacs is a different flavour of emacs (another very similar program). It's not emacs with the X-libraries included. The namning is a bit confusing.
  • Julian
    Julian over 13 years
    @klw - You want the emacs-X11 packages
  • starcorn
    starcorn over 13 years
    @Nifle - i got that installed, but I can't find the package for x-server. could possible give me a name for it as well? btw, you don't happen to know if Xming can be used instead for cygwin's X-server?
  • Julian
    Julian over 13 years
    @klw - Another x-server is perfectly fine, that's what I have used most of the time, but a quick look at the cygwin packages I think you want the X11 package called xorg-server
  • starcorn
    starcorn over 13 years
    @Nifle - I got the xorg installed now, and it seems to work when i issue startx in cygwin. However it just open up a black window with nothing in it. And in the cygwin console it just printing _XSERVTrans.SocketUNIXAccept: accept() failed . When I try to open emacs it still doesn't work. Do you know what the problem might be?
  • Julian
    Julian over 13 years
    @starcom - No idea, make sure you have installed all prerequsits or try Xming instrad. I haven't kept up with cygwin latly as I have switched to OSX for my work computer.