Xah Emacs Blog

Buy Xah Emacs Tutorial. Master emacs benefits for life.

Tips & Tricks for emacs and emacs lisp.

all you need to know about: Computer Keyboard Layouts & Keybinding Design & Analysis ⌨. major re-org.

a good basic intro to start emacs lisp. Write this and actually use it daily. Emacs Lisp: Find/Replace Multiple String Pairs

Wilfred Hughes has a article on many aspects of syntax coloring. See 〔The Definitive Guide To Syntax Highlighting By Wilfred Hughes. @ http://www.wilfred.me.uk/blog/2014/09/27/the-definitive-guide-to-syntax-highlighting/

Emacs Line Number Mode (on its own page)

Emacs: Uncolor/Unfontify Region or Buffer (on its own page)

Emacs: Auto Highlight Parenthesis: show-paren-mode (on its own page. Split off from How to Edit Lisp Code with Emacs)

Emacs Lisp: Insert Brackets by Pair. on its own page, and improved code so no need for my own external package. The page is separated from Emacs: Insert Parenthesis by Pair: electric-pair-mode.

re-organized the emacs lisp tutorial index page. Am shifting it into a proper book form, with coverage of each topics in logical order. Still lots to do. Thank you for reading.

Emacs Lisp: Regex Tutorial (on its own page)

Emacs: Text Pattern Matching (regex) tutorial (updated)

emacs kept struggling to gain followers.

the solution is real simple. Support the de facto standard keys for {Cut, Copy, Paste, Undo, Redo, Open, Close, New, Save}, by default out of the box. User will increase 10-fold in a couple of years, automatically.

but also, emacs keys will become more efficient.

the only real enemy to this is emacs hackers. Their reasons are typically inane, from “why should emacs be popular” to “emacs shouldn't be Notepad”. In one word, Cult.

There'll be nothing whatsoever emacs will lose by this change. In fact, it will become technically superior. And pave road for a set of more efficient keys.

this change, will be hard to pass rms, but it is not something he would absolutely refuse. Also, at least one of the current maintainer Stefan Monnier is very open to modernization changes as this.

currently, ideas like this will typically be met with scorn. But it can change. We need to voice more support for this.

if you have questions about this, I'd be happy to answer any questions.

how Model M keyboard sounds

IBM Model M keyboard buckling spring sound

IBM Model M keyboard, Unicomp

added a example without using thing-at-point. It's 5 more lines of code. Emacs Lisp: Using thing-at-point

lots updates today. Emacs Lisp: How to Find/Replace Text (on its own page)

Emacs Lisp: Problems of thing-at-point (on its own page)

Emacs Lisp: Using thing-at-point (major update)

Emacs Lisp: All About Processing Lines (minor update)

if you never wrote a emacs command before, make it so today. Emacs Lisp Idioms for Writing Interactive Commands (minor update)

geek + hack = geekhack, on keyboard & keybinding

these days, when seeing so so many whizbang ergonomic mechanical keyboard out there, now i'm more daring in thinking that any keyboard that's traditional PC shape is idiocy of the idiocy.

have you seen geekhack or deskthority? There, is where keyboard creatures live… drilling down every detail on keyboard, makers history, electronic schemas, molding of key plastics, key cap shape design schemas, with a million photos and drawing boards.

yesterday i was reading this http://geekhack.org/index.php?topic=62444.0

though, typical of hackers, usually they are lame on keybinding. In fact, you don't find much info about keybinding layout anywhere on the web. All you EVER hear about keybinding, is emacs vs vi, and Swap Caps Lock and Control.

in my study of keyboarding, one surprise is that, a programer typically type more keybinding than letter input 〔➤ Emacs's Command Frequency Statistics

So, this means, Qwerty vs Dvorak vs Colemak vs NEO… key layout is less important for programers. It's the command keybinding layout that whacks your hand.

thanks to Jon Snader for inspiration.

if you stutter in grammar, have a style tumor you can't excise, or in the plight of sufferage of prolixness, follow wordy english for treatment.

Emergency vi (vim tutorial) (for beginners. repost)

Emacs: How to Sort by Time, Size, in Dired? (new)

thanks to Jorge A Alfaro Murillo, Scott Bilik, Dave Pawson

A new update of emacs tutorial is out. Buy Xah Emacs Tutorial. Thank you.

If you already got it, The update will be send to you. If you changed your email, let me know at xah@xahlee.org. Thanks.

pure emacs lisp find replace grep regexp

added a option to “xah-find-replace-text” on whether to write to file.

get at https://github.com/xahlee/xah_file_util.el

i use it every week in past years, to find/replace/regexp 5 thousands files. Here's example how i used it today:

(xah-find-replace-text " ₁</" ", page 1</" "/home/xah/web/" "\\.html$" t t t t)
(xah-find-replace-text " ₂</" ", page 2</" "/home/xah/web/" "\\.html$" t t t t)
(xah-find-replace-text " ₃</" ", page 3</" "/home/xah/web/" "\\.html$" t t t t)
(xah-find-replace-text " ₄</" ", page 4</" "/home/xah/web/" "\\.html$" t t t t)
(xah-find-replace-text " ₅</" ", page 5</" "/home/xah/web/" "\\.html$" t t t t)
(xah-find-replace-text " ₆</" ", page 6</" "/home/xah/web/" "\\.html$" t t t t)
(xah-find-replace-text " ₇</" ", page 7</" "/home/xah/web/" "\\.html$" t t t t)
(xah-find-replace-text " ₈</" ", page 8</" "/home/xah/web/" "\\.html$" t t t t)
(xah-find-replace-text " ₉</" ", page 9</" "/home/xah/web/" "\\.html$" t t t t)
(xah-find-replace-text " ₁₀</" ", page 10</" "/home/xah/web/" "\\.html$" t t t t)
(xah-find-replace-text " ₁₁</" ", page 11</" "/home/xah/web/" "\\.html$" t t t t)
(xah-find-replace-text " ₁₂</" ", page 12</" "/home/xah/web/" "\\.html$" nil t t nil)
(xah-find-replace-text " ₁₃</" ", page 13</" "/home/xah/web/" "\\.html$" nil t t nil)
(xah-find-replace-text " ₁₄</" ", page 14</" "/home/xah/web/" "\\.html$" nil t t nil)
(xah-find-replace-text " ₁₅</" ", page 15</" "/home/xah/web/" "\\.html$" nil t t nil)
(xah-find-replace-text " ₁₆</" ", page 16</" "/home/xah/web/" "\\.html$" nil t t nil)
(xah-find-replace-text " ₁₇</" ", page 17</" "/home/xah/web/" "\\.html$" nil t t nil)
(xah-find-replace-text " ₁₈</" ", page 18</" "/home/xah/web/" "\\.html$" nil t t nil)
(xah-find-replace-text " ₁₉</" ", page 19</" "/home/xah/web/" "\\.html$" nil t t nil)

see also Problems of Calling Unix grep in Emacs

see also Emacs Lisp Exercise: replace-digits-by-subscript

example use of emacs lisp for batch text processing. Emacs Lisp Batch Text processing: Grep Find Replace Variations (repost)

emacs moving to Guile

Recently there's brouhaha again about emacs moving to Guile. Here's a post of clarification of what it means. https://lists.gnu.org/archive/html/emacs-devel/2014-09/msg00559.html

what's the best coding style?

Emacs: Tabs, Space, Indentation Setup#comment-1595298993

any coding style guide or concern should be ban'd. The only valid coding style advice is when it makes a algorithmic difference. Anything else, is hacker idiocy (to the extreme), and language idiocy, and the downward spiral and dead habit.

like keyboard & keybinding, the best hope is waiting for death to take care of the problem. (as Steve Jobs and Douglas Crockford said.)

the most idiotic programers, are the hacker types. The types that read hackernews, reddit, stackoverflow, (and graddaddy slashdot) etc everyday, and don't hesitate to tell you what you should do, about idioms & styles.

the only tool allowed for formatting related coding style, is one where you press a button and the entire file or directory is reformatted. (golang does it). Anything else, such as paredit, or most “lints”, is hacker idiocy.

the worst language, is a language that has lots of tricks & idioms. Perl is the dad, but went out of juice. Now Python. Ruby is designed to be sans coding style, but idiots create a style guide nevertheless.

what's the most efficient input system for alphabets that's got 10 more characters than English?

Yuri Khan, a great Russian programer, and one with extensive keyboard & keybinding modification, raised a question about how to input the 10 or so extra Russian letters. (he also uses Truly Ergonomic Keyboard)

He's got his own ideas. See discussion at https://plus.google.com/113859563190964307534/posts/Yxr1WivAu2K

i've done extensive research on this. see:

Keyboard: What's the Difference Between Alt Graph Key, Compose Key, Dead Key? (repost)

Emacs vs vi: How to Compute a Keybinding's Efficiency?

this suggest a scientific way to compute key efficiency. End the key debate once for all.

i hope someone might implement it. Or, i might do it eventually, but don't know what year.

GNU emacs's default key binding is no better than random keybinding.

there's a increase in ergoemacs-mode users since it went to FSF's repository. Let's get more people to use it!

best PC form keyboard for Mac

mac programer display and keyboard setup 69189 dan lentz
Dan Lentz's setup.

a friend (Dan lentz, Common Lisp and clojure expert) recently needed a keyboard to replace his Mac keyboard (he says it breaks every few months). I gave some recommendations. See: https://plus.google.com/+danlentz/posts/1oEtqpv6oEB

the keyboard i recommend according to his needs are:

Emacs Less-known Tips (minor update)

Emacs: Tabs, Space, Indentation Setup (updated)

Emacs: Delete Trailing Whitespace (on its own page)

Emacs Lisp: Setup Mouse Click to Highlight Matching Words (on its own page)

Emacs: Search & Highlight Words (minor update)

Keyboard revolution is here. Introducing, the Axios Keyboard ⌨

stackexchange emacs channel proposal passed. Join. http://area51.stackexchange.com/proposals/76571/emacs?referrer=hcehnezM28PzEQTGEFwH_Q2

fixed a bug in Emacs: Move Cursor by Paragraph or Text Block and Emacs Lisp: Move Cursor to Beginning of Line or Block. Thanks to Thorsten.

updated code. Emacs: Copy/Cut Current Line If No Selection

What to Do with Emacs Lisp? and my path to emacs lisp (minor edit)

Emacs Lisp: Count Lines, Words, Chars (minor update. Added a command to count region or line.)

Emacs Lisp: Single Key to Copy/Paste from Register (updated. No longer requiring a lib.)

in emacs's 1k+ default bindings , i only use 6, arrows and page up/down. Banish Key Chords Banish Key Chords

comment at https://plus.google.com/113859563190964307534/posts/hys14XrtDtX

does linux tiling window really suck? a challenge

F9 is switch to emacs

this is superb. you should, too. Tiling window is no good.

for how, and related tips, see:

vim: set your capslock to esc

if you use vim, it is critical that the Esc be a easy key. Some people make it “jj”, that's not good enough. The ideal position is either under your thumb, with a big key, or the traditional Caps Lock key position, and, must be a single key, not key chord.

See updated: Vim: How to Remap Escape Key?

for vim fans: Linux: How to Swap Caps Lock & Escape Keys?

what switch does space-cadget keyboard use?

i learn that, the Symbolics lisp machine's Space-cadet Keyboard uses Honeywell Hall Effect key switch, which is the highest quality key switch.

space-cadet keyboard 5
Space-cadet Keyboard

According to: http://deskthority.net/wiki/Honeywell_Hall_Effect:

Introduced in 1968, Micro Switch (a division of Honeywell) adapted their Hall effect switch technology to work in keyboards. These switches are among the highest quality ever produced by any keyboard switch company, with reliability being paramount to their design. For increased reliability, there are both 3 pin and 4 pin designs of the switch. The 4 pin are +5, GND and dual open-collector outputs, allowing wired-or of the X, Y keyboard matrix. These switches are naturally bounce-free!

The patent itself originates from 1969, but the design is aesthetically very different from the produced switches.

The Honeywell Hall Effect switch is most famous on some Symbolics keyboards, as well as the Space-cadet keyboard.

Keyfeel: Smooth linear switch, makes Cherry MX Black switches feel like they have sandpaper on the stems.

thanks to Yuriy Pitometsu

a new emacs binary site for Microsoft Windows. http://emacs-bin.sourceforge.net/

thx to Aaron Peromsik

see also Which Emacs to Download for Windows and Mac?

Keyboard Layouts Fight! Dvorak, Colemak, Workman, NEO, Bépo, … (minor update)

I do not believe, there's another soul in this world, who has a keyboard & keybinding setup more efficient than me.

sorry my friends. I had to say that.

Emacs: How to Override Minor Mode Keybinding (major update)

emacs: show isearch keys

try the command isearch-describe-bindings. It will list all keys for isearch. That is, when you call isearch-forwardCtrl+s】.

Thanks to Matt Fidler of ergoemacs-mode

see also: Emacs: How to Override Minor Mode Keybinding

smart whitespace-cleanup before save

Steve Purcell got a great idea about whitespace-cleanup.

whitespace-cleanup-mode is a minor mode which calls whitespace-cleanup before saving the current buffer, but only if the whitespace in the buffer was initially clean. It determines this by quickly checking to see if whitespace-cleanup would have any effect on the buffer.

see whitespace-cleanup-mode.

Emacs's Key Notation: What's the difference between "<return>" and "RET"? (thanks to Kumar)

Emacs's Key Notations Explained (/r ^M C-m RET <return> M- meta) (minor update)

Emacs Lisp: Delete Trailing Whitespace on Save and Compact Empty Lines (updated)

Emacs: Interactive Abbrev in Shell (major update)

Emacs Inferior Shell vs Terminal: What's the advantage of running shell inside emacs? (on its own page)


Emacs: What's the difference between {shell, term, ansi-term, eshell}? (on its own page)

emacs: using smex as ido interface to describe-function

if you are using smex, when in smex, you can press 【Ctrl+h f】to jump to describe-function of current command. This is fantastic, because, it basically becomes a ido interface for using describe-function. (the alternative is to use icomplete-mode, but that isn't as good as ido.)

Sacha Chua interviews Mickey Petersen of MasteringEmacs.org

See: 〔Emacs Chat: Mickey Petersen — Mastering Emacs By Sacha Chua. @ http://emacslife.com/emacs-chats/chat-mickey-petersen.html

Sacha Chua is super cute there. And, she's very intelligent, and nice, person. I must say, Mickey Petersen turns out to be a handsome dude. From this video, Mickey is in his spacious living room, well-groomed, wears a sparkling clean white shirt, into cooking. So is a bit different from typical hacker one'd imagine.

emacs vs vim tip jars 2014-09-04
“The Philz baristas at Facebook have learned their customers' weakness as evidenced by these tip jars. ” (from Jeremy Morrell)

comment at https://plus.google.com/113859563190964307534/posts/6QBHaBSocF8

emacs bookmark-jump

discovered bookmark-jump, updated at Emacs: Using Bookmark Feature. Somehow, i've never used that. (thanks to diesch and RobThorpe on reddit at http://www.reddit.com/r/emacs/comments/2f15sh/emacs_using_bookmark_feature/)

I haven't used bookmark for a couple of years. I use Emacs Lisp: Hotkeys to Open File Fast. Will have to give bookmark another shot.

emacs with-syntax-table pain

it turns out, if you use

(with-syntax-table (standard-syntax-table)
    (modify-syntax-entry ?\« "(»")
    (modify-syntax-entry ?\» ")«")
    ;;     )

it'll actually modify the global syntax table, the one returned by standard-syntax-table that is also used by fundamental-mode. (you can check by defining a function containing the above. Call the function. Then, open a new buffer, set it to “fundamental-mode”, then call “describe-syntax”, and check the french quote character's syntax. (by default, it has a syntax of punctuation.))

(info "(elisp) Standard Syntax Tables")

To work around it, you can just create a new syntax table and set it to a local variable, then call with-syntax-table with that.

for a sample code, see Emacs Lisp: How to Modify Syntax Table Temporarily (updated again. Refresh)

i haven't had time to figure out the detail why “with-syntax-table” is doing that. Maybe a bug, i don't know.

comment at https://plus.google.com/113859563190964307534/posts/WB5r4bg8ifZ

emacs syntax table is a major pain in the ASS!

after a hour, discovered that if you use “with-syntax-table”, and modify the syntax entry, it actually modifies the syntax table globally.

that is, for example, if you define the following:

(defun xah-select-text-in-bracket ()
  "Select text between the nearest brackets.
⁖  () [] {} «» ‹› “” 〖〗 【】 「」 『』 () 〈〉 《》 〔〕 ⦗⦘ 〘〙 ⦅⦆ 〚〛 ⦃⦄ ⟨⟩."
  (with-syntax-table (standard-syntax-table)
    (modify-syntax-entry ?\« "(»")
    (modify-syntax-entry ?\» ")«")
    (modify-syntax-entry ?\‹ "(›")
    (modify-syntax-entry ?\› ")‹")
    (modify-syntax-entry ?\“ "(”")
    (modify-syntax-entry ?\” ")“")

    (let (pos p1 p2)
      (setq pos (point))
      (search-backward-regexp "\\s(" nil t )
      (setq p1 (point))
      (forward-sexp 1)
      (setq p2 (point))
      (goto-char (1+ p1))
      (set-mark (1- p2)))))

and call the command, then, open a new buffer, set it to “fundamental-mode”, then call “describe-syntax”, you'll see tha the standard syntax table used by “fundamental-mode” is actually changed.

haven't had time to figure this one out yet. Just want to put out a warning first. My code here: Emacs Lisp: How to Modify Syntax Table Temporarily is not good since it modifies global syntax table. Keep tuned in for updates.

Emacs Lisp: How to Modify Syntax Table Temporarily (updated. Thanks to Jon Snader's mention @ http://irreal.org/blog/?p=2945)

Like it? or share