[Top][All Lists]

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

lockcaps.el 0.5

From: John Paul Wallington
Subject: lockcaps.el 0.5
Date: 12 Sep 2001 17:52:26 +0100
User-agent: Gnus/5.090003 (Oort 0.03) Emacs/ (i686-pc-linux-gnu)

Apologies for repeatedly posting.

;;; 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.5, 12 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, all self-inserting 
;; keys are upcase-d, and LEIM methods might work.

;;; 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 some others,
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)
        (let ((key 128))
          (while (< key 255)
            (define-key lockcaps-mode-map 
              (vector key) 'lockcaps-self-insert)
          (setq key (1+ key)))))
    (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)))
      (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 a character in upper case."
  (interactive "*p")
  (setq last-command-char (upcase last-command-char))
  (self-insert-command arg))

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

John Paul Wallington

Yow!  Are we wet yet?

reply via email to

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