[Top][All Lists]

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

Re: A problem with eval-after-load

From: Marcin Borkowski
Subject: Re: A problem with eval-after-load
Date: Thu, 17 Oct 2013 21:52:09 +0200

Wow, now I feel guilty of wasting your time on this lengthy email...
Thanks for the tips!

Dnia 2013-10-17, o godz. 04:37:07
Emanuel Berg <address@hidden> napisaƂ(a):

> Can't you do simply:
> (define-key emacs-lisp-mode-map (kbd "C-l d")
> 'eval-defun)
> (For your cases, of course.)

No, since I need to *undefine* keys, too.  (Now that I've read your
message, I know that I can just define them to nil - but this means two
lines of code for each function.  It's faster to copy and modify the
definition of the keymap;).)

Let me comment on your comments;).

> 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...).

No need to add/update after writing my code - but my solution was
indeed a bit faster, as I mentioned.

> (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).

I'm not sure I fully understand this, but it seems to me to low-level
for me.

> (define-key (current-global-map) (kbd "C-k")
>   'kill-line-if-not-empty-then-delete)
> Use of `current-global-map'.

I don't want to clutter it with things needed in one specific mode.

> (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.

As above.

> (defun init-C-o-prefix ()
>   (interactive)
>   (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 ()
>   (interactive)
>   (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).

Did not understand this.  (I could RTFM, of course, but I'm too lazy
after a day's work...  I'll look into this later.)

> (global-unset-key (kbd "C-x 1"))
> Unset keys you don't like, so those will exit your
> muscle memory.

Must remember this, might be handy some day.

> (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.

This is more or less what I wanted to achieve in the first place.

> (global-set-key [(control x) (k)] 'kill-this-buffer)
> Yet another notation.

And an interesting one.

> (global-set-key [insertchar] nil)
> `global-set-key' to nil sounds like
> `global-unset-key'...
> (eval-after-load 'view
>   '(progn
>      (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
> redundant.)
> (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.)

Interesting idea again.

> (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.

Indeed, though not in my case.

> (defun sentmail ()
>   "Dired the outbox directory, then focus the most recent mail."
>   (interactive)
>   (dired "~/Mail/sent")
>   (local-set-key (kbd "I") 'sentmail-show-prev-mail)
>   (local-set-key (kbd "K") 'sentmail-show-next-mail)
>   (revert-buffer)
>   (end-of-buffer)
>   (dotimes (i 7) (backward-word)) )
> Set keys *locally*.

"Locally" in the sense of "this mode", not "this buffer", I guess?

> (defun setup-scroll-keys ()
>   (interactive)
>   (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.

Thanks again!

Marcin Borkowski
Adam Mickiewicz University

reply via email to

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