gnu-emacs-sources
[Top][All Lists]
Advanced

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

lockcaps.el 0.4


From: John Paul Wallington
Subject: lockcaps.el 0.4
Date: 11 Sep 2001 19:06:44 +0100
User-agent: Gnus/5.090003 (Oort 0.03) Emacs/21.0.104.1 (i686-pc-linux-gnu)

I'm trying to get lockcaps.el to work for LEIM users.  It appears to work
for me using the french-azerty input method on GNU Emacs 21.

Any comments, fixes and improvements are much appreciated.


;;; 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.4, 11 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
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;; 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
      (progn
        (substitute-key-definition
         'self-insert-command 'lockcaps-self-insert
         lockcaps-mode-map global-map)
        ;; brain-damage follows...
        (let ((key 129))
          (while (< key 256)
            (global-set-key (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) 
                minor-mode-map-alist)))
(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)))
  (force-mode-line-update))
  

(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

Send your questions to ``ASK ZIPPY'', Box 40474,
 San Francisco, CA 94140, USA



reply via email to

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