[Top][All Lists]

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

Re: caps-mode.el

From: Kevin Rodgers
Subject: Re: caps-mode.el
Date: Mon, 09 Aug 2004 10:19:51 -0600
User-agent: Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv: Gecko/20020406 Netscape6/6.2.2

Christoph Conrad wrote:
> i was just curious if there is a shorter notation, and found that 26
> lines
>>(lambda () (interactive) (insert (string-to-char "A")))) ("b" .
> could be replaced by:
>   :keymap
>   (mapcar
>    (lambda(char) `(,(char-to-string char) .
>                    (lambda() (interactive) (insert (upcase ,char)))))
>   "abcdefghijklmnopqrstuvwxyz"))

Note this recommendation in define-minor-mode's doc string:

| Optional KEYMAP is the default (defvar) keymap bound to the mode keymap.
|   If it is a list, it is passed to `easy-mmode-define-keymap'
|   in order to build a valid keymap.  It's generally better to use
|   a separate MODE-map variable than to use this argument.

So eliminate the :keymap LIST altogether:

(defun caps-mode-self-insert-command (&optional n)
  "Like `self-insert-command', but uppercase the the typed character."
  (interactive "p")
  (let ((upcase-char (upcase last-command-char)))
    (insert (if (n > 1)
                (make-string n upcase-char)

(defvar caps-mode-keymap
  (let ((map (make-sparse-keymap)))
    (mapc (lambda (char)
            (define-key map 'caps-mode-self-insert-command))

Kevin Rodgers

reply via email to

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