Xah Emacs Blog

Buy Xah Emacs Tutorial. Master emacs benefits for life.

Tips & Tricks for emacs and emacs lisp.

A new version is out. Buy Xah Emacs Tutorial. Thanks.

Emacs Lisp: How to Write Comment/Uncomment Command in Major Mode (new)

Emacs's Menu Usability Problem (repost)

what features would you want for a keyboard

Reddit question: https://www.reddit.com/r/emacs/comments/3igjwa/what_features_would_you_want_for_a_keyboard/

See also:

Emacs: Graphical User Interface vs Terminal (someone asked on reddit)

Emacs: Unicode Tutorial (minor update)

emacs 24.5 is out. Where to Download Emacs for {Windows, Mac, Linux}

it's out in April. Somehow i missed it.

on linux, you should build it yourself. 〔➤ How to Build Emacs on Linux

xah fly keys Mode. Major update. Now you can load it without errors. No dependencies. I'll be polishin it more in coming days.

Emacs Lisp: Run Current File (now supports Java, and Clojure, TeX/LaTeX.)

Emacs: Copy/Cut All or Selection (new)

How to Edit Lisp Code with Emacs

Essential knowledge if you ever code emacs lisp.

emacs: should you use evil-mode?

here's my recommendation.

if you want efficient keyset, there are 3 choices. evil-mode, ergoemacs-mode, xah-fly-keys.

if you don't like modal keys, then ergoemacs-mode is the best. It also supports standard keys for open close new copy cut paste undo etc, like any other software. Install and use right away, no need to learn. Also, extremely efficient keys. Keys are based on statistics of command call, mapped to score of key position, and using Alt+key instead of Control for fundamental cursor commands or delete operations.

use evil-mode if you are also a vi user, or plan to use vi too in the future. Modal keys is more efficient than Control/Alt. This also has large user base.

if you want the utmost efficiency, use xah-fly-keys. It's modal like vi, but without any vi baggage or compatibility. Key choice based on statistics of command call. Most keys are same as ergoemacs but modal. You'll need to learn everything fresh.

When in xah-fly-keys, you NEVER need to press Control+x. Everything C-x is a sequence of 2 to 3 single keys. Meta key is never used neither. You can still use all gnu emacs keys because xah-fly-keys doesn't use any of emacs keys.

from question on g+ about whether one should use evil. https://plus.google.com/107417407213709101682/posts/JKuXLk83aN6

About keybinding, each point above i have detailed article about it. About 2 hundred articles on every aspect of keybinding and keyboard too. You can find them at the following indexes.

Emacs Lisp: Run Current File (minor update)

Emacs Autotetris Mode

elisp program that play emacs tetris-mode by itself.

See the package here: https://github.com/skeeto/autotetris-mode

See explanation here: http://nullprogram.com/blog/2014/10/19/

Chris Wellons is a expert emacs lisp programer. He wrote quite a few non-trivial emacs software.

non-trivial here means, takes several months to do, involving not just emacs lisp knowledge, but algorithms and protocols and languages outside of emacs. In contrast, a typical language major mode takes 1 day to a week.

Some of the notable include:

Wellons is also a professional Java developer. So, if you work with Java, i'd recommend looking into his emacs config.

Wellons has mentioned in sacha's emacs talk 〔http://sachachua.com/blog/2014/05/emacs-chat-christopher-wellons/〕 that he has read the emacs lisp manual cover-to-cover several times. (info "(elisp) index") (yours truly, haven't done so even once.)

Wellons's got quite a lot interesting things in his blog. Of all emacs blogs out there, if you want me to name just 1, i can only think of Chris Wellons.

in emacs, call display-time-world.

Emacs Lisp: Run Elisp Script in Shell (repost)

i do this every day for the past 6 years, text processing 5k html files.

#Emacs «how» ‘to’ 「type」 ‹curly› “quotes”, 〔and〕 【ALWAYS】 (insert) [Brackets] {by} 《Pair》 Emacs Lisp: Insert Brackets by Pair

Emacs Lisp: Cycle Replace Space Hyphen Underscore (updated code)

Clojure Instaparse Parser Tutorial

Emacs: subword-mode, superword-mode, camelCase, snake_case (minor update. repost)

Emacs Lisp: Make Backup of Current File (updated code. Now, if in dired, it'll backup current file or all marked files.)

thanks to reddit discussion, more keyboard added to

List of Keyboards with Topre Switch

reddit link at bottom.

Find File Location of a Feature Name

in emacs, if you know a feature name, you can locate the file by calling find-library

For example, call describe-variable then type “features”. Then pick any of the item. Then, call find-library, type that item. Emacs will jump to the file where the feature is defined.

〔➤ What's Emacs Lisp feature?

I usually do describe-function, then jump to the file location. But, find-library is more direct, and useful. Because sometimes you only know the feature name, not the command to invoke it.

got the tip from https://twitter.com/_wilfredh

List of Keyboards with Topre Switches (on its own page) This is the famous switch used in Happy Hacking Keyboard.

xah fly keys Mode

is now a minor mode.

if you have question using it, just ask me. Best way is just to post a comment on the page or on the github page. You can also ask me on twitter or g+. Email's ok too but sometimes got eaten by spam filter.

currently it's suitable for those who love to tweak emacs keys.

i've seen pretty much all emacs keybinding systems out there. Especially in the past few years with lots packages. Including, evil, hydra, god-mode, etc. They are, scientifically, less efficient. But, better than GNU emacs default.

if you want something quality that works out of the box with lots users, then i recommend:

the ergoemacs-mode is Alt+key based. Evil is vi based.

Emacs Conference 2015, San Francisco

There's a emacs conference, (a Saturday) in San Francisco, CA, USA.


register or plan at the above site.

i learned about it from the following emacs hangout.

2015-08-13 Emacs Hangout European Edition

sachachua leads the emacs hangout. Check out schedule and news at her site at http://sachachua.com/blog/tag/emacs-hangout/

emacs lisp programer for hire

if you have a emacs project, such as writing a mode for your company, i'm available. I charge $50/hour.

For basic mode, 1 hour would do.

Please contact me at 〔xahlee@gmail.com〕. (twitter ping me if i didn't respond. Sometimes new email are filtered by spam)

Emacs highlight current line

How to Set Emacs's User Interface to Modern Conventions (added a screenshot for global-hl-line-mode)

Emacs Lisp: Delete Current File (update from yesterday's code. Now it won't ask to save if buffer is modified)

Mac OS X: How to Create Keyboard Layout and Keybinding ⌨ (repost)

Mac OS X supports basics emacs keys. But you can add more.

Emacs and Microsoft Windows Tips


Emacs Lisp: Delete Current File.

A new version of the command. The new one doesn't make backup, but simply copy file content to emacs's clipboard first.

fun emacs lisp: emulate real typing

(defun insert-typewriter (str)
  "Insert STR into the current buffer as if you were typing it by hand.

Modified from
URL `https://gist.github.com/howardabrams/b5dc2082bcce46fdc9b8'
  (interactive "s")
   (lambda (char)
     (insert char)
     (sit-for (/ 1.0 (1+ (random 100)))))

;; test
(insert-typewriter "something, paste for example source code here.
Be sure to escape double quotes.")

via https://twitter.com/howardabrams

scifi author Tony Ballantyne on emacs

scifi author Tony Ballantyne (Recursion (novel) etc.), wrote a article on using emacs. See:

My Emacs Writing Setup By Tony Ballantyne. @ http://www.tonyballantyne.com/EmacsWritingTips.html

eshell now has doc

in emacs 24.4.1, there's finally documentation for eshell. Call info, then just go to the eshell point.

you can also read it online at GNU site at http://www.gnu.org/software/emacs/manual/html_mono/eshell.html

Emacs Lisp: Copy File Path of Current Buffer (improved code)

try this. blind fold yourself. Use your favorite language, favorite editor, write “hello world”, and run it.

did you succeed?

if so, it means, you can blind type, super fluent with your editor and without using mouse, familiar with your language.

comment at https://plus.google.com/113859563190964307534/posts/3SfNXQ6oc7D

Banish Key Chords. (repost. Whence Key Chord Came From? Is emacs keys or vi keys more efficient?)

Emacs: magit-mode Tutorial (minor update)

printed org-mode manual

there's a printed org-mode manual, published by GNU.

emacs org mode manual cover

Emacs: Manage Split Windows (repost)

emacs major version of magit is out. To upgrade, call list-packages, press U x.

Emacs: Convert Straight/Curly Quotes (updated code. fixed a out-of-range bug.)

Emacs: How to Sort by Time, Size, in Dired? new command.

added a manifesto at Xah Emacs Tutorial

Emacs Lisp: Word to Wikipedia HTML Link

Emacs Lisp: Make HTML Ruby Annotation (on its own page)

gnu emacs lisp reference manual emacs 24.5 2015-07
GNU emacs lisp reference manual, for emacs 24.5. 〔photo By Jules L White〕 amazon

There's a new hard-printed edition of GNU emacs lisp reference manual, for emacs 24.5. amazon

The elisp manual is also online at https://www.gnu.org/software/emacs/manual/elisp.html

I have a copy with different CSS at (info "(elisp) index")

see also Which Chapters of Elisp Manual to Read?

if you want to learn practical emacs lisp, as fast as possible, i recommend you give my tutorial a shot. Practical Emacs Lisp

new version. Emacs Package: xah-find.el grep/sed in Pure Emacs Lisp. Now, prompt for path regex defaults to your current buffer file's extension, if any.

Emacs Lisp: Batch Convert Line Ending in Dired (updated code)

Microsoft Universal Foldable Keyboard is now available. For your phone or tablet.

Logitech G910 Keyboard. New key switch: romer-g.

Programer Repetitive Strain Injury

every month, i see stories of programer Repetitive Strain Injury.

Here's another one i ran into today.

My Experience with Repetitive Strain Injury (RSI) By Yi Tang. @ http://blog.yitang.uk/2015/07/19/repetitive-strain-injury/

Those, who carelessly advocates GNU emacs keys, or swapping Capslock and Control, should be … well, kicked, hard. They don't know what they are talking about. Most of them don't touch type. And, they don't type that much.

This is not a matter of funny trolling. It is a bunch of vocal people spreading harm in society.

over the past 5 years, things got tremendously better. There are now quite a few alternative emacs keybinding systems than the GNU Eamcs default, and quite a lot people using them, and it is no longer being ridiculed upon (⁖ hydra, god mode, key-chord-mode, evil-mode, spacemacs, ergoemacs-mode). Meanwhile, many ergonomic keyboards coming out, with mechanical keys too. 〔➤ Best Keyboard for Emacs

Still, there are still people, who chants GNU Emacs keybinding and or Swap capslock/Control, as a mantra.

Emacs's Customization Tutorial (minor update)

Emacs Lisp: Make Backup of Current File (minor update)

i watched Sacha's emacs hangout today. I hope to join in in the future. See: http://sachachua.com/blog/2015/07/july-2015-emacs-hangout/

emacs lisp REPL, associate it with buffer

Today's hidden Emacs gem: pressing C-c C-b in an ielm buffer lets you associate it with a buffer, so you can inspect buffer-local variables.

from Wilfred Hughes, https://twitter.com/@_wilfredh

via jcs @ http://irreal.org/blog/?p=4222

emacs lisp command to HTML markup ruby

Emacs Lisp: Make HTML Ruby Annotation

been busy with javascript in past weeks… to learn JavaScript, please subscribe to my web dev blog Xah's Web Dev Blog

Keyboardio will be in San Francisco, Monday, July 13, 2015 from 7:00 PM to 10:00 PM (PDT). If you want to try the keyboard, go there. Might need to register first, do now. https://www.eventbrite.com/e/meet-the-keyboardio-model-01-san-francisco-tickets-17316336629

thanks to https://twitter.com/EmmanuelOga for headup.

Emacs: Run Shell in Emacs (major update)

Emacs: What's the difference between {shell, term, ansi-term, eshell}? (minor update)

Emacs: Command to Open Menu (on its own page)

Atom.io editor, JavaScript ES6, Xah JavaScript Tutorial

JavaScript libraries now outnumber any language's libraries.

Guthub's Atom.io editor is completely written in JavaScript. Part of it is released as “electron” framework, which allows writing desktop apps using {JavaScript, HTML, CSS}.

It's quite amazing. Atom.io, is essentially running in a web browser as app. All the GUI, is the browser in disguise. The components are node.js and Chrome (Google's open sourced part of Google Chrome browser). (node.js or its new fork node.io lets you run JavaScript as a language engine without browser, much the same way you run python, perl, ruby, etc. node.js is based on Google's V8 JavaScript engine (which is used by Google Chrome)).

ECMAScript 2015 Language Specification – ECMA-262 6th Edition is released last month, 5 years after the previous ECMAScript Language Specification - ECMA-262 Edition 5.1

I've been continuously working on my JavaScript Tutorial for more than a year now.

it's more complete and more accurate than my Emacs Lisp tutorial

There are Microsoft JavaScript tutorial, Mozilla's JavaScript tutorial, and few books that are free online. The Microsoft one is not bad, the Mozilla's lousy, as it's a wiki, but the reference section is great and indispensible, as it covers the hundreds of DOM objects and methods. There are a few other JavaScript turorial online i can think of.

I intend my JavaScript to be the best on the web, and i think am doing reasonably well. In particular, my tutorial is:

  1. Syntax focused. (or, in jargons, it takes the perspective of formal language.) That is, it take the approach of “what you see is what you get”. (as opposed to talking about a computing model underneath the language.)
  2. Clarity in explaining the confusing part of JavaScript object system.
  3. Example based. Every explanation comes with a self-contained example you can run, so its practically useful and veritably correct in browser.
  4. Concrete. No use of jargons or concepts of spurious software engineering point-of-view, such as “patterns”, “anti-patterns”.
  5. For people who already know how to program. You don't have to wade-thru tens of pages to learn what is a variable, function, module, etc.
  6. Concise. No story-telling style. Every word counts.

Give it a shot, and let me know what you think.

Xah JavaScript Tutorial by Example

emacs bug: can't paste into emacs

there's this bug that started to happen about a year ago. Emacs 24, and 25.

  • GNU bug report logs - #16737
  • From: Sujith Manoharan
  • Subject: 24.3.50; Yank causes hang
  • Date: Thu, 13 Feb 2014 09:10:55 +0530

Pasting content selected in a browser causes Emacs to hang completely sometimes. This is not consistently reproducible, but it happens after a few hours of usage, sometimes days.

from http://debbugs.gnu.org/cgi/bugreport.cgi?bug=16737#17

This happens to me when i use xah-find-replace-text on few thousand files. 〔➤ Emacs Package: xah-find.el grep/sed in Pure Emacs Lisp

not always, but most of the time.

the number of files doesn't seem to matter. But what matters is likely the number of replacements.

there are 10 or so people wrote in that thread who also have the problem. But, a reproducible step is hard to get.

however, there's a reproduction steps described here

From: "Alan D. Salewski"
To: 16737 @ debbugs.gnu.org
Subject: Re: bug#16737: Timed out waiting for reply from selection owner
Date: Sun, 14 Jun 2015 23:00:34 -0400

The below cookbook works to reproduce the issue for me every time, so I
can now trigger the issue on-demand.

As noted in message #149 above[0], I'm running the
'emacs24-lucid-24.4+1-5' package on Debian GNU/Linux; x86_64; 4 core
Intel i7.

I'm running an X11 window manager (sawfish) with no clipboard manager.

To reproduce the issue:

    1. $ type -a emacs
       emacs is /usr/bin/emacs

       $ readlink -f /usr/bin/emacs

       $ emacs -Q

       The "*scratch*" buffer is visible.

    2. M-x server-start

    3. In a terminal window (xterm in my case):

       $ emacsclient -t

       The "*scratch*" buffer is visible here, as well.

    4. Select a sizable bit of text to the X11 clipboard. A small amount
       of text won't trigger the issue, but I don't yet know what the
       boundary is. For my testing, I have a browser window open to
       this web page in iceweasel (firefox), and use the 'C-a' hotkey in
       that app followed by 'C-c' to select the full page of text:


    5. In the emacsclient window in the terminal emulator, paste the
       text from the clipboard. I use the middle button on my 3-button
       mouse to do this.

    6. Back in iceweasel, select any small amount of text (~20 chars is
       fine) from the same page (again, using 'C-c').

    7. In the X11 emacs frame, position the mouse pointer over the
       blinking cursor and press the middle mouse button to attempt a
       "paste" operation (mouse-yank-primary).

       Emacs appears to hang for about 20 seconds, and then the "Timed
       out waiting for reply..." message appears.

The cookbook works not only with the stock Debian 'emacs24-lucid'
package, but also with that package compiled with different build time
options (-g, -O0, -DTRACE_SELECTION). The cookbook also works when I
build with random other debugging code compiled in (all based on the
Debian source package emacs24-24.4+1). It does not seem to be sensitive
to being set up "just right".

A slight variation of the above cookbook works with the stock 'emacs24'
Debian package (same version as the '*-lucid' package above), which is
the variation compiled to use gtk. For this version, the small amount of
text selected in step 6 above does not seem to trigger the issue, but
pasting the full amount of text from the web page does. So the cookbook
variation here is to simply skip step 6 (or replace it with step 4, if
some other process has become the X11 selction "owner"). When running
this version, the paste into the X11 emacs frame is preceeded by a pause
and CPU spiking to 100%, the same as indicated by other reports.

Once the issue has been triggered, no further "paste" operations will
work in any emacs X11 frame that is part of the same emacs process, at
least not without using gdb to jump over these lines in
x_get_foreign_selection (xselect.c):

1241    if (NILP (XCAR (reading_selection_reply)))
1242      error ("Timed out waiting for reply from selection owner");

Once those are jumped, the "paste" operation completes (the text shows
up on the buffer, as desired), but the state is still hosed.

Pasting into 'emacsclient -t' buffers running in terminal emulator
windows (xterm) does continue to work, though. So if somebody is truly
desperate to keep a given emacs process alive, keeping a terminal-based
emacsclient window handy as a target for paste operations could serve as
a workaround once the issue has been triggered.


[0] message #149

Emacs, Atom, JavaScript

Atom 1.0 released. Syntax Coloring in Editors. Added Atom screenshot.

I'll be looking into Atom a lot.

Emacs Lisp: with-syntax-table Leaking Bug

Emacs vs Vim Tip jar (on its own page)

make the Menu/App Key as leader key. Emacs: How to Define Menu/App Key (much expanded. On its own page.)

emacs lisp manual is updated to for emacs 24.5. (info "(elisp) index")

Emacs Lisp: How to Name Your Major Mode (major update)

What's Emacs Lisp feature? (on its own page)

Syntax Coloring in Editors added Microsoft Visual Studio, Slime Text.

Should emacs be different? Alternate Title: New vs. Old: the interface issue that just won't go away

controversy. See: 〔《Should emacs be different? Alternate Title: New vs. Old: the interface issue that just won't go away》 @ http://www.reddit.com/r/emacs/comments/2yp9v7/should_emacs_be_ifferent/

my opinion posted there.

decades old issue. Note:

* there are just as many, who used emacs for 2 decades, believe that emacs default keys are the worst. You can see some of it in ergoemacs comments, some of which i've collected.

* you don't hear these people much because, such opinion are not inline with the emacs community, are raely propagated.

* i think emacs should turn on cua mode by default. More urgent than ever. Tons of new editors are still cropping up every year, and seems more so in recent years. Atom, Facebook's Atom derivative, and even Microsoft Code.

* In the past 5 years, in emacs 23 and 24, some controversial UI issues have been fought hard, and decision made towards modernization. For example, visual line arrow key movement. transient-mark-mode.

* emacs default keys are scientifically Repetitive Strain Injury inducing.

* emacs default keys, are not just bad for newbies, but are scientifically, technically, inefficient for expert emacs users.

* The ~7 de facto standard keys for copy cut paste undo open new save... if emacs adopts them, then, the keys would be technically, scientifically, more efficient, for long time emacs users, not just for newbies.

* I personally believe, emacs should adopt the ~7 de facto standard keys. because: 1, it will increase emacs users by i estimate at least 2 fold within one year. 2, it will make emacs keys more efficient for long time emacs users.

i have over a hundred articles on keybinding issues. The point mentioned above, especially about keys, i have scientific data to backup. If anyone is interested, ask me. It's all on my site, by the way.

I love emacs. Emacs the system, i think is still unbeatable in many ways. But its keys, i think is scientifically one of the worst, and as well the number one problem for new users to swallow. There are lots packages that provides alternative, but vast majority of emacs users (i believe more than 60%), are not those we see in online blogs or forums, and don't even know how to use packages. It needs to be the default.

for what's worth, that's my opinion. Thanks.

Syntax Coloring in Editors (major update. Commercial editor results added.)

keyboard key 2 vs b
keyboard key 2 vs b

result from yesterday's vote @ https://plus.google.com/113859563190964307534/posts/6xd4Xb71y5E

thanks to all who voted.

which key is easier to press, 2 or b?

vote here. https://plus.google.com/113859563190964307534/posts/6xd4Xb71y5E

Emacs: Run Interactive Clojure Shell/REPL in Emacs: CIDER if you are starting with Clojure, check it out.

Emacs Keybinding Syntax Examples (minor update)

List of Emacs Starter Kits (minor update)

emacs 24.1 variable: switch-to-visible-buffer

switch-to-visible-buffer → If non-nil, allow switching to an already visible buffer.

This variable was introduced, or its default value was changed, in version 24.1 of Emacs.

Keyboard: What's the Most Efficient Layout for Numbers?

Best Keyboard for Emacs (minor update; repost)

finally, we have a keyboard with a any key

keyboard.io model 01 right-side closeup
Keyboard.io Keyboard Model 01 ⌨

Emacs Lisp: HTML image-link Command (major rewrite)

Normal PC Keyboard with Many Thumb Keys

japanese keyboard
“Japanese USB wired PC keyboard” amazon

if you want a normal PC keyboard but with lots thumb keys for emacs hyper super, get this one.

for more, with mechanical keys, see: Should You Type Space After Comma? and Tiny Space Bar on Japanese Keyboards

Once you get such a keyboard, you can remap the thumb keys. For how to, see Keyboard Layout, Shortcuts Tutorial ⌨

this would beat many keyboard hacks that makes space bar do multiple things or quick key combos like df as leader key.

Emacs Lisp: Open File in External App (minor update code)

Emacs: New Empty Buffer (minor update)

Emacs: Xah CSS Mode, is ready for public use.

Major feature is keyword completion, and coloring of all keyword, not by form. (so, if there's a typo (invalid CSS), you'll know because it won't be colored.) See the link above for screenshot and more features.

Please give it a shot. I'm looking for comment and suggestions. I'll be submitting to MELPA. Thanks.

Emacs: Find & Replace Multiple Files by Function: Add Unicode Name in HTML (minor update, repost)

Emacs Lisp: Convert Color Formats: RGB, HSL, HSV (major updated code.)

Emacs: Working with CSS Color Values (minor update. repost)

Emacs: Copy/Cut Current Line If No Selection (fixed a issue when cut all also includes previous kill)

Emacs: narrow-to-defun, eval-defun, bug

Emacs: Abbrev and Templates for Emacs Lisp Mode

very old package. updated.

Practical Emacs Lisp (index re-organized)

New version of emacs tutorial is sent to previous buyers. If you didn't receive the update, please email me at xah@xahlee.org . Thanks.

A new version of emacs tutorial is out. Buy Xah Emacs Tutorial

Buy, blog. Thank you.

Emacs's M-key Notation vs Alt+key Notation (7 years old article. Repost. Minor update)

Emacs Lisp: Multi-Pair String Replacement with Report (updated)

Xah Emacs Packages

in past weeks, i polished several of my packages and submitted them to MELPA. Check them out in above link. In emacs, just call list-packages, then search for “xah”. 〔➤ Emacs: How to Install Packages Using ELPA, MELPA, Marmalade

I also like to thank Steve Purcell, who is currently maintaining MELPA. It's huge amount of work. I noticed, everyday, he actually tests incoming packages to check on quality. That's several per day, like full-time job.

Steve Purcell also wrote many emacs packages. You can follow him at:

Like it? Buy Xah Emacs Tutorial.