Certain keybindings don't work when using emacs in a terminal - emacs

I load GNU emacs in it's own window by typing emacs in the terminal.
I like to use the keybindings from pc-selection-mode, which allows you to highlight characters using shift-right or shift-left, or entire lines by pressing shift-up or shift-down.
The problem is that when I run emacs in the terminal by typing emacs -nw, the latter 2 keybindings don't work. I can highlight characters using shift-left and shift-right, but pressing shift-up and shift-down doesn't do anything. The cursor stays where it is.
How do I fix this problem? Why is it even occurring? I'm using GNU Emacs 23.1.1, and I've confirmed that the same version is being used both when emacs is in it's own window and when emacs is running inside the terminal.
Thanks for any help

A lot of times the bindings just aren't listed, or are mapped wrong. You can try M-x show-lossage (or C-h l) to see if the escape sequences reach emacs or not. If they do, you might want to try xterm-extras -- it's always worked even as I migrate between different versions of linux and solaris, and as I ssh between them (which is often a source of problems).

Related

C-y doesn't yank in emacs under tmux

Update
What's happening is that whenever I kill some text, it gets added to the kill-ring followed by an extra "". Then C-y just inserts the "". So the question is where is the extra "" coming from?
Original Question
I'm running emacs under tmux, and I can't get C-y (or even M-x yank) to insert content from the kill-ring. I do see Mark set in the minibuffer, which is normal behavior for yank; I just don't see anything getting yanked. I also see that "" gets added to the kill-ring each time I hit C-y.
I know that C-y is getting received by emacs by looking at the output of M-x view-lossage, and I know that C-y is bound to yank by looking at the keybindings with C-h b. Moreover, running M-x yank directly gives the exact same results.
When I repeat the experiment outside of tmux, it works as expected. For what it's worth, if I repeat the experiment with screen instead of tmux, C-y works as expected.
Some more details are that within tmux, I have tried running emacs with TERM=xterm-256color and TERM=screen-256color with the same result. Setting xterm-keys on or xterm-keys off in tmux doesn't seem to matter either. I've been closing every tmux session between each permutation I try, to make sure that my .tmux.conf is getting re-processed (And I know it is because other changes in my .tmux.conf do have an effect.)
In fact, I can even comment out my entire .tmux.conf, with the same result.
Also, I've tried it in both iTerm2 and Terminal.app (I'm on a mac), again with the same result.
So, I feel like I am at a dead-end here. Any ideas on how to better debug this problem?
I finally tracked it down to some code I had copied into my emacs init.el to allow copy-and-paste from my OSX clipboard. If I remove that code from my init.el, C-y works fine under tmux. (The code is here -- it worked great until I decided to try out tmux!) I'm still not sure exactly what the problem is, but it's easy to believe that it would affect the behavior of C-y.

Use semicolon in global-set-key for function in .emacs

I am trying to set [Ctrl]-[;] as a keybinding in my .emacs like this
(global-set-key "\C-;" 'comment-or-uncomment-region)
however it doesn't work when I try (i don't get any error messages, it just has no effect). It will work though if i try a normal character (such as setting it to "\C-p").
I have also tried
(global-set-key (kbd "C-;") 'comment-or-uncomment-region)
but I don't like this option because for me it doesn't work when i run "emacs -nw". Any thoughts on how I can do this?
EDIT:
When I run C-hcC-; in emacs -nw I get the output:
; runs the command self-insert-command
which is exactly the same as when I run C-hc; in emacs -nw
So I believe phils is right, that it is a terminal problem, because emacs never actually sees C-;, it only sees ;
Indeed C-; is typically not something your terminal is able to send to an underlying application like Emacs (so it works under a GUI but not in a terminal). But I wonder: why do you need such a binding anyway, given that M-; is already bound to comment-dwim which does comment/uncomment the region when the region is selected, so it provides a superset of comment-or-uncomment-region.
Using (kbd "C-;") is absolutely fine and correct.
I suspect when you type C-; when running emacs -nw, your terminal is not actually sending anything to Emacs.
So your problem is more likely to be a question of how to get your terminal to send C-; to Emacs (or alternatively how to get Emacs to recognise the sequence which is sent).
If you run emacs -Q -nw and type C-hcC-;, do you get a "C-; is undefined" message?
Assuming that it is a terminal issue, here are some related Q&As which may point you in the right direction, but it's going to depend upon the particular terminal you are using.
Binding M-<up> / M-<down> in Emacs 23.1.1
Send "C-(" to Emacs in VT100/xterm terminal (Mac OS X's Terminal)?
How does one send S-RET to Emacs in a terminal?
emacs -nw issues with cscope and terminals

In Cygwin emacs C-c is read as C-g

I recently installed cygwin and emacs, and when I try to exit the program (by pressing C-x C-c) the minibuffer reads "C-x C-g is undefined". When I type C-c the minibuffer reads "Quit" just like if I had typed C-g. To the best of my knowledge, it's just reading the c key as a g in the minibuffer. However, if I type c into a scratch buffer it correctly displays c. Or if I type M-x c, it correctly reads as c in the minibuffer.
Is this a common problem? How do I fix this?
Thanks so much for any help! It's driving me crazy. Right now, I have to exit out of Cygwin when I want to quit emacs because C-x C-c won't close the program!
This is a problem with the default Cygwin console, but it doesn't happen with other Cygwin terminals such as mintty, rxvt, or xterm, so you might want to try one of those. Also, I believe the issue with the console is fixed in recent Cygwin snapshots.

Ctrl - Tab key binding doesn't work in Linux

I have set a key binding in Emacs using:
(global-set-key (kbd "<C-tab>") 'switch-view )
: It works in Windows but Emacs in Linux seems to ignore it. Any ideas why?
My version of Emacs is 23.2 running in text mode (.nw)
In text mode, Emacs depend upon the terminal or the console for keys combination. Terminals and consoles don't support as many keys combination as Xorg and windows do, and C-TAB is a combination that don't exist in text mode: TAB is already the same than C-i, and C-C-something don't exists.
The window manager you are using is most likely 'kidnapping' it.
On mine (which is KDE), C-tab cycles through applications on the current desktop. You can configure which keystrokes should be ignored though... but your best bet may be to map switch-view to another key sequence in your ~/.emacs file.

A few Emacs noob questions

Sorry if these are obvious answers but I've googled around and can't seem to find what I'm looking for.
When I have multiple files open in split screen mode using C-x C-3 how do I close JUST the window I'm currently in and no other?
I'm using Ruby and it doesn't seem to auto indent my def end correctly.. is there a Ruby plugin that will fix this?
Is there a command to go to a specific line?
How do I interpret ruby from within emacs?
1. When I have multiple files open in split screen mode using C-x C-3 how do I close JUST the window I'm currently in and no other?
To close current view C-x 0. (Btw, I think you're referring to C-x 3.)
2. I'm using Ruby and it doesn't seem to auto indent my def end correctly.. is there a Ruby plugin that will fix this?
Have a look at
ruby-mode for emacs
RubyMode
3. Is there a command to go to a specific line?
Sure, M-g g (or M-x goto-line)
4. How do I interpret ruby from within emacs?
Don't know. You could try rubydebug.
You can also see C-h b which will give you key binding for the current-buffer to give you a lot of additional things that you might need. Once you install any Ruby Mode, you can also use C-h m to see key binding for that specific modes in your current buffer, including ruby mode.
for Q3) in addition you might want to know
C-h w COMMAND
will always show you the key binding for a funcion
C-h w goto-line RET
goto-line is on M-g g, M-g M-g, <menu-bar> <edit> <goto> <go-to-line>
for Q4) you could start a shell in a buffer, either M-x eshell or M-x shell and the simply run your script there.
Using the eshell configuration in [1] you can easily switch between the shell and your script source (pressing C-z).
[1] http://www.emacswiki.org/alex/2008-08-19_Emacs_on_Windows