From: Marcin Borkowski <mbork@wmi.amu.edu.pl>
To: help-gnu-emacs@gnu.org
Subject: Re: A problem with eval-after-load
Date: Thu, 17 Oct 2013 21:52:09 +0200 [thread overview]
Message-ID: <20131017215209.4b299ea6@aga-netbook> (raw)
In-Reply-To: <87bo2otyfn.fsf@nl106-137-194.student.uu.se>
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 <embe8573@student.uu.se> 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
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Adam Mickiewicz University
next prev parent reply other threads:[~2013-10-17 19:52 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-16 9:13 A problem with eval-after-load Marcin Borkowski
2013-10-16 17:48 ` Michael Heerdegen
2013-10-16 18:31 ` Marcin Borkowski
[not found] ` <mailman.4156.1381948316.10748.help-gnu-emacs@gnu.org>
2013-10-17 2:37 ` Emanuel Berg
2013-10-17 19:52 ` Marcin Borkowski [this message]
[not found] ` <mailman.4208.1382039548.10748.help-gnu-emacs@gnu.org>
2013-10-19 0:43 ` Emanuel Berg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20131017215209.4b299ea6@aga-netbook \
--to=mbork@wmi.amu.edu.pl \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.