Emacs(v21后)包含来自文件的delete trailing whitespace函数。我如何在Magit临时区域(delete-trailing-whitespace
)中提供magit-status
,以便我可以删除单个黑客或整个文件中的尾随空格?
答案 0 :(得分:3)
这是Sean的片段,根据Magit v2进行了调整:
(defun my-magit-delete-trailing-whitespace-from-file ()
"Remove whitespace from the current file."
(interactive)
(save-excursion
(magit-diff-visit-file-worktree (magit-file-at-point))
(delete-trailing-whitespace)
(save-buffer)
(kill-buffer))
(magit-refresh))
答案 1 :(得分:0)
感谢@ tarsius的精彩演绎!我设法调整它以删除线上的尾随空格。这需要' ws-trim'包已安装。
(defun my-magit-delete-trailing-whitespace ()
"Remove whitespace from the current file."
(interactive)
(save-excursion
(magit-diff-visit-file-worktree (magit-file-at-point))
(ws-trim-line nil)
(save-buffer)
(kill-buffer))
(magit-refresh))
(add-hook 'magit-status-mode-hook
(lambda ()
(local-set-key [deletechar] 'my-magit-delete-trailing-whitespace)))
我绑定了删除键,因为它不会用于magit-status-mode
中有用的任何内容。