From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tassilo Horn Newsgroups: gmane.emacs.devel Subject: Re: mykie.el Date: Thu, 09 Jan 2014 09:13:38 +0100 Message-ID: <87bnzl374d.fsf@gnu.org> References: <87bnzshlo5.fsf@flea.lifelogs.com> <87eh4kg2hv.fsf@flea.lifelogs.com> <871u0jcr8q.fsf@flea.lifelogs.com> <87bnzma369.fsf@flea.lifelogs.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1389255236 27919 80.91.229.3 (9 Jan 2014 08:13:56 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 9 Jan 2014 08:13:56 +0000 (UTC) Cc: Yuta Yamada , emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Jan 09 09:14:02 2014 Return-path: Envelope-to: ged-emacs-devel@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 1W1Aka-0000IQ-82 for ged-emacs-devel@m.gmane.org; Thu, 09 Jan 2014 09:14:00 +0100 Original-Received: from localhost ([::1]:50543 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W1AkZ-00069O-Q3 for ged-emacs-devel@m.gmane.org; Thu, 09 Jan 2014 03:13:59 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35195) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W1AkR-000688-Kv for emacs-devel@gnu.org; Thu, 09 Jan 2014 03:13:57 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W1AkL-0007uU-Kt for emacs-devel@gnu.org; Thu, 09 Jan 2014 03:13:51 -0500 Original-Received: from deliver.uni-koblenz.de ([141.26.64.15]:38316) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W1AkL-0007uO-Ec for emacs-devel@gnu.org; Thu, 09 Jan 2014 03:13:45 -0500 Original-Received: from localhost (localhost [127.0.0.1]) by deliver.uni-koblenz.de (Postfix) with ESMTP id 364B51A8466; Thu, 9 Jan 2014 09:13:44 +0100 (CET) X-Virus-Scanned: amavisd-new at uni-koblenz.de Original-Received: from deliver.uni-koblenz.de ([127.0.0.1]) by localhost (deliver.uni-koblenz.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ALVdxd2CjnzI; Thu, 9 Jan 2014 09:13:43 +0100 (CET) X-CHKRCPT: Envelopesender noch tsdh@gnu.org Original-Received: from thinkpad-t61 (tsdh.uni-koblenz.de [141.26.67.142]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by deliver.uni-koblenz.de (Postfix) with ESMTPSA id C60851A8455; Thu, 9 Jan 2014 09:13:43 +0100 (CET) Mail-Followup-To: Stefan Monnier , emacs-devel@gnu.org, Yuta Yamada In-Reply-To: (Stefan Monnier's message of "Wed, 08 Jan 2014 11:11:04 -0500") User-Agent: Gnus/5.130008 (Ma Gnus v0.8) Emacs/24.3.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 141.26.64.15 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:167870 Archived-At: Stefan Monnier writes: >> Shall I name this `define-key-contextual' or something else? > > I don't see anything "define-key ish" in there. It's a macro that > lets you define a *command*. FWIW, I'd much prefer the define-key-like approach you've suggested earlier this thread (sorry, can't look it up right now), i.e., where you can add different clauses separately. Ideally, it would be cool if it allowed to define the same key in different keymaps and still be working as expected. E.g.: (define-context-key outline-minor-mode-map (kbd "TAB") :predicate outline-heading-p :action org-cycle) (define-context-key emacs-lisp-mode-map (kbd "TAB") :predicate beginning-of-defun-p :action eval-defun) And then in a elisp buffer with outline-minor-mode enabled, if I'm on a outline heading, it would cycle through the outline states, if I'm at the beginning of a defun, if would eval it, and if I'm on neither of those, then it does what TAB would do usually. I already do have such a macro, but it doesn't allow defining multiple separate predicate-action combos for the same key. Falling back to the "do what TAB would do by default" does work, however. (Actually, you helped me implementing it.) --8<---------------cut here---------------start------------->8--- (defmacro th/define-context-key (keymap key dispatch) "Define KEY in KEYMAP to execute according to DISPATCH. DISPATCH is a form that is evaluated and should return the command to be executed. If DISPATCH returns nil, then the command normally bound to KEY will be executed. Example: (th/define-context-key hs-minor-mode-map (kbd \"\") (cond ((not (hs-already-hidden-p)) 'hs-hide-block) ((hs-already-hidden-p) 'hs-show-block))) This will make show a hidden block. If the block is shown, then it'll be hidden." `(define-key ,keymap ,key `(menu-item "context-key" ignore :filter ,(lambda (&optional ignored) ,dispatch)))) --8<---------------cut here---------------end--------------->8--- Bye, Tassilo