Windows, Emacs, Git Bash, and shell-command - windows

Windows 7. Emacs 24.3.1. Git 1.8.1.msysgit.1. I have the following in my equivalent .emacs file:
(if (equal system-type 'windows-nt)
(progn (setq explicit-shell-file-name
"C:/Program Files (x86)/Git/bin/sh.exe")
(setq shell-file-name "bash")
(setq explicit-sh.exe-args '("--login" "-i"))
(setenv "SHELL" shell-file-name)
(add-hook 'comint-output-filter-functions 'comint-strip-ctrl-m)))
This works great when I want to do M-x shell: I can pop open a shell and type "ls".
However, M-x shell-command is failing. When I try to run "ls" via shell-command (which should print its output in the *Shell Command Output* buffer, according to C-h f shell-command), I get a single error message:
"Searching for program: permission denied, bash"
There are some very old suggestions on the Google about call-process and many questions on StackOverflow about getting the shell to work in Emacs. Please note that M-x shell works great, and what I'd like to work is shell-command.
(Reason: https://github.com/donkirkby/live-py-plugin#installing-the-emacs-mode)

Try setting both variables to point to the same executable and make sure the path is in exec-path:
(setq explicit-shell-file-name
"C:/Program Files (x86)/Git/bin/bash.exe")
(setq shell-file-name explicit-shell-file-name)
(add-to-list 'exec-path "C:/Program Files (x86)/Git/bin")

I know this is an older question, but I found it while I was searching for help on the same issue, so here's the solution I use for my particular use case, in case it helps someone in the future.
I sync up my .emacs.d between all computers I use emacs on, which includes both Linux & Windows machines. I inserted this into my init.el file to automatically deal with this issue appropriately in a Windows environment:
;; Set Windows-specific preferences if running in a Windows environment.
(defun udf-windows-setup () (interactive)
;; The variable `git-shell-path' contains the path to the `Git\bin'
;; file on my system. I install this in
;; `%USERPROFILE%\LocalAppInfo\apps\Git\bin'.
(setq git-shell-path
(concat (getenv "USERPROFILE") "\\LocalAppInfo\\apps\\Git\\bin"))
(setq git-shell-executable
(concat git-shell-path "\\bash.exe"))
(add-to-list 'exec-path git-shell-path)
(setenv "PATH"
(concat git-shell-path ";"
(getenv "PATH")))
(message "Windows preferences set."))
(if (eq system-type 'windows-nt)
(udf-windows-setup))
Please note that the variable git-shell-path will need to be defined based on where you have git installed on your system. I install it in %USERPROFILE%\LocalAppInfo\apps\Git on the one Windows machine where I use it.

Using GitBash you can use the lein script instead of the lein.bat script. Put the lein script into a directory called bin in your user account on windows. GitBash should have that bin directory on its executable PATH, so you can run lein anywhere.
With this approach you do not need any configuration in Emacs Lisp.
See my full answer

Related

Configure path to PowerShell console in Cygwin Emacs

I have Emacs running via Cygwin istall. In Emacs I have installed (via package-install) powershell package; however, when I run M-x powershell I get the following error:
Searching for program: no such file or directory, c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe
The problem here is that instead of c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe the path to PowerShell.exe should be /cygdrive/c/windows/system32/WindowsPowerShell/v1.0/powershell.exe
My question is: how do I configure package powershell to point to the right path?
You can set the variable powershell-location-of-exe, either directly with setq in your .emacs file:
(setq powershell-location-of-exe "/cygdrive/c/windows/system32/WindowsPowerShell/v1.0/powershell.exe")
or through M-x customize-option.
Here is how I do it. It handles different cygwin drive prefixes (I have mine set to / in /etc/fstab):
(when (eq system-type 'cygwin)
(setq powershell-location-of-exe
(s-trim (shell-command-to-string "which powershell.exe"))))
s-trim is from the s.el library which is available on ELPA, you will need to add (require 's) at the top of your .emacs if you don't already have it. It is necessary because which seems to return a string with a trailing newline, though there is probably a built in Emacs function to get rid of that, I don't know it :-(

Spell Check in Emacs on Mac

I am not able to use Spell-Check in the Emacs on my Mac. I copied the .emacs file I had on my previous Fedora to my home folder in my Macbook. The ".emacs" has a line saying:
(global-set-key "\C-k" 'ispell)
When I type "control+k" in an open emacs terminal, I get the following error message in the minibuffer:
Searching for program: permission denied,/Applications/Emacs.app/Contents/Resources/list/textmodes/ispell.elc
When I looked for this address, I found that there is no "list" folder inside the "/Applications/Emacs.app/Contents/Resources/" folder.
When I do "locate ispell.elc", I get the following results:
/Applications/Emacs.app/Contents/Resources/lisp/textmodes/ispell.elc
/usr/local/share/emacs/24.2/lisp/textmodes/ispell.elc
/usr/share/emacs/22.1/lisp/textmodes/ispell.elc
How do I fix it?
I have the following in my emacs config:
(defmacro WhenOSX (&rest body)
`(if (eq system-type 'darwin)
(progn ,#body)
nil
)
)
(WhenOSX
(setq ispell-program-name "/usr/local/bin/aspell")
)
I install aspell via homebrew. The above macro lets me share my config across Linux, OSX, and others.
https://github.com/shaleh/dot-files/tree/master/emacs.d has my Emacs config containing bits I have gathered from around the web over the years. Enjoy.

Emacs in windows, gpg error

I am using emacs on windows. Whenever I look to encrypt file contents using epa-encrypt-file in gives the following error:
Searching for program: Permission denied, gpg
How do I correct this?
EDIT
I installed gpg at the same place as the .emacs and added this to .emacs:
(when (string-equal system-type "windows-nt")
(setq exec-path
'(
"e:/GnuPG/"
)
))
Now the shown error is:
peculiar error: "Can't decrypt", "Exit"
(setq explicit-shell-file-name
"C:/Program Files (x86)/Git/bin/bash.exe")
(setq shell-file-name explicit-shell-file-name)
(add-to-list 'exec-path "C:/Program Files (x86)/Git/bin")
see
Windows, Emacs, Git Bash, and shell-command

Can't find git executable

I'm using Emacs 24 on OS X 10.6.8. Doing magit-status says
Searching for program: no such file or directory, git
However, the Emacs shell is able to find git, so this does not seem to be a $PATH issue. What else could it be?
Try checking the value of exec-path variable. This controls the directories which are looked by Emacs for external executables (including git).
This is a customizable variable, and you can add the path to git to the list of existing directories.
I have the elisp snippet in my .emacs.d/init.el file for my Emacs install under OSX, which sets both the PATH and exec-path correctly.
;;; Set localized PATH for OS X
(defun my-add-path (path-element)
"Add the specified PATH-ELEMENT to the Emacs PATH."
(interactive "DEnter directory to be added to path: ")
(if (file-directory-p path-element)
(progn
(setenv "PATH" (concat (expand-file-name path-element) path-separator (getenv "PATH")))
(add-to-list 'exec-path (expand-file-name path-element)))))
(if (fboundp 'my-add-path)
(let ((my-paths (list "/opt/local/bin" "/usr/local/bin" "/usr/local/git/bin")))
(dolist (path-to-add my-paths (getenv "PATH"))
(my-add-path path-to-add))))
Emacs on OS X uses the system-wide environment variables, which can be overridden by creating a magic environment.plist XML file in the right directory. A better solution, though, is to have Emacs copy the value of $PATH from your shell, so that it matches what you see in Terminal.app.
#Anupam's answer is based on a snippet of code which I originally wrote for this purpose, but I've now improved that code and published it as a little elisp library called exec-path-from-shell which you can install from Marmalade or Melpa.

Text editor / IDE for Ruby similar to DrScheme

For those who haven't used DrScheme, window is split in two parts: one part is a file you're editing, and the other is interactive shell. When I run a file, it is loaded into interactive environment, so I can invoke functions I've defined etc. Interactive environment still has all the features of text editor (syntax highlighting, auto completion, etc...)
So is there an IDE for Ruby that doesn't just execute script I'm making, but loads it into irb instead, with all text editor goodies?
This exact request (even up to the fact that Dr Scheme motivated it) is what finally pushed me to learn Emacs.
Here's what i did to install it under Windows Vista:
Download Emacs from http://ftp.gnu.org/gnu/windows/emacs/emacs-22.3-bin-i386.zip
Unzip it to the directory of your choice
After unzipping it create an includes directory anywhere you wish and copy there both ruby-mode.el and ruby-inf.el (these come with the ruby distribution under the misc directory and can also be downloaded from Ruby's source
Modify your .emacs to tell it where to find your includes and and to use them
; directory to put various el files into
(add-to-list 'load-path "C:/emacs-22.3/includes")
;(1)modify .emacs to use ruby-mode
(autoload 'ruby-mode "ruby-mode"
"Mode for editing ruby source files" t)
(setq auto-mode-alist
(append '(("\\.rb$" . ruby-mode)) auto-mode-alist))
(setq interpreter-mode-alist (append '(("ruby" . ruby-mode))
interpreter-mode-alist))
;(2)set to load inf-ruby and set inf-ruby key definition in ruby-mode.
(autoload 'run-ruby "inf-ruby"
"Run an inferior Ruby process")
(autoload 'inf-ruby-keys "inf-ruby"
"Set local key defs for inf-ruby in ruby-mode")
(add-hook 'ruby-mode-hook
'(lambda ()
(inf-ruby-keys)
))
(optional) I also installed mode-compile.el from http://perso.tls.cena.fr/boubaker/distrib/mode-compile.el and made the corresponding edits in .emacs
; Install mode-compile
(autoload 'mode-compile "mode-compile"
"Compile current buffer based on the major mode" t)
(global-set-key "C-cc" 'mode-compile)
(autoload 'mode-compile-kill "mode-compile"
"Kill compilation launched by `mode-compile'" t)
(global-set-key "C-ck" 'mode-compile-kill)
With those changes Emacs will automatically identify a .rb file as ruby and do syntax highlighting. Then with the chord \C-c\C-s (Control-c, release and then Control-s) irb will start in the box below your file, and you can use all the keys defined by inf-ruby: (\M is the Meta Key which for Windows means Alt)
"\C-c\C-b" 'ruby-send-block
"\C-c\M-b" 'ruby-send-block-and-go
"\C-c\C-x" 'ruby-send-definition
"\C-c\M-x" 'ruby-send-definition-and-go
"\C-c\C-r" 'ruby-send-region
"\C-c\M-r" 'ruby-send-region-and-go
"\C-c\C-z" 'switch-to-ruby
"\C-c\C-l" 'ruby-load-file
"\C-c\C-s" 'run-ruby
If you did the optional step and installed mode-compile, you can also use \C-cc to send the current file to ruby instead of irb
I haven't worked with DrScheme yet, but Netbeans 6.5 includes a full-featured IRB. Have you given it a try?

Resources