Skip to content

Instantly share code, notes, and snippets.

@enisozgen
Created September 17, 2019 20:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enisozgen/dc7aff180d2ecf6824055fe47de0d437 to your computer and use it in GitHub Desktop.
Save enisozgen/dc7aff180d2ecf6824055fe47de0d437 to your computer and use it in GitHub Desktop.
# Works as famous command which is exist in simple.el
# https://github.com/emacs-mirror/emacs/blob/cbc10ec71e9f189e8d6fd5c6927aec4872e0fd96/lisp/simple.el#L957
# + Feature that I implement for function is you can select text as region than it will delete spaces if it's more than 1.
# - Feature: Base function allows you leave (n)Space I don't need this, so it is not exist.
(defun just-one-space-region (begin end)
"Deletes whitespaces for selected region if they more than one"
(interactive "r")
(if (use-region-p)
(save-excursion
(narrow-to-region begin end)
(goto-char (point-min))
(while (search-forward-regexp " " (point-max) 'NOERROR)
(progn
(fixup-whitespace)
(forward-char)))
(widen)))
(fixup-whitespace))
@enisozgen
Copy link
Author

There is currently some bug in the code. I'll update for later.

Sentence:Original `Problem is here`  >> Example example
Expected: Sentence `Problem is here` >> Example example
Result: Sentence `problem is here`>> Example example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment