I've been searching for an answer to this issue, I found
Emacs Client: difference between C-x k and C-x #
and
Emacs C-x C-c overriding save-buffers-kill-terminal if within last open frame
but it not exactly related. Here's the issue:
I have emacs started as a daemon and use emacsclient to connect to it.
I primary use emacsclient inside the OS X terminal with the -nw option.
The specfic command i use is:
/Applications/Emacs.app/Contents/MacOS/bin/emacsclient /tmp/foo -nw -c -s /tmp/emacs501/work_guigo
So I have two files in /tmp/, named foo and baa.
In my terminal.app, I open foo with
/Applications/Emacs.app/Contents/MacOS/bin/emacsclient /tmp/foo -nw -c -s /tmp/emacs501/work_guigo
Emacs tells me, "When done with a buffer, type C-x #", so I do that.
I'm done with it for now, but I'm not done with it for today, so I want the foo file to remain in my "C-x b" buffers list.
So I'm back in the terminal, I open baa with
/Applications/Emacs.app/Contents/MacOS/bin/emacsclient /tmp/baa -nw -c -s /tmp/emacs501/work_guigo
Now when I do a C-x b, I don't see foo in the list of open buffers.
This sucks. What should I do?
---some additional info:
emacs 24.5
using helm for "C-x b"
Sometimes, I find the answer to my own question.
In this case, it was a matter of having
(setq server-kill-new-buffers nil)
near the top of the init.el
Related
My environment:
OS: Linux CentOS 7 (x86_64)
PostgreSQL version: 10.5
Emacs 26.1
I use Emacs as the external editor in postgresql (set in my EDITOR environment variable). So whenever I type in psql shell, \e it opens Emacs where I can write/modify queries, views, functions, etc.
If I understand correctly, once Emacs is open, when I enter C-x C-s, that is, I save and then I quit C-x C-c, the content edited in Emacs is transferred to the query buffer to be parsed and executed (assuming it contains semicolon at the end). So basically each time I have to run \e then edit, then save and quit the editor to get the job done.
Now, given that I use Emacs for multiple programming languages, I've rather a big init file. As a result, it takes several seconds to start Emacs (both in -nw and GUI mode). Obviously this is quite annoying given the number of times that I have to open and quit the editor while I'm using \e in psql.
So my question is: Is there any way to let the external editor remain open and continue working with the same editor for further queries and somehow decide to transfer the result to query buffer without needing to quit the editor?
Run emacsclient instead of emacs. I have a script at ~/bin/editor:
#!/bin/sh
exec emacsclient -c -a '' "$#"
And then I set export EDITOR=$HOME/bin/editor in my ~/.bashrc.
The upshot is you only start Emacs once, and every time you run $EDITOR, it just attaches to the same Emacs session.
Also, I do
(global-set-key (kbd "C-x C-c") #'delete-frame)
(global-set-key (kbd "C-x C-S-c") #'save-buffers-kill-emacs)
so C-x C-c just deletes the frame instead of killing Emacs.
Just save the query to a temporary file, for example /tmp/q.sql and run \i /tmp/q.sql from psql multiple times from a second terminal.
This question already has an answer here:
Why does Ctrl+. not work when I bind it to a command in Emacs?
(1 answer)
Closed 9 years ago.
I recently installed jedi from el-get master branch.
jedi binds C-. for jedi:key-goto-definition but it's only working in X mode. It fails to bind when launched with -nw(no X) mode in both Emacs23 and Emacs24.
So, I tested simple binding in scratch buffer and then evaluated by C-x C-e.
(global-set-key (kbd "C-.") 'find-name-dired)
It worked well in X mode, but failed in no x mode(-nw).
Do you have any idea?
Thanks in advance,
Edited
Here are some results of C-h k C-. after installing above command:
$ emacs -nw -q (without X)
. runs the command self-insert-command, which is an interactive
built-in function in `C source code'.
It is bound to many ordinary text characters.
(self-insert-command N)
$ emacs -q (With X)
C-. runs the command find-name-dired, which is an interactive
autoloaded Lisp function in `find-dired.el'.
It is bound to C-..
(find-name-dired DIR PATTERN)
The terminal can't represent C-.. Find another key sequence and use ut, e.g. C-c ..
How can I have emacs start and be in the middle of a command input? Particularly, I want emacs to start in the middle of a command input find-file with a message in the small buffer saying:
Find file: ~/
and the cursor at the last character of it so that I can continue typing the remaining path to open the file I want.
You can execute one of the following commands on the command prompt or make a shell script containing it appropriately:
$ emacs -f find-file # if you want to start Emacs in the current direcoty
$ (cd ~; emacs -f find-file) # if you want to start Emacs in your home diretory
From the emacs(1) man page:
-f function, --funcall function
Excute the lisp function function
I have to admit that my lisp is a bit rusty, but this works for me. Drop it in your ~/.emacs file (or whatever init file you are using):
(add-hook 'emacs-startup-hook
(lambda ()
(if (= (length command-line-args) 1)
(call-interactively 'find-file))))
If you call emacs with no arguments, like this:
sawa#localhost:~$ emacs
It will invoke find-file for you. If, on the other hand, you invoke emacs with an argument, such as a filename, like this:
sawa#localhost:~$ emacs somefile.txt
It will default to just visiting somefile.txt
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).
I use Ubuntu8.10 and emacs-snapshot. Running shell-mode on emacs and input "ls" shows escape codes:
screenshot http://lh3.ggpht.com/_os_zrveP8Ns/SdMmohKNjmI/AAAAAAAADB4/VlKpr5H_7ZA/s512/screen.png
How can I get the output I expect?
You can use AnsiTerm which does support colors or you can enable AnsiColor for the normal shell:
(autoload 'ansi-color-for-comint-mode-on "ansi-color" nil t)
(add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)
Furthermore, you may choose another shell: M-x term or M-x eshell. The former provides an interface that is much closer to a real terminal emulator than shell-mode (once you start it, you can get out of the mode with C-c C-j and get in again with C-c C-k). The latter is a shell implementation written in Elisp (you can use the common shell commands as well as evaluating Lisp code).
Expanding on vatine's answer, you can add that inside your .cshrc (.tcshrc/.bashrc) wrapped with a check for the environment variable INSIDE_EMACS.
For example (from my .tcshrc):
if ( $?INSIDE_EMACS ) then
alias l 'ls --color=never'
endif
M-x ansi-color-for-comint-mode-on
The problem is that "l" is trying to colorise the output and emacs isn't having any of it. Try the following:
$ unalias l
$ alias l ls --color=never
I wrapped my alias ls ='ls --color=auto' in ~/.bashrc:
case "$TERM" in
xterm*|rxvt*)
if [ -x /usr/bin/dircolors ]; then
alias ls='ls --color=auto'
...
fi
;;
*)
;;
esac
This disables using color=auto in emacs.