Well I have been trying to get the WSL to work with emacs shell using this defun:
(defun sdev/win-bash-shell ()
"Run Linux Subsystem bash in shell mode."
(interactive)
(let ((explicit-shell-file-name "C:/Windows/System32/bash.exe"))
(call-interactively 'shell)))
The Error I get is Process shell exited abnormally with code 255.
I would appreciate any suggestions as to how to get this to work with emacs.
which bash
does show the pathname of bash within a WSL shell.
It shows WSL uses normal linux pathnames.
In my case it shows
/bin/bash
which should replace the windows pathname
C:/Windows/System32/bash.exe
in your code snippet.
Related
When running Racket in a command line, you can start running a racket program using
(enter! "yourfile.rkt")
How do we exit the current .rkt program while still keeping Racket open in the command line?
Using
(exit)
closes Racket altogether instead of the current .rkt program.
Maybe you could try it and the current namespace will restore to the original.
(enter! #f)
This is somewhat weird, I compiled from source postgresql. I've had no problem using psql at all.
$ psql -d rita
psql (9.3.2)
Type "help" for help.
rita=>
`
However when I try to run M-x sql-postgres on emacs, it prompts for user, password, database, host. But when I input the data in the minibuffer just appears: Unable to locate SQL program psql. I hope anyone can tell me how can I fix this, or what is happening.
Your psql isn't on the standard path.
You are likely setting the PATH in
~/.bashrc, and Emacs will not see it unless you launch Emacs from the terminal.
A solution is:
(setq sql-postgres-program "/usr/local/pgsql/bin/psql")
Or ln -s to /usr/bin if you want.
Alternatively, you can add the path to the psql binary to your emacs 'exec-path list as follows:
(add-to-list 'exec-path "/path/to/program")
(setenv PATH (mapconcat 'identity exec-path ":"))
I run Emacs on a Mac as my development environment. Launching emacs from the Dock doesn't include the path for programs installed via MacPorts. This is going to be a standard problem for anyone who has "non-standard" exec path elements and launches Emacs via their GUI. For me, OSX : MacPorts : /opt/local/... this includes psql, mysql, py-flakes and others. I could either set a variable for each add-on or modify exec-path. The setenv is needed where the elisp function defers searching the exec-path to the shell. The C-c C-v binding in python mode leverages the shell and the $PATH environment to find py-flakes.
The add-to-list is a simple solution that prepends the path to the list. One could make a case for more complex path wrangling in your .emacs file. YMMV.
I want to open a cmd.exe window with the project root directory as it's current directory.
Here is my elisp code:
(defun open-cmd-and-cd-to-project-root()
(interactive)
(projectile-mode t)
(cd (projectile-get-project-root))
(shell))
It opens a cmd shell in an Emacs buffer . But I want it opens a new native cmd.exe window running in Windows rather than a buffer running in Emacs. How can I do that?
Do this:
(let ((proc (start-process "cmd" nil "cmd.exe" "/C" "start" "cmd.exe")))
(set-process-query-on-exit-flag proc nil))
The set-process-query-on-exit-flag to nil is so it won't bother on closing emacs (we can't kill it anyway).
Depending on the system configuration, the start command will spin up a native terminal or explorer window.
I believe the choice is down to whether you allow multiple instances of the explorer shell (the file browser), but some other config might be involved (Local Group Policy, etc.)
M-! start
Your confusion stems from the fact that M-! creates an ad-hoc shell for executing commands by the default processor (cmd.exe, or rather cmdproxy.exe in this case), so starting a shell from a shell will not yield a separate terminal window.
start is a cmd.exe builtin, which opens a new shell window (again, subject to system configuration, as well as arguments passed to it).
Emacs M-x compile does not see any aliases set in .bashrc. If I use M-x shell then type the alias, it is fine. I tried sourcing .bashrc from /etc/profile, from ~/.profile, ~/bash_env, anything I can think of to no avail.
I am on Emacs 23 and Ubuntu 11. I start emacs using /usr/bin/emacs %F, from a desktop button.
Emacs inherits its environment from the parent process. How are you invoking Emacs - from the command line, or some other way?
What happens if you:
M-x compile RET C-a C-k bash -i -c your_alias RET
Invoking bash as an interactive shell (-i option) should read your .bashrc aliases.
Edit: I think both M-x shell-command and M-x compile execute commands in an inferior shell via call-process. Try the following in your .emacs (or just evaluate):
(setq shell-file-name "bash")
(setq shell-command-switch "-ic")
I notice that after evaluation of the above, .bashrc aliases are picked up for use by both M-x shell-command and M-x compile, i.e
M-x compile RET your_alias RET
should then work.
My environment: Emacs 24.1 (pretest rc1), OSX 10.7.3
Keith Flower's answer works but can result in some slowdowns due to .bashrc being unnecessarily loaded in other places (presumably many many times, my computer is not exactly under-powered but emacs was almost unusable when trying to use autocomplete.el).
An alternative way is to locally modify shell-command-switch only for the functions where it is needed. This can be done using emacs' "advice" feature to create a wrapper around those functions. Here's an example that modifies compile:
;; Define + active modification to compile that locally sets
;; shell-command-switch to "-ic".
(defadvice compile (around use-bashrc activate)
"Load .bashrc in any calls to bash (e.g. so we can use aliases)"
(let ((shell-command-switch "-ic"))
ad-do-it))
You need to write similar "advice" for each function that you want to use .bashrc (e.g. I also needed to define the same advice for recompile), just copy the above and replace compile in the above with another function name.
You may like emac's bash-completion :
https://github.com/szermatt/emacs-bash-completion
You'll be able to use tab completion of your aliases in the compilation minibuffer and in shell-mode.
Enjoy !
(they speak about it here Bash autocompletion in Emacs shell-mode )
I think compilation commands are not interpreted through a shell: they are juste exec'ed by emacs (which means aliases, shell functions and other shell-specific things are not taken into account).
Try to wrap you compilation command into a shell-script which would source the correct environment.
You can do this either with a full-fledged shell-script in the form
#!/bin/bash
source "~/.bashrc"
my_command
or directly in emacs with a compilation command of the form
bash -c "source ~/.bashrc; my_command"
See Is there a way to get my emacs to recognize my bash aliases and custom functions when I run a shell command? for a fix which doesn't run all your .bashrc and doesn't create these error messages:
bash: cannot set terminal process group (-1): Inappropriate ioctl for device
bash: no job control in this shell
I have followed instructions from How can I run Cygwin Bash Shell from within Emacs? this question and I have gone further and added the (setq explicit-bash-args '("--login" "-i")) command, however emacs continues to only display the dos prompt when I type M-x shell. In summery my .emacs file looks like this:
(defun cygwin-shell ()
"Run cygwin bash in shell mode."
(interactive)
(let ((explicit-shell-file-name "C:/cygwin/bin/bash"))
(call-interactively 'shell)))
(setq explicit-bash-args '("--login" "-i"))`
Please be gentle with the answers as I am right at the bottom of the famous vertical emacs learning curve!
If you implemented the answer from that question, note that you have to do M-x cygwin-shell to start bash. If you want to use it for every M-x shell you need to call
(setq explicit-shell-file-name "C:/cygwin/bin/bash")
Since you stated that you are learning, here's a few tips when trying this out.
type C-x C-f ~/.emacs to open your .emacs file in your user path.
Enter your function above at the end
M-x load-file [RET] .emacs: loads the buffer (no need to restart emacs)
C-h a: If you are interested in some specific action, you can look it up
C-h v [RET] variable: can inspect the variable, check the value of explicit-bash-args for instance
And, btw, I'm not sure what the "--login -i" does, but someone stated in a comment that you should have that so "ls" would work. If you have your cygwin bin path in your PATH environment variable, bash will find ls anyway. No need to escape the path variable either, this is handled by bash (do an echo $PATH in bash when you get it working and you'll see).