Improve kill-word

master
Jacopo De Simoi 8 years ago
parent 319bec7ae3
commit d794fe152a
  1. 34
      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

Loading…
Cancel
Save