elisp - How to toggle letter cases in a region in emacs -


how can toggle case of letters (switch uppercase letters lowercase , lowercase letters uppercase) of region's text in emacs?

there listed commands conversion nothing toggling.

example:

please toggle letter case

should become:

please toggle letter case

i wrote you; did not have thorough testing, appears seek.

the logic behind loop on every single character in text. if character equal character in downcase, append return string in upcase. if not, append in downcase. @ end, delete region , insert return string.

it works immediate on page of text, though i'd wary use on huge texts (should fine still).

(defun toggle-case ()   (interactive)   (when (region-active-p)     (let ((i 0)       (return-string "")       (input (buffer-substring-no-properties (region-beginning) (region-end))))       (while (< (- (region-end) (region-beginning)))     (let ((current-char (substring input (+ 1))))       (if (string= (substring input (+ 1)) (downcase (substring input (+ 1))))           (setq return-string             (concat return-string (upcase (substring input (+ 1)))))         (setq return-string           (concat return-string (downcase (substring input (+ 1)))))))     (setq (+ 1)))       (delete-region (region-beginning) (region-end))       (insert return-string)))) 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -