Function: tildify-space

tildify-space is an autoloaded, interactive and byte-compiled function defined in tildify.el.gz.

Signature

(tildify-space)

Documentation

Convert space before point into a hard space if the context is right.

If
 * character before point is a space character,
 * character before that has "w" character syntax (i.e. it's a word
   constituent),
 * tildify-space-pattern matches when looking-back (no more than 10
   characters) from before the space character, and
 * all predicates in tildify-space-predicates return non-nil,
replace the space character with value of tildify-space-string and return t.

Otherwise, if
 * tildify-double-space-undos variable is non-nil,
 * character before point is a space character, and
 * text before that is a hard space as defined by
   tildify-space-string variable,
remove the hard space and leave only the space character.

This function is meant to be used as a post-self-insert-hook.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/textmodes/tildify.el.gz
;;;###autoload
(defun tildify-space ()
  "Convert space before point into a hard space if the context is right.

If
 * character before point is a space character,
 * character before that has \"w\" character syntax (i.e. it's a word
   constituent),
 * `tildify-space-pattern' matches when `looking-back' (no more than 10
   characters) from before the space character, and
 * all predicates in `tildify-space-predicates' return non-nil,
replace the space character with value of `tildify-space-string' and
return t.

Otherwise, if
 * `tildify-double-space-undos' variable is non-nil,
 * character before point is a space character, and
 * text before that is a hard space as defined by
   `tildify-space-string' variable,
remove the hard space and leave only the space character.

This function is meant to be used as a `post-self-insert-hook'."
  (interactive)
  (let* ((p (point)) (p-1 (1- p)) (n (- p (point-min)))
         (l (length tildify-space-string)) (l+1 (1+ l))
         case-fold-search)
    (when (and (> n 2) (eq (preceding-char) ?\s))
      (cond
       ((and (eq (char-syntax (char-before p-1)) ?w)
             (save-excursion
               (goto-char p-1)
               (looking-back tildify-space-pattern (max (point-min) (- p 10))))
             (run-hook-with-args-until-failure 'tildify-space-predicates))
        (delete-char -1)
        (insert tildify-space-string)
        t)
       ((and tildify-double-space-undos
             (> n l+1)
             (string-equal tildify-space-string
                           (buffer-substring (- p l+1) p-1)))
        (goto-char p-1)
        (delete-char (- l))
        (goto-char (1+ (point)))
        nil)))))