Emacs on Windows for C++ development configuration? - emacs

Has anyone set up cygwin and some emacs to work well under a 64-bit Windows 7?
I tried downloading cygwin recently, and by default not even dired works reliably, there are odd shell prompt characters, I get a lot of warnings, in one case C-c was read as C-g and caused various errors. (Neither xemacs nor emacs worked for me, where by "work" I mean that dired and shell work, and without warnings).
I just want the usual emacs development tools: gdb-mode, shell-mode, compiling, tag-search to work as normal.
I was hoping someone who has done this recently with cygwin could share whatever relevant shell files, emacs files, environment variables, and so on to make this all work. Should all these things just work out of the box?

You should check out ntemacs, with this code in your .emacs everything is working great with cygwin:
;; -- sets up cygwin
(let* ((cygwin-root "c:/cygwin")
(cygwin-bin (concat cygwin-root "/bin")))
(when (and (eq 'windows-nt system-type)
(file-readable-p cygwin-root))
(setq exec-path (cons cygwin-bin exec-path))
(setenv "PATH" (concat cygwin-bin ";" (getenv "PATH")))
(setq shell-file-name "bash")
(setenv "SHELL" shell-file-name)
(setq explicit-shell-file-name shell-file-name)
(add-hook 'comint-output-filter-functions 'comint-strip-ctrl-m)))

I use a hideous Frankenstein mix of "native" Win32 emacs (http://alpha.gnu.org/gnu/emacs/pretest/windows/emacs-23.1.97-bin-i386.zip is the latest, but I'm using an older version) and Cygwin -- for bash, find, etc. It's taken me years to tweak things to my liking, and it's still a pretty bumpy experience.
Anyway it's worth trying.

I use a straight clean install of Emacs, gcc, gdb, make, etc from Cygwin (currently 1.7.15, but I've been doing this for years) and my standard dotfiles (.emacs, .bashrc/.bash_profile) that have been tweaked (but not really heavily) to be portable across Linux and Cygwin, and everything works fine for me. Occasionally I run into problems (like with processing2-mode where Processing doesn't have a Cygwin package yet, so it wants native Windows paths, but that's easily enough fixed and out of the ordinary. It almost sounds to me like something is fundamentally broken on your setup; could you give more details? Otherwise all I can recommend is wipe and do a clean reinstall.

Related

Emacs24 , org-mode, can't find `latex'(needed to convert LaTeX fragments fo images)

I want to use the command C-c C-x C-l to preview latex code in org-mode. Since the emacs-nox cannot do this, I tried apt-get install emacs24. However, after I have installed the emacs24 with GUI, I get an error like
can't find \`latex'(needed to convert LaTeX fragments to images)
I have installed texlive2016, and I can latex *.tex in shell command.
I added the /paht/to/latex to .emacs, but it don't work well.
Adding the following to my init.el makes it work:
;; Making emacs find latex (so that C-c C-x C-l works on orgmode)
(setenv "PATH" (concat ":/Library/TeX/texbin/" (getenv "PATH")))
(add-to-list 'exec-path "/Library/TeX/texbin/")
It is not a very pretty solution, but it does the job and is very easy to modify and understand.
This solution worked on a Mac running macOS Sierra and Emacs v25.1.
My crystal ball tells me that the problem is that you're not starting the GUI Emacs from a terminal, so it can't inherit your $PATH settings. See for example https://emacs.stackexchange.com/questions/10722/ (that question is within OSX, but the same problem appears in other systems).
Apparently you can set env-vars globally (so that they affect all applications, including those started directly from the GUI) in ~/.pam_environment (that's for GNU/Linux systems). Note that this is only consulted when you login, so you need to logout+login for changes to take effect.

Emacs can't find gofmt in go-mode

I'm trying to use Emacs for golang programming. I downloaded the go-mode package and installed it. My .emacs is:
(require 'go-mode)
When I'm opening *.go files, go-mode enables correctly. But I can't save any *.go files because when I'm trying to save *.go files I'm getting an error in the minibuffer that says
gofmtprogram not found.
Golang installed (version 1.3), gofmt works from terminal.
How can I solve this problem?
Thank you.
On OSX I'm usingthe following in .emacs/init.el
(use-package exec-path-from-shell
:ensure t
:init (exec-path-from-shell-initialize))
to insure that Emacs are using the correct path.
Make sure you have gofmt in your PATH. (echo $PATH) to check, if you can't run gofmt in your shell, it is likely that emacs won't as well.
gofmt on my setup is in $GOBIN/gofmt, but I think it can be as well be in one of the $GOPATH/bin.
If you have it in your path, chances are that you have an emacs configuration that sets the path. Change as needed.
If you installed via a packet manager, chances are that gofmt will be somewhere else. (I think brew puts it in /usr/local/bin)
Small tip when this happen and you really need to save: switch back to text-mode (M-x text-mode).

Swank server startup failure

Emacs SLIME can't connect to swank, because apparently swank cannot initialize correctly.
It says some back end function not implemented. However, my swamp backend is SBCL, which is supported. I am using windows xp os.
A similar issue was found posted at the following link, but no solution.Link to similar issue
Am I missing any configuration file for Swank? Or perhaps emacs and SBCL versions I am using have compatibility issues? In that case, where can I get the correct compatibility matrix for windows?
I'm mostly using Linux, but it's very easy to run into conflicts if you have multiple versions of slime/swank code installed.
The best method is to use quicklisp and make sbcl/emacs not use any other code (at least in your first attempt):
sbcl --no-userinit --no-sysinit --load ~/quicklisp/setup.lisp
(asdf:initialize-source-registry '(:source-registry :ignore-inherited-configuration))
(ql:quickload "quicklisp-slime-helper")
(swank:create-server :port 4545 :dont-close t :coding-system "utf-8-unix")
Then start emacs as:
emacs -q -name SLIME -eval '(progn (load (expand-file-name "~/quicklisp/slime-helper.el")) (slime-connect "localhost" 4545))'
http://www.pchristensen.com/blog/articles/installing-sbcl-emacs-and-slime-on-windows-xp
Use this or any other manual, which describes how to install Emacs, sbcl and slime separately. But using the latest releases. Then it will be easier to find the problem than it is now.
This is not exactly an answer to the problem, more of an alternative.
I think some interfaces/ method definitions that Swank expects, need to be implemented by SBCL. I shifted the lisp implementation to CLisp from SBCL, and after some setup tweaking, got it to work. So, I think Swank is fine but SBCL is not.
Just for information, CLisp cannot work with short windows path, the ones that look like "Progra~1", while SBCL expects short paths. CLisp also gave some problem with the temp folder in Windows, for which a variable had to be added to the .emacs file, but after that was setup quickly.
There seem to be lots of differences between the various Lisp implementations' ports to Windows, which would not be a problem had better documentation been present. All this had to be gleaned from different blogs and mailing list.
As soon as a better answer to the original problem comes along, I'll accept that.

Emacs - Can't get Flymake to work with JSHint

I'm trying to get JSHint to work with Flymake.
jshint is indeed installed in /opt/bin and works. /opt/bin is in Emacs' exec-path.
I've followed the directions on the EmacsWiki and have this in my init.el:
(defun flymake-jshint-init ()
(let* ((temp-file (flymake-init-create-temp-buffer-copy
'flymake-create-temp-inplace))
(local-file (file-relative-name
temp-file
(file-name-directory buffer-file-name))))
(list "jshint" (list local-file))))
(setq flymake-err-line-patterns
(cons '("^ [[:digit:]]+ \\([[:digit:]]+\\),\\([[:digit:]]+\\): \\(.+\\)$"
nil 1 2 3)
flymake-err-line-patterns))
(add-to-list 'flymake-allowed-file-name-masks
'("\\.js\\'" flymake-jshint-init))
When I open JavaScript files, my modeline appears as:
[(Javascript Flymake* AC)]
This is odd because the * usually doesn't appear when I'm using Flymake with C++ or Python. According to the Flymake docs, Flymake* means "Flymake is currently running." However, Flymake isn't showing any errors.
I've checked the *Messages* buffer but it only lists a few lines of Fontifying foo.js... (regexps...................). No errors.
Other suggestions?
Try using M-: to execute (setq flymake-log-level 3), which will cause flymake to print debug info into *Messages*.
Here's how I use flymake with jslint, which works nicely for me -- that code might give you a clue about what's going wrong for you.
You might also consider js2-mode, which provides some language-aware lint-like warnings without resorting to running an external process.
I found a project called jshint-mode and tried that. It created a buffer called *jshint-mode* which revealed the error: JSHint couldn't find the formidable module.
I ran M-x setenv in Emacs to set NODE_PATH so that jshint could find the formidable library. I also set NODE_PATH in /etc/profile.
jshint-mode did not work for me (I use Linux Mint 14 'Nadia') -- I was getting errors with "flymake's configuration" when it runs curl to talk to the Node.js instance running the jshint script. This was perplexing, and I'm not familiar with ELisp to go around messing with the .el files.
I solved this by instead going straight to the Emacs flymake project fork on github which now has support for jshint built-in (it needs to be installed as npm -g install jshint which in turn requires you to install npm and node.js if you haven't already). This made things work.
One more caveat: on my Linux box, node was an executable already existing in /usr/sbin and I had to make a symbolic link named node in /usr/local/bin to override the former. This was necessary as the Node.js binary for Linux Mint (possibly Ubuntu as well, I haven't checked) is named nodejs instead and will cause many scripts written assuming a binary name of node to fail. You can test this by typing node: if it is the pre-existing binary it generally returns to the prompt silently, but if it is Node.js it prompts you with a > (you can Ctrl-D to quit out of there)

Emacs + Cygwin setup under windows !

I just downloaded Emacs and Cygwin for Windows(Vista in my case). Have no idea how to set them up.
Any help would be appreciated !
Thanks !
I use these libraries, in this order:
(require 'cygwin-mount)
(require 'setup-cygwin)
They are both available on EmacsWiki:
http://www.emacswiki.org/emacs/cygwin-mount.el
http://www.emacswiki.org/emacs/setup-cygwin.el
Step 1: Install libraries
http://www.emacswiki.org/emacs/cygwin-mount.el
http://www.emacswiki.org/emacs/setup-cygwin.el
Step 2: Install cygwin to C:\cygwin (This requirement is hardcoded in setup-cygwin.el, so just do it unless you are willing to modify setup-cygwin.el).
Step 3: Add following code into your .emacs or .emacs.d/init.el. Please note the variable cygwin-mount-cygwin-bin-directory is not set by default in cygwin-mount.el, I suggest using hard coded path (I mean "c:/cygwin/bin" actually) since the cygwin install path is already hardcoded by setup-cygwin.el.
(setq *win32* (eq system-type 'windows-nt) )
;; win32 auto configuration, assuming that cygwin is installed at "c:/cygwin"
(if *win32*
(progn
(setq cygwin-mount-cygwin-bin-directory "c:/cygwin/bin")
(require 'setup-cygwin)
;(setenv "HOME" "c:/cygwin/home/someuser") ;; better to set HOME env in GUI
))
Maybe try posting your question on http://superuser.com
But:
Installing Emacs on Windows 95/98/2K/NT/ME/XP/Vista/Windows 7
Quick Start Guide for those more experienced with Windows
Use cygwin-mount.el to integrate Cygwin with Emacs:
http://www.khngai.com/emacs/cygwin.php
You might also want to replace the DOS Shell with the Cygwin bash, that's also covered.
You can find instructions here.
There're several way to integrate emacs with cygwin as follows:
emacs-nox under cygwin. Not attractive!
emacs-X11 under cygwin. An X server is needed like XMing or Cygwin/X. A bit slow and heavy.
emacs-w32 under cygwin.
emacs under windows. You need some configuration to make emacs recognize the cygwin environment. Difficult for beginners.
I'd recommend using emacs-w32 with cygwin, which uses native Windows GUI so that you don't have to start an xserver just to run emacs and you don't need to write/download any tricky code to make emacs aware of cygwin env as other answers do.
Just install emacs-w32 and run it from mintty and here you go. FYI, if you want to start emacs "independently", write a .bat file with D:\cygwin\bin\run.exe /usr/bin/bash.exe --login -i -c /usr/bin/emacs-w32.exe inside or, as I do, write a .ahk script to start emacs with hotkey F12.