emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: mykie.el


From: Stefan Monnier
Subject: Re: mykie.el
Date: Fri, 03 Jan 2014 23:34:01 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

> Here's an example of context-dependent usage:

> (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)

> (many other keywords are available, e.g. :prog for activating only in
> programming modes)

Is that really much better than:

  (global-set-key "\C-j"
     (lambda ()
       (interactive)
       (cond
        (current-prefix-arg (fill-region (point-at-bol) (point-at-eol)))
        ((and (use-region-p) (eolp))
         (call-interactively 'query-replace-regexp))
        (t
         (delete-trailing-whitespace)
         (case major-mode
           (org-mode (org-return-indent))
           (t        (newline-and-indent)))))))

IIUC the need for "context dependent bindings" becomes more interesting
when you want the different cases to be specified independently.
As in

  (my-global-set-key "\C-j"
                     :predicate current-prefix-arg
                     :action (fill-region (point-at-bol) (point-at-eol)))

  (my-global-set-key "\C-j"
                     :predicate (and (use-region-p) (eolp))
                     :action 'query-replace-regexp)

I'm not sure exactly how best to do that, tho.


        Stefan



reply via email to

[Prev in Thread] Current Thread [Next in Thread]