[Top][All Lists]

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

lockcaps.el 0.8

From: John Paul Wallington
Subject: lockcaps.el 0.8
Date: 25 Sep 2001 04:19:52 +0100
User-agent: Gnus/5.090003 (Oort 0.03) Emacs/ (i686-pc-linux-gnu)

Changes since last version:
        Inversion of case vs. forcing upper case is a user option
        (thanks to Jeff Dwork for suggesting this).
        First stab at using custom; customizing lockcaps-all-keys
        doesn't immediately rebuild lockcaps-mode-map, which is bad
        form... suggestions gladly received.

;;; 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.8, 25 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:

;; Simulates Caps Lock.  Inspired by Hemlock on CMU Common Lisp and
;; capslock.el, a quick and dirty Emacs 19 caps-lock minor mode
;; by Eberhard Mattes <address@hidden>.

;; Thanks to:
;; Pavel Janík for suggesting supporting input methods, although the
;; resultant brain-damage is entirely my fault.
;; Deepak Goel for suggesting inverting case rather than forcing upper case.
;; Jeff Dwork for suggesting making inverting/forcing an option.

;;; Code:

(defgroup lockcaps nil
  "Simulate Caps Lock"
  :group 'convenience)

(defcustom lockcaps-all-keys nil
  "*Simulate Caps Lock for a-z only or other characters too."
  :type '(choice (const :tag "a-z only" nil)
                 (const :tag "Other characters too" t))
  :group 'lockcaps)

(defcustom lockcaps-invert nil
  "*Using Shift with lockcaps inverts case or forces upper case."
  :type '(choice (const :tag "Invert case" t)
                 (const :tag "Force upper case" nil))           
  :group 'lockcaps)

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

(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 (< 127 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, simulating Caps Lock."
  (interactive "*p")
  (setq last-command-char
        (if lockcaps-invert
            (if (equal (downcase last-command-char) last-command-char)
                (upcase last-command-char)
              (downcase last-command-char))
          (upcase 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]