how to set a kill string length criterion for storing in kill ring

1

Is there a way to tell emacs ignore kill that are less than 4 characters long? It is quite annoying to have a lot of single character kills in evil mode. Thank you!

godblessfq

Posted 2015-04-12T22:28:21.560

Reputation: 331

2I suspect that you will need to track down the relevant functions you are using to add data to the kill-ring -- e.g., kill-new and kill-region -- and modify those functions. There is no simple length variable I am aware of that permits a user to specify a certain minimum length before data is added to the kill-ring. Other alternatives include modifying specific functions that are in turn calling other functions responsible for saving information to the kill-ring (which in turn may be using kill-new or kill-region). – lawlist – 2015-04-12T23:24:30.817

So we can add a advice to those functions.Thank you! – godblessfq – 2015-04-13T15:29:30.697

1Dunno why someone downvoted you. I think this kind of question is helpful. My suggestion would be to send an enhancement request (M-x report-emacs-bug) asking for a hook of filter functions, to be able to control what gets added as a kill. In Emacs 23 they added option kill-do-not-save-duplicates, for example, which is good. But it would be good for users to be able to further discriminate wrt what gets added to the kill-ring. Instead of adding an option for each such possibility (e.g., for your case, kill-ring-entry-length), we should be able to add a filter function to a hook. – Drew – 2015-04-15T18:12:35.320

Answers

1

The filter mechanism is already in 24.4. Thanks to glucas. https://emacs.stackexchange.com/questions/8097/how-do-i-filter-kill-ring-contents

(defvar kill-ring-entry-length 3)
(defun my/replace-blank-kill (args)
  (let ((string (car args))
        (replace (cdr args))
        (last (car-safe kill-ring)))
    (when (or (and last (string-blank-p last))
           (< (length last) kill-ring-entry-length))
      (setq replace t))
    (list string replace)))

(advice-add 'kill-new :filter-args #'my/replace-blank-kill)

godblessfq

Posted 2015-04-12T22:28:21.560

Reputation: 331