Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs - Skip whitespace kills

I'm trying to make the kill ring essentially ignore whitespace only entries (tabs, newlines, just spaces, etC), I'm fairly new to elisp and I'm pretty sure the way to do is by doing defadvice but I have a few questions.

  • Would it better to stop whitespace entries from ever getting into the kill ring in the first place, or to skip them on yank? I assumed the latter.

In which case, I'm completely lost on which function I should advise, its between current-kill, yank, and insert-for-yank - but am not entirely sure which I should manipulate to not yank whitespace from the kill ring.

Thanks!

EDIT: I'm pretty sure the way to do this is to manipulate `current-kill' to keep calling itself until it reaches a non whitespace entry? (or the end of the ring, whichever comes first)

like image 855
user652650 Avatar asked Oct 07 '22 20:10

user652650


2 Answers

From the comments it seems that you are having problems with whitespaces in your kill-ring since you kill whitespace lines. My solution would be to avoid killing whitespace lines and to use the function delete-blank-line (C-x C-o) instead. This reduces a group a blank lines (including whitespaces and tabs) to a single blank line.

like image 61
Nicolas Dudebout Avatar answered Oct 10 '22 03:10

Nicolas Dudebout


I wrote a package clean-kill-ring.el that provides functionality for controlling what is allowed in the kill ring.

By default enabling clean-kill-ring-mode prevents blank strings from entering the kill ring, but further customization is possible as well.

like image 32
Nicholas Hubbard Avatar answered Oct 10 '22 03:10

Nicholas Hubbard