paredit keybindings with GUI vs terminal emacs - emacs

I'm struggling with this odd behaviour; paredit's commands of interest, namely paredit-forward-slurp-sexp, bound to C-), and paredit-forward-barf-sexp, bound to C-}, as well as their "backwards" counterparts, work in a GUI emacs, but don't work in terminal one. The functions themselves do work, but not their keybindings. From running C-h f:
paredit-forward-slurp-sexp is an interactive compiled Lisp function in
‘paredit.el’.
It is bound to <C-right>, C-).
not sure what's wrong, but it sure doesn't appear to be bound to those. All the other common keybindings seem to be working as promised, but not these ones. Don't even know where to start exploring.

thanks to the comment above, the problem was indeed the terminal-to-emacs transmission of keypresses; replacing native Mac Terminal with ITerm2 solved it.

Related

emacs + konsole: key binding problems [duplicate]

In org-mode, pressing M-S-RET (meta-shift-return) will create a new TODO on a new line. This key sequence sends M-RET to emacs through my terminal. I've checked this with C-h c ESC-S-RET, which returns M-RET is undefined in the mini-buffer.
I'm using Snow Leopard with Emacs 23.2.1 running in Terminal.app. There is no option to define a RET sequence in the terminal keyboard preferences.
Any idea what's causing the missing SHIFT? Workarounds?
You can get Emacs to pretend that it got S-RET with C-x # S RET (note uppercase S).
This also works for adding control, meta, alt, hyper or super modifiers; type C-x # C-h for the list of bindings. The Modifier Keys section in the Emacs manual mentions this as well.
In general, lots of keystrokes are simply impossible to send via a terminal, since terminals emulate an old protocol that only allowed 256 separate keys (or maybe only 128).
Chances are, when you press S-RET, Terminal.app does exactly the same thing as if you'd pressed RET. Thus Emacs has no way to distinguish those two cases.
Cross-linking to other Q&As:
If you are using an xterm, then the modifyOtherKeys option may facilitate that binding. See the following for details:
Send "C-(" to Emacs in VT100/xterm terminal (Mac OS X's Terminal)?
I suspect Emacs recognises those codes by default, but if not then also see input-decode-map as described here: Binding M-<up> / M-<down> in Emacs 23.1.1
See explanation and alternative shortcuts for TTY here.
Some of these have worked for me in a terminal in Ubuntu Linux (both locally and over SSH), but not all of them seem to work. For example, the alternative provided for S-RET (which I expected to run org-table-copy-down) instead seems to run org-clone-subtree-with-time-shift for some reason. However, I have found the list of alternatives useful, particularly those with the M- prefix. For example ESC UP for M-UP to move text around in tables.

Some shortcuts don't work on emacs beginning with C-c

In Haskell-mode, the shortcut C-c C-= is defined to do something.
Trying this shortcut, I realized that emacs do not recognize the shortcut C-c C-=.
Indeed, when I try the shortcut on emacs, the buffer write C-c = is not defined although I pressed C- C-=. I have the same problem with some other symbols like '.' or '§'. But shortcuts like C-c C-l or C-c C-c work.
I try to remove my .emacs but I have the same problem.
a friend have the same problem as me.
Both we are on ArchLinux (64 bits) and we use emacs in console. The keyboard is an azerty.
The problem come from emacs ? Arch Linux ?
Your terminal can't send Emacs C-= so you can't use that key sequence. (Emacs would recognise it if it received it, but that won't happen.)
Your options are:
Run GUI Emacs.
Use M-x name-of-command RET (for whatever command is bound to the key sequence you're not able to use). Use C-hm to see the major mode's bindings, or C-hb to see all current bindings, in order to learn what those command names are.
Create new custom keybindings for the commands in question (i.e. bindings which your terminal can send to Emacs).
Find a different terminal emulator with enhanced key sequence abilities. The vast majority of them will be no better than what you have, because they're all adhering to the limitations of the terminals they're emulating. The most capable one I know of is http://invisible-island.net/xterm/xterm.html but you may need to compile it yourself, and then expect to spend lots of time configuring it. (It's not a trivial solution, though, and xterm requires a GUI environment, so running GUI Emacs is much simpler.)
Use C-x#c<key> instead of C-<key>.
With that last option, you can use a sequence your terminal can send to fake a sequence that it can't send.
C-cC-= would become C-cC-x#c=
If you really wanted to use that last option, you can set a custom binding to simplify the sequence (may be necessary in some instances to avoid conflicting with existing sequences). See the end of https://stackoverflow.com/a/24804434/324105 for more information.
To add to phils' post - another option is an Emacs package (which I wrote), which can teach Emacs and terminals how to properly recognize all PC keyboard keys and modifier key combinations:
https://github.com/CyberShadow/term-keys
The default configuration already includes encoding key combinations like Ctrl=, as well as similar variations.

Emacs key bindings change in terminal emulator

I notice that some Emacs key bindings change in terminal emulator (xfce4-terminal).
For example: M-SPC under TTY sets the mark, but in xfce4-terminal it does nothing.
Also:
C-- is undo in TTY and does nothing in terminal emulator
C-/ is erase char backward in TTY, and undo in terminal emulator
Is there any solution to prevent the burden of learning two rules? I just want them as usual in TTY console.
It's not an Emacs problem so much as a terminal problem. Terminal emulators can be limited in the control and escape sequences they can send, so it's probably the case that the emulators you cited are swallowing your special characters before they even reach Emacs. Try hitting C-h l (or M-x view-lossage) to see if your key combinations are arriving in Emacs.
In addition to the answer that Legoscia cited, also check out this thread and this thread.
Unless you have a strong reason to stay in a terminal, you might consider running the GUI version and then running one of the various shells within it (eg, shell, eshell, ansi-term).

How to redefine Fortran comment character for Emacs?

I am coding in fortran90 on Emacs (no-windows mode) with fortran-mode. I have only used Emacs for Python for which it works without problem but now that I have switched to fortran90 I have many little issues that I don't know how to configure.
The biggest problem I have is with the commenting region command. I usually use M-; to comment regions but I get something like this:
c$$$ if (x1.eq.0) then
I know about the command
C-x r t
which actually does the trick (I can insert a ! at the beginning of each line) but I am so used to the M-; command and I wish I could keep using it. Also, with the latter command I can comment and un-comment the region.
So what I want to do is to replace the symbol for commenting in (and only in) fortran-mode. And such that it works every time I open/close Emacs with fortran-mode.
Thanks!
I haven't coded in Fortran for the last 30 years (!), and I'm not acquainted with Fortran mode in Emacs. But looking at library fortran.el I see that there are some user options for customizing comment behavior. Take a look at them by using M-x customize-group fortran-comment. The doc for each should be self-explanatory. If not, more info is available in the Emacs manual -- see node Fortran and its subnodes, in particular, node Fortran Comments. It specifically talks about M-; in the context of Fortran mode, for instance.

Emacs Prelude, Smartparens, and OsX

I'm using OSX 10.9, iTerm2, Emacs Prelude, and Clojure with all the modes that entails most relevantly, smartparens. Good so far.
The short version is: has anybody out there found a harmonious way to use all of this together with OSX Mission Control?
The longer version goes: I want to be able to use commands like sp-forward-slurp-sexp, which has a default keybinding of C-<right>, better known as the default OS-level shortcut for "switch Spaces right via Mission Control." I can re-map that fairly easily (say, to C-Shift-<right>) -- but now, I discover that C-<right> actually seems to be sending something like M-[1;4A. Instead of triggering sp-forward-slurp-sexp, you get sp-wrap-with-pair "[". Uhm.
I dug up this dissertation on re-mapping keys, which is very thorough, but also involves re-mapping rather a deal of stuff, then disabling the parts of paredit that are listening for the M-[ command. While this technically seems to work, I actually rather like having sp-wrap-with-pair enabled. Perhaps a better option would be to embrace the theoretically equivalent C-( -- except iTerm2 only interprets that as a literal 9, and C-) as 0. This SO post chews on this problem, and gets as far as a tantalizing comment suggesting that C-( and C-) simply be re-mapped to escape sequences that emacs can map back to C-( and C-) -- but frankly, I haven't a clue how to figure out what escape sequences those should be.
Bringing it all home: has anybody found a way to use all of these tools (Mission Control, iTerm2, Emacs Prelude, smartparens) together without having to re-wire or disable parts of some or most of them? Or: who has the most elegant re-wiring? Anybody figured out the C-)-to-escape-sequence-back-to-C-) trick yet?
Edit
Stabbing in the dark, I've done the following:
1. Set iTerm to send an escape sequence for the keyboard shortcut Ctrl-Shift-0 (C-S-)) of SPRTPRN.
2. Put this in my emacs config:
(define-key input-decode-map "\eSPRTPRN" [C-right-paren])
(global-set-key [C-right-paren] (kbd "C-)"))
...it does not work, but I've a hunch I'm getting closer. I think.
Edit, Again
I realized something: the notion that Shift doesn't work here doesn't make sense to me. At least on my emacs install, M-< and M-> jump to the beginning and end of a buffer, respectively -- and to use those commands, I have to actually press Meta-Shift-<. Huh.