From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Emanuel Berg Newsgroups: gmane.emacs.help Subject: Re: A problem with eval-after-load Date: Thu, 17 Oct 2013 04:37:07 +0200 Organization: Aioe.org NNTP Server Message-ID: <87bo2otyfn.fsf@nl106-137-194.student.uu.se> References: <20131016111314.7fa2ccc9@aga-netbook> <87bo2pnm2p.fsf@web.de> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1381977613 993 80.91.229.3 (17 Oct 2013 02:40:13 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 17 Oct 2013 02:40:13 +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 04:40:18 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 1VWdVZ-0002eh-Jz for geh-help-gnu-emacs@m.gmane.org; Thu, 17 Oct 2013 04:40:17 +0200 Original-Received: from localhost ([::1]:50045 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VWdVZ-00088Z-0t for geh-help-gnu-emacs@m.gmane.org; Wed, 16 Oct 2013 22:40:17 -0400 Original-Path: usenet.stanford.edu!goblin1!goblin2!goblin.stu.neva.ru!aioe.org!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 156 Original-NNTP-Posting-Host: /ZLK7EtDT1dvbkmVtWlLYw.user.speranza.aioe.org Original-X-Complaints-To: abuse@aioe.org User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux) X-Notice: Filtered by postfilter v. 0.8.2 Cancel-Lock: sha1:wTPu6NUjr7jc0nFO1z6jhnpMAkQ= Mail-Copies-To: never Original-Xref: usenet.stanford.edu gnu.emacs.help:201784 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:94053 Archived-At: Can't you do simply: (define-key emacs-lisp-mode-map (kbd "C-l d") 'eval-defun) (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 "") '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") 'kill-line-if-not-empty-then-delete) 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 () (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). (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 `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.) (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." (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*. (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. -- Emanuel Berg, programmer-for-rent. CV, projects, etc at uXu underground experts united: http://user.it.uu.se/~embe8573