Skip to content

Instantly share code, notes, and snippets.

@enisozgen
Created September 17, 2019 20:48
Show Gist options
  • Save enisozgen/c04370e7b6d736657364d0c83f57d941 to your computer and use it in GitHub Desktop.
Save enisozgen/c04370e7b6d736657364d0c83f57d941 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))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment