2

I'm "new" with Emacs. I'm making my own set up but I can't do one thing with killing words. You know what M-DEL does by default, but I want to make like Sublime Text or VIM. I'll do an example (this is the original text):

Hi, I'm captainepoch < first post here!

And this is how I do on vim or Sublime Text:

Hi, I'm captainepoch
< first post here▮

Do M-DEL

Hi, I'm captainepoch
< first post▮

Do M-DEL

Hi, I'm captainepoch
< first▮

Do M-DEL

Hi, I'm captainepoch
<▮

Do M-DEL

Hi, I'm captainepoch
▮    

Here, there's nothing at the beginning of the line and doing M-DEL in vim makes the cursor go to the end of the previous line.

Hi, I'm captainepoch▮

Do M-DEL

Hi, I'm▮

Do M-DEL

Hi, I'▮

Do M-DEL

Hi, I▮

Do M-DEL

Hi,▮

Do M-DEL

Hi▮

This final M-DEL will end up deleting the whole text.

A friend of mine did this function:

(defun backward-kill-word (arg)
  (interactive "p")
  (let ((init-pos (point))
        (line-begin (line-beginning-position)))
    (if (/= (point) line-begin)
        (kill-word (- arg)))))

And it does the job until it got the <, which does this:

Hi, I'm captainepoch
<▮ 

Do M-DEL

Hi, I'm▮ 
5
  • Welcome to Emacs.SE! Could you please clarify exactly what you want your function to do? It's a little hard to follow what you want from the example.
    – Dan
    Jul 21, 2016 at 15:01
  • Hi @Dan, thank you! I want to delete words individually, in the example it does from bottom to top. When I use emacs and do M-DEL, It deletes words but if the last 2 characters are < (< and a space), it deletes that two and the previous word on the previous line. I'd like to delete text as Sublime does.
    – user11867
    Jul 21, 2016 at 15:08
  • 1
    @captainepoch I have updated the question.. I hope that's what you meant. Jul 21, 2016 at 15:49
  • 2
    @captainepoch syntax-subword package might get you close to what you want; I have not used it. Jul 21, 2016 at 15:52
  • @KaushalModi Thank you so much, It's just what I mean! And the package works like a charm!
    – user11867
    Jul 22, 2016 at 8:36

1 Answer 1

1

I came from sublime as well and was looking for the behavior. I achieve the results you are describing by using syntax-subword which I think can be installed through MELPA. Here is my syntax-subword configuration (I use use-package):

(use-package syntax-subword
  :init
  (setq syntax-subword-skip-spaces t)
  :config
  (global-syntax-subword-mode))

For you, it should be enough to do M-x package-install syntax-subword, and then add the following to your config file:

(setq syntax-subword-skip-spaces t)
(global-syntax-subword-mode))

I hope this setup works for you; it has been so long since I have configured Emacs without use-package that I might have missed a step (e.g., you may need to require the package). However, on my setup using that package I tested your example, and it works the way you want it to.

1
  • You solution is just what I want, thank you so much!
    – user11867
    Jul 22, 2016 at 8:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.