[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: mykie.el
From: |
Stefan Monnier |
Subject: |
Re: mykie.el |
Date: |
Mon, 06 Jan 2014 19:37:01 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) |
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
- Re: enable MELPA & Marmalade by defaul [was: mykie.el], (continued)
Re: mykie.el, Stefan Monnier, 2014/01/03
- Re: mykie.el, Leo Liu, 2014/01/04
- Re: mykie.el, Mitchel Humpherys, 2014/01/05
- Re: mykie.el, Nicolas Richard, 2014/01/06
- Re: mykie.el, Ted Zlatanov, 2014/01/06
- Re: mykie.el,
Stefan Monnier <=
- Re: mykie.el, Ted Zlatanov, 2014/01/07
- Re: mykie.el, Stefan Monnier, 2014/01/07
- Re: mykie.el, Ted Zlatanov, 2014/01/08
- Re: mykie.el, Stefan Monnier, 2014/01/08
- Re: mykie.el, Ted Zlatanov, 2014/01/08
- Re: mykie.el, Stefan Monnier, 2014/01/08
- Re: mykie.el, Tassilo Horn, 2014/01/09
- Re: mykie.el, Stefan Monnier, 2014/01/09
- Re: mykie.el, Yuta Yamada, 2014/01/09
- Re: mykie.el, Yuta Yamada, 2014/01/11