[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A problem with eval-after-load

From: Emanuel Berg
Subject: Re: A problem with eval-after-load
Date: Thu, 17 Oct 2013 04:37:07 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux)

Can't you do simply:

(define-key emacs-lisp-mode-map (kbd "C-l d")

(For your cases, of course.)

Possibly you have to `require' or even `load' before. If
it doesn't work, test that.

Otherwise, I have all thinkable solutions. If you can
figure out how all that works you are a smarter man than
I am. (From now on: code *first*, then *comment*.)

(let ((the-map Buffer-menu-mode-map))
  (define-key the-map "\C-o" nil)
  (define-key the-map (kbd "i") 'previous-line)
  (define-key the-map (kbd "k") 'next-line)
  (define-key the-map (kbd "w") 'kill-this-buffer)

Compact solution but can be slow to add/update single
entries. I don't think you need "kbd" for "i", "k", and
"w" - the C-o is set to nil not to take precedence over
a global shortcut (note the different notations - no
practical difference, what I can see...).

(define-key input-decode-map [?\u0113] [S-caps])
(global-set-key (kbd "<S-caps>") 'buffer-menu)

To get weird keys to work. You have to set them up in
the ttys (or "the Linux VTs" so they will send those
Unicode chars instead of what they normally do).

(define-key (current-global-map) (kbd "C-k")

Use of `current-global-map'.

(let ((the-map (current-global-map)))
  (define-key the-map "\M-u" 'downcase-word)
  (define-key the-map "\C-a" 'back-to-indentation) ; etc.

A combination on that.

(defun init-C-o-prefix ()
  (define-prefix-command 'C-o-prefix)
  (global-set-key "\C-o" 'C-o-prefix)
  (init-C-o-keys) )
(add-hook 'after-init-hook 'init-C-o-prefix)

A new prefix key. Initialized after everything is done,
probably so not to get reset by something else, later.

(defun init-C-o-keys ()
  (let ((the-map (current-global-map)))
    (define-key the-map "\C-od"     'eval-defun)
    (define-key the-map "\C-o\C-om" 'man) ; etc.

How that happens (same old).

(global-unset-key (kbd "C-x 1"))

Unset keys you don't like, so those will exit your
muscle memory.

(setq ada-mode-hook
          (lambda ()
          ; ...
            (define-key ada-mode-map (kbd "C-j") 'nil)

Perhaps it will be triggered more often than necessary
(not that it takes any time to set a key).

(eval-after-load 'bibtex '(define-key bibtex-mode-map
(kbd "C-j") nil))

Should be once.

(global-set-key [(control x) (k)] 'kill-this-buffer)

Yet another notation.

(global-set-key [insertchar] nil)

`global-set-key' to nil sounds like

(eval-after-load 'view
     (let ((the-map view-mode-map))
       (define-key the-map "\C-j" nil)
       (define-key the-map "k" 'scroll-down-1)
       (define-key the-map "i" 'scroll-up-1)
       (define-key the-map "w" 'delete-window) )))

Same old, but several keys. (The `progn' seems

(global-set-key (kbd "C-j") 'jump-to-register)
(set-register ?a (cons 'file "/sudo::/etc/apt/sources.list"))
(set-register ?b (cons 'file "~/News/my-kill"))
(set-register ?C (cons 'file "/sudo::/etc/default/console-setup"))
(set-register ?c (cons 'file "~/.irssi/config"))
;; etc.

Use *registers* as keys... (Note the case sensitivity,
and the sudo prefix.)

(define-key (current-global-map)
  [remap save-buffers-kill-terminal] 'no-confirm-emacs-quit)

If you are happy with the *key*.

(global-set-key (kbd "M-W") 'w3m-browse-url-new-tab)

Just because it is related to a specific mode, it may
still be useful to be able to access globally with the
same shortcut.

(defun sentmail ()
  "Dired the outbox directory, then focus the most recent mail."
  (dired "~/Mail/sent")
  (local-set-key (kbd "I") 'sentmail-show-prev-mail)
  (local-set-key (kbd "K") 'sentmail-show-next-mail)
  (dotimes (i 7) (backward-word)) )

Set keys *locally*.

(defun setup-scroll-keys ()
  (let ((map (current-global-map)))
    (define-key map (kbd "C-M-j") 'scroll-left-1-or-prefix)
    (define-key map (kbd "C-M-l") 'scroll-right-1-or-prefix)
    (define-key map (kbd "M-i")   'scroll-up-1)
    (define-key map (kbd "M-k")   'scroll-down-1) ))
(add-hook 'after-init-hook 'setup-scroll-keys)

Function to do it, on a hook. (The word "map" should
perhaps be avoided.)

(define-key the-map "\C-o\C-ow" (lambda () (interactive) (w3m)))

Lambda notation, if you don't like function
calls. Perhaps like the "inline" of C++, or macros of C,
if it has any practical significance.

Emanuel Berg, programmer-for-rent. CV, projects, etc at uXu
underground experts united:

reply via email to

[Prev in Thread] Current Thread [Next in Thread]