LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 06-23-2010, 02:11 PM   #1
Willard
LQ Newbie
 
Registered: Nov 2009
Posts: 17

Rep: Reputation: 0
emacs in a terminal : problems with ctrl


Greetings.

I am one of those weirdos that likes running emacs from a terminal. I always do this because I sometimes must (when editing remotely through SSH), so I won't have to switch between a graphical editor and a terminal editor.

Usually, things work just fine. However, problems arise when I must send a "control-something" (like "C-RET" and "C-,") command to my editor. In graphical mode, this works fine. In a terminal, it does not.

In the current terminal that I am using (gnome-terminal), typing "C-RET" will send "C-j" to my editor. Furthermore, typing "C-," will send "," to my editor.

A non-solution would be to "not use these commands". However, I am using some major emacs modes (proofgeneral/coq-mode and agda2-mode), which have keyboard shortcuts like this:

"C-c C-RET"

"C-c C-,"

These are very useful shortcuts, and I am crippled without them.

So far, I am getting around this issue by adding to my .emacs configuration file an entry which makes emacs behave as expected when emacs receives this incorrect command:

(global-set-key (kbd "C-c C-j") 'proof-goto-point)

I would, however, prefer not to have to do this for every major mode I use. Furthermore, if a mode happens to use "C-c C-j", then this re-set keybinding will override it.

My question is the following:

PROBLEM: How do I ensure that emacs correctly interprets a "C-X" command, where X is *any* character?

A noteworthy detail here is that when I run emacs in an xterm, typing "C-," will in fact send "C-," to emacs. However, typing "C-RET" will send "C-<return>" to emacs. So the problem seems to be how the terminal translates a CTRL-something to a key, and sends it to emacs. So one solution could be to

SOL.1: Make sure your terminal sends the right signals to emacs.

However, this may not be possible (I am not about to dig into the belly of a terminal implementation, or to implement my own terminal emulator). Alternatively, we could accept that a terminal sends CTRL-something incorrectly to emacs / emacs interprets CTRL-something incorrectly. Accepting this, the solution to this problem would be to

SOL.2: Make sure emacs interprets the incorrect signals correctly.

A third option, which is probably the easiest one, is to realize that this is too challenging, and

SOL.3: Make sure that emacs reacts correctly when seeing "C-<return>", when emacs is run in an xterm.

(this seems to be the only problem with running emacs in an xterm.)

I am writing this here because I do not know how to proceed with any of these solutions, and am hoping someone here does.

Kind regards,
Willard.
 
Old 06-23-2010, 05:22 PM   #2
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 167Reputation: 167
Typically this is related to your termcap, what terminal program are you using and what term are you telling the system that you're using? Do you have any additional keymaps?
 
Old 06-23-2010, 07:50 PM   #3
Willard
LQ Newbie
 
Registered: Nov 2009
Posts: 17

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by rweaver View Post
Typically this is related to your termcap, what terminal program are you using and what term are you telling the system that you're using?
I am (was) using gnome-terminal. I followed this guide to make any application running in my terminal aware that I am using a terminal that can display more than 8 colours.
Code:
willard@naglfar:~
> env | grep TERM
TERM=xterm-256color
XTERM_SHELL=/bin/bash
XTERM_LOCALE=en_US.utf8
XTERM_VERSION=XTerm(256)
COLORTERM=gnome-terminal
Quote:
Originally Posted by rweaver View Post
Do you have any additional keymaps?
I changed the way X treats "Caps Lock".
Code:
willard@naglfar:~
> cat .Xmodmap
remove lock = Caps_Lock
add control = Caps_Lock
I tried working more with xterm to have it understand all the CTRL-X I need, and realised that there is in fact no problem with "C-RET". However, "C-SPC" (control space) was a problem; emacs received "C-@". This seems to be the only issue with running emacs in an xterm.

Just in case this can cause problems, here are the configurations I made to xterm:
Code:
willard@naglfar:~
> cat .Xresources
xterm*foreground:      gray
xterm*background:      black
XTerm*metaSendsEscape: true
XTerm*font:            9x15
Xft.antialias:         1
Xft.hinting:           1
Xft.hintstyle:         hintfull
Xft.dpi:               96
The xterm*metaSendsEscape: true turned out to be important, for else emacs would interpret "M-x" (alt x) as "ø" (a random forum somewhere suggested that this was an issue with using the UTF8 locale as opposed to the ISO8859-1 locale).

In case it is relevant, here is my (ugly) .emacs file.
Code:
willard@naglfar:~
> cat .emacs
;; Set default character encoding to UTF-8.
(set-language-environment "UTF-8")
(set-input-mode (car (current-input-mode))
  (nth 1 (current-input-mode))
  0)
(setq locale-coding-system 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(set-selection-coding-system 'utf-8)
(prefer-coding-system 'utf-8)

;; Replace tabs with spaces, etc.
(setq-default tab-width 8)
(setq-default c-basic-offset 4)
(setq-default indent-tabs-mode nil)

;; Have emacs store temporary files in ~/.emacs-backup.
(defvar user-temporary-file-directory "~/.emacs-backup")
(make-directory user-temporary-file-directory t)
(setq backup-by-copying t)
(setq backup-directory-alist
      `(("." . ,user-temporary-file-directory)
        (,tramp-file-name-regexp nil)))
(setq auto-save-list-file-prefix
      (concat user-temporary-file-directory ".auto-saves-"))
(setq auto-save-file-name-transforms
      `((".*" ,user-temporary-file-directory t)))

;; remove toolbar in graphical emacs
(tool-bar-mode -1)

;; remove scrollbar in graphical emacs
(scroll-bar-mode -1)

(if (null window-system)
    (defvar config-is-graphical-window-system nil)
    (defvar config-is-graphical-window-system t))

(setq auto-mode-alist (cons '("\\.jr$" . java-mode) auto-mode-alist))

(autoload 'flyspell-mode "flyspell" "On-the-fly spelling checker." t)
(add-hook 'LaTeX-mode-hook 'flyspell-mode)

(autoload 'coq-mode "coq" "Major mode for editing Coq vernacular." t)
(autoload 'proofgeneral "proofgeneral" "Generic front-end for proof assistants." t)

;;(global-set-key (kbd "C-c C-j") 'proof-goto-point)
;;(global-set-key (kbd "C-c ,") 'agda2-goal-and-context-and-inferred)

;; proofgeneral customization
(custom-set-variables
  ;; custom-set-variables was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 '(agda2-include-dirs (quote ("." "/home/willard/Programs/Installed/lib-0.3/src"))))

;; abda setup
(load-file (let ((coding-system-for-read 'utf-8))
                (shell-command-to-string "agda-mode locate")))
Currently, I have switched from gnome-terminal to using xterm, and am doing alright so far. However, if I would be able to use gnome-terminal instead without trouble, I would be much happier. Any suggestions on how to do this are much appreciated.

Cheers,
Willard.
 
Old 06-25-2010, 01:31 PM   #4
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 167Reputation: 167
Try switching to TERM=linux in gnome-terminal and see if things work correctly (modify the other relevent bits).
 
Old 06-26-2010, 02:20 AM   #5
Willard
LQ Newbie
 
Registered: Nov 2009
Posts: 17

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by rweaver View Post
Try switching to TERM=linux in gnome-terminal and see if things work correctly (modify the other relevent bits).
Setting TERM=linux changed nothing; emacs in gnome-terminal will still interpret "C-c C-RET" as "C-c C-j", and similar badness for ".", ",", "SPC", and other characters.
 
Old 09-13-2011, 04:18 PM   #6
vmurali
LQ Newbie
 
Registered: Sep 2011
Posts: 1

Rep: Reputation: Disabled
I am in a similar boat (a vim user, forced to use emacs because of Proof General). I mostly ssh (using putty) to my workstation from a windows laptop, which doesn't run the entire X server stack. I was wondering if you found a solution to make gnome-terminal (and putty, which is more relevant for me) send the right keys? I read somewhere that C-j is "return" for emacs and so it seems to me that the terminals are simply omitting the Ctrl key.
 
  


Reply

Tags
ctrl, emacs, terminal


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
emacs+gnome-terminal+KDE+openSUSE - ctrl+arrow keys not working openSauce Linux - Software 4 04-03-2009 04:31 AM
emacs ctrl-m is RET. how to change ? Horos23 Linux - Software 1 11-12-2007 11:53 PM
Alt no longer META key when using in-terminal option of Emacs (emacs -nw) frznchckn Linux - Software 1 06-02-2007 02:41 AM
ctrl+c & ctrl+v equivalent for Gnome terminal window? halfpower Linux - General 2 11-29-2005 02:57 AM
no ctrl-a or ctrl-z in emacs or on command line? ashlock Fedora 5 12-30-2003 08:00 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:03 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration