From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Kaushal Modi Newsgroups: gmane.emacs.help Subject: Re: How to get the ~ functionality of vi Date: Thu, 02 Jun 2016 16:14:12 +0000 Message-ID: References: <87shx44fbk.fsf@Equus.decebal.nl> <86h9dkfghn.fsf@student.uu.se> <87pos8p1js.fsf@elfie.nowhere.com> <87eg8n51ae.fsf@Equus.decebal.nl> <877fefg2h0.fsf@talkietoaster.mmweg.rwth-aachen.de> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1464886669 7392 80.91.229.3 (2 Jun 2016 16:57:49 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 2 Jun 2016 16:57:49 +0000 (UTC) To: Thorsten Bonow , help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Jun 02 18:57:44 2016 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 1b8VwF-0001Dv-Ql for geh-help-gnu-emacs@m.gmane.org; Thu, 02 Jun 2016 18:57:44 +0200 Original-Received: from localhost ([::1]:49170 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8VwF-0005aT-2f for geh-help-gnu-emacs@m.gmane.org; Thu, 02 Jun 2016 12:57:43 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54498) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8VGL-0000rV-SK for help-gnu-emacs@gnu.org; Thu, 02 Jun 2016 12:14:27 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b8VGJ-0000vP-2q for help-gnu-emacs@gnu.org; Thu, 02 Jun 2016 12:14:24 -0400 Original-Received: from mail-oi0-x234.google.com ([2607:f8b0:4003:c06::234]:33987) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8VGI-0000vJ-S6 for help-gnu-emacs@gnu.org; Thu, 02 Jun 2016 12:14:22 -0400 Original-Received: by mail-oi0-x234.google.com with SMTP id e72so84978762oib.1 for ; Thu, 02 Jun 2016 09:14:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=L2stwCxW+orN9V82VhNFDPNTJ1MiPUcNqVOt+ioJ2wo=; b=lWetjxdSlpZn7MqybyS2wN+U32BhBSBeX6iLe8o/kbVDXkpxZyJh4ysJpAqlMx2DOU wEMUlPxnoXLhV1IeL8iJuNUmg3HlE+fzZbZZTfEMWNtvAyBAvTyOb68d26f0JpUA9npJ CE3Jl0fs1C4kBHs66mmJze/vHJQmJ8ILbHX0pslrfqq9tOczgq7BZkZyayFui46gVj9Y rXguPu5TlFL34SOTUfWO0E7nxAwmTNRzX3go/69nC2Gj03xUzqkmgG53wSR3ZRCqINY4 yckYrtteEvvs8mjyTW/31Gs0PnErEK/+KHjDefMYtYOJS3lxZNk9k+hHVsayHT0VBXRa C0yA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=L2stwCxW+orN9V82VhNFDPNTJ1MiPUcNqVOt+ioJ2wo=; b=EmNymBNT9tNhk1+cBCFygUnRgKKufeX1YNjXc0UZ2mKVqZvQ7+xVUL2IA1AX8A3C/e 8dKG4icWwg1p5Ev9YaYWvx9PEpcOqk/SP7Kfcpypsjk+IdXG0LBYowfgjrKMAPdTHu/y PG59sQmbJkOgS2j6Di8UEzdj8+dndDXxPDLlgm5J/mg2dZwE10rL4KB+Zar1EmRAWMCp 6iUdVEboig/O3J5/aP+yk4pZ0rOleOXlL4whItVXfmA6jVTtGbMPxkca/5oIBHQjLqgw uAWsYrs8A+NLsyjZHZEcO82UQ1soWEr+MwZ9QJvVlVKne0G0hL0WXTQwYT7gDFaHvKYR tYmA== X-Gm-Message-State: ALyK8tIShPaqupw62E8I+9h9XJ2DzzbBKpL0GxUSajL0IPo2RK+rl6e1N7VI1neMzAG8Ll6Wdd69mwm8rr+zSA== X-Received: by 10.202.239.132 with SMTP id n126mr27858601oih.98.1464884062323; Thu, 02 Jun 2016 09:14:22 -0700 (PDT) In-Reply-To: <877fefg2h0.fsf@talkietoaster.mmweg.rwth-aachen.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:4003:c06::234 X-Content-Filtered-By: Mailman/MimeDel 2.1.21 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 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" Xref: news.gmane.org gmane.emacs.help:110259 Archived-At: Check out http://ergoemacs.org/emacs/modernization_upcase-word.html Here is my implementation based off that [1]. (needs use-package, hydra and region-bindings-mode packages: all of which I consider as good as core packages) (defun xah-cycle-letter-case (arg) "Cycle the letter case of the selected region or the current word. Cycles from 'lower' -> 'Capitalize' -> 'UPPER' -> 'lower' -> .. C-u M-x xah-cycle-letter-case -> Force convert to upper case. C-u C-u M-x xah-cycle-letter-case -> Force convert to lower case. C-u C-u C-u M-x xah-cycle-letter-case -> Force capitalize." (interactive "p") (let (p1 p2 (deactivate-mark nil) (case-fold-search nil)) (if (use-region-p) (setq p1 (region-beginning) p2 (region-end)) (let ((bds (bounds-of-thing-at-point 'word))) (setq p1 (car bds) p2 (cdr bds)))) (cl-case arg (4 (put this-command 'next-state "UPPER")) ; Force convert to upper case (16 (put this-command 'next-state "lower")) ; Force convert to lower case (64 (put this-command 'next-state "Capitalize")) ; Force capitalize (t (when (not (eq last-command this-command)) (save-excursion (goto-char p1) (cond ;; lower -> Capitalize ((looking-at "[[:lower:]]") (put this-command 'next-state "Capitalize")) ;; Capitalize -> UPPER ((looking-at "[[:upper:]][[:lower:]]") (put this-command 'next-state "UPPER")) ;; Default: UPPER -> lower (t (put this-command 'next-state "lower"))))))) (cl-case (string-to-char (get this-command 'next-state)) ; `string-to-char' returns first character in string (?U (upcase-region p1 p2) ;; UPPER -> lower (put this-command 'next-state "lower")) (?l (downcase-region p1 p2) ;; lower -> Capitalize (put this-command 'next-state "Capitalize")) ;; Capitalization is a better option here than upcasing the initials ;; because (upcase-initials "abc") -> "Abc" (good) ;; (upcase-initials "ABC") -> "ABC" (not what I expect most of the times) ;; (capitalize "abc") -> "Abc" (good) ;; (capitalize "ABC") -> "Abc" (good) (t (capitalize-region p1 p2) ;; Capitalize -> UPPER (put this-command 'next-state "UPPER"))))) (defun modi/upcase () (interactive) (xah-cycle-letter-case 4)) (defun modi/downcase () (interactive) (xah-cycle-letter-case 16)) (defun modi/capitalize () (interactive) (xah-cycle-letter-case 64)) (bind-keys :map region-bindings-mode-map ("~" . xah-cycle-letter-case)) (defhydra hydra-change-case (:color blue :hint nil) " _C_apitalize _U_PCASE _d_owncase __ =E2=86=92Cap= =E2=86=92UP=E2=86=92down=E2=86=92 " ("C" modi/capitalize) ("c" modi/capitalize) ("U" modi/upcase) ("u" modi/upcase) ("d" modi/downcase) ("l" modi/downcase) ("" xah-cycle-letter-case :color red) ("M-c" xah-cycle-letter-case :color red) ("q" nil "cancel" :color blue)) [1]: https://github.com/kaushalmodi/.emacs.d/blob/aae4262ef4ddb6834683f1c72c5615= 3261b779d5/setup-files/setup-editing.el#L688 On Thu, Jun 2, 2016 at 12:06 PM Thorsten Bonow < thorsten.bonow@withouthat.org> wrote: > >>>>> Cecil Westerhof writes: > > > Cecil Westerhof writes: > > > In vi you can use ~ to flip the case of a character. Does Emacs has > something > > like that? > > Hi, > > "viper", the vi emulation already included has `viper-toggle-case'. > > So what about this? > > (require 'viper); loading viper but not enabling it > (global-set-key "\C-cf" 'viper-toggle-case) > > If you don't mind the overhead of loading the whole package for just one > function. But you don't have to reinvent the wheel and use a maintained > defun. > > Toto > > -- > Sent from my GNU Emacs running on GNU/Linux > --=20 --=20 Kaushal Modi