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

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

Re: How to get the ~ functionality of vi


From: Emanuel Berg
Subject: Re: How to get the ~ functionality of vi
Date: Fri, 27 May 2016 21:37:31 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)

Cecil Westerhof <address@hidden> writes:

> The thing-at-point did not work for me.

OK, try

    (require 'thingatpt)

first.

It is a useful thing even tho your code is
perhaps (?) better in this case.

> I like to flip a lot of characters in one
> swell swoop.

OK, you can use the C-u prefix to do that.

So `C-c f'         is 4^0 = 1,
   `C-u C-c f'     is 4^1 = 4,
   `C-u C-u C-c f' is 4^2 = 16, and so on; and
   `C-u x C-c f'   is x!

This can be implemented like this:

    (require 'cl-macs)

    (defun flip-case (times)
      (interactive "p")
      (cl-dotimes (_ times)
        (let ((c (string-to-char (thing-at-point 'char t))))
          (delete-char 1)
          (cond ((and (>= c ?A) (<= c ?Z)) (insert-char (downcase c)))
                ((and (>= c ?a) (<= c ?z)) (insert-char (upcase c)))
                (t                         (insert-char c)))) ))

    (global-set-key "\C-cf" #'flip-case)

-- 
underground experts united .... http://user.it.uu.se/~embe8573
Emacs Gnus Blogomatic ......... http://user.it.uu.se/~embe8573/blogomatic
                   - so far: 42 Blogomatic articles -                   


reply via email to

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