emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] externals/caps-lock ce94899 1/2: * caps-lock: New package.


From: Stefan Monnier
Subject: [elpa] externals/caps-lock ce94899 1/2: * caps-lock: New package.
Date: Tue, 1 Dec 2020 15:20:21 -0500 (EST)

branch: externals/caps-lock
commit ce94899c7619e748e8a811ad8cdeb09918e7ecd8
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>

    * caps-lock: New package.
---
 caps-lock.el | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/caps-lock.el b/caps-lock.el
new file mode 100644
index 0000000..24729a4
--- /dev/null
+++ b/caps-lock.el
@@ -0,0 +1,50 @@
+;;; caps-lock.el --- Caps-lock as a minor mode       -*- lexical-binding: t -*-
+
+;; Copyright (C) 2014  Free Software Foundation, Inc.
+
+;; Author: Stefan Monnier <monnier@iro.umontreal.ca>
+;; Version: 1.0
+
+;; 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 3 of the License, 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.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;;; Code:
+
+(defvar caps-lock-commands
+  '(self-insert-command isearch-printing-char)
+  "List of commands that are subject to `caps-lock-mode'.")
+
+;;;###autoload
+(define-minor-mode caps-lock-mode
+  "Make self-inserting keys invert the capitalization."
+  :global t
+  (if caps-lock-mode
+      (add-hook 'pre-command-hook #'caps-lock--pch)
+    (remove-hook 'pre-command-hook #'caps-lock--pch)))
+
+(defun caps-lock--pch ()
+  (when (and (characterp last-command-event)
+             (or (memq this-command caps-lock-commands)
+                 (eq this-command (key-binding [remap self-insert-command]))))
+    (setq last-command-event
+          (condition-case nil
+              (let ((up (upcase last-command-event)))
+                (if (eq up last-command-event)
+                    (downcase last-command-event)
+                  up))
+            (error last-command-event)))))
+
+(provide 'caps-lock)
+;;; caps-lock.el ends here



reply via email to

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