[Top][All Lists]

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

cool stuff with caps-mode.el

From: Emanuel Berg
Subject: cool stuff with caps-mode.el
Date: Tue, 15 Oct 2013 19:32:04 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux)

I made some changes to the caps-mode.el.

I think the caps lock key is so big and close, it is a
*waste* to use it for caps lock (which I almost never

For acronyms, I use abbrev, so I just type them in

But sometimes, for example in C code, you need (want)
to write constants in all caps (as you are used to
do/read that). Then, the caps key could be
useful. That's why I think caps-mode is *great* because
then you could do "virtual caps" on a per-buffer basis
(if you change buffer, or switch from Emacs to the
shell, you don't have to 1) *remember*, and 2) actually
*do* disable the caps lock).

Anyway, the changes I made:

1. A wrapper to get away with that annoying
confirmation message (that is especially annoying if
you are in the metabuffer because then for a second it
hides what you are typing).

But, even cooler:

2. When you are done typing your C constant, or
whatever, it automatically changes back to
lowercase. Only 1-9, A-Z, a-z, and the underscore (_)
will keep in the the mode.

But in some rare, rare cases, perhaps you do C and you
make function calls which take tons of arguments, all
constants. Then you don't want to revert on "," (for
example). So I made a variable and a function to
disable the "auto revert" change.

(Both that and the enable of the minor mode itself must
be shortcutted, of course, to be useful. I left that
out as all people like their own keys.)

Let me know what you think. If you like the idea, feel
free to implement it any way you like (of course). If
not, I'm happy to have this lass all by myself :)

(defvar *case-auto-revert* t)
(setq *case-auto-revert* t)

(defun char-alphanum-or-underscore (c)
  (or (eq c ?_)
      (and (>= c ?1) (<= c ?9))
      (and (>= c ?A) (<= c ?Z))
      (and (>= c ?a) (<= c ?z)) ))

(defun caps-mode-self-insert-command (&optional n)
  (interactive "p")
  (let ((the-char last-command-char))
    (if (and *case-auto-revert*
             (not (char-alphanum-or-underscore the-char)) )
        (caps-mode 0))
    (insert-char (upcase the-char) n) ))

(defun toggle-caps-mode-auto-revert ()
  (setq *case-auto-revert* (not *case-auto-revert*) ))

(defun toggle-caps-mode ()
  (if caps-mode (caps-mode 0) (caps-mode)) )

(defvar caps-mode-map
  (let ((map (make-keymap)))
    (substitute-key-definition 'self-insert-command
                               map global-map)
    map) )

(define-minor-mode caps-mode
  "Toggle caps mode.
With no argument, this command toggles the mode.
Non-null prefix argument turns on the mode.  Null
prefix argument turns off the mode."
  :init-value nil
  :lighter " Caps")

Emanuel Berg, programmer-for-rent. CV, projects, etc at uXu
underground experts united:

reply via email to

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