From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: mykie.el Date: Mon, 06 Jan 2014 19:37:01 -0500 Message-ID: References: <87bnzshlo5.fsf@flea.lifelogs.com> <87eh4kg2hv.fsf@flea.lifelogs.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1389055037 23053 80.91.229.3 (7 Jan 2014 00:37:17 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 7 Jan 2014 00:37:17 +0000 (UTC) Cc: Yuta Yamada To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Jan 07 01:37:23 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 1W0Kfa-0005xY-0V for ged-emacs-devel@m.gmane.org; Tue, 07 Jan 2014 01:37:22 +0100 Original-Received: from localhost ([::1]:38242 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W0KfZ-0004ks-Lh for ged-emacs-devel@m.gmane.org; Mon, 06 Jan 2014 19:37:21 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55872) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W0KfO-0004kL-2W for emacs-devel@gnu.org; Mon, 06 Jan 2014 19:37:17 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W0KfG-0002gN-NZ for emacs-devel@gnu.org; Mon, 06 Jan 2014 19:37:10 -0500 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.181]:19652) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W0KfG-0002gG-JU for emacs-devel@gnu.org; Mon, 06 Jan 2014 19:37:02 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Av4EABK/CFFFxKG9/2dsb2JhbABEvw4Xc4IfAQVWIxALNBIUGA2ISMEtjWGDKQOIYZwZgV6DFQ X-IPAS-Result: Av4EABK/CFFFxKG9/2dsb2JhbABEvw4Xc4IfAQVWIxALNBIUGA2ISMEtjWGDKQOIYZwZgV6DFQ X-IronPort-AV: E=Sophos;i="4.84,565,1355115600"; d="scan'208";a="44300919" Original-Received: from 69-196-161-189.dsl.teksavvy.com (HELO pastel.home) ([69.196.161.189]) by ironport2-out.teksavvy.com with ESMTP/TLS/ADH-AES256-SHA; 06 Jan 2014 19:37:01 -0500 Original-Received: by pastel.home (Postfix, from userid 20848) id 5B11162F04; Mon, 6 Jan 2014 19:37:01 -0500 (EST) In-Reply-To: <87eh4kg2hv.fsf@flea.lifelogs.com> (Ted Zlatanov's message of "Mon, 06 Jan 2014 17:38:20 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 206.248.154.181 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:167556 Archived-At: SM> Is that really much better than [vanilla Emacs lisp]? > Yes. The difference is huge for a beginner. I'm far from convinced. The beginner will have to learn the mykie-specific sublanguage. Maybe it's slightly simpler, but then this effort won't help him understand other code. Making it easier to customize Emacs is great, but it's better if it also gets you some way towards hacking on Emacs so as to become a contributor. Of course, there are cosmetic issues in the mykie.el syntax that rub me the wrong way. Most obvious is the need to quote code. I already spend enough time telling people not to quote their lambdas and trying to fix code that abuses `eval' in all kinds of useless ways. Starting from (mykie:global-set-key "C-j" :default '(progn (delete-trailing-whitespace) (case major-mode (org-mode (org-return-indent)) (t (newline-and-indent)))) :C-u&eolp '(fill-region (point-at-bol) (point-at-eol)) :region 'query-replace-regexp) I'd suggest to first get rid of the quotes and the `mykie:global-set-key' (so that it can be used with local-set-key, define-key, you name it): (global-set-key "C-j" (smkie :default (progn (delete-trailing-whitespace) (case major-mode (org-mode (org-return-indent)) (t (newline-and-indent)))) :C-u&eolp (fill-region (point-at-bol) (point-at-eol)) :region 'query-replace-regexp)) Then I suggest we use a parenthesized syntax, and descriptive name, to be more Lispish: (global-set-key "C-j" (sm-combined-command (:default (delete-trailing-whitespace) (case major-mode (org-mode (org-return-indent)) (t (newline-and-indent)))) (:C-u&eolp (fill-region (point-at-bol) (point-at-eol))) (:region 'query-replace-regexp))) Also, since the user knows about "t is default" from "case", we might as well get rid of ":default": (global-set-key "C-j" (sm-combined-command (:C-u&eolp (fill-region (point-at-bol) (point-at-eol))) (:region 'query-replace-regexp) (t (delete-trailing-whitespace) (case major-mode (org-mode (org-return-indent)) (t (newline-and-indent)))))) And sm-combined-command is a very simple macro: (defconst sm-combined-command-predicates '((:region . (use-region-p)) (:C-u . current-prefix-arg) (:C-u&eolp . (and current-prefix-arg (eolp))) ...)) (defmacro sm-combined-command (branches) `(lambda () (interactive) (cond ,@(mapcar (lambda (branch) `(,(or (cdr (assq (car branch) sm-combined-command-predicates)) (car branch)) ,@(pcase (cdr branch) (`(',cmd) `((call-interactively ',cmd))) (,cmds cmds)))) branches)))) -- Stefan