Function: just-one-space

just-one-space is an interactive and byte-compiled function defined in simple.el.gz.

Signature

(just-one-space &optional N)

Documentation

Delete all spaces and tabs around point, leaving one space (or N spaces).

Interactively, N is the prefix numeric argument. If N is negative, delete newlines as well, leaving -N spaces. See also cycle-spacing.

View in manual

Probably introduced at or before Emacs version 22.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/simple.el.gz
(defun just-one-space (&optional n)
  "Delete all spaces and tabs around point, leaving one space (or N spaces).
Interactively, N is the prefix numeric argument.
If N is negative, delete newlines as well, leaving -N spaces.
See also `cycle-spacing'."
  (interactive "*p")
  (let ((orig-pos        (point))
        (skip-characters (if (and n (< n 0)) " \t\n\r" " \t"))
        (num             (abs (or n 1))))
    (skip-chars-backward skip-characters)
    (constrain-to-field nil orig-pos)
    (let* ((num   (- num (skip-chars-forward " " (+ num (point)))))
           (mid   (point))
           (end   (progn
                    (skip-chars-forward skip-characters)
                    (constrain-to-field nil orig-pos t))))
      (delete-region mid end)
      (insert (make-string num ?\s)))))