How can I bind C-. in Emacs launched with -nw? [duplicate] - emacs

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 ..

Related

Set up emacs server so that it dies when the last frame is closed

I have run into issues using the emacs server started when I log in and emacsclient. Specifically, I use the same emacs server for different R projects things get ugly and commands from different projects end up going to the same R session.
My work around is to invoke a second server with /usr/bin/emacs --daemon=Rmd-1 when I log in. I have a bash script written such that the first .Rmd file I work with attaches to this daemon and then the command /usr/bin/emacs --daemon=Rmd-2 is issued. If I end up working with a second .Rmd file, then this server is used and a third server is started with /usr/bin/emacs --daemon=Rmd-3 and ready to work with another .Rmd file if needed.
This works pretty well except for one thing. Because after many years I am hard wired to end my emacs session using C-x C-c by the end of the day I have many emacs servers running. I'm looking for a way to trigger save-buffers-kill-emacs when the C-x C-c command is given in an emacsclient running on a daemon matching "Rmd-[0-9]+". I can't see any emacsclient options that would do that and I'm at a loss as to how to edit my custom.el file.
Can some one help me?
(note I'm running GNU Emacs 27.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.30) on Ubuntu 22.04)
Drawing on McNisse's suggestion, adding the following to my personal.el file seems to give me the desired behavior.
;; Remap C-c C-x if daemon name matches "Rmd-[0-9]+"
;;
(cond
((string-prefix-p "Rmd-" (daemonp))
(global-set-key (kbd "C-x C-c") 'save-buffers-kill-emacs)
)
)

Emacs: "C-x #" killing buffer

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

ansi-term won't find file under current directory? [duplicate]

This question already has answers here:
How can I have term.el (ansi-term) track directories if using anyhting other than bash
(2 answers)
Closed 8 years ago.
It's a very strange problem. I think it must caused my incorrect configuration of ansi-term, but i still can't find out where it is.
The issue is: when i in ansi-term and press M-x find-file, the prompt isn't current directory but the path i entered in my previous find file action. So when i change directory, it still display the same directory. So i have to enter the current directory every time. But it works very well in M-x shell and M-x eshell
Does the same thing happen when you start Emacs without your init file, i.e., emacs -Q? If so, that's the designed behavior or (especially if you use a development snapshot) perhaps an Emacs bug.
If not, then bisect your init file recursively to find out which part of it causes this behavior. To do that, use, e.g., command comment-region (see prefix arg in doc) to comment and uncomment a block of text. Comment out 1/2 of your init file, then 3/4, then 7/8,...,
each time testing whether the uncommented portion causes or removes the problematic behavior. You will very quickly identify what causes the behavior.
Because the path of emacs is different from that of term, it can only be changed by use the emacs command "cd".
So to solve this problem, I add the following code to my emacs configure file. The method is
find the pid of current term
find current working directory(cwd) of this pid.
I use multi-term, I think the method will be similar on ansi-term.
(defadvice term-send-input (after update-cwd)
(let* ((pid (process-id (get-buffer-process (current-buffer))))
(cwd (shell-command-to-string
(format "lsof -p %d -Fn | awk 'NR==2{print}' | sed \"s/n\\//\\//\" | tr -d '\n'" pid))))
(cd cwd)
(message (concat "change emacs path to: " cwd))))
(ad-activate 'term-send-input)
Then you can bound the key of term-send-input to <enter>. When you press <enter> in term, the emacs will change to the same path with the current path of term.
BTW, I use Mac Os. If you are on Linux, you can use the following code to find cwd.
(cwd (file-truename (format "/proc/%d/cwd" pid)))

I want to run the cygwin bash shell from native windows emacs app

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).

py-python-command ignored

I'm using python-mode 6.0.1 on OS X, emacs 23.3 (http://emacsformacosx.com/ version).
I'm trying to get C-c C-c to default to python 3.
I have the following in my .emacs:
(setq py-python-command "/usr/local/bin/python3")
And when I run C-h b py-python-command, it tells me the value is that (correctly).
However, running C-c C-c still opens 2.7.2.
I also tried adding:
(setq py-which-shell "/usr/local/bin/python3")
as suggested here: Both Python 2 and 3 in Emacs, but that doesn't change anything (py-which-shell does get changed, but it still launches 2.7.2).
Any ideas?
Try adding the following code to your Emacs init file:
(add-hook 'python-mode-hook
(lambda ()
(setq py-python-command "python3")
(setq py-default-interpreter "python3")))
py-default-interpreter for now is an alias only, delivered for backward compatibility
You might have encountered a bug.
Please file a report giving some example code at
https://bugs.launchpad.net/python-mode
Should the buffer code contain a shebang specifying pythonVERSION , than this takes precedence over default setting.
You may enforce executing buffer through specific pythonVERSION by calling
a command of class py-execute-buffer-pythonVERSION
See menu PyExec, entry Execute buffer ...