From: Xah Lee
Subject: Emacs's Command Frequency and default keyboard shortcuts
Date: 
Message-ID: <1159914415.055557.32190@i3g2000cwc.googlegroups.com>
Here's a visual layout of the default keybinds in emacs:
http://xahlee.org/emacs/emacs_kb_shortcuts.html

A important aspect in designing default keyboard shortcuts is have kb
shortcuts for the most frequently used commands, and, the top most
frequently used commands should have most easily-pressed keystrokes.
For example, they should be on the home row.

Use this program to compute the command frequency of your emacs use.
 http://xahlee.org/emacs/command-frequency.el

Once you have accumulated 20k runs of self-insert-command, please send
me the results.
I hope to comile some stats. I will do a report here when i get
results.

Thanks. 

  Xah
  ···@xahlee.org
∑ http://xahlee.org/

From: Xah Lee
Subject: Re: Emacs's Command Frequency and default keyboard shortcuts
Date: 
Message-ID: <1160574910.715784.64440@i42g2000cwa.googlegroups.com>
here's my results.

; start 2006-10-05T21:31:39-07:00
; end 2006-10-11T06:52:03-07:00
; http://xahlee.org/emacs/command-frequency.el

28723	self-insert-command
9578	next-line
7431	previous-line
4402	backward-word
3428	forward-word
2544	kill-region
2394	isearch-printing-char
1820	forward-char
1669	delete-backward-char
1426	backward-char
1169	save-buffer
905	newline
751	yank
701	backward-delete-char-untabify
682 kill-buffer-silently
580	scroll-up
496	mwheel-scroll
439	isearch-forward
387	other-window
379	undo
372	previous-history-element
372	dired-next-line
362	delete-char
320	scroll-down
285	minibuffer-complete
277	isearch-other-meta-char
276	execute-extended-command
264	dired
262	set-mark-command
260	isearch-other-control-char
236	move-beginning-of-line
232	dired-advertised-find-file
194	find-file
177	beginning-of-buffer
162	revert-buffer
160	move-end-of-line
147	recenter
138	dired-previous-line
135	isearch-repeat-forward
134	kill-ring-save
131	extend-selection
126	delete-other-windows
119	end-of-buffer
113	eval-last-sexp
111	isearch-backward
109	minibuffer-keyboard-quit
108	split-window-vertically
104	ibuffer-mark-for-delete
104	mouse-drag-region
102	fill-paragraph
94	ignore
88	shell-command
88	exit-minibuffer
83	isearch-repeat-backward
83	mouse-set-point
81	keyboard-quit
76	nil
71	lisp-indent-line
71	describe-function
68	just-one-space
65	grep
62	browse-url-of-buffer
56	wrap-url
56	delete-window
54	mark-whole-buffer
53	python-backspace
53	center-line
51	x-w
51	handle-switch-frame
50	sgml-close-tag
48	describe-key
47	dired-do-query-replace-regexp
37	shell-command-on-region
37	Info-follow-nearest-node
33	kill-buffer-silently
33	html-paragraph
32	query-replace
28	,bbedit
28	next-buffer
27	x-note
26	dired-mark-files-regexp
26	bookmark-bmenu-list
25	Info-up
23	ibuffer-forward-line
23	bookmark-bmenu-this-window
23	switch-to-buffer
22	query-replace-regexp
22	remove-hard-wrap
21	x-b
20	previous-buffer
19	ibuffer-backward-line
19	minibuffer-complete-and-exit
18	ibuffer
18	string-rectangle
18	tt
17	cperl-electric-backspace
17	ispell-word
16	isearch-abort
16	other-frame
16	sgml-slash
15	compile-goto-error
15	insert-p
14	word-entry
14	beginning-of-defun
14	universal-argument-other-key
14	universal-argument
14	next-history-element
13	ffap
12	ibuffer-mark-forward
12	dired-do-rename
11	set-variable
11	backward-up-list
11	apropos-command
10	ff
10	ibuffer-visit-buffer
10	ibuffer-update
10	date
10	dt
10	dired-do-copy
9	insert-register
9	tag-image2
9	sgml-maybe-name-self
9	command-frequency-display
8	ibuffer-do-save
8	ibuffer-mark-unsaved-buffers
8	forward-sexp
8	html-list-item
7	kill-line-backward
7	ibuffer-do-kill-on-deletion-marks
7	html-headline-2
7	grep-find
7	minibuffer-complete-word
7	set-input-method
7	downcase-word
6	upcase-initials-region
6	Info-menu
6	line-spacing-toggle
6	newline-and-indent
6	describe-variable
6	dired-do-flagged-delete
6	dired-flag-file-deletion
6	replace-string
6	back-to-indentation
6	quoted-insert
5	htmlize-buffer
5	toggle-input-method
5	(lambda nil (interactive) (let ((orig-function (symbol-function
(quote message)))) (unwind-protect (progn (defun message (string &rest
arguments) (let* ((s1 (concat prompt (buffer-substring
(shell-command/minibuffer-prompt-end) (point-max)))) (s2 (apply
(function format) string arguments)) (w (- (window-width) (string-width
s1) (string-width s2) 1))) (funcall orig-function (if (>= w 0) (concat
s1 (make-string w 32) s2) s2)) (if (sit-for 0.3) (funcall orig-function
s1)) s2)) (require (quote shell)) (require (quote comint))
(run-hook-with-args-until-success (quote
shell-command-complete-functions))) (fset (quote message)
orig-function))))
5	upcase-word
5	lisp-complete-symbol
5	mouse-set-font
5	View-quit
5	mode-exited
4	name-last-kbd-macro
4	exchange-point-and-mark
4	dired-unmark-all-marks
4	wikipfy-block
4	replace-quotes
4	#[nil 쀀⃿ﷂ!‡ [split-window-vertically find-file
~/web/emacs/unicode.txt] 2 nil nil]
4	dired-create-directory
4	atom-entry
4	Info-mouse-follow-nearest-node
4	info
3	kill-rectangle
3	indent-for-tab-command
3	sgml-delete-tag
3	what-cursor-position
3	isearch-delete-char
3	#[nil 쀀挀蜀 寲] 1 inserts a unicode char. nil]
3	man
3	html-headline-3
3	dired-up-directory
3	dired-mark
3	push-button
3	mark-sexp
3	Info-history-back
3	make-frame-command
2	insert-kbd-macro
2	replace-html-chars
2	digit-argument
2	scroll-bar-toolkit-scroll
2	undefined
2	mac-dnd-handle-drag-n-drop-event
2	date-tag
2	yank-pop
2	complete-symbol
2	mouse-save-then-kill
2	replace-list
2	copy-to-register
2	mouse-select-window
2	mouse-drag-mode-line
2	dired-flag-backup-files
2	isearch-toggle-case-fold
2	move-to-window-line
2	wrap-url-simple
1	kmacro-end-macro
1	kmacro-start-macro
1	isearch-edit-string
1	open-unicode-template
1	eval-region
1	insert-upright-arrow
1	tmm-menubar
1	Info-exit
1	mouse-set-region
1	kill-buffer
1	view-emacs-news
1	indent-new-comment-line
1	list-colors-display
1	html-headline-1
1	dired-show-file-type
1	dired-sort-toggle-or-edit
1	html-mode
1	html-helper-mode
1	text-mode
1	goto-line
1	kill-line
1	count-lines-page
1	view-lossage
1	comment-dwim
1	set-goal-column
1	(lambda (event) (interactive e) (setq tabbar-last-selected-tab (quote
(aladdin5.html . HTML))) (when tabbar-select-tab-function
(select-window (posn-window (event-start event))) (funcall
tabbar-select-tab-function event (quote (aladdin5.html . HTML)))
(force-mode-line-update) (sit-for 0)))
1	tabbar-mode
1	isearch-yank-line
1	html-href-anchor
1	sgml-attributes
1	describe-mode
1	backward-sexp
1	describe-prefix-bindings
1	quit-window
1	pendo-entry
1	isearch-ring-advance
1	eval-buffer


Please send me yours. Thanks.


Xah Lee wrote:
> Here's a visual layout of the default keybinds in emacs:
> http://xahlee.org/emacs/emacs_kb_shortcuts.html
>
> A important aspect in designing default keyboard shortcuts is have kb
> shortcuts for the most frequently used commands, and, the top most
> frequently used commands should have most easily-pressed keystrokes.
> For example, they should be on the home row.
>
> Use this program to compute the command frequency of your emacs use.
>  http://xahlee.org/emacs/command-frequency.el
>
> Once you have accumulated 20k runs of self-insert-command, please send
> me the results.
> I hope to comile some stats. I will do a report here when i get
> results.
> 
> Thanks. 
> 
>   Xah
>   ···@xahlee.org
> ∑ http://xahlee.org/
From: Xah Lee
Subject: Re: Emacs's Command Frequency and default keyboard shortcuts
Date: 
Message-ID: <1160946907.074793.146430@f16g2000cwb.googlegroups.com>
Of interest!

(global-set-key (kbd "M-<left>") 'previous-user-buffer)
(global-set-key (kbd "M-<right>") 'next-user-buffer)
(global-set-key (kbd "M-S-<left>") 'previous-emacs-buffer)
(global-set-key (kbd "M-S-<right>") 'next-emacs-buffer)

(defun next-user-buffer ()
  "Switch to the next user buffer in cyclic order.\n
User buffers are those not starting with *."
  (interactive)
  (next-buffer)
  (let ((i 0))
    (while (and (string-match "^*" (buffer-name)) (< i 10))
      (setq i (1+ i)) (next-buffer) )))

(defun previous-user-buffer ()
  "Switch to the next user buffer in cyclic order.\n
User buffers are those not starting with *."
  (interactive)
  (previous-buffer)
  (let ((i 0))
    (while (and (string-match "^*" (buffer-name)) (< i 10))
      (setq i (1+ i)) (previous-buffer) )))

(defun next-emacs-buffer ()
  "Switch to the next emacs buffer in cyclic order.\n
Emacs buffers are those starting with *."
  (interactive)
  (next-buffer)
  (let ((i 0))
    (while (and (not (string-match "^*" (buffer-name))) (< i 10))
      (setq i (1+ i)) (next-buffer) )))

(defun previous-emacs-buffer ()
  "Switch to the next user buffer in cyclic order.\n
Emacs buffers are those starting with *."
  (interactive)
  (previous-buffer)
  (let ((i 0))
    (while (and (not (string-match "^*" (buffer-name))) (< i 10))
      (setq i (1+ i)) (previous-buffer) )))

  Xah
  ···@xahlee.org
∑ http://xahlee.org/
From: John Sullivan
Subject: Re: Emacs's Command Frequency and default keyboard shortcuts
Date: 
Message-ID: <87hcy5gni0.fsf@ashbery.wjsullivan.net>
"Xah Lee" <···@xahlee.org> writes:

> Of interest!
>

In Emacs 22:

,----[ C-h f next-buffer RET ]
| next-buffer is an interactive compiled Lisp function in `simple.el'.
| It is bound to C-x <C-right>, C-x <right>, <menu-bar> <buffer> <next-buffer>.
| (next-buffer)
| 
| Switch to the next buffer in cyclic order.
`----

,----[ C-h f previous-buffer RET ]
| previous-buffer is an interactive compiled Lisp function in `simple.el'.
| It is bound to C-x <C-left>, C-x <left>, <menu-bar> <buffer> <previous-buffer>.
| (previous-buffer)
| 
| Switch to the previous buffer in cyclic order.
| 
| [back]
`----

There is also already cyclebuffer.el.

http://www.emacswiki.org/cgi-bin/wiki/CycleBuffer

-- 
-John Sullivan
-http://www.wjsullivan.net
-GPG Key: AE8600B6
From: Xah Lee
Subject: Re: Emacs's Command Frequency and default keyboard shortcuts
Date: 
Message-ID: <1161062844.177986.12580@f16g2000cwb.googlegroups.com>
Raoul Gough wrote:
«I've begun to notice that C-x is really quite awkward for me to type
(this is on a US QWERTY layout). My usual finger positions for this
key-chord are left little finger on CTRL and left middle on X, which
puts the left middle finger under an unusual strain since it's cramped
up diagonally. Any ideas on improving this situation?»

Thanks for reminding me of this extremely fucked emacs design, which
has escaped my notice.

The need to press x with modifiers, is the single most frequently
needed operation in emacs. This is so critical that the command
frequency list doesn't even bring the issue up, since these prefix
keystrokes are needed to call up any command.

The Control-x is possibly the most awkward key combination on a
standard keyboard, and unfortunately, it is the key strokes that emacs
wants people to use the most. It is in fact, the sole contribution to
the well-known “emacs pinky” repetitive strain injury, and is one
of the main driving force for people to detest emacs.

Given that we are stuck with the C-x (at least for now), for a article
on How To Avoid The Emacs Pinky Problem, see
 http://xahlee.org/emacs/emacs_pinky.html

In short, one of the most important thing is that you should use a
proper keyboard with large modifier keys, and with them positioned on
both sides of the keyboard in a symmetric way to the left/right home
keys, so that the right side set are actually touch-type functional.

(keyboard layout and the physical keyboard design are the other
extremely fucked up products of shameless fuckers in our society (and
supported as a side effect of political struggle by our tech geekers.
That's why we still have it to this day.))

Many people, as a sloppy work-around with the emacs pinky problem,
swaps the conventional positions of the left Control key and Cap Lock
key. This does work as a work around, but is not a solution as tech
geekers drivels about.

As we have discussed before, the most used commands must have the most
easy-to-type keystrokes. The C-x, as a prefix keystroke for calling
emacs command, therefore must have the most easy to type.

Assume that we are given the physical design of a conventional keyboard
and the common qwerty layout, then the most comfortable key combo for
the control combination would be one of the DF or JK keys, both are
under the home row pressed by the index and middle fingers. And given
that most keyboards don't have a touch-type-functional right set
Control and Meta keys, therefore JK would be the optimal choices for
the command prefix keys. (so that, the left hand can hold down the
modifier keys, and the other hand, can press J or K. Between the
choices of J vs K, K is probably better since the longer middle finger
makes it more comfortable to type. Therefore, C-x and M-x really should
be C-t and M-k.

On the dvorak keyboard (which is one major fix up of the fucked
keyboard layout that is qwerty which by itself contributed to endless
hand injuries), the right hand index finger's key is T. Thus, on the
dvorak layout, the C-x should be C-t.

(Note: if you are using dvorak, the x is the qwerty's b, so that you
can type C-x by having your left hand hold down control on the left
side, and right hand's index finger moves to the lower left to press
the x. However, this won't work if you are using a Split Keyboard
(which is a major fix up to the fucked up physical keyboard design). On
a split keyboard, the Qwerty's B is on the left side of the keyboard,
and is very awkward to press C-b either with left hand itself or both
left and right hands. (photo here
http://xahlee.org/emacs/i/ms_wnm_keyboard.jpg ))

I use a Dvorak keyboard layout. I use a split key physical keyboard. I
have C-x remapped to C-t.

Please see also:
Modernization of Emacs
http://xahlee.org/emacs/modernization.html

  Xah
  ···@xahlee.org
∑ http://xahlee.org/
From: Jochem Huhmann
Subject: Re: Emacs's Command Frequency and default keyboard shortcuts
Date: 
Message-ID: <m2slhnt8z7.fsf@marvin.revier.com>
"Xah Lee" <···@xahlee.org> writes:

> The Control-x is possibly the most awkward key combination on a
> standard keyboard, and unfortunately, it is the key strokes that emacs
> wants people to use the most. It is in fact, the sole contribution to
> the well-known “emacs pinky” repetitive strain injury, and is one
> of the main driving force for people to detest emacs.

Why does anyone need a finger to press the Control key? Try to keep your
fingers in the home position (index fingers on f and j) and press and
hold left Control with your hand without moving any finger. Works fine
for me. If I had to use my pinky for that, I'd have moved back to vi
long ago.


        Jochem

-- 
 "A designer knows he has arrived at perfection not when there is no 
 longer anything to add, but when there is no longer anything to take away."
 - Antoine de Saint-Exupery 
From: ··········@yahoo.co.uk
Subject: Re: Emacs's Command Frequency and default keyboard shortcuts
Date: 
Message-ID: <1161252885.029804.141170@f16g2000cwb.googlegroups.com>
Jochem Huhmann wrote:
> "Xah Lee" <···@xahlee.org> writes:
>
> > The Control-x is possibly the most awkward key combination on a
> > standard keyboard, and unfortunately, it is the key strokes that emacs
> > wants people to use the most. It is in fact, the sole contribution to
> > the well-known "emacs pinky" repetitive strain injury, and is one
> > of the main driving force for people to detest emacs.
>
> Why does anyone need a finger to press the Control key? Try to keep your
> fingers in the home position (index fingers on f and j) and press and
> hold left Control with your hand without moving any finger. Works fine
> for me. If I had to use my pinky for that, I'd have moved back to vi
> long ago.

That seems difficult to me! I assume you're managing to hold it down
with the palm of your hand - have you got one of those over-sized
control keys on your keyboard?

I've tried out using C-j remapped to be the same as C-x as follows:

(global-set-key "\C-j" 'Control-X-prefix) ;; Was newline-and-indent

C-j is really easy to type on a QWERTY layout. Unfortunately some of
the major modes have C-j in their mode-maps, so it can get remapped to
something ordinary like sh-newline-and-indent.

So what I'm trying now is a modified CAPSLOCK which maps to the HYPER
modifier and then maping H-j to be an equivalent C-x prefix key*.
Unfortunately, this isn't ideal either, since some of the keys in
ctl-x-map are designed to work with the control key held down. e.g.
it's more awkward to type H-j C-q than C-x C-q.

Maybe I'll stick with C-j and use find-file-hooks to reset C-j after
the major mode has messed with it...

I also noticed that iswitchb-mode sets up some keys like this:

(global-set-key "\C-xb" 'iswitchb-buffer)

instead of

(define-key ctl-x-map "b" 'iswitchb-buffer)

Is this a bug in iswitchb-mode?

* Emacs complains about "\H-j" as a key specifier with the error
"Invalid modifier in string". I had to follow the FAQ's advice and map
H-j to something interactively and then examine command-history to find
out that [16777322] is the vector specifying H-j.

-- 
Raoul Gough.
From: Johan Bockgård
Subject: Re: Emacs's Command Frequency and default keyboard shortcuts
Date: 
Message-ID: <yoijk62wh0q5.fsf@gamma02.me.chalmers.se>
··········@yahoo.co.uk writes:

> * Emacs complains about "\H-j" as a key specifier with the error
> "Invalid modifier in string".

Hyper events can't be put in strings. You can use a vector, [?\H-j],
or the kbd macro, (kbd "H-j").

-- 
Johan Bockgård
From: Bernd Schmitt
Subject: Re: Emacs's Command Frequency and default keyboard shortcuts
Date: 
Message-ID: <453a9883$0$29037$9b622d9e@news.freenet.de>
On 19.10.2006 12:14, ··········@yahoo.co.uk wrote:
> So what I'm trying now is a modified CAPSLOCK which maps to the HYPER
> modifier and then maping H-j to be an equivalent C-x prefix key*.
> Unfortunately, this isn't ideal either, since some of the keys in
> ctl-x-map are designed to work with the control key held down. e.g.
> it's more awkward to type H-j C-q than C-x C-q.
This is very interesting, how do you  map CAPSLOCK to the HYPER
modifier? Could this be done with emacs-lisp only, too?

curiously,
Bernd

P.S. f'up2 comp.emacs, ok?
From: Stefan Monnier
Subject: Re: Emacs's Command Frequency and default keyboard shortcuts
Date: 
Message-ID: <jwvlkncjqht.fsf-monnier+comp.emacs.xemacs@gnu.org>
> (global-set-key "\C-j" 'Control-X-prefix) ;; Was newline-and-indent

> C-j is really easy to type on a QWERTY layout. Unfortunately some of
> the major modes have C-j in their mode-maps, so it can get remapped to
> something ordinary like sh-newline-and-indent.

You can try

  (define-key key-translation-map [?\C-j] [?\C-x])

But this will not only turn `C-j k' into `C-x k' but also `C-j C-j' into
`C-x C-x'.  Another option:

  (define my-remap-mode-map
    (let ((map (make-sparse-keymap)))
      (define-key map [?\C-j] 'Control-X-prefix)
      map))
  (define-minor-mode my-remap-mode
    "A minor mode to remap C-j to C-x."
    :global t)
  (my-remap-mode 1)

It may still be overridden by other minor modes, but at least it will
override major mode bindings.  In Emacs-22 you'll be able to use
emulation-mode-map-alists, which takes precedence over minor-mode bindings.

> I also noticed that iswitchb-mode sets up some keys like this:

> (global-set-key "\C-xb" 'iswitchb-buffer)

> instead of

> (define-key ctl-x-map "b" 'iswitchb-buffer)

> Is this a bug in iswitchb-mode?

Arguably, yes.  Although it shouldn't affect you: as long as your C-x is
still bound to Control-X-prefix, then the above will modify the
Control-X-prefix map and will thus also affect your C-j prefix.

> * Emacs complains about "\H-j" as a key specifier with the error
> "Invalid modifier in string". I had to follow the FAQ's advice and map
> H-j to something interactively and then examine command-history to find
> out that [16777322] is the vector specifying H-j.

Don't use strings to represent key-sequences.  [16777322] is usually written
[?\H-j].  Emacs also accepts the XEmacs syntax [(hyper j)], or [(hyper ?j)].


        Stefan
From: Evan Monroig
Subject: Re: Emacs's Command Frequency and default keyboard shortcuts
Date: 
Message-ID: <87vemj9uj6.fsf@gmail.com>
"Xah Lee" <···@xahlee.org> writes:
[...]
> On the dvorak keyboard (which is one major fix up of the fucked
> keyboard layout that is qwerty which by itself contributed to endless
> hand injuries), the right hand index finger's key is T.

Under the right hand index is the letter H, isn't it?  T is on its
right.

(unless I have a strange dvorak layout..)

Evan