From: Cecil Westerhof <Cecil@decebal.nl>
To: help-gnu-emacs@gnu.org
Subject: Re: How to get the ~ functionality of vi
Date: Fri, 27 May 2016 10:54:17 +0200 [thread overview]
Message-ID: <87eg8n51ae.fsf@Equus.decebal.nl> (raw)
In-Reply-To: 87pos8p1js.fsf@elfie.nowhere.com
On Friday 27 May 2016 06:28 CEST, Jean-Jacques Rétorré wrote:
> ven. 27 mai 2016, Emanuel Berg <embe8573@student.uu.se> disait :
>
>> Cecil Westerhof <Cecil@decebal.nl> 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))) ) )
I expected that there was a function I overlooked, but I did not.
Luckily it is easy to add the missing functionality in Emacs. :-D
The thing-at-point did not work for me. I rewrote it to:
(defun flip-case ()
(interactive)
(let ((c (char-after)))
(when c
(delete-char 1)
(insert-char
(if (eq c (upcase c))
(downcase c)
(upcase c))))))
I also added a check for there being a current character.
For the keyboard shortcut I use:
(global-set-key (kbd "C-~") 'flip-case)
I like to flip a lot of characters in one swell swoop.
Thanks for putting me in the right direction.
--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
next prev parent reply other threads:[~2016-05-27 8:54 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-26 22:36 How to get the ~ functionality of vi Cecil Westerhof
2016-05-27 1:15 ` Emanuel Berg
2016-05-27 4:28 ` Jean-Jacques Rétorré
2016-05-27 8:54 ` Cecil Westerhof [this message]
2016-05-27 11:33 ` Thorsten Bonow
2016-05-27 19:41 ` Emanuel Berg
2016-06-02 16:14 ` Kaushal Modi
[not found] ` <mailman.703.1464884068.1216.help-gnu-emacs@gnu.org>
2016-06-02 17:15 ` Emanuel Berg
2016-06-02 17:28 ` Kaushal Modi
[not found] ` <mailman.715.1464888555.1216.help-gnu-emacs@gnu.org>
2016-06-02 20:39 ` Emanuel Berg
2016-06-02 21:00 ` Kaushal Modi
2016-06-03 5:07 ` Marcin Borkowski
[not found] ` <mailman.730.1464901264.1216.help-gnu-emacs@gnu.org>
2016-06-02 21:07 ` Emanuel Berg
2016-06-03 9:21 ` Joost Kremers
2016-06-03 10:51 ` Emanuel Berg
2016-05-27 19:37 ` Emanuel Berg
2016-05-27 19:37 ` Emanuel Berg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87eg8n51ae.fsf@Equus.decebal.nl \
--to=cecil@decebal.nl \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.