How do you run iex from Emacs? - emacs

I keep on getting this warning when I run iex using elixir-mode-iex from Emacs:
Warning: could not run smart terminal, falling back to dumb one
I think that this just means that I don't get tab completion, which I'm fine with. But I'd like a smart terminal if it's possible with elixir-mode in Emacs.

elixir-mode-iex uses the comint-mode major mode to interactive with iex. That also means that it's acting just like a dumb terminal (doesn't have the ability to process special escape sequences etc see here).
As a workaround you just could use term which sends any key press directly to the subprocess itself. You could write a function like the following:
(defun my-elixir-iex ()
(interactive)
(term "iex"))
I'm working on an iex Alchemist.el integration, which brings functionality like Inf-Ruby has. But until it's done try to just use iex via term
Cheers
Samuel

It looks like that warning occurs when IEX can't find tty support. You can enable tty mode in emacs by invoking it with -nw.

Related

Emacsclient crashes when evaluating window functions

To not bore anyone here with specifics, whenever I evaluate an expression similar to this one:
emacsclient -t -e '(set-buffer *scratch*)'
the client will flash up on the terminal and crash.
This seems to be happening with all window-changing functions. Is the client not supposed to work like that? Running this in a normal emacs session does not cause this problem.
You're also using -t, but I'm not exactly sure why.
Is your emacs running in another tty session?
Or is your emacs running in windowing mode (e.g. on X Windows)?
If I have emacs running in windowing mode and I run the following command from another xterm window, then everything works exactly as I would expect it to:
emacsclient -c -e '(set-buffer "*scratch*")
Note in particular the -c option, and the fact that the buffer name is a string and so must be enclosed in double-quotes.

How can I write to standard output in Emacs

I am trying to debug an Emacs program performance wise. In particular, I suffer an extremely long startup time (~5' compared to ~1' for a bare Emacs) on a remote connection via WLAN, cellphone etc. In this context, any message written is no help, for the display is not refreshed at all.
What I would like to do is to write onto the "standard output" of the Linux process. I am aware of the --batch mode but this is no help to me because I want to use Emacs interactively.
So how can I write messages out to the Linux-standard output (as opposed to the Emacs standard output)?
You can output to standard error like this:
(print "hello world" #'external-debugging-output)
or
(princ "hello world" #'external-debugging-output)
This can buffer, so be careful.It's not possible to output to standard out at the moment. I'm going to add that, I think!
Start emacs as a daemon (emacs --daemon) and any messages during the start-up sequence will be sent to stdout or stderr, as described by lunaryorn.
Connect to the server with emacsclient
The simplest way to kill the server is M-x kill-emacs RET
For details see C-hig (emacs) Emacs Server RET
Works for me in centos 6.8 (GNU Emacs 23.1.1):
(append-to-file "here I come to save the day\n" nil "/dev/stdout")
Try also using "/dev/tty" in place of "/dev/stdout":
Unclear from question if you intend to redirect "emacs -nw" stdout to a file and monitor that file externally (then use "/dev/stdout"); or are ok with writing to "/dev/tty" thus polluting the self-same tty of the main "emacs -nw" display.
If starting a GUI version of emacs, in such a way it may lose attachment to originating tty, can abuse environment variables to communicate an originating shell's tty to elisp.
This works for me using Aquamacs in Mac OS X. Launching from a bash shell:
$ MY_TTY=$(tty) open /Applications/Aquamacs\ Emacs.app &
then in emacs:
(append-to-file "here I come to save the day\n" nil (getenv "MY_TTY"))

emacs CUA-mode OK in X but not working console

I have been struggling to get emacs CUA-mode working in the console where it works fine in X (in an xterm using emacs -nw).
The main features I want are shift-movement selection and ^C,^V,^X but any more would be helpful. So far I am using a local keyboard and monitor but ultimate goal is to get all this working over ssh using something like putty.
So far I have been working on getting my terminal to output the same control sequences that emacs expects to see for shift-movement (specifically S-<down> or <S-down>) and this works in the console when shift-select-mode is set in .emacs. So far so good, so I can shift select text from any emacs invocation type: X-windows, terminal ($TERM=linux or $TERM=xterm). This site has been very useful.
Shift-<down> displays as follows using cat -v and emacs happily maps <S-down> to this control sequence.
cat -v (then type shift-down)
^[O2B
Here's the problem, switch on cua-mode and the shift-selection stops working but ^C,^V and ^X starts working !? So I can either have shift-selection or ^C,^V,^X but not both at the same time.
-------
Setup:
emacs 23
Raspberry Pi
Raspian (similar to Debian)
You might like to try a more recent version of Emacs, since cua-mode has been slowly changed to use the same code as shift-select-mode. In Emacs-24.4, cua-mode actually uses shift-select-mode directly.

Emacs: Tramp doesn't work

I tried to open a remote file via Emacs via Tramp.
(require 'tramp)
(setq tramp-default-method "ssh")
I get a message from Emacs
Tramp: Waiting for prompts from remote shell
Emacs hung and did not respond to any action after that
Emacs was installed on Windows; the remote file was on a Linux machine.
If the account you're connecting to uses some weird fancy shell prompt, then there is a good chance that this is what makes tramp trip.
Log in as root, then enter
PS1="> "
(that's a normal, standard shell (ZSH, BASH, younameit) prompt, one that tramp will understand)
then switch to the user account, and launch emacs -q (to make sure that your .emacs is not causing this mess) and try to C-x C-f /sudo:root#localhost:/etc/hosts and see what's what.
You can (not recommended) also customize the regexp that defines what tramp expects :
M-x customize-variable RET tramp-terminal-prompt-regexp
My approach :
Make sure the variable tramp-terminal-type is set to "dumb"
M-x customize-variable RET tramp-terminal-type
Test that in your .*shrc and serve the correct prompt :
case "$TERM" in
"dumb")
PS1="> "
;;
xterm*|rxvt*|eterm*|screen*)
PS1="my fancy multi-line \n prompt > "
;;
*)
PS1="> "
;;
esac
Your Windows ssh client is the key here, and the 'ssh' Tramp method is almost certainly wrong.
If you're using Cygwin, then you need to use the 'sshx' method, and you probably need to use ssh-agent to handle authentication. Details are here:
Using tramp with EmacsW32 and cygwin, possible?
I imagine the same applies to any stand-alone ssh client which does not require a full Cygwin installation, but does use the Cygwin DLLs. (I mention this, because I'm pretty sure I remember seeing such a thing.)
If you're using PuTTY then you want the 'plink' method, as Alex Ott pointed out. If the Wiki doesn't suffice, a search here will probably turn up solutions for configuring that approach.
Other alternatives I can suggest are:
Use the Cygwin-native Emacs. That will be slower than NTEmacs, but Tramp seems to work well with the 'ssh' method, and password-prompting works as well.
Host a Linux VM on your Windows box, and run Emacs on that. That's a fairly large hoop to jump through, but it's my preferred way of using Tramp when working in Windows.
Well, this is a defect of tramp.
The real solution is to prevent loading .bashrc when tramp is used. (because now it is PS1, but it can be PATH, or any other thing that your .bashrc will do that will displease tramp...).
This can be done by asking ssh to set an environment variable, and testing it in .bashrc:
Add this to ~/.emacs:
(require 'tramp-sh nil t)
(setf tramp-ssh-controlmaster-options (concat "-o SendEnv TRAMP=yes " tramp-ssh-controlmaster-options))
and that at the beginning of ~/.bashrc:
if [ ! -z ${TRAMP-x} ] ; then
return
fi
Another default of tramp is that it doesn't have a variable to pass random arguments to the ssh command, we have to piggy-back on tramp-ssh-controlmaster-options.
Had you checked Emacs wiki for solution? ssh is in PATH? It's also recommended to use plink on MS Windows - see section "Inline methods" in Tramp documentation
If the problem is your fancy custom prompt in the remote shell, an easy workaround is to add to your .bashrc or equivalent:
if [[ $TERM == "dumb" ]]; then
export PS1="$ "
fi
After you define your PS1.
Note: the credit goes to ChasingLogic as this is their suggestion in this thread.
By the way -- if You need tramp to sudo -- You can actually sudo without tramp using sudoedit.
Currently I'm using this bash function:
erf () { SUDO_EDITOR="emacsclient -a emacs" sudoedit $#; }

Commands from .bashrc not available in Emacs

I have some aliases and functions defined in ~/.bashrc.
I start emacs from a terminal window using emacs -nw
When I execute M-x shell-command, the aliases and functions from ~/.bashrc are not available, but give a "command not found".
I've googled quite a bit but all the posts I come across say, if I understand them correctly, that ~/.bashrc is the place where this should work (rather than ~/.profile or ~/.bash_profile).
What am I missing?
Aliases are available only in interactive shell - a snapshot from bash man page:
Aliases are not expanded when the
shell is not interactive, unless the
expand_aliases shell option is set
using shopt
(see the description of shopt under SHELL BUILTIN COMMANDS below).
If you start Emacs from an interactive shell (in which .bashrc, etc. have executed), then the commands from your .bashrc should be available for both shell-command and shell, at least that's how it works for me.
But yeah as the other answer says, there is not real way to get a .bashrc environment in emacs. There are some documentation about a .emacs_bash file, but that never worked for me.
Okay misread your question here. If you are looking for functions and aliases instead of commands by changing paths in .bashrc, the non-interactiveness is the problem. I guess you can change the default argument to shell-command (take a look at explicit-bash-args) to make bash interactive, but that probably has unintended consequences.
The accepted answer correctly states that "aliases are available only in interactive shell".
This means that in order to load (rightly located indeed) aliases from ~/.bashrc, an interactive shell would have to be launched with Emacs's M-x shell-command (M-!).
To achieve this, add -i (interactive) switch to the M-x shell-command with:
(setq shell-command-switch "-ic")
Side Note, not Emacs related:
On some operating systems users would need to add the line source ~/.bashrc to ~/.bash_profile (or similar), since ~/.bashrc is not always auto-read by a system.