From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Marcin Borkowski Newsgroups: gmane.emacs.help Subject: Re: A problem with eval-after-load Date: Thu, 17 Oct 2013 21:52:09 +0200 Organization: WMI UAM Message-ID: <20131017215209.4b299ea6@aga-netbook> References: <20131016111314.7fa2ccc9@aga-netbook> <87bo2pnm2p.fsf@web.de> <87bo2otyfn.fsf@nl106-137-194.student.uu.se> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1382039554 6300 80.91.229.3 (17 Oct 2013 19:52:34 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 17 Oct 2013 19:52:34 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Oct 17 21:52:38 2013 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1VWtcb-0002EO-FV for geh-help-gnu-emacs@m.gmane.org; Thu, 17 Oct 2013 21:52:37 +0200 Original-Received: from localhost ([::1]:54018 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VWtcb-0003b6-53 for geh-help-gnu-emacs@m.gmane.org; Thu, 17 Oct 2013 15:52:37 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:43230) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VWtcM-0003aB-ER for help-gnu-emacs@gnu.org; Thu, 17 Oct 2013 15:52:27 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VWtcH-0001P4-IS for help-gnu-emacs@gnu.org; Thu, 17 Oct 2013 15:52:22 -0400 Original-Received: from msg.wmi.amu.edu.pl ([2001:808:114:2::50]:44124) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VWtcH-0001OG-3B for help-gnu-emacs@gnu.org; Thu, 17 Oct 2013 15:52:17 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by msg.wmi.amu.edu.pl (Postfix) with ESMTP id 5EC1D4E1F3 for ; Thu, 17 Oct 2013 21:52:14 +0200 (CEST) Original-Received: from msg.wmi.amu.edu.pl ([127.0.0.1]) by localhost (msg.wmi.amu.edu.pl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id tnwOovbYYOKn for ; Thu, 17 Oct 2013 21:52:14 +0200 (CEST) Original-Received: from aga-netbook (99-52.echostar.pl [213.156.99.52]) by msg.wmi.amu.edu.pl (Postfix) with ESMTPSA id 038A24E1F2 for ; Thu, 17 Oct 2013 21:52:13 +0200 (CEST) In-Reply-To: <87bo2otyfn.fsf@nl106-137-194.student.uu.se> X-Mailer: Claws Mail 3.8.1 (GTK+ 2.24.17; i686-pc-linux-gnu) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:808:114:2::50 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:94061 Archived-At: 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 napisa=C5=82(a): > Can't you do simply: >=20 > (define-key emacs-lisp-mode-map (kbd "C-l d") > 'eval-defun) >=20 > (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. >=20 > 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*.) >=20 > (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) > ) >=20 > 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 "") 'buffer-menu) >=20 > 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) >=20 > 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. >=20 > 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) >=20 > A new prefix key. Initialized after everything is done, > probably so not to get reset by something else, later. >=20 > (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. >=20 > 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")) >=20 > 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) > )) >=20 > Perhaps it will be triggered more often than necessary > (not that it takes any time to set a key). >=20 > (eval-after-load 'bibtex '(define-key bibtex-mode-map > (kbd "C-j") nil)) >=20 > 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) >=20 > Yet another notation. And an interesting one. > (global-set-key [insertchar] nil) >=20 > `global-set-key' to nil sounds like > `global-unset-key'... >=20 > (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) ))) >=20 > Same old, but several keys. (The `progn' seems > redundant.) >=20 > (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. >=20 > 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) >=20 > If you are happy with the *key*. >=20 > (global-set-key (kbd "M-W") 'w3m-browse-url-new-tab) >=20 > 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)) ) >=20 > 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) >=20 > Function to do it, on a hook. (The word "map" should > perhaps be avoided.) >=20 > (define-key the-map "\C-o\C-ow" (lambda () (interactive) (w3m))) >=20 > 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! --=20 Marcin Borkowski http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski Adam Mickiewicz University