Emacs Evil mode: how to create a new text object to select words with any non-space characters? -


i trying create new text object in evil. example, text object iw select subsets of strings containing hyphens. want new text object match words non-space characters. got far is:

(evil-define-text-object evil-inner-space (count &optional beg end type)   "select inner space."   :extend-selection nil   (evil-regexp-range count beg end type "[ \n]" " " t))  (define-key evil-inner-text-objects-map " " 'evil-inner-space) 

this code fails correctly match words @ end of line. works words @ beginning of line \n.

i tried many things did not work. trouble me when not work, don't know if due wrong regexp or limitations in evil-regexp-range. example, using \s- reports error, seems limitation in evil.

update: evil-regexp-range replaced evil-select-paren. works on current evil , has same usage old one:

(defmacro define-and-bind-text-object (key start-regex end-regex)   (let ((inner-name (make-symbol "inner-name"))         (outer-name (make-symbol "outer-name")))     `(progn        (evil-define-text-object ,inner-name (count &optional beg end type)          (evil-select-paren ,start-regex ,end-regex beg end type count nil))        (evil-define-text-object ,outer-name (count &optional beg end type)          (evil-select-paren ,start-regex ,end-regex beg end type count t))        (define-key evil-inner-text-objects-map ,key (quote ,inner-name))        (define-key evil-outer-text-objects-map ,key (quote ,outer-name))))) 

original answer:

if end defining more 1 new text object, repetition can annoying, if want bind both inner , outer objects. if hit barrier, try this:

(defmacro define-and-bind-text-object (key start-regex end-regex)   (let ((inner-name (make-symbol "inner-name"))         (outer-name (make-symbol "outer-name")))     `(progn       (evil-define-text-object ,inner-name (count &optional beg end type)         (evil-regexp-range count beg end type ,start-regex ,end-regex t))       (evil-define-text-object ,outer-name (count &optional beg end type)         (evil-regexp-range count beg end type ,start-regex ,end-regex nil))       (define-key evil-inner-text-objects-map ,key (quote ,inner-name))       (define-key evil-outer-text-objects-map ,key (quote ,outer-name))))) 

usage:

; between dollar signs: (define-and-bind-text-object "$" "\\$" "\\$")  ; between pipe characters: (define-and-bind-text-object "|" "|" "|")  ; regex "b" regex "c", bound k (invoke "vik" or "vak"): (define-and-bind-text-object "k" "b" "c") 

(this more wanted, i'll leave here in case helps :)


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -