Switching from XEmacs to Emacs

My first editor in the *nix world was Emacs. When I started university, some friend showed me how to get started. I have never really become a power user with it, but it is the tool I use for random small editing tasks. At some point in time when I started using Linux on desktop more often I put some effort into making Emacs work well with my habits, and in the process I actually settled on XEmacs. At the time I believe it was more advanced than Emacs, more defaults worked out of the box, and the GUI actually had a button for copying text. This was important since I could never remember how to do that from the keyboard (I could only remember how to cut).

It is now 2009, and I think Emacs has long since eclipsed XEmacs in features etc. At least on Ubuntu, Emacs also comes with the important copy toolbar button ;). Besides, when I log in to remote systems they will almost certainly have Emacs but not XEmacs, meaning I can’t just upload my XEmacs customizations file and expect things to work. So I decided to see if I could make Emacs work at least as well as my XEmacs does.

Most of the settings were trivial; just copy to .emacs. Keyboard customization uses slightly different syntax in Emacs, but it was an easy conversion. The problematic things were font size and clipboard functionality. I wanted a bigger font size, and the best solution I found was to set the font face height explicitly (actual value will depend on your resolution and your likes), but the following gives me a nice 80×63 Emacs window that will use half horizontal and 100% vertical space:

;; With my resolution, dpi and fonts this let's me display 80x63 geometry
(set-face-attribute 'default nil :height 100)

The XEmacs clipboard worked out of the box with my X and Gnome settings, but Emacs needed some tweaks:

;; Make copy and paste work with other applications
(global-set-key [\C-z] 'undo)
(global-set-key [\C-x] 'clipboard-kill-region)
(global-set-key [\C-c] 'clipboard-kill-ring-save)
(global-set-key [\C-v] 'clipboard-yank)
(setq x-select-enable-primary nil) ; stops killing/yanking interacting with primary X11 selection 
(setq x-select-enable-clipboard t) ; makes killing/yanking interact with clipboard X11 selection

Incidentally, with those settings I have no problems with copying and pasting text since the key combinations are the same as in any other program I use. So I could even take out the toolbar, since I only needed it for copying.

Since I do most of my programming in Eclipse, I also wanted matching comment/uncomment region settings:

;; Comment/uncomment reqion similar to Eclipse: C-/ and C-? (control shift /)
(global-set-key [(control /)] 'comment-region)
(global-set-key [(control \?)] 'uncomment-region)

Probably my nicest customization (although not written by me) is to be able to cycle between buffers with Ctrl-tab and Ctrl-Shift-tab. They are kind of long, so see the links below.

I think I found the answers to most of my problems on EmacsWiki.

I have always found other people’s (X)Emacs customization files fascinating reads, so if you are like me, here you go: .emacs and .xemacs/custom.el.

Update: As was pointed out in the comments, binding C-x etc. breaks havoc with many Emacs bindings. However, I did this only after I was unable to get CUA mode to work properly (namely, copy and paste did not work between Emacs and other applications). But I gave it one more try, and it seems like adding these things to .emacs does indeed make copy and paste work like I want:

(cua-mode t)
(transient-mark-mode 1) ;; No region when it is not highlighted
(setq cua-keep-region-after-copy t) ;; Standard Windows behaviour

Of course, remove the lines that bound C-z, C-x, C-c and C-v (since CUA mode does that).

Similar Posts:

    None Found


  1. deong:

    For the love of all that is holy, don’t just indiscriminately rebind C-x and C-c. I’m not even sure how you’re able to do simple stuff like saving a file or exiting emacs anymore, unless you’re relying on always having a toolbar or remembering to type ‘M-x save-buffer’ or something.

    What you seem to want is built into Emacs under the name “CUA Mode”, CUA being Microsoft’s name for their set of keyboard shortcuts. It does the same thing as most of your customizations, except for the minor difference that it leaves Emacs in a state that actually works.

    Just put (cua-mode 1) in your .emacs and be done with it. Type “C-x fcua-mode” to read the documentation. Of course, since you’ve globally rebound C-x, you won’t be able to read the documentation that way, so be sure to get rid of your customizations first.

  2. deong:

    Oops, markdown ate my notation…

    The command to see the documentation is “C-x f ENTER cua-mode ENTER”

  3. Heikki Toivonen:

    I tried CUA mode first, but it wouldn’t work properly with other applications. If I copied text in Emacs with CUA mode, it would not paste into other applications.

    Also, I am able to open files and quit, for example, and given that I don’t use Emacs that much I haven’t really run into limitations yet.

    But yes, if I could get CUA mode to work properly, I would rather use it than my own explicit key bindings.

  4. nisha:

    Is there a way in xemacs to change the default frame colors? I am new to xemacs and having problems is setting up the default background and foreground colors of a frame.

  5. Heikki Toivonen:

    @nisha: Did you try http://burtleburtle.net/justine/Tech/xcolors.html

    You can probably set the X properties for xemacs too.