Emacs: delete whitespaces or a word

后端 未结 4 2026
故里飘歌
故里飘歌 2020-12-01 17:21

How can I configure emacs to work in the same way as other modern editors where pressing Alt+D or Alt+Backspace deletes either ad

4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-01 17:46

    This has most likely been solved before, but instead of looking for code, we can write our own. So much fun!

    This is how I would do it, hope it helps.

    (defun kill-whitespace-or-word ()
      (interactive)
      (if (looking-at "[ \t\n]")
          (let ((p (point)))
            (re-search-forward "[^ \t\n]" nil :no-error)
            (backward-char)
            (kill-region p (point)))
        (kill-word 1)))
    

    Then bind it to a key:

    (global-set-key (kbd "M-d") 'kill-whitespace-or-word)
    

提交回复
热议问题