I want dW and dB to not delete brackets in racket (all 3 kinds [, (, {).

I'm looking at changing W and not w because w is still useful for changing parts of an identifier, e.g. I can easily change any-of-these-dash-separated-parts individually.

There is no explicit entry for W in documentation https://www.emacswiki.org/emacs/EmacsSyntaxTable

So I'm left wondering how I might modify it.

1 Answer 1


Short answer: No.

Long answer: evil-maps.el defines inner and outer text objects, dW and dB corresponding to the following outer ones:

(define-key evil-outer-text-objects-map "W" 'evil-a-WORD)
(define-key evil-outer-text-objects-map "B" 'evil-a-curly)

Their definition in evil-commands.el:

(evil-define-text-object evil-a-WORD (count &optional beg end type)
  "Select a WORD."
  (evil-select-an-object 'evil-WORD beg end type count))

(evil-define-text-object evil-a-curly (count &optional beg end type)
  "Select a curly bracket (\"brace\")."
  :extend-selection nil
  (evil-select-paren ?{ ?} beg end type count t))

You'll have to define your own text objects instead. The API for that is that a text object is expected to be a range of start and end position. evil-select-an-object is the most generic way of doing this, it repurposes the thingatpt.el API for which defines objects in terms of forward (and optionally backward) movement. This means that all that's necessary to use evil-WORD as argument, is to define forward-evil-WORD. Look at its definition to get an idea how simple it is to define a custom version of that:

(defun forward-evil-WORD (&optional count)
  (evil-forward-nearest count
                        #'(lambda (&optional cnt)
                            (evil-forward-chars "^\n\r\t\f " cnt))

Chances are you only need to adjust the charset passed to evil-forward-chars.

For the other text object, tricky, you'd most certainly be better off defining text objects for symbols and s-expressions. This has been done before: https://github.com/luxbock/evil-cleverparens

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.