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

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

Re: input methods for mathematical glyphs


From: Emanuel Berg
Subject: Re: input methods for mathematical glyphs
Date: Wed, 08 Dec 2021 19:43:32 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

> My second thought is a virtual keyboard and a shortcut to
> enable it (say `C-h g' for "CHange to Greek" :)), that
> keyboard will then take over the normal keyboard so if you
> press 'd' a downcase delta will be inserted (and so on), and
> either it will automatically go back to the normal keyboard
> at that point after insertion, _or_ you'd have to do `C-h g'
> again for it to return ...

If you like this idea, it can be done easily (I think) based
on this:

;;; caps-back.el --- one-keystroke word pre-capitalizer -*- lexical-binding: t 
-*-
;;;
;;; Commentary:
;;;
;;; Author: Emanuel Berg (incal) <moasenwood@zoho.eu>
;;; Created: 2021-05-23
;;; Keywords: caps lock key
;;; License: GPL3+
;;; URL: https://dataswamp.org/~incal/emacs-init/caps-back.el
;;; Version: 2.0.0
;;;
;;; This minor mode capitalizes the entire next word that is
;;; typed, at the same time as it is typed, then quietly
;;; disables itself at the word boundary.
;;;
;;; For this to work efficiently, a short and close keystroke,
;;; optimally a single key, should be assigned to invoke the
;;; minor mode, which happens with the
;;; `toggle-caps-mode' function.
;;;
;;; Setup a shortcut like this:
;;;
;;;   (global-set-key KEY #'toggle-caps-mode)
;;;
;;; Then, hit \\[toggle-caps-mode] and type one and only one
;;; WORD in caps.
;;;
;;; Code:

(defun char-alphanum-or-dash (c)
  "True if C is a character, a number, or a dash."
  (or (eq c ?-)
      (member c '(?å ?Å ?ä ?Ä ?ö ?Ö))
      (and (>= c ?1) (<= c ?9))
      (and (>= c ?A) (<= c ?Z))
      (and (>= c ?a) (<= c ?z)) ))

(defun caps-mode-self-insert-command (n)
  "Insert the `last-command-event' char N times.
Uppercase unless something else than an alphanum or a dash."
  (interactive "p")
  (let*((the-char last-command-event)
        (alphanum-or-dash (char-alphanum-or-dash the-char)))
    (if alphanum-or-dash
        (insert-char (upcase the-char) n)
      (caps-mode 0)
      (insert-char the-char n) )))

(defvar caps-mode-map
  (let ((map (make-keymap)))
    (substitute-key-definition #'self-insert-command
                               #'caps-mode-self-insert-command
                               map global-map)
    map) )

(define-minor-mode caps-mode
  "Caps on you."
  :init-value nil
  :lighter " Caps")

(defun toggle-caps-mode ()
  "Toggle Caps mode."
  (interactive)
  (caps-mode 'toggle) )

(provide 'caps-back)
;;; caps-back.el ends here

-- 
underground experts united
https://dataswamp.org/~incal




reply via email to

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