dimanche 16 août 2015

Make delete-forward do what I mean

  • If you're on a non-space character, delete forward until the next space character.
  • If you're on a space character, delete forward until the next non-space character
(defun my-delete-space-forward ()
  (interactive)
  (let* ((char (buffer-substring-no-properties (point) (1+ (point))))
         (notspace-rx (rx (not (any "\t\n "))))
         (space-rx (rx (any "\t\n ")))
         (rx (if (string-match-p space-rx char) notspace-rx space-rx))
         (end-pos (save-excursion
                    (search-forward-regexp rx nil 'end))))

    (delete-region (point) (if end-pos (1- end-pos) (point-max)))))

Aucun commentaire:

Enregistrer un commentaire