How can I remove trailing spaces from a piece in magite?

Emacs (post v21) includes a function to remove trailing spaces from a file. How to make delete-trailing-whitespace accessible in the intermediate area of ​​Magit (from magit-status ) so that I can remove trailing spaces from individual groups or entire files?

+6
source share
2 answers

This is a fragment of Sean configured on 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)) 
+3
source

Thanks @tarsius for your trick! I was able to tweak it to remove only trailing spaces for a line in a dot. To do this, install the ws-trim package.

 (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))) 

I bind the delete key, as this is not used for anything useful in magit-status-mode .

0
source

Source: https://habr.com/ru/post/958584/


All Articles