[Top][All Lists]

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

lockcaps.el 0.7

From: John Paul Wallington
Subject: lockcaps.el 0.7
Date: 23 Sep 2001 02:49:42 +0100
User-agent: Gnus/5.090003 (Oort 0.03) Emacs/ (i686-pc-linux-gnu)

Changes since last version:
        Inverts case rather than forcing upper case (thanks to Deepak
        Goel for pointing out how Caps Lock normally behaves).
        Doesn't blindly assume standard case table is a char table,
        merely rather hopes it is.

;;; lockcaps.el --- caps lock mode for Emacs 

;; Copyright (C) 2001 John Paul Wallington

;; Author:  John Paul Wallington <address@hidden>
;; Created: 5 Sep 2001
;; Version: 0.7, 23 Sep 2001
;; Keywords: convenience

;; This file is not part of GNU Emacs.

;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 2, or (at
;; your option) any later version.

;; This program is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; General Public License for more details.

;;; Commentary:

;; Whilst playing with Hemlock on CMU Common Lisp I did:
;;      M-x apropos lock
;; and the first match was:
;; "Caps Lock Mode\n  Simulate having a CAPS LOCK key."
;; What a neat idea.  A Google search for capslock.el garnered:
;; capslock.el, a quick and dirty Emacs 19 caps-lock minor mode
;; by Eberhard Mattes <address@hidden>
;; dated 19-May-1993.
;; It had been done already.  Rats.  Anyway, this is my version.
;; This version implements a minor-mode keymap rather than changing 
;; the global keymap.  It doesn't need special minibuffer precautions.
;; If you (setq lockcaps-all-keys t) before loading then lockcaps
;; might apply to chars beyond a-z.

;;; Code:

(defvar lockcaps-mode nil
  "Mode variable for lockcaps minor mode.")
(make-variable-buffer-local 'lockcaps-mode)

(defvar lockcaps-all-keys nil
  "Non-nil means include all self-inserting keys, and every char of the 
standard case map (if the standard case map is a char-table), 
in `lockcaps-mode-map'.")

(defvar lockcaps-mode-map nil
  "Keymap for lockcaps minor mode.")

(unless lockcaps-mode-map
  (setq lockcaps-mode-map (make-keymap))
  (if lockcaps-all-keys
         'self-insert-command 'lockcaps-self-insert
         lockcaps-mode-map global-map)
        (when (char-table-p (standard-case-table))
           #'(lambda (key value)
               (if (< 128 key)
                   (define-key lockcaps-mode-map
                     (vector key) 'lockcaps-self-insert)))
    (let ((keys
           '(?a ?b ?c ?d ?e ?f ?g ?h ?i ?j ?k ?l ?m 
                ?n ?o ?p ?q ?r ?s ?t ?u ?v ?w ?x ?y ?z
                ?A ?B ?C ?D ?E ?F ?G ?H ?I ?J ?K ?L ?M
                ?N ?O ?P ?Q ?R ?S ?T ?U ?V ?W ?X ?Y ?Z)))
      (while keys
        (define-key lockcaps-mode-map
          (char-to-string (car keys)) 'lockcaps-self-insert)
        (setq keys (cdr keys))))))

(or (assq 'lockcaps-mode minor-mode-map-alist)
    (setq minor-mode-map-alist
          (cons (cons 'lockcaps-mode lockcaps-mode-map) 
(or (assq 'lockcaps-mode minor-mode-alist)
    (setq minor-mode-alist
          (cons '(lockcaps-mode " CAPS") minor-mode-alist)))

(defun lockcaps-mode (&optional arg)
  "Toggle lockcaps minor mode."
  (interactive "P")
  (setq lockcaps-mode
        (if (null arg)
            (not lockcaps-mode)
          (> (prefix-numeric-value arg) 0)))

(defun lockcaps-self-insert (arg)
  "Insert the character you type, inverting case."
  (interactive "*p")
  (setq last-command-char
        (if (equal (downcase last-command-char) last-command-char)
            (upcase last-command-char)
          (downcase last-command-char)))
  (self-insert-command arg))

(provide 'lockcaps)
;;; lockcaps.el ends here

John Paul Wallington

reply via email to

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