From d794fe152ad0df2f50be5726b05f966c433278bd Mon Sep 17 00:00:00 2001 From: Jacopo De Simoi Date: Fri, 8 Jun 2018 00:49:10 -0400 Subject: [PATCH] Improve kill-word --- global.org | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/global.org b/global.org index 0a22b00..35a27e2 100644 --- a/global.org +++ b/global.org @@ -1070,6 +1070,40 @@ (emacs-lisp-docstring-fill-column t)) (fill-paragraph nil region))) #+END_SRC +** kill-word + dwim manage space after kill-word. This has been pasted from [[https://www.reddit.com/r/emacs/comments/3nlws0/automanage_spaces_post_word_kills/][this reddit post]]. + #+BEGIN_SRC emacs-lisp + (defun modi/just-one-space-post-kill-word (&rest _) + "Function to manage white space after `kill-word' operations. + + 1. If point is at the beginning of the line after possibly some white space, + remove that white space and re-indent that line. + 2. If there is space before or after the point, ensure that there is only + one white space around the point. + 3. Otherwise, do nothing. + + During the whole operation do not change the point position with respect to the + surrounding white space. + + abc| def ghi <-- point on the left of white space after 'abc' + abc| ghi <-- point still before white space after calling this function + abc |def ghi <-- point on the right of white space before 'def' + abc |ghi <-- point still after white space after calling this function." + (save-excursion ; maintain the initial position of the pt with respect to space + (cond ((looking-back "^ *") ; remove extra space at beginning of line + (just-one-space 0) + (indent-according-to-mode)) + ((or (looking-at " ") + (looking-back " ")) ; adjust space only if it exists + (just-one-space 1)) + (t ; do nothing otherwise, includes case where the point is at EOL + )))) + ;; Delete extra horizontal white space after `kill-word' and `backward-kill-word' + (advice-add 'kill-word :after #'modi/just-one-space-post-kill-word) + #+END_SRC + + #+RESULTS: + * Main packages ** Magit #+BEGIN_SRC emacs-lisp