From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Emanuel Berg Newsgroups: gmane.emacs.help Subject: cool stuff with caps-mode.el Date: Tue, 15 Oct 2013 19:32:04 +0200 Organization: Aioe.org NNTP Server Message-ID: <87siw2e8ya.fsf@nl106-137-194.student.uu.se> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1381858522 15715 80.91.229.3 (15 Oct 2013 17:35:22 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 15 Oct 2013 17:35:22 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Oct 15 19:35:25 2013 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1VW8Wi-0000NU-OM for geh-help-gnu-emacs@m.gmane.org; Tue, 15 Oct 2013 19:35:24 +0200 Original-Received: from localhost ([::1]:43209 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VW8Wi-0008UH-80 for geh-help-gnu-emacs@m.gmane.org; Tue, 15 Oct 2013 13:35:24 -0400 Original-Path: usenet.stanford.edu!news.kjsl.com!feeder.erje.net!eu.feeder.erje.net!news.mixmin.net!aioe.org!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 89 Original-NNTP-Posting-Host: /ZLK7EtDT1dvbkmVtWlLYw.user.speranza.aioe.org Original-X-Complaints-To: abuse@aioe.org User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux) X-Notice: Filtered by postfilter v. 0.8.2 Cancel-Lock: sha1:XRmpiBtuRu9K4DaAj6x3QFozep0= Mail-Copies-To: never Original-Xref: usenet.stanford.edu gnu.emacs.help:201755 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:94024 Archived-At: I made some changes to the caps-mode.el. I think the caps lock key is so big and close, it is a *waste* to use it for caps lock (which I almost never use). For acronyms, I use abbrev, so I just type them in lowercase. But sometimes, for example in C code, you need (want) to write constants in all caps (as you are used to do/read that). Then, the caps key could be useful. That's why I think caps-mode is *great* because then you could do "virtual caps" on a per-buffer basis (if you change buffer, or switch from Emacs to the shell, you don't have to 1) *remember*, and 2) actually *do* disable the caps lock). Anyway, the changes I made: 1. A wrapper to get away with that annoying confirmation message (that is especially annoying if you are in the metabuffer because then for a second it hides what you are typing). But, even cooler: 2. When you are done typing your C constant, or whatever, it automatically changes back to lowercase. Only 1-9, A-Z, a-z, and the underscore (_) will keep in the the mode. But in some rare, rare cases, perhaps you do C and you make function calls which take tons of arguments, all constants. Then you don't want to revert on "," (for example). So I made a variable and a function to disable the "auto revert" change. (Both that and the enable of the minor mode itself must be shortcutted, of course, to be useful. I left that out as all people like their own keys.) Let me know what you think. If you like the idea, feel free to implement it any way you like (of course). If not, I'm happy to have this lass all by myself :) (defvar *case-auto-revert* t) (setq *case-auto-revert* t) (defun char-alphanum-or-underscore (c) (or (eq c ?_) (and (>= c ?1) (<= c ?9)) (and (>= c ?A) (<= c ?Z)) (and (>= c ?a) (<= c ?z)) )) (defun caps-mode-self-insert-command (&optional n) (interactive "p") (let ((the-char last-command-char)) (if (and *case-auto-revert* (not (char-alphanum-or-underscore the-char)) ) (caps-mode 0)) (insert-char (upcase the-char) n) )) (defun toggle-caps-mode-auto-revert () (interactive) (setq *case-auto-revert* (not *case-auto-revert*) )) (defun toggle-caps-mode () (interactive) (if caps-mode (caps-mode 0) (caps-mode)) ) (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 "Toggle caps mode. With no argument, this command toggles the mode. Non-null prefix argument turns on the mode. Null prefix argument turns off the mode." :init-value nil :lighter " Caps") -- Emanuel Berg, programmer-for-rent. CV, projects, etc at uXu underground experts united: http://user.it.uu.se/~embe8573