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: Jean-Jacques Rétorré
Subject: Re: How to get the ~ functionality of vi
Date: Fri, 27 May 2016 06:28:23 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)

ven. 27 mai 2016,  Emanuel Berg <address@hidden> disait :

> Cecil Westerhof <address@hidden> writes:
>
>> In vi you can use ~ to flip the case of
>> a character. Does Emacs has something
>> like that?
>
> Try this:
>
>     (defun flip-case ()
>       (interactive)
>       (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)

That won't work for accented chars.
Probably this should :

(defun flip-case ()
  (interactive)
  (let ((c (string-to-char (thing-at-point 'char t))))
    (delete-char 1)
    (insert-char
        (if (eq c (upcase c))
         (downcase c)
         (upcase c))) ) )

--
JJR.


reply via email to

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